赞
踩
找数字出现次数最多的个数
map<int,int> book; int a[maxn]; int main() { int t; cin >> t; while (t--) { book.clear(); int n; cin >> n; for(int i=1;i<=n;i++) { cin >> a[i]; book[a[i]]++; } int maxx=-1; for(int i=1;i<=n;i++) { maxx=max(maxx,book[a[i]]); } cout << maxx << endl; } }
构造,分情况讨论
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); int main() { ios; int t; cin >> t; while (t--) { int q,d; cin >> q >> d; for(int i=1;i<=q;i++) { int num; cin >> num; bool flag=false; if(num>=10*d) { cout<< "YES" << endl; continue;} for(int k=1;k<=9;k++) { if(num<k*d) break; if((num-k*d)%10==0) flag=true; } if(flag) cout << "YES" << endl; else cout << "NO" << endl; } } }
ll d[maxn],dd[maxn]; map<ll,int> book; int main() { int t; scanf("%d",&t); while (t--) { book.clear(); ll n,cnt=0; scanf("%lld",&n); for(int i=1;i<=2*n;i++) { scanf("%lld",&d[i]); book[d[i]]++; if(book[d[i]]==1) dd[++cnt]=d[i]; } sort(dd+1, dd+1+cnt); bool flag=true; for(int i=1;i<=2*n;i++) { if(book[d[i]]!=2) { flag=false; break; } } ll a1r=0; if(flag) { for(int i=n;i>=2;i--) { ll tmp=dd[i]-dd[i-1],tt=2*(i-1); if(tmp%tt) { flag=0; break;} a1r+=(n-i+1)*tmp/tt; } } if(dd[1]<=2*a1r || (dd[1]-2*a1r)%n || (dd[1]-2*a1r)/n%2) flag=0; if(flag) printf("YES\n"); else printf("NO\n"); } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。