CF 894B.Ralph And His Magic Field

题目:https://cn.vjudge.net/problem/CodeForces-894B

AC代码(C++):

#include
#include
#include
#include
#include
#include
#include


#define INF 0x3f3f3f3f
#define eps 1e-8
typedef unsigned long long ULL;
typedef long long ll;


using namespace std;


ll n, m;
int k;


ll fpow(ll a, ll b, ll MOD) {//快速幂
ll r = 1, base = a%MOD;
while (b) {
if (b & 1) r *= base, r %= MOD;
base *= base;
base %= MOD;
b >>= 1;
}
return r;
}


int main() {
while (cin >> n >> m >> k) {
if (n % 2 != m % 2 && k == -1)cout << 0 << endl;
else cout << fpow(fpow(2, (n - 1), (ll)1000000007), m - 1, (ll)1000000007) << endl;
}


system("pause");
}

总结: 数学题. 解为当n和m一奇一偶且k=-1时结果为0, 其余时候结果为2^(n-1)(m-1). 前半部分证明: 不妨设n为奇m为偶, 每一行有奇数个-1, 有奇数行则总共有偶数个-1; 每一列有奇数个-1, 有偶数列则总共有奇数个-1. 前后矛盾所以不存在, 结果为0.

你可能感兴趣的:(cf)