Atcoder ABC 141

Atcoder ABC 141

A - Weather Prediction

SB题啊,不讲。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;

char ch[50];

int main() {
    scanf("%s",ch+1);
    if(ch[1] == 'S') puts("Cloudy");
    if(ch[1] == 'C') puts("Rainy");
    if(ch[1] == 'R') puts("Sunny");
    //system("pause");
    return 0;
}

B - Tap Dance

暴力判断每一位是否合法就行。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>

using namespace std;

#define LL long long
#define N 100010

char ch[N];
bool flag = 1;

int main() {
    scanf("%s",ch+1);
    int len = strlen(ch + 1);
    for(int i = 1 ; i <= len ; i++) {
        if(i % 2 == 1) {
            if(ch[i] == 'R' || ch[i] == 'U' || ch[i] == 'D') continue;
            else {
                flag = 0;
                break;
            }
        }
        if(i % 2 == 0) {
            if(ch[i] == 'L' || ch[i] == 'U' || ch[i] == 'D') continue;
            else {
                flag = 0;
                break;
            }
        }
    }
    if(flag) puts("Yes");
    else puts("No");
    //system("pause");
    return 0;
}

C - Attack Survival

直接暴力会T的飞起,所以需要优化。
因为每一轮除了回答问题的人,其他人的值全部 $ -1 $ 。
所以我们可以考虑先全部 $ -1 $ ,再对回答问题的人 $ +1 $ 即可。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>

using namespace std;

#define LL long long
const int N = 1e5 + 100;

int a[N],n,k,q,x;

int main() {
    scanf("%d%d%d",&n,&k,&q);
    for(int i = 1 ; i <= n ; i++) a[i] = k - q;
    /*while(q--) {
        scanf("%d",&x);
        for(int i = 1 ; i <= n ; i++) a[i]--;
        a[x]++;
    }*/
    while(q--) {
        scanf("%d",&x);
        a[x]++;
    }
    for(int i = 1 ; i <= n ; i++) {
        if(a[i] > 0) puts("Yes");
        else if(a[i] <= 0) puts("No");
    }
    //system("pause");
    return 0;
}

D - Powerful Discount Tickets

贪心,拿个堆维护一下。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
 
using namespace std; 

#define LL long long
const int N = 1e5 + 100;

LL num[N],dis,m,n; 
priority_queue<LL> qu;

inline int fast_pow(int x, int y) {
	int ans = 1; 
	while(y) {
		if(y & 1) ans = x * ans; 
		y >>= 1; 
		x = x * x; 
	}
	return ans; 
}

int main() {
	scanf("%lld%lld",&n,&m);
	for (int i = 1; i <= n; i++) {
		scanf("%lld",&num[i]);
		qu.push(num[i]); 
	}
	if (n == 1) {
		if(log2(num[1]) + 1 <= m) puts("0"); 
		else printf("%lld
", num[1] / fast_pow (2, m)); 
		return 0; 
	}
	while(m) {
		int now = qu.top(); 
		if(now == 0) break; 
		qu.pop(); 
		int cost = 0; 
		if(qu.top() == 0) {
			if(log2 (now) + 1 <= m) qu.push(0); 
			else qu.push(now/fast_pow(2, m)); 
			break; 
		}
		while(now/fast_pow(2, cost) - now/fast_pow(2, cost + 1) >= qu.top() - qu.top()/2 && cost + 1 <= m) cost++; 
		m -= cost; 
		qu.push(now/fast_pow(2, cost)); 
	}
	while(!qu.empty()) {
		dis += qu.top(); 
		qu.pop(); 
	}
	printf("%lld
", dis);
	//system("pause"); 
	return 0; 
}

E - Who Says a Pun?

直接SA,没了。

原文地址:https://www.cnblogs.com/Repulser/p/11532242.html