23暑假友谊赛No.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=50+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353; const int inf=0x3f3f3f3f3f3f; const double eps=1e-6; const int dx[4]={-1,0,1,0}; const int dy[4]={0,1,0,-1}; void solve(){ vector<int>ve(4); for(int i=0;i<4;++i)cin>>ve[i]; int x;cin>>x; for(int i=0;i<4;++i){ if(ve[i]<x)cout<<x-ve[i]<<' '; else cout<<0<<' '; } } 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
思路:整理下式子发现答案是n*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=50+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353; const int inf=0x3f3f3f3f3f3f; const double eps=1e-6; const int dx[4]={-1,0,1,0}; const int dy[4]={0,1,0,-1}; void solve(){ int n;cin>>n; cout<<(n%mod)*(n%mod)%mod; } 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=50+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353; const int inf=0x3f3f3f3f3f3f; const double eps=1e-6; const int dx[4]={-1,0,1,0}; const int dy[4]={0,1,0,-1}; struct E{ string a; double k; bool operator<(const E&e)const{ if(k!=e.k)return k>e.k; return a<e.a; } }; void solve(){ string s;cin>>s; int n;cin>>n; vector<string>ve(n); vector<E>ans; for(int i=0;i<n;++i){ cin>>ve[i]; if(ve[i].size()==s.size()){ int m=0; for(int j=0;j<s.size();++j){ m+=(ve[i][j]==s[j]); } double kk=m*1.0/s.size(); ans.push_back({ve[i],kk}); } } if(ans.size()==0){ sort(ve.begin(),ve.end()); for(int i=0;i<ve.size();++i)cout<<ve[i]<<'\n'; }else{ sort(ans.begin(),ans.end()); for(int i=0;i<ans.size();++i){ if(ans[i].k==ans[0].k){ cout<<ans[i].a<<'\n'; }else break; } } } 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
思路:每个数取最大或最小带来的贡献是最大的;
dp[i][j]表示前i个数的情况且第i个数在j(j=0,j=1)位置的最大值,j=0表示a[i]取1,j=1表示a[i]取b[i];
#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=1e5+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353; const int inf=0x3f3f3f3f3f3f; const double eps=1e-6; const int dx[4]={-1,0,1,0}; const int dy[4]={0,1,0,-1}; int dp[N][2]; void solve(){ int n;cin>>n; vector<int>ve(n); for(int i=0;i<n;++i)cin>>ve[i]; for(int i=1;i<n;++i){ dp[i][0]=max(dp[i-1][0],dp[i-1][1]+abs(ve[i-1]-1)); dp[i][1]=max(dp[i-1][0]+abs(ve[i]-1),dp[i-1][1]+abs(ve[i-1]-ve[i])); } cout<<max(dp[n-1][0],dp[n-1][1]); } 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
思路:倒着取654321,哪个缺补哪里
#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=1e5+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353; const int inf=0x3f3f3f3f3f3f; const double eps=1e-6; const int dx[4]={-1,0,1,0}; const int dy[4]={0,1,0,-1}; void solve(){ int s;cin>>s; vector<int>k(7); for(int i=1;i<=6;++i)cin>>k[i]; int now=k[6]+k[5]+k[4]+(k[3]+3)/4; k[1]=max(0ll,k[1]-11*k[5]); int c=k[4]*5; int d=min(k[2],c); k[2]-=d,c-=d; if(c)k[1]=max(0ll,k[1]-c*4); c=4-k[3]%4; if(c!=4){ d=2*c-1; int c1=min(k[2],d); k[2]-=c1; int d1=c*9-c1*4; k[1]=max(0ll,k[1]-d1); } if(k[2]>0){ c=(k[2]+8)/9; now+=c; d=9-k[2]%9; if(d!=9)k[1]=max(0ll,k[1]-d*4); } if(k[1]>0){ c=(k[1]+35)/36; now+=c; } if(now>s)cout<<"No\n"; else cout<<"Yes\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
唤 标签:typedef,const,23,int,long,solve,No.2,友谊赛,define From: https://www.cnblogs.com/bible-/p/17583374.html