【结论?】这是一颗树吗?
程序员文章站
2022-03-26 11:24:56
...
1
1 0
2
2 1 1
3
3 2 2 2
4
3 1 2 1
1
Possible
2
Possible
3
Impossible
4
Possible
就。。推着推着就发现一个结论???
???
然后特判1啥的就没了
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int n, sum, a[105], ans;
int main()
{
scanf("%d", &n);
if (n == 1) {
int x;
scanf("%d", &x);
if (!x) printf("Possible");
else printf("Impossible");
return 0;
}
else {
for (int i = 1; i <= n; ++i)
{
scanf("%d", &a[i]);
if (a[i] <= 0) {
printf("Impossible");
return 0;
}//判负
if (a[i] == n) {
printf("Impossible");
return 0;
}
ans += a[i];
}
if (ans / 2 == n - 1) printf("Possible");
else printf("Impossible");
}
return 0;
}
上一篇: 实现一颗红黑树