2017CCPC秦皇岛(C、E、L、M)

C - Crusaders Quest

#include<bits/stdc++.h>
using namespace std;
#define clr(a) memset(a, 0, sizeof(a))
#define line cout<<"-------------"<<endl

typedef long long ll;
const int maxn = 1e5 + 10;
const int MAXN = 1e6 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int N = 11;

int n, m;
char s[N];

int main(){
    int T;
    cin >> T;
    while(T--){
        clr(s);
        scanf("%s", s);
        bool flag = false;
        char str;
        for(int i=0; i<7; i++){
            if(s[i] == s[i+1] && s[i] == s[i+2]){
                flag = true;
                str = s[i];
                break;
            }
        }
        if(flag){
            char a[11];
            int pos = 0;
            for(int i=0; i<9; i++){
                if(s[i] != str){
                    a[pos ++] = s[i];
                }
            }
            int ans = 2;
            for(int i=0; i<6; i++){
                if(a[i] == a[i+1] && a[i] == a[i+2]){
                    ans = 3;
                    break;
                }
            }
            cout << ans << endl;
        }
        else {
            int ans = 1;
            char a[11];
            int pos = 0;
            for(int i=0; i<9; i++){
                if(s[i] != 'a') a[pos++] = s[i];
            }
            for(int i=0; i<6; i++){
                if(a[i] == a[i+1] && a[i] == a[i+2]){
                    ans = 2;
                    break;
                }
            }
            clr(a); pos = 0;
            for(int i=0; i<9; i++){
                if(s[i] != 'o') a[pos++] = s[i];
            }
            for(int i=0; i<6; i++){
                if(a[i] == a[i+1] && a[i] == a[i+2]){
                    ans = 2;
                    break;
                }
            }
            clr(a); pos = 0;
            for(int i=0; i<9; i++){
                if(s[i] != 'g') a[pos++] = s[i];
            }
            for(int i=0; i<6; i++){
                if(a[i] == a[i+1] && a[i] == a[i+2]){
                    ans = 2;
                    break;
                }
            }
            cout << ans << endl;
        }
    }

    return 0;
}

E - String of CCPC

#include<bits/stdc++.h>
using namespace std;
#define clr(a) memset(a,0,sizeof(a))

const int maxn = 2e5+10;
const int MAXN = 1e6+10;
const int INF = 0x3f3f3f3f;
const int N = 1010;

char s[maxn];
int n, cnt;

int main(){
    int T;
    scanf("%d", &T);
    while(T--){
        clr(s);
        cnt = 0;
        scanf("%d %s", &n, s);
        bool flag = false;
        for(int i=0; i<n; i++){
            if(s[i] == 'C' && s[i+1] == 'C' && s[i+2] == 'P' && s[i+3] == 'C'){
                cnt ++;
                s[i+2] = '#'; s[i+1] = '#';
            }
        }
        for(int i=0; i<n; i++){
            if(s[i] == 'C' && s[i+1] == 'C' && s[i+2] == 'C' && !flag){
                cnt ++; flag = true;
            }
            if(s[i] == 'C' && s[i+1] == 'P' && s[i+2] == 'C' && !flag){
                cnt ++; flag = true;
            }
            if(s[i] == 'C' && s[i+1] == 'C' && s[i+2] == 'P' && !flag){
                cnt ++; flag = true;
            }
        }
        cout << cnt << endl;
    }
    return 0;
}

L - One-Dimensional Maze

#include<bits/stdc++.h>
using namespace std;
#define clr(a) memset(a, 0, sizeof(a))
#define line cout<<"-------------"<<endl

typedef long long ll;
const int maxn = 1e5 + 10;
const int MAXN = 1e6 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int N = 1010;

int n, m;
char s[MAXN];

int main(){
    int T;
    cin >> T;
    while(T--){
        clr(s);
        scanf("%d%d",&n, &m);
        scanf("%s", s+1);
        int ans = 0;
        int num1 = 0, num2 = 1;
        if(s[m] == 'L'){
            for(int i=2; i<=m-1; i++){
                if(s[i] == 'R') num1 ++;
            }
            for(int i=m+1; i<=n-1; i++){
                if(s[i] == 'L') num2 ++;
            }
            ans = min(num1, num2);
        }
        else{
            for(int i=m+1; i<=n-1; i++){
                if(s[i] == 'L') num1 ++;
            }
            for(int i=2; i<=m-1; i++){
                if(s[i] == 'R') num2 ++;
            }
            ans = min(num1, num2);
        }
        cout << ans <<endl;
    }

    return 0;
}

M - Safest Buildings

#include<bits/stdc++.h>
using namespace std;
#define clr(a) memset(a, 0, sizeof(a))
#define line cout<<"-------------"<<endl

typedef long long ll;
const int maxn = 1e5 + 10;
const int MAXN = 1e6 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int N = 1010;
const double eps = 1e-8;

int n;
double R, r;
struct node{
    int id;
    double r, x, y, s;
}p[N], pre;

double solve(node a, node b){
    double dis = sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
    if(a.r + b.r <= dis) return 0;
    if(a.r - b.r >= dis)
        return acos(-1.0) * b.r * b.r;
    if(b.r - a.r >= dis)
        return acos(-1.0) * a.r * a.r;
    else{
        double A1 = acos((a.r * a.r + dis * dis - b.r * b.r) / (2 * dis * a.r));
        double A2 = acos((b.r * b.r + dis * dis - a.r * a.r) / (2 * dis * b.r));
        return a.r * a.r * A1 + b.r * b.r * A2 - sin(A1) * a.r * dis;
    }
}
bool cmp(node a, node b){
    return a.s > b.s;
}

int main(){
    int T;
    cin >> T;
    while(T--){
        clr(p);
        scanf("%d%lf%lf", &n, &R, &r);
        pre.r = R-r; pre.x = pre.y = 0.0; pre.s = R*R;
        for(int i=1; i<=n; i++){
            scanf("%lf%lf", &p[i].x, &p[i].y);
            p[i].id = i; p[i].r = r;
            p[i].s = solve(p[i], pre);
        }
        double maxx = -1.0;
        int f[N];
        int num = 1;
        sort(p+1, p+n+1, cmp);
        f[1] = p[1].id;
        for(int i=2; i<=n; i++){
            if(fabs(p[i].s - p[1].s) > eps) break;
            f[++num] = p[i].id;
        }
        sort(f+1, f+num+1);
        printf("%d\n", num);
        for(int i=1; i<=num; i++){
            if(i == num) printf("%d\n", f[i]);
            else printf("%d ", f[i]);
        }
    }
    return 0;
}
/*
2
3 10 5
3 4
3 5
3 6
3 10 4
-7 -6
4 5
5 4
*/

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值