Codeforces Round #372 (Div. 2)
A题,每次输入的时候记录,保留上一个的值,做差判断
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<bits/stdc++.h> #define C 0.5772156649 #define pi acos(-1.0) #define ll long long #define mod 1000000007 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-7; const int N=1000000+10,maxn=100+10,inf=0x3f3f3f; int main() { ios::sync_with_stdio(false); cin.tie(0); int n,k,last,ans=1; cin>>n>>k; for(int i=0;i<n;i++) { int a; cin>>a; if(i==0)last=a; else { if(a-last>k)ans=1; else ans++; } last=a; } cout<<ans<<endl; return 0; } /******************** ********************/
B题, 每26个判断一边,如果没有重复的字母就可以,然后依次填充,其他的填A就行了
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<bits/stdc++.h> #define C 0.5772156649 #define pi acos(-1.0) #define ll long long #define mod 1000000007 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-7; const int N=1000000+10,maxn=100+10,inf=0x3f3f3f; bool vis[30]; int main() { ios::sync_with_stdio(false); cin.tie(0); string s; cin>>s; for(int i=0;i+25<s.size();i++) { memset(vis,0,sizeof vis); int ok=1; for(int j=0;j<26;j++) { if(s[i+j]=='?')continue; if(!vis[s[i+j]-'A'])vis[s[i+j]-'A']=1; else ok=0; } if(ok) { // cout<<i<<s.substr(49,s.size())<<endl; queue<char>p; for(int j=0;j<26;j++) if(!vis[j]) p.push((char)(j+'A')); for(int j=0; j<26; j++) { if(s[i+j]!='?')continue; s[i+j]=p.front(),p.pop(); } for(int j=0;j<s.size();j++) if(s[j]=='?') s[j]='A'; cout<<s<<endl; return 0; } } cout<<-1<<endl; return 0; } /******************** ABABABBAB????????????ABABABABA???????????ABABABABA?????????KLCSJB?????????Z ********************/
C题,找规律,可以注意到 k*x+m=p*p,p%(k+1)==0,又因为每次m=p,那么就代表上一层的m%k==0,则令p=k*(k+1),则可通过递推求解
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<bits/stdc++.h> #define C 0.5772156649 #define pi acos(-1.0) #define ll long long #define mod 1000000007 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-7; const int N=1000000+10,maxn=100+10,inf=0x3f3f3f; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n; cin>>n; ll k,m=2; for(ll k=1;k<=n;k++) { ll p=k*(k+1); cout<<(k+1)*(k+1)*k-m/k<<endl; m=p; } return 0; } /******************** ********************/
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
n = int(input()) m = 2 for k in range(n): print((k+2)*(k+2)*(k+1)-(int)(m/(k+1))) m = (k+1)*(k+2)
D题,最短路,对于每个0边,我们记录下来,首先把0边改成1,如果最短路>L,则不行,再改成inf,如果最短路<L,则不行,再通过二分对0边进行调整,假设有k条0边,我们可以对k-1条0边赋值1,最后一条赋值最短路-已知边-k+1,当最短路很大 的时候可以把k-1条边赋值1e9,其他的相减
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<bits/stdc++.h> #define C 0.5772156649 #define pi acos(-1.0) #define ll long long #define mod 1000000007 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-7; const int N=100000+10,maxn=100+10,inf=0x3f3f3f3f3f; struct edge{ int from,to,Next,c; }e[N*2]; int cnt,head[N]; int d[N]; int n,m,L,s,t; bool vis[N]; vector<int>p; void add(int u,int v,int w) { e[cnt].to=v; e[cnt].c=w; e[cnt].Next=head[u]; head[u]=cnt++; } void spfa() { memset(vis,0,sizeof vis); vis[s]=1; memset(d,inf,sizeof d); d[s]=0; queue<int>q; q.push(s); while(!q.empty()) { int x=q.front(); q.pop(); vis[x]=0; for(int i=head[x];~i;i=e[i].Next) { int To=e[i].to,W=e[i].c; if(d[To]>d[x]+W) { d[To]=d[x]+W; if(!vis[To]) { vis[To]=1; q.push(To); } } } } } int getspfa(ll c) { // cout<<c<<" "; for(int i=0;i<p.size();i++) { e[p[i]].c=e[p[i]^1].c=1+min(c,(ll)1e9); // cout<<e[p[i]].c<<" "; c-=e[p[i]].c-1; } // cout<<endl; spfa(); return d[t]; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n>>m>>L>>s>>t; cnt=0; memset(head,-1,sizeof head); for(int i=0;i<2*m;i+=2) { cin>>e[i].from>>e[i].to>>e[i].c; if(e[i].c==0)p.push_back(cnt); add(e[i].from,e[i].to,e[i].c); add(e[i].to,e[i].from,e[i].c); } if(getspfa(0)>L||getspfa(p.size()*(1e9))<L) { cout<<"NO"<<endl; return 0; } ll l=0,r=p.size()*(1e9); while(l<=r) { ll mid=(l+r)/2; if(getspfa(mid)>L)r=mid-1; else if(getspfa(mid)<L)l=mid+1; else break; } cout<<"YES"<<endl; for(int i=0;i<2*m;i+=2) cout<<e[i].from<<" "<<e[i].to<<" "<<e[i].c<<endl; return 0; } /******************** 4 4 13 1 3 1 3 14 2 3 0 2 0 0 1 0 0 ********************/