反思:
- 读题不严谨,A题以为的求和是保证最后全部加起来不会是x,所以就想成了如果no的话只能是一个元素的时候,其他步骤都与正解相同
- 想法不够细腻,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
太妙了
// 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;
}