Codeforces Round 886 (Div. 4)
思路:最大的两个数的和大于等于10则YES
#include<bits/stdc++.h> using namespace std; #define int long long typedef pair<int,int>PII; typedef pair<string,int>PSI; typedef pair<string,string>PSS; const int N=1e6+5,INF=0x3f3f3f3f,Mod=1e9+7; const double eps=1e-6; void solve(){ int a[3]; cin>>a[0]>>a[1]>>a[2]; sort(a,a+3); if((a[1]+a[2])>=10)cout<<"YES\n"; else cout<<"NO\n"; } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int t=1; //init(); cin>>t; while(t--){ solve(); } return 0; }View Code
思路:找出a小于等于10的,对应的最大的b
#include<bits/stdc++.h> using namespace std; #define int long long typedef pair<int,int>PII; typedef pair<string,int>PSI; typedef pair<string,string>PSS; const int N=1e6+5,INF=0x3f3f3f3f,Mod=1e9+7; const double eps=1e-6; void solve(){ int n;cin>>n; int ans,ma=-1; for(int i=0,a,b;i<n;++i){ cin>>a>>b; if(a<=10&&b>ma){ ans=i+1; ma=b; } } cout<<ans<<'\n'; } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int t=1; //init(); cin>>t; while(t--){ solve(); } return 0; }View Code
思路:枚举8*8,找出所有英文字符
#include<bits/stdc++.h> using namespace std; #define int long long typedef pair<int,int>PII; typedef pair<string,int>PSI; typedef pair<string,string>PSS; const int N=1e6+5,INF=0x3f3f3f3f,Mod=1e9+7; const double eps=1e-6; void solve(){ string s[8]; string ans=""; for(int i=0;i<8;++i){ cin>>s[i]; for(int j=0;j<8;++j){ if(s[i][j]!='.')ans.push_back(s[i][j]); } } cout<<ans<<'\n'; } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int t=1; //init(); cin>>t; while(t--){ solve(); } return 0; }View Code
题意:操作有:任意排序、任意移出,问最小的移出数使得序列中相邻两个数的差不大于k;
思路:对序列排序后,找出相邻两个数不超k的最长序列长度s,答案为n-s
#include<bits/stdc++.h> using namespace std; #define int long long typedef pair<int,int>PII; typedef pair<string,int>PSI; typedef pair<string,string>PSS; const int N=1e6+5,INF=0x3f3f3f3f,Mod=1e9+7; const double eps=1e-6; void solve(){ int n,k;cin>>n>>k; vector<int>ve(n); for(int i=0;i<n;++i)cin>>ve[i]; sort(ve.begin(),ve.end()); int ans=1; for(int i=1,c=ve[0],p=1;i<n;++i){ if(abs(ve[i]-c)<=k)p++; else{ ans=max(ans,p); p=1; } c=ve[i]; if(i==n-1)ans=max(ans,p); } cout<<n-ans<<'\n'; } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int t=1; //init(); cin>>t; while(t--){ solve(); } return 0; }View Code
题意:所有图片下都有宽为w的框架,问w为多少时所有图片加上框架后的面积刚好为c
思路:c=(s1+2*w)2+(s2+2*w)2+...+(sn+2*w)2=(s12+s22+...sn2)+4*n*w2+4*w*(s1+s2+...+sn),二分w即可
#include<bits/stdc++.h> using namespace std; //#define int long long #define int __int128 typedef pair<int,int>PII; typedef pair<string,int>PSI; typedef pair<string,string>PSS; const int N=1e6+5,INF=0x3f3f3f3f,Mod=1e9+7; const double eps=1e-6; int read() { int res=0; char scan[1005]; scanf("%s",scan); for(int i=0;i<strlen(scan);i++) res*=10,res+=scan[i]-'0'; return res; } void print(int num) { if(num>9) print(num/10); putchar(num%10+'0'); } void solve(){ int n,c; n=read(),c=read(); vector<int>s(n); int s1=0,s2=0; for(int i=0;i<n;++i){ s[i]=read(); s1+=s[i]*s[i]; s2+=s[i]; } int l=0,r=1e9,ans; auto check=[&](int x){ int y=s1+4*x*s2+4*x*x*n; return y>=c; }; while(l<=r){ int mid=l+r>>1; if(check(mid))ans=mid,r=mid-1; else l=mid+1; } cout<<(long long)ans<<'\n'; } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int t=1; //init(); t=read(); while(t--){ solve(); } return 0; }View Code
思路:统计所有ai及其个数,枚举ai所有不大于n的倍数,统计其个数,最大的个数即为答案
#include<bits/stdc++.h> using namespace std; #define int long long //#define int __int128 typedef pair<int,int>PII; typedef pair<string,int>PSI; typedef pair<string,string>PSS; const int N=3e2+5,INF=0x3f3f3f3f,Mod=1e9+7; const double eps=1e-6; void solve(){ int n;cin>>n; map<int,int>mp; vector<int>ve(n+1); for(int i=0,x;i<n;++i){ cin>>x; mp[x]++; } for(auto v:mp){ for(int i=v.first;i<=n;i+=v.first)ve[i]+=v.second; } cout<<*max_element(ve.begin(),ve.end())<<'\n'; return ; } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int T=1; //init(); cin>>T; while(T--){ solve(); } return 0; }View Code
思路:统计所有平行四条轴线上的点的个数;若一条线上有s个点,贡献为C(s,2),由于可以是双向的,再乘上2;统计所有线的贡献
#include<bits/stdc++.h> using namespace std; #define int long long //#define int __int128 typedef pair<int,int>PII; typedef pair<string,int>PSI; typedef pair<string,string>PSS; const int N=1e6+5,INF=0x3f3f3f3f,Mod=1e9+7; const double eps=1e-6; void solve(){ int n;cin>>n; map<int,int>mp1,mp2,mp3,mp4; for(int i=0,x,y;i<n;++i){ cin>>x>>y; mp1[x-y]++; mp2[x+y]++; mp3[x]++; mp4[y]++; } int ans=0; for(auto v:mp1)ans+=v.second*(v.second-1); for(auto v:mp2)ans+=v.second*(v.second-1); for(auto v:mp3)ans+=v.second*(v.second-1); for(auto v:mp4)ans+=v.second*(v.second-1); cout<<ans<<'\n'; } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int t=1; //init(); cin>>t; while(t--){ solve(); } return 0; }View Code
思路:用图来表示,所有关系用带权无向边存。遍历所有点,若该点没有确定,则确定该点,而后遍历与该点相连的所有点,维护距离;根据点是否被确定过,判断距离是否冲突
#include<bits/stdc++.h> using namespace std; #define int long long //#define int __int128 typedef pair<int,int>PII; typedef pair<string,int>PSI; typedef pair<string,string>PSS; const int N=3e2+5,INF=0x3f3f3f3f,Mod=1e9+7; const double eps=1e-6; void solve(){ int n,m;cin>>n>>m; vector<PII>ve[n+1]; for(int i=0,a,b,d;i<m;++i){ cin>>a>>b>>d; ve[a].push_back({b,d}); ve[b].push_back({a,-d}); } vector<int>d(n+1,INF); for(int i=1;i<=n;++i){ if(d[i]!=INF)continue; d[i]=0; queue<int>q;q.push(i); while(q.size()){ int t=q.front();q.pop(); for(auto v:ve[t]){ if(d[v.first]==INF){ d[v.first]=d[t]+v.second; q.push(v.first); }else if(d[v.first]!=d[t]+v.second){ cout<<"NO\n";return ; } } } } cout<<"YES\n"; return ; } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int T=1; //init(); cin>>T; while(T--){ solve(); } return 0; }View Code
标签:typedef,const,886,int,Codeforces,long,solve,Div,define From: https://www.cnblogs.com/bible-/p/17572970.html