abc354
D
思路
可以纯模拟,但写的码就是一坨,就像我一样,大佬的话思路就是把两个点都位移到第一象限,然后用前缀和的思路去写,再以4个块为一个周期,最后再处理细节
我的答辩代码
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include<cmath>
using namespace std;
#define endl '\n'
using ll = long long;
using pii = pair<int, int>;
using piii = pair<int, pii>;
#define fi first
#define se second
int bt1[5]={0,2,3,3,4},bt2[5]={0,1,3,4,4};
void solve() {
ll x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
ll t1=(x1%4+4)%4,t2=(x2%4+4)%4;
if(t2) t2=4-t2;
ll d=(x2+t2)-(x1-t1);
ll sum1=d/4*4*(y2-y1);
ll ft1=y2-y1;
if(ft1&1){
sum1-=(ft1/2*(bt1[t1]+bt2[t1]));
sum1-=(ft1/2*(bt1[4]+bt2[4]-bt1[4-t2]-bt2[4-t2]));
if(y1&1) sum1-=(bt2[t1]),sum1-=(bt2[4]-bt2[4-t2]);
else sum1-=(bt1[t1]),sum1-=(bt1[4]-bt1[4-t2]);
}
else{
sum1-=(ft1/2*(bt1[t1]+bt2[t1]));
sum1-=(ft1/2*(bt1[4]+bt2[4]-bt1[4-t2]-bt2[4-t2]));
}
cout<<sum1<<endl;
}
int main() {
cin.tie(nullptr)->ios::sync_with_stdio(false);
int _ = 1;
// cin>>_;
while (_--) {
solve();
}
return 0;
}
E
思路
这题是一个博弈dp
首先N为18,可以用状态压缩,
2
18
2^{18}
218不超过100万。转移的话,首先dp[i]
代表Takahashi 拿,牌的状态为i,赢了就是true,输了就是false,首先dp[0]
肯定是false,
如果dp[i]
能转移到dp[j]=false
的情况,那么dp[i]
就是·true的,如果它转移到的情况全是true的,即全是Aoki会赢的情况,那么dp[i]
就是false的
代码
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define endl '\n'
using ll = long long;
using pii = pair<int, int>;
using piii = pair<int, pii>;
#define fi first
#define se second
void solve() {
int n;
cin >> n;
vector<bool> dp(1 << n, false);
vector<int> a(n), b(n);
for (int i = 0; i < n; i++)
cin >> a[i] >> b[i];
for (int i = 0; i < (1 << n); i++) {
for (int j = 0; j < n; j++) {
for (int k = j + 1; k < n; k++)
if (a[j] == a[k] || b[j] == b[k])
if ((i >> j & 1) && (i >> k & 1))
dp[i] = dp[i] || !dp[i - (1 << j) - (1 << k)];
}
}
if (dp[(1 << n) - 1]) cout << "Takahashi" << endl;
else cout << "Aoki" << endl;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int _ = 1;
// cin >> _;
while (_--) {
solve();
}
return 0;
}