标签:poj
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 19859 | Accepted: 11492 |
Description
1 4 3 2 9 7 18 22
Input
Output
Sample Input
1 4 3 2 9 7 18 22 0 2 4 8 10 0 7 5 11 13 1 3 0 -1
Sample Output
3 2 0
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int a[30];
int main()
{
int i,k,n,res;
while(scanf("%d",&a[0]),a[0]!=-1){
n=1;
while(scanf("%d",&a[n]),a[n++]);
n--;
res=0;
sort(a,a+n);
for(i=0;i<n;i++){
k=lower_bound(a+i+1,a+n,a[i]*2)-a;
if(a[k]==a[i]*2)
res++;
}
printf("%d\n",res);
}
return 0;
}#include <stdio.h>
#include <string.h>
#include <math.h>
#define eps 1e-9
#define max(a,b) (a)>(b)?(a):(b)
int res,a[20];
int vis[110];
int b[110];
int main()
{
int i,n;
while(scanf("%d",&a[0]) && a[0]!=-1)
{
n=1;
while(scanf("%d",&a[n]),a[n++]);
n--;
memset(vis,0,sizeof(vis));
memset(b,0,sizeof(b));
for(i=0;i<n;i++)
b[a[i]]=1;
res=0;
for(i=0;i<n;i++)
{
if(b[a[i]*2])
{
vis[a[i]*2]=1;
vis[a[i]]=1;
res++;
}
}
printf("%d\n",res);
}
return 0;
}标签:poj
原文地址:http://blog.csdn.net/u013068502/article/details/45048875