周末训练 感觉题目难度区分好离谱 easy的特别easy 难的根本玩不明白 二个小时9题后就开始挂机了
Secrete Master Plan
#include<bits/stdc++.h>
using namespace std;
int T,a,b,c,d,aa,bb,cc,dd,cas;
int main(){
scanf("%d",&T);
while (T--){
scanf("%d%d%d%d",&a,&b,&c,&d);
scanf("%d%d%d%d",&aa,&bb,&cc,&dd);
cas++;printf("Case #%d: ",cas);
if (a==aa&&b==bb&&c==cc&&d==dd) puts("POSSIBLE");
else if (a==bb&&b==dd&&c==aa&&d==cc) puts("POSSIBLE");
else if (a==dd&&b==cc&&c==bb&&d==aa) puts("POSSIBLE");
else if (a==cc&&b==aa&&c==dd&&d==bb) puts("POSSIBLE");
else puts("IMPOSSIBLE");
}
return 0;
}
The Battle of Chibi
#include<cstdio>
#include<iostream>
#include<queue>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<cstring>
#include<unordered_map>
#include<set>
#include<cassert>
#include<bitset>
using namespace std;
#define REP(i,a,b) for(int i=(a),i##_end_=(b);i<i##_end_;++i)
#define DREP(i,a,b) for(int i=(a),i##_end_=(b);i>i##_end_;--i)
#define M 1003
#define ll long long
#define ld long double
static const int Mod = 1000000007;
int t,n,m,k;
int A[M],B[M];
int F[M],T[M];
void Add(int x,int f) {
while (x <= n)
T[x] = (T[x]+f)%Mod, x += x & -x;
}
int Query(int x){
int s = 0;
while (x) {
s = (s + T[x]) % Mod;
x ^= x & -x;
}
return s;
}
int main() {
scanf("%d", &t);
REP(_,1,t+1){
scanf("%d%d", &n,&m);
REP(i, 0, n)scanf("%d", &A[i]),B[i]=A[i];
sort(B, B + n);
REP(i, 0, n) {
A[i] = lower_bound(B, B + n, A[i]) - B + 1;
F[i] = 1;
}
REP(i, 1, m) {
memset(T, 0, sizeof(T));
REP(j, 0, n) {
int f = F[j];
F[j] = Query(A[j] - 1);
Add(A[j],f);
}
}
int s = 0;
REP(j,0,n)
s = (s + F[j]) % Mod;
printf("Case #%d: %d\n", _, s);
}
return 0;
}
Pick The Sticks
#include<bits/stdc++.h>
#define int long long
#define N 4005
using namespace std;
int T,n,L,l,v,cas=0,dp[N][3];
signed main(){
scanf("%lld",&T);
while (T--){
memset(dp,-127,sizeof(dp));
int ans=0;dp[0][0]=0;
scanf("%lld%lld",&n,&L);L*=2;
for (int i=1;i<=n;i++){
scanf("%lld%lld",&l,&v);ans=max(ans,v);
for (int j=L;j>=l;j--){
for (int k=2;~k;k--){
if (j-l*2>=0) dp[j][k]=max(dp[j][k],dp[j-l*2][k]+v);
if (k) dp[j][k]=max(dp[j][k],dp[j-l][k-1]+v);
}
}
}
for (int i=1;i<=L;i++)
for (int j=0;j<=2;j++) ans=max(ans,dp[i][j]);
printf("Case #%lld: %lld\n",++cas,ans);
}
return 0;
}
Ba Gua Zhen
#include <bits/stdc++.h>
#define mk make_pair
#define N 500005
typedef long long ll;
using namespace std;
int T, n, m, x, y;
ll z;
int cnt;
ll b[N];
int fa[N];
ll dep[N];
vector<pair<int, ll> > g[N];
struct node {
int x, y;
ll z;
} a[N];
inline void insert(long long x) {
for (int i = 63; ~i; i--) {
if (!((1ll << (long long)i) & x))
continue;
if (!b[i]) {
b[i] = x;
break;
} else
x ^= b[i];
}
}
inline ll query() {
ll ans = 0;
for (int i = 63; ~i; i--)
if ((ans ^ b[i]) > ans)
ans ^= b[i];
return ans;
}
void dfs1(int x, int fa) {
for (auto [v, w] : g[x]) {
if (v == fa)
continue;
dep[v] = dep[x] ^ w;
dfs1(v, x);
}
}
int find(int x) {
if (x == fa[x])
return x;
return fa[x] = find(fa[x]);
}
int cas = 0;
long long getInt(void) {
int ch = getchar();
ll res = 0;
while (!isdigit(ch))
ch = getchar();
for (; isdigit(ch); ch = getchar())
res = (res << 1) + (res << 3) + (ch - '0');
return res;
}
signed main() {
T = getInt();
while (T--) {
n = getInt(), m = getInt();
cnt = 0;
for (int i = 1; i <= n; i++)
g[i].clear();
for (int i = 1; i <= n; i++)
fa[i] = i;
for (int i = 1; i <= m; i++) {
x = getInt(), y = getInt(), z = getInt();
if (find(x) == find(y)) {
a[++cnt].x = x;
a[cnt].y = y;
a[cnt].z = z;
continue;
}
fa[find(x)] = find(y);
g[x].push_back(mk(y, z));
g[y].push_back(mk(x, z));
}
for (int i = 0; i <= 63; i++)
b[i] = 0;
dfs1(1, -1);
for (int i = 1; i <= cnt; i++)
insert(dep[a[i].x] ^ dep[a[i].y] ^ a[i].z);
printf("Case #%d: %lld\n", ++cas, query());
}
return 0;
}
The Battle of Guandu
#include<cstdio>
#include<iostream>
#include<queue>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<cstring>
#include<unordered_map>
#include<set>
#include<cassert>
#include<bitset>
using namespace std;
#define REP(i,a,b) for(int i=(a),i##_end_=(b);i<i##_end_;++i)
#define DREP(i,a,b) for(int i=(a),i##_end_=(b);i>i##_end_;--i)
#define M 100003
#define ll long long
#define ld long double
ll read() {
ll x = 0, f = 1; char ch = getchar();
for (; ch < '0' || ch>'9'; ch = getchar()) if (ch == '-') f = -1;
for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
return x * f;
}
int T, n, m;
int U[M], V[M], W[M], Q[M];
ll Dis[M];
vector<pair<int, int> >E[M];
struct Node {
int x;
ll d;
bool operator <(const Node& _)const {
return d > _.d;
}
};
priority_queue<Node>PQ;
int main() {
T = read();
REP(_,1,T+1){
m = read(), n = read();
REP(i, 0, m)U[i] = read();
REP(i, 0, m)V[i] = read();
REP(i, 0, m)W[i] = read();
REP(i, 1, n+1)Q[i] = read();
memset(Dis, 0x3f, sizeof(Dis));
REP(i, 1, n + 1)E[i].clear();
REP(i, 0, m)if (Q[V[i]] == 0)
Dis[U[i]] = min(Dis[U[i]], (ll)W[i]);
else if(U[i]!=V[i])
E[V[i]].push_back(make_pair(U[i],W[i]));
REP(i, 1, n + 1)if(Dis[i]!=0x3f3f3f3f3f3f3f3f)
PQ.push((Node){i,Dis[i]});
while (!PQ.empty()) {
int x = PQ.top().x;
ll d = PQ.top().d;
PQ.pop();
if (d != Dis[x])continue;
for (auto ed : E[x])
if (Dis[ed.first] > d + ed.second)
PQ.push((Node){ed.first,Dis[ed.first] = d + ed.second });
}
ll Ans = 0;
bool Flag = 0;
// REP(i, 1, n + 1)cerr << Dis[i] << ' '; cerr << endl;
REP(i, 1, n + 1)if (Q[i]==2) {
if (Dis[i] == 0x3f3f3f3f3f3f3f3f) {
Flag = 1; break;
}
Ans += Dis[i];
}
printf("Case #%d: %lld\n",_,Flag?-1:Ans);
}
return 0;
}
Ancient Go
#include<cstdio>
#include<iostream>
#include<queue>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<cstring>
#include<unordered_map>
#include<set>
#include<cassert>
#include<bitset>
using namespace std;
#define REP(i,a,b) for(int i=(a),i##_end_=(b);i<i##_end_;++i)
#define DREP(i,a,b) for(int i=(a),i##_end_=(b);i>i##_end_;--i)
#define M 13
#define ll long long
#define ld long double
static const int Mod = 1000000007;
static const int N = 10;
char C[M][M];
bool Vis[M][M];
int T,s;
int Xp[] = { 1,0,-1,0 };
int Yp[] = { 0,1,0,-1 };
void DFS(int x,int y) {
Vis[x][y] = 1;
REP(p, 0, 4)if (!Vis[x + Xp[p]][y + Yp[p]]) {
if (C[x + Xp[p]][y + Yp[p]] == 'o')
DFS(x + Xp[p], y + Yp[p]);
else if (C[x + Xp[p]][y + Yp[p]] == '.')
s++, Vis[x + Xp[p]][y + Yp[p]] = 1;
}
}
int main() {
scanf("%d", &T);
REP(_,1,T+1){
REP(i, 1, N)
scanf("%s", C[i] + 1);
REP(i, 0, N)C[i][0] = C[0][i] = C[i][N] = C[N][i] = 'x';
memset(Vis, 0, sizeof(Vis));
bool Flag = 0;
REP(i, 1, N)REP(j, 1, N)if (C[i][j] == 'o' && !Vis[i][j]) {
s = 0;
DFS(i,j);
Flag |= (s == 1);
if (Flag)break;
REP(x, 0, N)REP(y, 0, N)if (Vis[x][y] && C[x][y] == '.')
Vis[x][y] = 0;
}
printf("Case #%d: ", _);
puts(Flag ? "Can kill in one move!!!" : "Can not kill in one move!!!");
}
return 0;
}
Sudoku
#include <bits/stdc++.h>
#define coint const int
using namespace std;
char mp[6][6];
int row[6], col[6];
int blk[6], bel[6][6];
int found = 0;
void dfs(int x, int y) {
if (x > 4) {
for (int i = 1; i <= 4; ++i) {
puts(mp[i] + 1);
}
found = 1;
return;
}
if (y > 4) {
dfs(x + 1, 1);
return;
}
if (mp[x][y] != '*') {
dfs(x, y + 1);
return;
}
for (int i = 1; i <= 4 && !found; ++i) {
if (row[x] & (1 << i) || col[y] & (1 << i) || blk[bel[x][y]] & (1 << i))
continue;
row[x] |= (1 << i), col[y] |= (1 << i), blk[bel[x][y]] |= (1 << i);
mp[x][y] = i + '0';
dfs(x, y + 1);
row[x] ^= (1 << i), col[y] ^= (1 << i), blk[bel[x][y]] ^= (1 << i);
mp[x][y] = '*';
}
return;
}
int main(void) {
int t;
scanf("%d", &t);
bel[1][1] = bel[1][2] = bel[2][1] = bel[2][2] = 1;
bel[1][3] = bel[1][4] = bel[2][3] = bel[2][4] = 2;
bel[3][1] = bel[3][2] = bel[4][1] = bel[4][2] = 3;
bel[3][3] = bel[3][4] = bel[4][3] = bel[4][4] = 4;
for (int ca = 1; ca <= t; ++ca) {
for (int i = 1; i <= 4; ++i)
scanf("%s", mp[i] + 1);
printf("Case #%d:\n", ca);
memset(row, 0, sizeof row);
memset(col, 0, sizeof col);
memset(blk, 0, sizeof blk);
for (int i = 1; i <= 4; ++i)
for (int j = 1; j <= 4; ++j)
if (mp[i][j] != '*') {
coint num = mp[i][j] - '0';
row[i] |= (1 << num);
col[j] |= (1 << num);
blk[bel[i][j]] |= (1 << num);
}
found = 0;
dfs(1, 1);
}
return 0;
}
Mahjong
#include<cstdio>
#include<iostream>
#include<queue>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<cstring>
#include<unordered_map>
#include<set>
#include<cassert>
#include<bitset>
using namespace std;
#define REP(i,a,b) for(int i=(a),i##_end_=(b);i<i##_end_;++i)
#define DREP(i,a,b) for(int i=(a),i##_end_=(b);i>i##_end_;--i)
#define ll long long
#define ld long double
static const int M = (1 << 18) + 33;
static const int Mod = 1000000007;
int T,n,m;
int ID[M],tot,P[M],pt;
int E[103][5];
int F[103][3][3][2];
int G[2][73][203];
bool OK[103];
inline void Upd(int &a,const int &b) {
if (b >= 0)a = a + b >= Mod ? a + b - Mod : a + b;
else a = a + b < 0 ? a + b + Mod : a + b;
}
inline int GetS(int F[3][3][2]) {
int S = 0;
REP(i, 0, 3)REP(j, 0, 3)REP(k, 0, 2)
S = (S << 1) | F[i][j][k];
return S;
}
int DFS(int p){
int S = GetS(F[p]);
if (ID[S])return S;
ID[S] = ++tot;
P[tot] = S;
OK[tot] = F[p][0][0][1];
REP(x, 0, 5) {
int q = p + 1;
memset(F[q], 0, sizeof(F[q]));
REP(i, 0, 3)REP(j, 0, 3)REP(k, 0, 2)if (F[p][i][j][k]) {
int u = x - i - j;
if (u >= 0)
F[q][j][u >= 3 ? u - 3 : u][k] = 1;
if(!k){
int u = x - 2 - i - j;
if (u >= 0)
F[q][j][u][1] = 1;
}
}
E[ID[S]][x]=DFS(q);
}
return S;
}
int main() {
F[0][0][0][0] = 1;
DFS(0);
scanf("%d", &T);
REP(_,1,T+1){
scanf("%d%d", &n, &m);
memset(G, 0, sizeof(G));
G[0][ID[GetS(F[0])]][0] = 1;
bool p = 0;
int Tmp;
REP(i, 0, n) {
REP(j, 1, tot + 1) REP(t, 0, m + 1)if (Tmp = G[p][j][t]) {
REP(x, 0, 5)if (t + x <= m && E[j][x])
Upd(G[!p][ID[E[j][x]]][t + x], Tmp);
G[p][j][t] = 0;
}
p = !p;
}
int Ans = 0;
REP(i, 1, tot + 1)if (OK[i])Upd(Ans, G[p][i][m]);
//cerr << G[p][i][m] << ','; cerr << endl;
printf("Case #%d: %d\n", _, Ans);
}
return 0;
}
Game Rooms
#include<bits/stdc++.h>
#define int long long
#define N 100005
using namespace std;
int T,n,cas=0,a[N],b[N],sum[N][2],mul[N][2],dp[N][2];
inline int calc(int l,int r,int k){
int mid=(l+r)>>1;
if (l==1) return sum[r][k^1]*(r+1)-mul[r][k^1];
if (r==n) return mul[r][k^1]-mul[l-1][k^1]-(sum[r][k^1]-sum[l-1][k^1])*(l-1);
return (mul[mid][k^1]-mul[l-1][k^1])-(l-1)*(sum[mid][k^1]-sum[l-1][k^1])+(sum[r][k^1]-sum[mid][k^1])*(r+1)-(mul[r][k^1]-mul[mid][k^1]);
}
signed main(){
scanf("%lld",&T);
while (T--){
scanf("%lld",&n);
for (int i=1;i<=n;i++) scanf("%lld%lld",&a[i],&b[i]);
for (int i=1;i<=n;i++){
sum[i][0]=sum[i-1][0]+a[i];
sum[i][1]=sum[i-1][1]+b[i];
mul[i][0]=mul[i-1][0]+a[i]*i;
mul[i][1]=mul[i-1][1]+b[i]*i;
}
memset(dp,127,sizeof(dp));
dp[0][0]=dp[0][1]=0;
for (int i=1;i<=n;i++)
for (int j=0;j<i;j++){
if (i==n&&!j) continue;
for (int k=0;k<2;k++)
dp[i][k]=min(dp[i][k],dp[j][k^1]+calc(j+1,i,k));
}
printf("Case #%lld: %lld\n",++cas,min(dp[n][0],dp[n][1]));
}
return 0;
}
Huatuo's Medicine
#include <bits/stdc++.h>
#define coint const int
using namespace std;
int main(void) {
int t;
scanf("%d", &t);
for (int ca = 1; ca <= t; ++ca) {
int n;
scanf("%d", &n);
printf("Case #%d: %d\n", ca, n * 2 - 1);
}
return 0;
}