题解 P6857 【梦中梦与不再有梦】
InformationEntropy · · 题解
本题的实质就是求有
当一个无向图有 0 个或 2 个奇点(度为奇数的点),那么它就是一个欧拉图,可以一笔画完所有的边。
考虑到
当
Code:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
typedef double db;
template<class T>inline void read(T &x)
{//快读
x = 0;
T f = 1;
char ch = getchar();
while (ch < '0' || ch > '9')
{
if (ch == '-')
{
f = -1;
}
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
x = x * 10 + ch - 48;
ch = getchar();
}
x *= f;
}
int main()
{
ll t, n;//不开 long long 见祖宗
read(t);
for (int i = 1; i <= t; i++)
{
read(n);
if (n == 0 || n == 1)
{
cout << 0 << '\n';//注意特判
} else if (n == 2) {
cout << 1 << '\n';
} else if (n % 2 == 1) {
cout << n*(n - 1) / 2 << '\n';
} else {
cout << n*(n - 1) / 2 - n / 2 + 1 << '\n';
}
}
return 0;
}