比赛 |
20160407 |
评测结果 |
WWWAWTTTTT |
题目名称 |
吊灯 |
最终得分 |
10 |
用户昵称 |
KZNS |
运行时间 |
5.300 s |
代码语言 |
C++ |
内存使用 |
12.64 MiB |
提交时间 |
2016-04-07 11:54:19 |
显示代码纯文本
//KZNS
#include <fstream>
using namespace std;
//
ifstream fin ("dividec.in");
ofstream fout ("dividec.out");
const int Nmax = 1200003;
//
int N;
int fa[Nmax] = {0};
int cts[Nmax] = {0};
int uts[Nmax] = {0};
bool fff;
//
int main() {
fin >> N;
fa[1] = 0;
fin >> fa[2];
char c;
for (int i = 3; i <= N; i++)
fin >> c >> fa[i];
/////#1
fout << "Case #1:" << endl;
for (int i = 1; i <= N; i++)
cts[i] = 1;
for (int i = N; i > 1; i--)
cts[fa[i]] += cts[i];
for (int i = 1; i <= N; i++) {
if (N%i==0) {
fff = true;
for (int j = 1; j <= N; j++)
uts[j] = cts[j];
for (int j = N; j > 1; j--) {
if (uts[j] == i) {
uts[fa[j]] -=cts[j];
}
else {
if (uts[j] > i) {
fff = false;
continue;
}
}
}
fout << i <<endl;
}
}
/////////
for (int k = 2; k <= 10; k++) {
for (int i = 2; i <= N; i++) {
fa[i] = (fa[i]+19940105)%(i-1) + 1;
}
fout << "Case #" << k << ":" << endl;
for (int i = 1; i <= N; i++)
cts[i] = 1;
for (int i = N; i > 1; i--)
cts[fa[i]] += cts[i];
for (int i = 1; i <= N; i++) {
if (N%i==0) {
fff = true;
for (int j = 1; j <= N; j++)
uts[j] = cts[j];
for (int j = N; j > 1; j--) {
uts[fa[j]] -= cts[j]-uts[j];
if (uts[j] == i) {
uts[fa[j]] -=uts[j];
}
else {
if (uts[j] > i) {
fff = false;
continue;
}
}
}
if (fff)
fout << i <<endl;
}
}
}
return 0;
}
//UBWH