2020CCPC秦皇岛赛后补题

it2024-03-17  54

总结:我是傻逼 A:签到题。

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #include<bits/stdc++.h> #define int long long using namespace std; typedef pair<int,int> pii; typedef long long ll; const int INF = 0x3f3f3f3f; const double eps = 1e-5; const int mod = 999911659; const int N = 100010; signed main(){ //IOS; #ifdef ddgo freopen("C:\\Users\\asus\\Desktop\\ddgoin.txt","r",stdin); #endif int tt; cin>>tt; for(int t=1;t<=tt;t++){ int r,b; cin>>r>>b; int u = r*(r-1)/2,d = (r+b)*(r+b-1)/2; int k = __gcd(u,d); cout<<"Case #"<<t<<": "<<u/k<<"/"<<d/k<<endl; } return 0; }

总结:我是傻逼 E: 双指针。 头指针指向a,尾指针指向b, 把a,b全部加到一个结构体。按从大到小排序。 找到a的下界b,计算出a到b有多少个学生满足。 注意,由于单调性,tail严格往后走,当头指针往后移,把这个标记减去就行。

注意,若把一个人的两个分数全部舍去,一定不能满足,则break;

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #include<bits/stdc++.h> //#define int long long using namespace std; typedef pair<int,int> pii; typedef long long ll; const int INF = 0x3f3f3f3f; const double eps = 1e-5; const int mod = 999911659; const int N = 1e6+10; int n,p,res; int vis[N],book[N]; struct Node{ int a,b; bool operator<(const Node&T)const{ return a>T.a; } }node[N]; signed main(){ IOS; #ifdef ddgo freopen("C:\\Users\\asus\\Desktop\\ddgoin.txt","r",stdin); #endif int tt; cin>>tt; for(int t=1;t<=tt;t++){ cin>>n>>p; int cnt = 1; res = 0; for(int i=1;i<=n;i++){ int a,b; cin>>a>>b; node[cnt++] = {a,i}; node[cnt++] = {b,i}; vis[i] = vis[i+n] = 0; book[i] =book[i+n] = 0; } sort(node+1,node+cnt); int now_cnt = 0; for(int head=1,tail=1;tail<cnt;head++){ int k = ceil(1.0*node[head].a*p/100.0); while(tail < cnt && node[tail].a >= k){ vis[node[tail].b]++; if(vis[node[tail].b] == 1) now_cnt ++; tail ++; } res = max(res,now_cnt); if(--vis[node[head].b] == 0) now_cnt--; if(++book[node[head].b] == 2) break; } cout<<"Case #"<<t<<": "<<res<<endl; } return 0; }

总结:我是傻逼 F: 差不多签到。题上说加一个人就减1,且有朋友的人加了而他朋友没加也会减1. -> 最优情况是把一个有朋友关系的集合全部加入 -> 当一个集合朋友对(a与b为朋友则为1对)大于人的个数,则把这个集合全部加入。

开始想的dfs求连通块,把每一块分开,发现维护朋友对比较困难。 并查集 -> 板子多一个维护朋友对。

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #include<bits/stdc++.h> #define int long long using namespace std; typedef pair<int,int> pii; typedef long long ll; const int INF = 0x3f3f3f3f; const double eps = 1e-5; const int mod = 999911659; const int N = 2e6+10; int fa[N],siz[N],eage_cnt[N]; bool vis[N]; int find(int x){ if(x != fa[x]) fa[x] = find(fa[x]); return fa[x]; } signed main(){ IOS; #ifdef ddgo freopen("C:\\Users\\asus\\Desktop\\ddgoin.txt","r",stdin); #endif int tt; cin>>tt; for(int t=1;t<=tt;t++){ int n,m; cin>>n>>m; for(int i=1;i<=n;i++) fa[i] = i,vis[i] = false,siz[i] = 1,eage_cnt[i] = 0; for(int i=0;i<m;i++){ int a,b; cin>>a>>b; a = find(a);b = find(b); if(a == b){ eage_cnt[a]++; }else{ fa[a] = b; siz[b] += siz[a]; eage_cnt[b] += eage_cnt[a] + 1; } } int res = 0; for(int i=1;i<=n;i++){ int a = find(i); if(!vis[a]){ if(eage_cnt[a] > siz[a]) res += eage_cnt[a] - siz[a]; vis[a] = true; } } cout<<"Case #"<<t<<": "<<res<<endl; } return 0; }

总结:我是傻逼 G: 枚举题目上的那个值的k次方。 分段,每一段中能被当前段的(i-1)整除就选。 每一段的上界为 i k i^k ik,下界为上一次的上界 打个表look. i 的上界 为 sqrt(n) 考虑 当 k = 2 的时候 i k i^k ik -> 不能超过 n i就不超过sqrt(n);。 注意 i == 2 那里的特判 和 k >= 30。

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #include<bits/stdc++.h> #define int long long using namespace std; typedef pair<int,int> pii; typedef long long ll; const int INF = 0x3f3f3f3f; const double eps = 1e-5; const int mod = 999911659; const int N = 100010; int qmi(int a,int b){ int res = 1; while(b){ if(b & 1) res = res * a; a = a*a; b >>= 1; } return res; } signed main(){ //IOS; #ifdef ddgo freopen("C:\\Users\\asus\\Desktop\\ddgoin.txt","r",stdin); #endif int tt; cin>>tt; for(int t=1;t<=tt;t++){ int n,k; cin>>n>>k; if(k == 1 || k >= 30) cout<<"Case #"<<t<<": "<<n<<endl; else{ int cnt = 0,last = 1; for(int i=2;(i-1)<=n/(i-1);i++){ int j = qmi(i,k); j = min(j,n); if(i == 2) cnt --; cnt += (j - last)/(i-1) + 1; last = j; if(j >= n) break; } cout<<"Case #"<<t<<": "<<cnt<<endl; } } return 0; }

总结:我是傻逼

最新回复(0)