标签:
#include<stdio.h> //#include<bits/stdc++.h> #include<string.h> #include<iostream> #include<math.h> #include<sstream> #include<set> #include<queue> #include<vector> #include<algorithm> #include<limits.h> #define inf 0x3fffffff #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define LL long long using namespace std; int main() { printf("12\n"); return 0; }
5 3 1 3 4 4 6 1 3 8 3 11 12
2 2
#include<stdio.h> //#include<bits/stdc++.h> #include<string.h> #include<iostream> #include<math.h> #include<sstream> #include<set> #include<queue> #include<map> #include<vector> #include<algorithm> #include<limits.h> #define inf 0x3fffffff #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define LL long long using namespace std; int a; map<int,int> q; int main() { int n,m; int i; int ans; while(cin>>n>>m) { ans=0; for(i=1;i<=n;i++) { q[i]=1; } for(i=0;i<m;i++) { cin>>a; q[a]=0; } map<int,int>::iterator it; for(it=q.begin();it!=q.end();it++) { // cout<<it->first<<" "<<it->second<<endl; if(it->second!=0) { ans++; } } cout<<ans<<endl; q.clear(); } return 0; }
2 3 zhuzhu zhuzhu xiaoxin 2 zhuzhu zhuzhu
zhuzhu zhuzhu
也是用map存一下,然后根据题意来就好了,这题和HDU1004题相似
#include<stdio.h> //#include<bits/stdc++.h> #include<string.h> #include<iostream> #include<math.h> #include<sstream> #include<set> #include<queue> #include<map> #include<vector> #include<algorithm> #include<limits.h> #define inf 0x3fffffff #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define LL long long using namespace std; map<string,int> q; int main() { int t; string s; while(cin>>t) { while(t--) { int n; int i; cin>>n; for(i=0; i<n; i++) { cin>>s; q[s]++; } map<string,int>::iterator it; for(it=q.begin(); it!=q.end(); it++) { // cout<<it->first<<" "<<it->second<<endl; if(n%2==0) { if(it->second>=(n/2)) { cout<<it->first<<endl; break; } } else { if(it->second>=(n/2+1)) { cout<<it->first<<endl; break; } } } q.clear(); } } return 0; }
2015苏州大学ACM-ICPC集训队选拔赛(1) 1001 1002 1010
标签:
原文地址:http://www.cnblogs.com/yinghualuowu/p/5076766.html