Codeforces Global Round 14

反思:

  1. 读题不严谨,A题以为的求和是保证最后全部加起来不会是x,所以就想成了如果no的话只能是一个元素的时候,其他步骤都与正解相同
  2. 想法不够细腻,b题没有完全考虑所有的情况

A Phoenix and Gold

有大佬随机化过了,但是我没过嘤嘤嘤

// Problem: A. Phoenix and Gold
// Contest: Codeforces - Codeforces Global Round 14
// URL: https://codeforces.com/contest/1515/problem/A
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// Code by: ING__
// 
// Powered by CP Editor (https://cpeditor.org)

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#define ll long long
#define re return
#define Endl "\n"
#define endl "\n"

using namespace std;

typedef pair<int, int> PII;

int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};

int T;
int n, x;
int a[119];

int main(){
	cin >> T;
	while(T--){
		cin >> n >> x;
		int summ = 0;
		for(int i = 1; i <= n; i++){
			cin >> a[i];
			summ += a[i];
		}
	
		if(summ == x){
			cout << "NO" << Endl;
			continue;
		}
		
		sort(a + 1, a + 1 + n);
		
		summ = 0;
		
		for(int i = 1; i <= n; i++){
			summ += a[i];
			if(summ == x){
				summ -= a[i];
				swap(a[i], a[i + 1]); // 前提就是每个元素都不相同,
				summ += a[i];
			}
		}
		
		cout << "YES" << endl;
		for(int i = 1; i <= n; i++){
			cout << a[i] << " ";
		}
		cout << endl;
	}
	re 0;
}

B Phoenix and Puzzle

t 组数据,每组数据输入一个整数 n,表示给定的相同等腰直角三角形的数量。

询问是否能够用上所有三角形拼出一个无空洞的正方形。

能做到输出 YES ,否则输出 NO。


做的时候是我想的太简单了,光想着2的幂次就行了,没想到每个单位还能再拼

在这里插入图片描述

就像左下角那个那样

所以只需要判断,如果n可以写成2x或4x,其中x是平方数,那么答案是YES。否则为NO。

// Problem: B. Phoenix and Puzzle
// Contest: Codeforces - Codeforces Global Round 14
// URL: https://codeforces.com/contest/1515/problem/B
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// Code by: ING__
// 
// Powered by CP Editor (https://cpeditor.org)

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#include <bitset>
#define ll long long
#define re return
#define Endl "\n"
#define endl "\n"

using namespace std;

typedef pair<int, int> PII;

int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};

int T;
int n;

int main(){
	cin >> T;
	while(T--){
		cin >> n;
		if(n & 1){
			cout << "NO" << Endl;
			continue;
		}
		
		n /= 2;
		
		int x = sqrt(n);
		if(x * x == n){
			cout << "YES" << Endl;
			continue;
		}
		
		if(n % 2 == 0){ // n是4的倍数
			n /= 2;
			x = sqrt(n);
			if(x * x == n){
				cout << "YES" << Endl;

			}
			else{
				cout << "NO" << Endl;
			}
			continue;			
		}
		
		else{
			cout << "NO" << Endl;
		}
	}
	re 0;
}

C Phoenix and Towers

比赛的时候想到了肯定是贪心,但是因为被打击了就没继续往下想

从小到大按顺序放就好了

因为任意一个塔的高度都不会超过x,所以说任意两个塔的高度差都不会大于x,所以让每一层都尽可能的小,就一定能保证不会超过x

学习了一下大佬的妙解,大佬blog,大佬cf

太妙了

// Problem: C. Phoenix and Towers
// Contest: Codeforces - Codeforces Global Round 14
// URL: https://codeforces.com/contest/1515/problem/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// Code by: ING__
// 
// Powered by CP Editor (https://cpeditor.org)

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#define ll long long
#define re return
#define Endl "\n"
#define endl "\n"

using namespace std;

typedef pair<int, int> PII;

int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};

int T;
int n, m, x;

int main(){
	cin >> T;
	while(T--){
		priority_queue<PII, vector<PII>, greater<PII>> q;
		
		cin >> n >> m >> x;
		
		for(int i = 1; i <= m; i++) q.push({0, i});
		
		cout << "YES" << Endl;
		
		for(int i = 1; i <= n; i++){
			int t;
			cin >> t;
			
			auto f = q.top();
			q.pop();
			
			cout << f.second << " ";
			
			q.push({f.first + t, f.second});
		}
		cout << endl;
	}
	re 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值