Educational Codeforces Round 32
Posted %%%%%
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Educational Codeforces Round 32相关的知识,希望对你有一定的参考价值。
水
#include "iostream" #include "iomanip" #include "string.h" #include "stack" #include "queue" #include "string" #include "vector" #include "set" #include "map" #include "algorithm" #include "stdio.h" #include "math.h" #pragma comment(linker, "/STACK:102400000,102400000") #define bug(x) cout<<x<<" "<<"UUUUU"<<endl; #define mem(a,x) memset(a,x,sizeof(a)) #define step(x) fixed<< setprecision(x)<< #define mp(x,y) make_pair(x,y) #define pb(x) push_back(x) #define ll long long #define endl ("\n") #define ft first #define sd second #define lrt (rt<<1) #define rrt (rt<<1|1) using namespace std; const ll mod=1e9+7; const ll INF = 1e18+1LL; const int inf = 1e9+1e8; const double PI=acos(-1.0); const int N=1e5+100; int n,ans,a[N]; int main(){ ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>n; for(int i=1; i<=n; ++i){ cin>>a[i]; } for(int i=2; i<n; ++i){ if(a[i]>a[i-1] && a[i]>a[i+1]) ans++; if(a[i]<a[i-1] && a[i]<a[i+1]) ans++; } cout<<ans<<endl; return 0; }
水
#include "iostream" #include "iomanip" #include "string.h" #include "stack" #include "queue" #include "string" #include "vector" #include "set" #include "map" #include "algorithm" #include "stdio.h" #include "math.h" #pragma comment(linker, "/STACK:102400000,102400000") #define bug(x) cout<<x<<" "<<"UUUUU"<<endl; #define mem(a,x) memset(a,x,sizeof(a)) #define step(x) fixed<< setprecision(x)<< #define mp(x,y) make_pair(x,y) #define pb(x) push_back(x) #define ll long long #define endl ("\n") #define ft first #define sd second #define lrt (rt<<1) #define rrt (rt<<1|1) using namespace std; const ll mod=1e9+7; const ll INF = 1e18+1LL; const int inf = 1e9+1e8; const double PI=acos(-1.0); const int N=1e5+100; char s[1005]; int l, r, u, d; int main(){ int n; cin>>n; cin>>s; int x=0, y=0, ans=0; for(int i=0; i<n; ++i){ if(s[i]==‘U‘) u++; if(s[i]==‘D‘) d++; if(s[i]==‘L‘) l++; if(s[i]==‘R‘) r++; } cout<<(min(l,r)+min(u,d))*2; return 0; }
水
#include "iostream" #include "iomanip" #include "string.h" #include "stack" #include "queue" #include "string" #include "vector" #include "set" #include "map" #include "algorithm" #include "stdio.h" #include "math.h" #pragma comment(linker, "/STACK:102400000,102400000") #define bug(x) cout<<x<<" "<<"UUUUU"<<endl; #define mem(a,x) memset(a,x,sizeof(a)) #define step(x) fixed<< setprecision(x)<< #define mp(x,y) make_pair(x,y) #define pb(x) push_back(x) #define ll long long #define endl ("\n") #define ft first #define sd second #define lrt (rt<<1) #define rrt (rt<<1|1) using namespace std; const ll mod=1e9+7; const ll INF = 1e18+1LL; const int inf = 1e9+1e8; const double PI=acos(-1.0); const int N=1e5+100; int n, vis[300]; char s[N]; bool check(int x){ mem(vis,0); for(int i=1; i<=x; ++i){ vis[s[i]]++; } for(int i=1; i<=n-x; ++i){ if(s[i]==s[i+x]) continue; if(vis[s[i+x]]>0) vis[s[i+x]]++; vis[s[i]]--; } for(int i=‘a‘; i<=‘z‘; ++i){ if(vis[i]>0) return 1; } return 0; } int main(){ cin>>s+1; n=strlen(s+1); int l=1, r=n, ans=n; while(l<=r){ int mid=l+r>>1; if(check(mid)){ ans=mid, r=mid-1; } else l=mid+1; } cout<<ans<<endl; return 0; }
D Almost Identity Permutations
错排 水
#include "iostream" #include "iomanip" #include "string.h" #include "stack" #include "queue" #include "string" #include "vector" #include "set" #include "map" #include "algorithm" #include "stdio.h" #include "math.h" #pragma comment(linker, "/STACK:102400000,102400000") #define bug(x) cout<<x<<" "<<"UUUUU"<<endl; #define mem(a,x) memset(a,x,sizeof(a)) #define step(x) fixed<< setprecision(x)<< #define mp(x,y) make_pair(x,y) #define pb(x) push_back(x) #define ll long long #define endl ("\n") #define ft first #define sd second #define lrt (rt<<1) #define rrt (rt<<1|1) using namespace std; const ll mod=1e9+7; const ll INF = 1e18+1LL; const int inf = 1e9+1e8; const double PI=acos(-1.0); const int N=1e5+100; ll ans,n,k,a[6]={1,0,1,2,9}; ll C(int n, int m){ ll ret=1; for(int i=0; i<m; ++i){ ret*=n-i; } for(int i=1; i<=m; ++i) ret/=i; return ret; } int main(){ cin>>n>>k; for(int i=0; i<=k; ++i){ ans+=C(n, i) * a[i]; } cout<<ans<<endl; return 0; }
题解在这里
以上是关于Educational Codeforces Round 32的主要内容,如果未能解决你的问题,请参考以下文章
Educational Codeforces Round 7 A
Educational Codeforces Round 7
Educational Codeforces Round 90
Educational Codeforces Round 33