2017 Qinhuangdao Site CCPC E&&M

E - String of CCPC ZOJ - 3985

Portal: https://cn.vjudge.net/contest/227061#problem/E

Title:

Give a string, judge the number of CCPCs and judge whether adding a number can form a CCPC.
(From the original question, you can only get one point at most, otherwise it is a negative point to draw a coordinate axis, which is very good)

analyze:

CCPC This is a direct CCP CPC CCC can get 1 point. The key problem here is to solve the common letter problem of CCPC and its subsequences. It is conceivable that P is unique in CCPC. If CCPC, we directly i+=2, skipping CCP CPC. Let's make a special judgment on whether the appearance of CCC will constitute a CCPC..

emmmm pay attention to capitalization!

#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

Portal: https://cn.vjudge.net/contest/227061#problem/M

Title:

There is a safe area with a center of (0, 0) and a radius of R, which will be reduced to a safe area with a radius of r (always contained or tangent to the original circle). There are n houses, and the safe house with the highest probability has several output number.

analyze:

1. When R<=2r, there is a certain safety circle
2.R>2r There is an equivalent safety circle
3.[|R-2r|,R], the probability will continue to decrease

If the square is processed, there is no need to classify and discuss
my code.

#include <bits/stdc++.h>
using namespace std;
const int maxn=11111;
int d[maxn];
struct ss
{
    double dis;
    int id;
} a[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;
            a[i].dis=x*x+y*y;
            a[i].id=i;
            if(a[i].dis<=dd*dd)
                d[cnt++]=i;
            if(tt==-1||a[i].dis<=tt)
                tt=a[i].dis;
        }
        if(cnt==0)
        {
            for(int i=1; i<=n; i++)
                if(a[i].dis==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;
}

The code of teammates
feels a bit cumbersome,
but upper_bound is really easy to use

#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\n", tmp.dis);
        sort(a + 1, a + 1 + n);
//        for(int i = 1; i <= n; i++){
//            printf("%d %d\n", 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\n", 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('\n');
    }
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325317919&siteId=291194637