Codeforces Round 1007 (Div. 2)
https://codeforces.com/contest/2071 Signed-off-by: Frederick Chen <seventeen@ohdragonboi.cn>
This commit is contained in:
parent
49dcb8adc3
commit
e59963f998
@ -0,0 +1,28 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
#define lo long long
|
||||||
|
#define INF INT_MAX
|
||||||
|
#define LLM LONG_LONG_MAX
|
||||||
|
#define endl "\n"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
const int N = 1e7 + 10;
|
||||||
|
/*
|
||||||
|
toothless. #17
|
||||||
|
@fredcss_dev
|
||||||
|
*/
|
||||||
|
|
||||||
|
int t, k;
|
||||||
|
|
||||||
|
bool wczffl_503(int k) {
|
||||||
|
return (k % 3 == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
signed main() {
|
||||||
|
cin >> t;
|
||||||
|
while (t--){
|
||||||
|
cin >> k;
|
||||||
|
if (wczffl_503(k)) cout << "YES" << endl;
|
||||||
|
else cout << "NO" << endl;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
76
codeforces/Codeforces Round 1007 (Div. 2)/B_Perfecto.cpp
Normal file
76
codeforces/Codeforces Round 1007 (Div. 2)/B_Perfecto.cpp
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
#define lo long long
|
||||||
|
#define INF INT_MAX
|
||||||
|
#define LLM LONG_LONG_MAX
|
||||||
|
#define endl "\n"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
const int N = 1e7 + 10;
|
||||||
|
/*
|
||||||
|
toothless. #17
|
||||||
|
@fredcss_dev
|
||||||
|
*/
|
||||||
|
|
||||||
|
bool f(lo x) {
|
||||||
|
if (x < 0) return false;
|
||||||
|
lo root = sqrtl(x);
|
||||||
|
return root * root == x;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wczffl_503() {
|
||||||
|
int n;
|
||||||
|
cin >> n;
|
||||||
|
lo total = 1LL * n * (n + 1) / 2;
|
||||||
|
if (f(total)) {
|
||||||
|
cout << "-1\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
vector<lo> s(n + 1);
|
||||||
|
for (int i = 1; i <= n; ++i) {
|
||||||
|
s[i] = (2LL * n - i + 1) * i / 2;
|
||||||
|
}
|
||||||
|
vector<bool> jhd(n + 1, false);
|
||||||
|
for (int i = 1; i <= n - 1; ++i) {
|
||||||
|
if (f(s[i])) {
|
||||||
|
jhd[i] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bool bad = false;
|
||||||
|
for (int i = 1; i <= n; ++i) {
|
||||||
|
lo now = s[i];
|
||||||
|
if (i <= n - 1 && jhd[i]) {
|
||||||
|
now--;
|
||||||
|
}
|
||||||
|
if (f(now)) {
|
||||||
|
bad = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (bad) {
|
||||||
|
cout << "-1\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
vector<int> p(n);
|
||||||
|
for (int i = 0; i < n; ++i) {
|
||||||
|
p[i] = n - i;
|
||||||
|
}
|
||||||
|
for (int i = 1; i <= n - 1; ++i) {
|
||||||
|
if (jhd[i]) {
|
||||||
|
swap(p[i - 1], p[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int x : p) {
|
||||||
|
cout << x << ' ';
|
||||||
|
}
|
||||||
|
cout << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
signed main()
|
||||||
|
{
|
||||||
|
int t;
|
||||||
|
cin >> t;
|
||||||
|
while (t--) {
|
||||||
|
wczffl_503();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
#define lo long long
|
||||||
|
#define INF INT_MAX
|
||||||
|
#define LLM LONG_LONG_MAX
|
||||||
|
#define endl "\n"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
const int N = 1e7 + 10;
|
||||||
|
/*
|
||||||
|
toothless. #17
|
||||||
|
@fredcss_dev
|
||||||
|
*/
|
||||||
|
|
||||||
|
vector<int> f(int root, const vector<vector<int>>& adj) {
|
||||||
|
vector<int> post_order;
|
||||||
|
stack<tuple<int, int, bool>> s;
|
||||||
|
s.push({root, -1, false});
|
||||||
|
|
||||||
|
while (!s.empty()) {
|
||||||
|
auto [node, parent, visited] = s.top();
|
||||||
|
s.pop();
|
||||||
|
if (visited) {
|
||||||
|
post_order.push_back(node);
|
||||||
|
} else {
|
||||||
|
s.push({node, parent, true});
|
||||||
|
for (int neighbor : adj[node]) {
|
||||||
|
if (neighbor != parent) {
|
||||||
|
s.push({neighbor, node, false});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return post_order;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wczffl_503() {
|
||||||
|
int t;
|
||||||
|
cin >> t;
|
||||||
|
while (t--) {
|
||||||
|
int n, st, en;
|
||||||
|
cin >> n >> st >> en;
|
||||||
|
vector<vector<int>> adj(n + 1);
|
||||||
|
for (int i = 0; i < n - 1; ++i) {
|
||||||
|
int u, v;
|
||||||
|
cin >> u >> v;
|
||||||
|
adj[u].push_back(v);
|
||||||
|
adj[v].push_back(u);
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<int> p = f(en, adj);
|
||||||
|
if (p.back() != en) {
|
||||||
|
p.push_back(en);
|
||||||
|
}
|
||||||
|
for (int x : p) {
|
||||||
|
cout << x << ' ';
|
||||||
|
}
|
||||||
|
cout << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
wczffl_503();
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user