Codeforces Round #693 (Div. 3)

skyepodium·2021년 1월 4일
0

A. Cards for Friends

#include <iostream>
 
using namespace std;
 
int t, w, h, n, cnt;
 
int main () {
    scanf("%d", &t);
    
    for(int test_case=1; test_case<=t; test_case++) {
        scanf("%d %d %d", &w, &h, &n);
        
        cnt = 1;
        
        while(w > 0 && w%2==0) {
            cnt = cnt * 2;
            w = w / 2;
        }
        while(h > 0 && h%2==0) {
            cnt = cnt * 2;
            h = h / 2;
        }
        if(cnt >= n) {
            printf("YES\n");
        }
        else{
            printf("NO\n");
        }
    }
}

B. Fair Division

#include <iostream>
 
using namespace std;
 
int t, n, num, one_cnt, two_cnt;;
 
int main () {
    scanf("%d", &t);
    
    for(int test_case=1; test_case<=t; test_case++) {
        scanf("%d", &n);
        
        one_cnt = two_cnt = 0;
 
        for(int i=0; i<n; i++) {
            scanf("%d", &num);
            if(num == 1) one_cnt++;
            else two_cnt++;
        }
        
        int total_sum = one_cnt * 1 + two_cnt * 2;
        if(total_sum % 2 == 1) {
            printf("NO\n");
        }
        else {
            int half = total_sum / 2;
            
            int two_count = half / 2;
            int one_count = half - two_count * 2;
            
            if(two_count <= two_cnt && one_count <= one_cnt) {
                printf("YES\n");
            }
            else {
                
                int one_count = half / 1;
                int two_count = half - one_count * 1;
 
                if(two_count <= two_cnt && one_count <= one_cnt) {
                    printf("YES\n");
                }
                else{
                    printf("NO\n");
                }
            }
 
            
        }
    }
}

C. Long Jumps

#include <iostream>
#define max_int 200001
using namespace std;
 
int t, n, a[max_int], d[max_int], result;
 
int max(int a, int b) {
    return a > b ? a : b;
}
 
 
int main () {
    scanf("%d", &t);
    
    for(int test_case=1; test_case<=t; test_case++) {
        scanf("%d", &n);
        
        result = 0;
        
        for(int i=1; i<=n; i++) {
            scanf("%d", &a[i]);
            d[i] = a[i];
        }
        
        for(int i=1; i<=n; i++) {
            int next_idx = i + a[i];
            
            if(next_idx <= n) {
                d[next_idx] = max(d[next_idx], d[i] + a[next_idx]);
            }
        }
        
        for(int i=1; i<=n; i++) {
            result = max(result, d[i]);
        }
        
        printf("%d\n", result);
    }
}

여기서 부터는 대회때 못풀고, 다시 푼것들

D. Even-Odd Game

#include <iostream>
#include <algorithm>
#define max_int 200001
#define llu unsigned long long int
using namespace std;

llu alice_score, bob_score;
int t, n, a[max_int], cur = 0;
bool is_alice;

bool cmp(const int &a, const int &b) {
	return a > b;
}

void init () {
	is_alice = true;
	alice_score = bob_score = 0;	
}

void solve() {
	scanf("%d", &n);
	
	init();
	
	for(int i=1; i<=n; i++) {
		scanf("%d", &a[i]);
	}
	
	sort(a + 1, a + 1 + n, cmp);
	
	for(int i=1; i<=n; i++) {
		cur = a[i];
		if(is_alice) {
			if(cur % 2 == 0) alice_score += cur;
		}	
		else{
			if(cur % 2 == 1) bob_score += cur;
		}
		is_alice = !is_alice;
	}
	
	if(alice_score == bob_score) {
		printf("Tie\n");
	}
	else if(alice_score > bob_score) {
		printf("Alice\n");
	}
	else{
		printf("Bob\n");
	}
}

int main () {
	scanf("%d", &t);
	
	while(t--) {
		solve();
	}
}
profile
callmeskye

0개의 댓글