2019 Multi-University Training Contest 8
Acesrc and Good Numbers
题意求<=x最大的n,满足1−n中的所有数的数位中数d出现了n次
从网上找了个板子,是求1−n中d出现的次数,这里叫它count(n,d)复杂度logn
因为我们要找<=x最大的n
我们先算一下count(x,d)
如果count(x,d)==x
自然x就是我们想要的结果
如果count(x,d)<x
我们就可以直接把x赋值成count(x,d)
因为他们之间的数肯定是大于我们想要的结果的
如果count(x,d)>x
我们假设x是一个m位数,并且他的所有位数都是d
在这样的情况下我们只需要重新让x=x−(count(x,d)−x)/m即可
因为在最坏的情况下所有的位数都是d
我们要想让count(x,d)和x相等,至少要它减去(count(x,d)−x)/m个数
Calabash and Landlord
Quailty and CCPC
#include <bits/stdc++.h> using namespace std; const double eps=1e-6; int n,d; struct node { char name[15]; int x,y; bool operator<(const node &b)const { if (x==b.x) { return y<b.y; } else { return x>b.x; } } }a[101000]; int main() { int _; scanf("%d",&_); while(_--) { scanf("%d%d",&n,&d); for (int i=1; i<=n; i++) { scanf("%s %d %d",a[i].name,&a[i].x,&a[i].y); } sort(a+1,a+n+1); double kk=n*d*0.1; int k=kk; if (fabs(fabs(k-kk)-0.5)<eps) { k++; printf("%s ",a[k].name); } else { printf("Quailty is very great "); } } }
Roundgod and Milk Tea
#include <bits/stdc++.h> using namespace std; const int maxn=1000100; typedef long long ll; ll ans1,ans2,suma,sumb; int a[maxn],b[maxn],n,tmp; int main() { int _; scanf("%d",&_); while (_--) { suma=sumb=0; ans2=0; scanf("%d",&n); for (int i=1; i<=n; i++) { scanf("%d%d",&a[i],&b[i]); suma+=a[i]; sumb+=b[i]; } ans1=min(suma,sumb); for (int i=1; i<=n; i++) { tmp=min(a[i]*1ll,sumb-b[i]); ans2+=tmp; } printf("%lld ",min(ans1,ans2)); } }