zoukankan      html  css  js  c++  java
  • 2017 Qinhuangdao Site CCPC E&&M

    E - String of CCPC ZOJ - 3985

    传送门:https://cn.vjudge.net/contest/227061#problem/E

    题意:

    给出字符串,判断CCPC的个数以及判断是否添一个数能够构成CCPC.
    (由原题得出 最多只能得一分 不然就是负分 画个坐标轴很好想)

    分析:

    CCPC这个是直接可以的分的 CCP CPC CCC是可以得一分的,这里的关键问题是解决CCPC和其子序列的公用字母问题。可以想到的是在CCPC中P是唯一的所有如果CCPC,我们直接i+=2,跳过了CCP CPC。再特判一下CCC出现是否会构成CCPC.. 就好啦

    emmmm 注意大小写!

    #include<bits/stdc++.h>
    using namespace std;
    string ccpc="CCPC";
    string cpc="CPC";
    string ccp="CCP";
    string ccc="CCC";
    int main()
    {
        int t;
        cin>>t;
        while(t--)
        {
            int n;
            cin>>n;
            string s;
            cin>>s;
            int cnt=0;
            bool flag=0;
            for(int i=0; i<n; i++)
            {
                if(s.substr(i,4)==ccpc)
                {
                    cnt++;
                    i+=2;
                    continue;
                }
                if(flag) continue;
                string tmp = s.substr(i,3);
                if(tmp==ccp||tmp==cpc||tmp==ccc)
                {
                    if(tmp==ccc &&s.substr(i+1, 4)==ccpc)
                        continue;
                    cnt++;
                    flag = 1;
                }
            }
            cout<<cnt<<endl;
        }
        return 0;
    }
    

    M - Safest Buildings ZOJ - 3993

    传送门:https://cn.vjudge.net/contest/227061#problem/M

    题意:

    有圆心为(0,0) 半径为R的安全区域,会缩小为半径为r的安全区(始终包含或相切在原来圆中) 有n个房子,概率最大的安全的房子有几个并输出编号。

    分析:

    1.R<=2r时候 存在必然安全圈
    2.R>2r 存在等价安全圈
    3.[|R-2r|,R],概率会不断的减小

    平方处理的话不需要分类讨论了
    我的代码 本来写了一些不需要的东西 看了队友代码意识到自己的代码可以再精简一点

    #include <bits/stdc++.h>
    using namespace std;
    const int maxn=11111;
    int d[maxn];
    double dist[maxn];
    int main()
    {
        int t;
        cin>>t;
        while(t--)
        {
            int n,dd,tt;
            cin>>n;
            int R,r;
            cin>>R>>r;
            dd=R-2*r;
            tt=-1;
            int cnt=0;
            int x,y;
            for(int i=1; i<=n; i++)
            {
                cin>>x>>y;
                dist[i]=x*x+y*y;
                if(dist[i]<=dd*dd)
                    d[cnt++]=i;
                if(tt==-1||dist[i]<=tt)
                    tt=dist[i];
            }
            if(cnt==0)
            {
                for(int i=1; i<=n; i++)
                    if(dist[i]==tt)
                        d[cnt++]=i;
            }
    
            cout<<cnt<<endl;
            for(int i=0; i<cnt; i++)
            {
                if(i==cnt-1) cout<<d[i]<<endl;
                else cout<<d[i]<<' ';
            }
        }
        return 0;
    }
    
    
    

    队友的代码
    虽然略有繁琐
    ...
    但是upper_bound是真的好用

    #include <bits/stdc++.h>
    using namespace std;
    
    const int maxn = 11111;
    struct bd{
        int dis;
        int id;
        bool operator < (const bd & bd1) const{
            return dis < bd1.dis;
        }
    }a[maxn];
    
    bool cmp(bd bd1, bd bd2){
        return bd1.id < bd2.id;
    }
    
    int main() {
        int t;
        scanf("%d", &t);
        while(t--) {
            int n;
            scanf("%d", &n);
            int R, r;
            scanf("%d %d", &R, &r);
            int dd = R - 2 * r;
            for(int i = 1; i <= n; ++i) {
                int x, y;
                scanf("%d %d", &x, &y);
                a[i].dis = (x * x + y * y);
                a[i].id = i;
            }
            bd tmp;
            tmp.dis = dd * dd;
    //        printf("%d
    ", tmp.dis);
            sort(a + 1, a + 1 + n);
    //        for(int i = 1; i <= n; i++){
    //            printf("%d %d
    ", a[i].id, a[i].dis);
    //        }
            int pos = upper_bound(a + 1, a + 1 + n, tmp) - a - 1;
            tmp.dis = a[1].dis;
            if(pos == 0)
                pos = upper_bound(a + 1, a + 1 + n, tmp) - a - 1;
            printf("%d
    ", pos);
            sort(a + 1, a + 1 + pos, cmp);
            for(int i = 1; i <= pos; i++) {
                if(i != 1)
                    printf(" %d", a[i].id);
                else
                    printf("%d", a[i].id);
            }
            putchar('
    ');
        }
        return 0;
    }
    
  • 相关阅读:
    JavaScript模态对话框类
    事件模块的演变(1)
    html5中可通过document.head获取head元素
    How to search for just a specific file type in Visual Studio code?
    What do 'lazy' and 'greedy' mean in the context of regular expressions?
    正则非获取匹配 Lookahead and Lookbehind ZeroLength Assertions
    regex length 正则长度问题
    Inversion of Control vs Dependency Injection
    How to return View with QueryString in ASP.NET MVC 2?
    今天才发现Google Reader
  • 原文地址:https://www.cnblogs.com/muvseea/p/8997354.html
Copyright © 2011-2022 走看看