K <= (N + 1) / 2c++
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define MAXN 40005 #define eps 1e-12 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } int N,K; int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif read(N);read(K); if(K <= (N + 1) / 2) puts("YES"); else puts("NO"); }
點度都不超過3spa
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define MAXN 40005 #define eps 1e-12 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } int deg[5]; int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif int a,b; for(int i = 1 ; i <= 3 ; ++i) { read(a);read(b); ++deg[a];++deg[b]; } for(int i = 1 ; i <= 4 ; ++i) { if(deg[i] >= 3) {puts("NO");return 0;} } puts("YES"); }
先給本身加到A塊餅乾
而後判斷一下B - A是否大於2,而後就用兩次不斷的換B - A
不然就直接一直拍得一次餅乾就行code
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define MAXN 40005 #define eps 1e-12 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } int64 K,A,B; int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif read(K);read(A);read(B); int64 now = 1; if(now < A) { int64 t = min(A - now,K); now += t; K -= t; } if(B - A > 2) { now += K / 2 * (B - A); K %= 2; } now += K; out(now);enter; }
DEF我作題順序是反的,D題我作的有點智障
FE作完以後一開榜19,D作完掉到45
你們AK水平那麼高= =
事實上就是一個有點智障的dp
空 偶 奇 偶 空
每一個段均可覺得0,若是一個數在空段代價是它的值,奇數在偶段代價爲1,偶數在奇數段代價爲1,0在偶數段代價爲2get
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define MAXN 200005 #define eps 1e-12 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } int L; int64 dp[MAXN][6],A[MAXN]; void Solve() { read(L); for(int i = 1 ; i <= L ; ++i) {read(A[i]);} for(int i = 1 ; i <= 4 ; ++i) dp[0][i] = 1e16; dp[0][0] = 0; for(int i = 1 ; i <= L ; ++i) { dp[i][0] = dp[i - 1][0] + A[i]; int t = A[i] & 1; dp[i][1] = min(dp[i - 1][1],dp[i - 1][0]); dp[i][2] = min(min(dp[i - 1][1],dp[i - 1][0]),dp[i - 1][2]); if(A[i] % 2 == 0) dp[i][2]++; dp[i][3] = min(dp[i - 1][2],dp[i - 1][3]); if(A[i] & 1) {dp[i][1]++;dp[i][3]++;} if(A[i] == 0) {dp[i][1] += 2;dp[i][3] += 2;} dp[i][4] = min(min(dp[i - 1][3],dp[i - 1][2]),min(dp[i - 1][1],dp[i - 1][4])); dp[i][4] += A[i]; } int64 res = dp[L][0]; for(int i = 1 ; i <= 4 ; ++i) res = min(res,dp[L][i]); out(res);enter; } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); }
若是選的行數肯定了,那麼選某一列的奇偶性也會肯定,若是奇數有a列,偶數有b列,\(a + b = M\)
那麼方案數是選a中奇數個,b隨便選
方案數是\(2^{a - 1}\cdot 2^{b}\),發現這個就是\(2^{M - 1}\)
因此只要存在a便可,即選的行數的數異或起來值不爲0,轉而求異或爲0的方案,直接上線性基便可it
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define MAXN 40005 #define eps 1e-12 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } const int MOD = 998244353; int N,M; int a[305][305]; int b[305][305],cnt; int inc(int a,int b) { return a + b >= MOD ? a + b - MOD : a + b; } int mul(int a,int b) { return 1LL * a * b % MOD; } void update(int &x,int y) { x = inc(x,y); } int fpow(int x,int c) { int res = 1,t = x; while(c) { if(c & 1) res = mul(res,t); t = mul(t,t); c >>= 1; } return res; } void Solve() { read(N);read(M); for(int i = 1 ; i <= N ; ++i) { for(int j = 1 ; j <= M ; ++j) { read(a[i][j]); } } for(int i = 1 ; i <= N ; ++i) { for(int j = 1 ; j <= M ; ++j) { if(a[i][j]) { if(!b[j][j]) { for(int k = 1 ; k <= M ; ++k) b[j][k] = a[i][k]; ++cnt; break; } else { for(int k = 1 ; k <= M ; ++k) a[i][k] ^= b[j][k]; } } } } int ans = inc(fpow(2,N),MOD - fpow(2,N - cnt)); ans = mul(ans,fpow(2,M - 1)); out(ans);enter; } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); }
直接轉二維平面,而後第i步能走到的點\((a,b)\)a個紅球,b個藍球,要知足a小於等於前i我的紅球總和,b小於等於前i我的藍球總和class
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define MAXN 40005 #define eps 1e-12 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } const int MOD = 998244353; char s[2005]; int sum[2005][2],N; int dp[4005][4005]; int inc(int a,int b) { return a + b >= MOD ? a + b - MOD : a + b; } int mul(int a,int b) { return 1LL * a * b % MOD; } void update(int &x,int y) { x = inc(x,y); } void Solve() { scanf("%s",s + 1); N = strlen(s + 1); for(int i = 1 ; i <= N ; ++i) { sum[i][0] = sum[i - 1][0]; sum[i][1] = sum[i - 1][1]; if(s[i] == '0') sum[i][0] += 2; if(s[i] == '1') {sum[i][0]++;sum[i][1]++;} if(s[i] == '2') sum[i][1] += 2; } dp[0][0] = 1; for(int i = 1 ; i <= 2 * N ; ++i) { int t = min(i,N); for(int j = 0 ; j <= i ; ++j) { int a = j,b = i - j; if(a <= sum[t][0] && b <= sum[t][1]) { if(a) update(dp[a][b],dp[a - 1][b]); if(b) update(dp[a][b],dp[a][b - 1]); } } } out(dp[sum[N][0]][sum[N][1]]);enter; } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); }