标签:acm算法
3 1 1 2 4 2 1 4 3
1 -1
找出现数字大于2/n的。
#include <cstdio>
#include <cmath>
#include <queue>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
int n;
while(cin>>n)
{
int a[10005];
int i,x;
int ans;
memset(a,0,sizeof(a));
for(i=0; i<n; i++)
{
cin>>x;
a[x]++;
}
ans=n/2;
int flag=0;
for(i=0; i<=10000; i++)
{
if(a[i]>ans)
{
flag=1;
cout<<i<<endl;
break;
}
}
if(!flag)
cout<<-1<<endl;
}
return 0;
}
The mook jongTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 585 Accepted Submission(s): 419 Problem Description

ZJiaQ want to become a strong man, so he decided to play the mook jong。ZJiaQ want to put some mook jongs in his backyard. His backyard consist of n bricks that is 1*1,so it is 1*n。ZJiaQ want to put a mook jong in a brick. because of the hands of the mook jong, the distance of two mook jongs should be equal or more than 2 bricks. Now ZJiaQ want to know how many ways can ZJiaQ put mook jongs legally(at least one mook jong). Input
There ar multiply cases. For each case, there is a single integer n( 1 < = n < = 60)
Output
Print the ways in a single line for each case.
Sample Input
Sample Output
Source
Recommend
|
水dp。
#include <cstdio>
#include <cmath>
#include <queue>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
ll m[111];
ll solve(int i)
{
if (m[i] != 0)
return m[i];
m[i] = solve(i-1) + solve(i-3) + 1;
return m[i];
}
int main()
{
int n;
m[0] = 0;
m[1] = 1;
m[2] = 2;
m[3] = 3;
while (cin >> n)
cout << solve(n) << endl;
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:acm算法
原文地址:http://blog.csdn.net/sky_miange/article/details/47683943