Educational Codeforces Round 64 (Rated for Div. 2)

http://codeforces.com/contest/1156

A:(wa到菜哭) 刚开始秒A了,结果是官方出题给错图了,然后,,wa了好几发

主要点:考虑下面这种情况,

Educational Codeforces Round 64 (Rated for Div. 2)_第1张图片

也就是说当某个地方顺序为 31 2时,只加2个点

#include
using namespace std;
typedef long long ll;
const int N = 1e6+100;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int a[N],n;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int i = 1;i <= n;i ++) cin >> a[i];
    ll cnt = 0;
    bool flag = false;
    for(int i = 2;i <= n;i ++){
        if(a[i-1] == 1){
            if(a[i] == 2){
                if(i >= 3 && a[i-2] == 3) cnt += 2;
                else cnt += 3;
            }else cnt += 4;
        }else if(a[i-1] == 2){
            if(a[i] == 1) cnt += 3;
            else flag = true;
        }else{
            if(a[i] == 1) cnt += 4;
            else flag = true;
        }
    }
    if(flag) cout << "Infinite";
    else cout << "Finite" << endl << cnt;
    return 0;
}

B:把字符串分割成 a c e,  b d f...两个串,然后1拼2 或者 2拼1 

#include
using namespace std;
typedef long long ll;
const int N = 1e6+100;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int a[26];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int T;
    cin >> T;
    while(T --){
        string s,s1="",s2="";
        cin >> s;
        sort(s.begin(),s.end());
        for(int i = 0;i < s.size();i ++) if((s[i]-'a')&1) s2 += s[i]; else s1 += s[i];
        if(abs(s1[0]-s2[s2.size()-1]) != 1) cout << (s2+s1);
        else if(abs(s2[0]-s1[s1.size()-1]) != 1) cout << (s1+s2);
        else cout << "No answer";
        cout << '\n';
    }
    return 0;
}

C题:我先用multiset然后二分,卡在第七个点,现在没找出来错,感觉应该是二分找的时候可能会出错

正解:最大为 n/2对,所以双指针分别从开头和(n+1)/2开始遍历,一对一对找,

#include
using namespace std;
typedef long long ll;
const int N = 1e6+100;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n,z;
    cin >> n >> z;
    vector v(n);
    for(int & x:v) cin >> x;
    sort(v.begin(),v.end());
    int i = 0, j = (n+1)>>1;
    for(;i < n && j < n;j ++){
        if(v[j]-v[i] >= z) i ++;
    }
    cout << i;
    return 0;
}

 

你可能感兴趣的:(Codeforces)