zoukankan      html  css  js  c++  java
  • Codeforces Round #685 (Div. 2)

    Codeforces Round #685 (Div. 2)

    A - Subtract or Divide

    可以除掉很大的因数,答案只会是0,1,2,3

    #include <stdio.h>
    #include <iostream>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <queue>
    #include <map> 
    #include <stack>
    #include <sstream>
    #include <set>
    // #pragma GCC optimize(2)
    
    //#define int long long
    #define ls u<<1
    #define rs u<<1|1
    #define rep(i,a,n) for(int i=a;i<=n;i++)
    #define rush() int T;scanf("%d",&T);for(int Ti=1;Ti<=T;++Ti)
    #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define mm(i,v) memset(i,v,sizeof i);
    #define mp(a, b) make_pair(a, b)
    #define pi acos(-1)
    #define fi first
    #define se second
    
    using namespace std;
    typedef long long ll;
    typedef double db;
    typedef pair<int, int > PII;
    priority_queue< PII, vector<PII>, greater<PII> > que;
    stringstream ssin; //  ssin << string   while ( ssin >> int)
    const ll LINF = 0x7fffffffffffffffll;
    
    const int N = 4e5 + 5, M = 4e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f;
    ll n, x;
    
    inline ll read() {
        char c=getchar();ll x=0,f=1;
        while(c<'0'||c>'9'){if(c=='-')f=-1; c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0'; c=getchar();}
        return x*f;
    }
    
    
    int main()
    {
        #ifndef ONLINE_JUDGE
            freopen("in.txt","r",stdin);
            freopen("out.txt","w",stdout);
        #endif
        n = read();
        while (n--) {
            x = read();
            if (x == 1) puts("0");
            else if (x == 2) puts("1");
            else if (x % 2 == 0 || x == 3) puts("2");
            else puts("3");
        }
    
        // #ifndef ONLINE_JUDGE
        //     system("pause");
        // #endif
    }
    View Code

    B - Non-Substring Subsequence

    暴力判断两边l、r两边的情况

    #include <stdio.h>
    #include <iostream>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <queue>
    #include <map> 
    #include <stack>
    #include <sstream>
    #include <set>
    // #pragma GCC optimize(2)
    
    //#define int long long
    #define ls u<<1
    #define rs u<<1|1
    #define rep(i,a,n) for(int i=a;i<=n;i++)
    #define rush() int T;scanf("%d",&T);for(int Ti=1;Ti<=T;++Ti)
    #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define mm(i,v) memset(i,v,sizeof i);
    #define mp(a, b) make_pair(a, b)
    #define pi acos(-1)
    #define fi first
    #define se second
    
    using namespace std;
    typedef long long ll;
    typedef double db;
    typedef pair<int, int > PII;
    priority_queue< PII, vector<PII>, greater<PII> > que;
    stringstream ssin; //  ssin << string   while ( ssin >> int)
    const ll LINF = 0x7fffffffffffffffll;
    
    const int N = 4e5 + 5, M = 4e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f;
    int _, n, q;
    char s[N];
    
    inline ll read() {
        char c=getchar();ll x=0,f=1;
        while(c<'0'||c>'9'){if(c=='-')f=-1; c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0'; c=getchar();}
        return x*f;
    }
    
    
    int main()
    {
        #ifndef ONLINE_JUDGE
            freopen("in.txt","r",stdin);
            freopen("out.txt","w",stdout);
        #endif
        _ = read();
        while (_--) {
            n = read();
            q = read();
            scanf("%s", s + 1);
            while (q--) {
                int l, r;
                bool flag = 0;
                l = read(); r = read();
                for (int i = 1; i < l; ++i) {
                    if (s[i] == s[l]) {
                        flag = 1;
                        break;
                    }
                }
                for (int i = r + 1; i <= n; ++i) {
                    if (s[i] == s[r]) {
                        flag = 1;
                        break;
                    }
                }
                if (flag) puts("YES");
                else puts("NO");
                
            }
        }
    
        // #ifndef ONLINE_JUDGE
        //     system("pause");
        // #endif
    }
    View Code

    C - String Equality

    开两个桶,一直把状态往后移,判断下位置是否合法即可

    #include <stdio.h>
    #include <iostream>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <queue>
    #include <map> 
    #include <stack>
    #include <sstream>
    #include <set>
    // #pragma GCC optimize(2)
    
    //#define int long long
    #define ls u<<1
    #define rs u<<1|1
    #define rep(i,a,n) for(int i=a;i<=n;i++)
    #define rush() int T;scanf("%d",&T);for(int Ti=1;Ti<=T;++Ti)
    #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define mm(i,v) memset(i,v,sizeof i);
    #define mp(a, b) make_pair(a, b)
    #define pi acos(-1)
    #define fi first
    #define se second
    
    using namespace std;
    typedef long long ll;
    typedef double db;
    typedef pair<int, int > PII;
    priority_queue< PII, vector<PII>, greater<PII> > que;
    stringstream ssin; //  ssin << string   while ( ssin >> int)
    const ll LINF = 0x7fffffffffffffffll;
    
    const int N = 2e6 + 5, M = 4e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f;
    int _, n, k;
    char s[N], t[N];
    int a[30], b[30];
    
    inline ll read() {
        char c=getchar();ll x=0,f=1;
        while(c<'0'||c>'9'){if(c=='-')f=-1; c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0'; c=getchar();}
        return x*f;
    }
    
    
    int main()
    {
        #ifndef ONLINE_JUDGE
            freopen("in.txt","r",stdin);
            freopen("out.txt","w",stdout);
        #endif
        _ = read();
        while (_--) {
            mm(a, 0);
            mm(b, 0);
            n = read(); k = read();
            scanf("%s", s + 1);
            scanf("%s", t + 1);
    
            rep(i, 1, n) a[s[i] - 'a' + 1]++;
            rep(i, 1, n) b[t[i] - 'a' + 1]++;
    
            bool flag = 0;
            rep(i, 1, 26) {
                if (a[i] < b[i]) {
                    flag = 1;
                    break;
                }
                a[i] -= b[i];
                b[i] = 0;
                if (a[i] % k) {
                    flag = 1;
                    break;
                }
                a[i + 1] += a[i];
            }
            if (a[26] != b[26]) {
                flag = 1;
            }
            if (flag) puts("NO");
            else puts("YES");
        }
    
        // #ifndef ONLINE_JUDGE
        //     system("pause");
        // #endif
    }
    View Code

    D - Circle Game

    可以发现对于后手来说最优解一定是对照先手走对角线,只需判断 d - floor(d /(sqrt(2)*k))和 k 的大小即可

    会有精度问题所以不能直接比较,可以通过便利来求出最终的区间来规避精度问题

    #include <stdio.h>
    #include <iostream>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <queue>
    #include <map> 
    #include <stack>
    #include <sstream>
    #include <set>
    // #pragma GCC optimize(2)
    
    //#define int long long
    #define ls u<<1
    #define rs u<<1|1
    #define rep(i,a,n) for(int i=a;i<=n;i++)
    #define rush() int T;scanf("%d",&T);for(int Ti=1;Ti<=T;++Ti)
    #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define mm(i,v) memset(i,v,sizeof i);
    #define mp(a, b) make_pair(a, b)
    #define pi acos(-1)
    #define fi first
    #define se second
    
    using namespace std;
    typedef long long ll;
    typedef double db;
    typedef pair<int, int > PII;
    priority_queue< PII, vector<PII>, greater<PII> > que;
    stringstream ssin; //  ssin << string   while ( ssin >> int)
    const ll LINF = 0x7fffffffffffffffll;
    
    const int N = 4e5 + 5, M = 4e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f;
    ll _, d, k;
    int sg[N];
    
    inline ll read() {
        char c=getchar();ll x=0,f=1;
        while(c<'0'||c>'9'){if(c=='-')f=-1; c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0'; c=getchar();}
        return x*f;
    }
    
    int main()
    {
        _ = read();
        while (_--)
        {
            d = read(); k = read();
            ll t = 0;
            while (t*k*t*k + t*k*t*k <= d*d)
                ++t;
            --t;
            ++t; --t;
            ll u = floor(sqrt(d*d - t*t*k*k) / k) - t;
            if (u & 1) puts("Ashish");
            else puts("Utkarsh");
    
            // mm(sg, 0);
            // ll r = d / k;
            // for (int i = r; i >= 0; --i) {
            //     ll h = d * d - i * i * k * k;
            //     double hh = sqrt(h);
            //     h = floor(hh);
            //     ll tp = h / k;
            //     if (i == r) {
            //         cout << h << '
    ';
            //         cout << hh << '
    ';
            //         cout << tp << '
    ';
            //         puts("");
            //     }
            //     if (i == r) {
            //         if (tp & 1) sg[i] = 1;
            //         else sg[i] = 2;
            //     } else {
            //         if (sg[i + 1] == 2) sg[i] = 1;
            //         else {
            //             sg[i] = 2;
            //         }
            //     }
            // }
            // // cout << sg[2] << '
    ';
            // if (sg[0] == 2) puts("Utkarsh");
            // else puts("Ashish");
        }
        return 0;
    }
    View Code
  • 相关阅读:
    使用::befor和::after伪元素在网站中添加图标
    使用LESS对CSS进行预处理
    window.innerWidth和document.body.clientWidth的区别
    javascript原型链继承
    javascript中的类型检测
    ASP.NET网站报Service Unavailable错误的解决办法
    在ASP.NET MVC中使用UEditor无法提交的解决办法
    EasyUI DataGrid设置列宽为百分比导致表头和内容错位的解决方法
    使用JS读取本地文本文件(兼容各种浏览器)
    美化上传文件按钮
  • 原文地址:https://www.cnblogs.com/mwh123/p/14018100.html
Copyright © 2011-2022 走看看