Educational Codeforces Round 35 (Rated for Div. 2) A B C D
Educational Codeforces Round 35 (Rated for Div. 2)
A Nearest Minimums
题目链接:
http://codeforces.com/contest/911/problem/A
思路:
- 找出最小值之间的最小差距即可
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 100005;
ll a[maxn];
int b[maxn];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int n;
cin>>n;
ll minnum=1000000000;
int mindis=100005;
for(int i=0;i<n;++i) cin>>a[i],minnum=min(minnum,a[i]);
int index=0;
for(int i=0;i<n;++i) if(a[i]==minnum) b[index++]=i;
for(int i=1;i<index;++i) mindis=min(mindis,b[i]-b[i-1]);
cout<<mindis<<endl;
return 0;
}
B Two Cakes
题目链接:
http://codeforces.com/contest/898/problem/B
思路:
- 枚举答案,看两部分各自能够分成多少份。分数总和必须大于等于给定的份数,找到最大答案即可跳出。
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int n,a,b,res,index;
cin>>n>>a>>b;
index=min(a,b);
for(int i=1;i<=index;++i) {
if(a/i+b/i>=n) res=i;
else break;
}
cout<<res<<endl;
return 0;
}
C Three Garlands
题目链接:
http://codeforces.com/contest/898/problem/C
思路:
- 暴力大法。枚举所有可能的情况
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 100005;
bool vis[maxn];
bool f(int a, int b, int c) {
int x1=1,x2=1,x3=1;
memset(vis,false,sizeof(vis));
for(int i=1;i<maxn;++i) if(!vis[i]) {x1=i;break;}
for(int i=x1;i<maxn;i+=a) vis[i]=true;
for(int i=1;i<maxn;++i) if(!vis[i]) {x2=i;break;}
for(int i=x2;i<maxn;i+=b) vis[i]=true;
for(int i=1;i<maxn;++i) if(!vis[i]) {x3=i;break;}
for(int i=x3;i<maxn;i+=c) vis[i]=true;
for(int i=1;i<maxn;++i) if(!vis[i]) return false;
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int k1,k2,k3;
cin>>k1>>k2>>k3;
bool flag=false;
if(f(k1,k2,k3)) flag=true;
if(f(k1,k3,k2)) flag=true;
if(f(k2,k1,k3)) flag=true;
if(f(k2,k3,k1)) flag=true;
if(f(k3,k1,k2)) flag=true;
if(f(k3,k2,k1)) flag=true;
if(!flag) cout<<"NO"<<endl;
else cout<<"YES"<<endl;
return 0;
}
D Inversion Counting
题目链接:
http://codeforces.com/contest/898/problem/D
思路:
- 相邻两个数调换,如果两数不相等就会使得的逆序对数发生奇偶性变化。要注意,给定的数字序列中两两不同。
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1504;
int a[maxn];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int n,m,l,r,res;
res=0;
cin>>n;
for(int i=1;i<=n;++i) cin>>a[i];
for(int i=1;i<n;++i) for(int j=i+1;j<=n;++j) if(a[i]>a[j]) res++;
cin>>m;
while(m--) {
cin>>l>>r;
int index=(l+r)/2;
res+=(r-l+1)/2;
for(int i=l;i<=index;++i) swap(a[i],a[l+r-i]);
if(res%2) cout<<"odd"<<endl;
else cout<<"even"<<endl;
}
return 0;
}