标签:
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
水题
1 //##################### 2 //Author:fraud 3 //Blog: http://www.cnblogs.com/fraud/ 4 //##################### 5 #include <iostream> 6 #include <sstream> 7 #include <ios> 8 #include <iomanip> 9 #include <functional> 10 #include <algorithm> 11 #include <vector> 12 #include <string> 13 #include <list> 14 #include <queue> 15 #include <deque> 16 #include <stack> 17 #include <set> 18 #include <map> 19 #include <cstdio> 20 #include <cstdlib> 21 #include <cmath> 22 #include <cstring> 23 #include <climits> 24 #include <cctype> 25 using namespace std; 26 #define XINF INT_MAX 27 #define INF 0x3FFFFFFF 28 #define MP(X,Y) make_pair(X,Y) 29 #define PB(X) push_back(X) 30 #define REP(X,N) for(int X=0;X<N;X++) 31 #define REP2(X,L,R) for(int X=L;X<=R;X++) 32 #define DEP(X,R,L) for(int X=R;X>=L;X--) 33 #define CLR(A,X) memset(A,X,sizeof(A)) 34 #define IT iterator 35 typedef long long ll; 36 typedef pair<int,int> PII; 37 typedef vector<PII> VII; 38 typedef vector<int> VI; 39 40 int a[1000100]; 41 int b[1000100]; 42 int h[1000100]; 43 int p[1000100]; 44 int ans[1000100]; 45 bool cmp(int x,int y){ 46 if(h[x]==h[y])return x<y; 47 return h[x]<h[y]; 48 } 49 int Scan() 50 { 51 int res, ch=0; 52 while(!(ch>=‘0‘&&ch<=‘9‘)) ch=getchar(); 53 res=ch-‘0‘; 54 while((ch=getchar())>=‘0‘&&ch<=‘9‘) 55 res=res*10+ch-‘0‘; 56 return res; 57 } 58 void Out(int a) 59 { 60 if(a>9) 61 Out(a/10); 62 putchar(a%10+‘0‘); 63 } 64 65 66 int main() 67 { 68 ios::sync_with_stdio(false); 69 int n,m; 70 while(scanf("%d%d",&n,&m)!=EOF){ 71 for(int i=0;i<n;i++) 72 a[i]=Scan(); 73 sort(a,a+n); 74 b[0]++; 75 int tot=0; 76 for(int i=1;i<n;i++){ 77 if(a[i]==a[i-1])b[tot]++; 78 else b[++tot]=1; 79 } 80 for(int i=0;i<m;i++)h[i]=Scan(); 81 for(int i=0;i<m;i++)p[i]=i; 82 sort(p,p+m,cmp); 83 int j=0; 84 int k=0; 85 for(int i=0;i<m;i++){ 86 if(j>=n)break; 87 while(a[j]<h[p[i]]){ 88 j++; 89 if(j>=n)break; 90 if(a[j]!=a[j-1])k++; 91 } 92 if(j>=n)break; 93 if(h[p[i]]==a[j]){ 94 ans[p[i]]=b[k]; 95 b[k]=0; 96 } 97 } 98 for(int i=0;i<m;i++){ 99 Out(ans[i]); 100 puts(""); 101 } 102 } 103 104 return 0; 105 }
BestCoder Round #36 (hdu5199)Gunner(水题)
标签:
原文地址:http://www.cnblogs.com/fraud/p/4397197.html