寒假刷题-动态规划
来源:互联网 发布:linux ftp服务安装 编辑:程序博客网 时间:2024/05/16 18:17
Time Limit:1000MS Memory Limit:32767KB 64bit IO Format:%I64d & %I64u
Submit
Status
Description
"OK, you are not too bad, em... But you can never pass the next test." feng5166 says.
"I will tell you an odd number N, and then N integers. There will be a special integer among them, you have to tell me which integer is the special one after I tell you all the integers." feng5166 says.
"But what is the characteristic of the special integer?" Ignatius asks.
"The integer will appear at least (N+1)/2 times. If you can't find the right integer, I will kill the Princess, and you will be my dinner, too. Hahahaha....." feng5166 says.
Can you find the special integer for Ignatius?
Input
The input contains several test cases. Each test case contains two lines. The first line consists of an odd integer N(1<=N<=999999) which indicate the number of the integers feng5166 will tell our hero. The second line contains the N integers. The input is terminated by the end of file.
Output
For each test case, you have to output only one line which contains the special number you have found.
Sample Input
5
1 3 2 3 3
11
1 1 1 1 1 5 5 5 5 5 5
7
1 1 1 1 1 1 1
Sample Output
3
5
1
G - 免费馅饼
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit
Status
Description
都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼。说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉落在他身旁的10米范围内。馅饼如果掉在了地上当然就不能吃了,所以gameboy马上卸下身上的背包去接。但由于小径两侧都不能站人,所以他只能在小径上接。由于gameboy平时老呆在房间里玩游戏,虽然在游戏中是个身手敏捷的高手,但在现实中运动神经特别迟钝,每秒种只有在移动不超过一米的范围内接住坠落的馅饼。现在给这条小径如图标上坐标:
为了使问题简化,假设在接下来的一段时间里,馅饼都掉落在0-10这11个位置。开始时gameboy站在5这个位置,因此在第一秒,他只能接到4,5,6这三个位置中其中一个位置上的馅饼。问gameboy最多可能接到多少个馅饼?(假设他的背包可以容纳无穷多个馅饼)
Input
输入数据有多组。每组数据的第一行为以正整数n(0<n<100000),表示有n个馅饼掉在这条小径上。在结下来的n行中,每行有两个整数x,T(0<T<100000),表示在第T秒有一个馅饼掉在x点上。同一秒钟在同一点上可能掉下多个馅饼。n=0时输入结束。
Output
每一组输入数据对应一行输出。输出一个整数m,表示gameboy最多可能接到m个馅饼。
提示:本题的输入数据量比较大,建议用scanf读入,用cin可能会超时。
Sample Input
6
5 1
4 1
6 1
7 2
7 2
8 3
0
Sample Output
4
I - 最少拦截系统
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit
Status
Description
某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹.
怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少套拦截系统.
Input
输入若干组数据.每组数据包括:导弹总个数(正整数),导弹依此飞来的高度(雷达给出的高度数据是不大于30000的正整数,用空格分隔)
Output
对应每组数据输出拦截所有导弹最少要配备多少套这种导弹拦截系统.
Sample Input
8 389 207 155 300 299 170 158 65
Sample Output
2
代码:
B:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct nood{
int shu,ge;
}fen[100000];
bool cmp(nood xx,nood yy){
return xx.ge>yy.ge;
}int s[1001000];
int main()
{
int n,m;
while (~scanf("%d",&n))
{
memset(s,0,sizeof(s));
memset(fen,0,sizeof(fen));
int a,p=1;
while (n--)
{
scanf("%d",&a);
if (s[a])
fen[s[a]].ge++;
else
{
s[a]=p;
fen[p].shu=a;
fen[p].ge++;
p++;
}
}
sort(fen,fen+p,cmp);
printf("%d\n",fen[0].shu);
}
return 0;
}
H:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int shu[15][100100];
int main()
{
int n;
while (~scanf("%d",&n))
{
if (n==0) break;
int t=0,a,b;
memset(shu,0,sizeof(shu));
for (int i=0;i<n;i++)
{
scanf("%d%d",&a,&b);
shu[a][b]++;
t=max(t,b);
}
for (int i=t-1;i>=0;i--)
{
shu[0][i]=max(shu[0][i+1],shu[1][i+1])+shu[0][i];
for (int j=1;j<=10;j++)
shu[j][i]=max(max(shu[j+1][i+1],shu[j][i+1]),shu[j-1][i+1])+shu[j][i];
}
printf("%d\n",shu[5][0]);
}
return 0;
}
I:
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
int n;
while (~scanf("%d",&n))
{
int heigh[5200];
bool wu[5200]={false};
bool flag;
for (int i=0;i<n;i++)
scanf("%d",&heigh[i]);
int ii,jj,pp=0,sum=0;
while (pp<n)
{
sum++;
jj=pp;flag=true;
for (int ii=pp+1;ii<n;ii++)
{
if (wu[ii]) continue;
if (heigh[ii]<=heigh[jj])
{
wu[ii]=true;
jj=ii;
}
else if (flag)
{
pp=ii;
flag=false;
}
}
if (flag)
break;
}
printf("%d\n",sum);
}
return 0;
}
- 寒假刷题-动态规划
- sduacm16级寒假训练 动态规划(一)
- sduacm16级寒假训练 动态规划(二)
- sduacm16级寒假训练 动态规划(一)
- sduacm16级寒假训练 动态规划(二)
- 寒假规划
- 寒假集训作业(6)——动态规划初步
- 动态规划刷题总结
- 寒假竞赛时间规划
- 寒假刷题计划
- 寒假集训作业(9)——动态规划初步(2)
- hdu 2079 选课时间 DP动态规划 母函数 穷举 寒假集训1 07
- 动态规划 HDU 动态规划题集
- 2014年寒假学习规划
- 终于放假咯~寒假规划
- 动态规划题
- 动态规划笔试题
- 动态规划笔试题
- 偏颇之论——志不同道不合,节约对方的时间,就是最大的尊重。
- 数组名是一个指针常量吗?
- Hust oj 1812 小乐乐想出门(基础dp)
- C语言——源码、反码、补码
- java集合面试题
- 寒假刷题-动态规划
- javascript 小白学习指南 继承
- linux 关机命令及流程
- 字符编码杂谈
- Kafka - 消费接口分析
- lua next用法
- BFS广度优先搜索
- Hbase 批量数据BulkLoad 导入使用
- 大一学生数据结构与算法的先后取舍