首页 > 代码库 > Codeforces Round #258

Codeforces Round #258

A.Game With Sticks

  就发现选定一个点之后,会删除相应的行列,即n-1,m-1,所以只需要看min(n,m)是基是偶

#include <iostream>#include <cstdio>#include <cstdlib>using namespace std;int n, m;int main(){#ifdef LOCAL    freopen("451A.in", "r", stdin);#endif    cin >> n >> m;    n = min(n, m);    if(n&1) cout << "Akshat" << endl;    else    cout << "Malvika" << endl;    return 0;}

 

B.Sort the Array

  把中间逆序之后整个串是递增的,所以原串是递增、递减、递增,所以只需要找到中间串的头,尾,然后判断逆序之后,是否整个串是递增的,最后步一开始被我忽略了...

  感觉不是很好写,所以又想,既然逆序之后是递增的,那我用把原数组排序,再用比较是否相同的方法找到中间串的头尾,然后对中间串比较a[i] == b[j],i从左边开始,j从右边开始

 

  一开始中间串比较结束条件写成了i <= j 这样只比较了一半...判断是不是回文才该这样啊...应该i <= r 全部扫一遍

 

#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>using namespace std;const int maxn = 100000+50;int n, l, r;long a[maxn], b[maxn];int main(){#ifdef LOCAL    freopen("451B.in", "r", stdin);#endif    cin >> n;    for(int i = 1; i <= n; i++) {        cin >> a[i];        b[i] = a[i];    }    l = r = 1;    sort(b+1, b+1+n);    for(int i = 1; i <= n; i++)        if(a[i] != b[i]) {            l = i;            break;        }               for(int i = n; i >= 1; i--)        if(a[i] != b[i]) {            r = i;            break;        }    bool ok = true;    for(int i = l, j = r; i <= r; i++, j--)        if(a[i] != b[j]) {            ok = false;            break;        }    if(ok)  cout << "yes" << endl << l <<   << r << endl;    else    cout << "no" <<endl;    return 0;}

 

C.Predict Outcome of the Game

  初看不知道怎么搞,就随便先样例试着推一下

  然后发现好像把x-y=d1,y-z=d2列出来,结合x+y+z=k(x,y,z代表球队胜率场数)

  是能够把y解出来的!!!代入就能把三个未知数解出来...题目的问法也很傻逼,就问你能不能

  所以分四种情况的方程来解(见代码),注意能不能整除,以及容易推出的结论,yes = x and y and z < n/3 (n不能整除3就直接挂啦)

  当然检查解是否大于0也是必要的,至于整数,代码中都是整数的封闭运算

 

#include <iostream>#include <cstdio>#include <cstdlib>using namespace std;int t;long long x, y, z, n, k, d1, d2;bool ok;bool check(){    long long up = n/3;    if(x < 0 || y < 0 || z < 0)    return false;    if(x > up || y > up || z > up)    return false;    if(x+y+z != k)    return false;    return true;}int main(){#ifdef LOCAL    freopen("451C.in", "r", stdin);#endif    scanf("%d", &t);    while(t--) {        ok = false;        scanf("%lld%lld%lld%lld", &n, &k, &d1, &d2);        if(n % 3) {            cout << "no" << endl;            continue;        }        //x-y=d1        //y-z=d2        //x-2y+z=d1-d2        y = k-d1+d2;        if(y % 3 == 0) {            y /= 3;            x = d1+y;            z = y-d2;            if(check())                ok = true;        }        //x-y=d1        //z-y=d2        //x-2y+z=d1+d2        y = k-d1-d2;        if(y % 3 == 0) {            y /= 3;            x = y+d1;            z = y+d2;            if(check())                ok = true;        }        //y-x=d1        //y-z=d2        //-x+2y-z=d1+d2        y = k+d1+d2;        if(y % 3 == 0) {            y /= 3;            x = y-d1;            z = y-d2;            if(check())                ok = true;        }        //y-x=d1        //z-y=d2        //-x+2y-z=d1-d2        y = k+d1-d2;        if(y % 3 == 0) {            y /= 3;            x = y-d1;            z = y+d2;            if(check())                ok = true;        }        if(ok)    cout << "yes" << endl;        else    cout << "no" << endl;    }}

 

  也是运气比较好,虽然B挂了,A+C也有1400+分,然后400+,rank 1600咯 保住了蓝名

 

  做CF就先稳住前三题,上分妥妥的