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 
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>a[i],minnum=min(minnum,a[i]);
    int index=0;
    for(int i=0;i

B Two Cakes

题目链接:

http://codeforces.com/contest/898/problem/B

思路:

  • 枚举答案,看两部分各自能够分成多少份。分数总和必须大于等于给定的份数,找到最大答案即可跳出。

代码:

#include 
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<

C Three Garlands

题目链接:

http://codeforces.com/contest/898/problem/C

思路:

  • 暴力大法。枚举所有可能的情况

代码:

#include 
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>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"<

D Inversion Counting

题目链接:

http://codeforces.com/contest/898/problem/D

思路:

  • 相邻两个数调换,如果两数不相等就会使得的逆序对数发生奇偶性变化。要注意,给定的数字序列中两两不同。

代码:

#include 
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;ia[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"<