博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
USACO Breed Proximity
阅读量:5325 次
发布时间:2019-06-14

本文共 1942 字,大约阅读时间需要 6 分钟。

Breed Proximity

TimeLimit: 2 Second   MemoryLimit: 64 Megabyte

Totalsubmit: 46   Accepted: 10  

Description

Farmer John's N cows (1 <= N <= 50,000) are standing in a line, each
described by an integer breed ID.
Cows of the same breed are at risk for getting into an argument with
each-other if they are standing too close.  Specifically, two cows of the
same breed are said to be "crowded" if their positions within the line
differ by no more than K (1 <= K < N).  
Please compute the maximum breed ID of a pair of crowded cows.

Input

* Line 1: Two space-separated integers: N and K.
* Lines 2..1+N: Each line contains the breed ID of a single cow in the
       line.  All breed IDs are integers in the range 0..1,000,000.
There are 6 cows standing in a line, with breed IDs 7, 3, 4, 2, 3, and 4. 
Two cows of equal breed IDs are considered crowded if their positions
differ by at most 3.

Output

* Line 1: The maximum breed ID of a crowded pair of cows, or -1 if
       there is no crowded pair of cows.
The pair of cows with breed ID 3 is crowded, as is the pair of cows with
breed ID 4

Sample Input

6 3

7
3
4
2
3
4

Sample Output

4

Source

USACO

 
思路:
 
代码:
#include 
#include
#include
#include
#include
using namespace std;int map[51010];int can_be[1100000];int the_last_max;int n,k;int main(){ while(~scanf("%d%d",&n,&k)) { memset(map,0,sizeof(map)); memset(can_be,0,sizeof(can_be)); int the_k; the_last_max = -1; for(int i = 1;i <= n;i ++) { scanf("%d",&map[i]); if(i - k - 1 >= 1) can_be[map[i - k - 1]] = 0; if(can_be[map[i]] == 1 && map[i] > the_last_max) the_last_max = map[i]; can_be[map[i]] = 1; } printf("%d\n",the_last_max); } return 0;}

 

转载于:https://www.cnblogs.com/GODLIKEING/p/3426706.html

你可能感兴趣的文章
POJ 3670 DP LIS?
查看>>
空心菱形的显示
查看>>
Eclipse 常用快捷键清单
查看>>
redis 存储时间区间的数据
查看>>
STM32F0库函数初始化系列:进入STOP模式,外部中断唤醒
查看>>
p1525 关押罪犯
查看>>
使用Html5shiv.js让ie支持html5
查看>>
DBA 优化法则
查看>>
用Python连接SQLServer抓取分析数据、监控 (pymssql)
查看>>
升级ruby后再安装cocodPod
查看>>
MySQL数据库8(十三)高级数据操作之select指令
查看>>
随心测试_Python Se_002<不同浏览器驱动>
查看>>
在ASP.NET WebService 中如何使用 WebMethod 属性
查看>>
一个很详细的web.xml讲解
查看>>
Java输入输出流
查看>>
java实现文件的复制
查看>>
BZOJ 4695 最假女选手 线段树
查看>>
好的分析报告应该包含的内容
查看>>
使用GIT的失败过程
查看>>
Unity3d 协程的注意问题(新手须注意,老手须加勉)
查看>>