A - Biscuits

dp[i][0/1]表示当前和是偶数还是奇数,直接转移即可

#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 1000005
#define eps 1e-10
//#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,P;
int a[55];
int64 dp[55][2];
void Solve() {
read(N);read(P);
for(int i = 1 ; i <= N ; ++i) read(a[i]);
dp[0][0] = 1;
for(int i = 1 ; i <= N ; ++i) {
int k = a[i] & 1;
dp[i][0] = dp[i - 1][0];dp[i][1] = dp[i - 1][1];
dp[i][k ^ 0] += dp[i - 1][0];
dp[i][k ^ 1] += dp[i - 1][1];
}
out(dp[N][P]);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

B - Moderate Differences

A和B差值在\(N \times C\)和\((N-1) \times D\)之间肯定能达到

因为下降操作和上升操作差不多,那么我们默认所有的下降操作都在前面

容易发现,当我们进行\(i\)次至少为\(C\)的下降后

\(-i \times C + (N - 1 - i) \times C\)和\(-i \times C + (N - 1 - i) \times D\)之间的也可以达到

且这样能构造最多的重合的区间

#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 1000005
#define eps 1e-10
//#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;
int64 A,B,C,D;
bool check(int64 a,int64 b) {
return B - A >= a && B - A <= b;
}
void Solve() {
read(N);read(A);read(B);read(C);read(D);
for(int i = 0 ; i <= N - 1 ; ++i) {
int64 u = (N - 1 - i) * D - C * i,d = (N - 1 - i) * C - C * i;
if(check(d,u)) {puts("YES");return;}
u = C * i - (N - 1 - i) * C,d = C * i - (N - 1 - i) * D;
if(check(d,u)) {puts("YES");return;}
}
puts("NO");
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

C - Snuke and Spells

假如\(i\)出现了\(A[i]\)次,那么覆盖\([i - A[i],i]\)这个区间,然后找\([0,L]\)没有被覆盖的区间长度,就是答案

可以\(O(1)\)处理修改

#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 1000005
#define eps 1e-10
//#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,M;
int A[MAXN];
int cnt[MAXN],cov[MAXN],ans;
void Solve() {
read(N);read(M);
for(int i = 1 ; i <= N ; ++i) {
read(A[i]);
cnt[A[i]]++;
cov[A[i] - cnt[A[i]] + 1]++;
}
for(int i = 1 ; i <= N ; ++i) {
if(!cov[i]) ++ans;
}
int x,y;
for(int i = 1 ; i <= M ; ++i) {
read(x);read(y);
if(A[x] - cnt[A[x]] + 1 >= 1) {
if(!--cov[A[x] - cnt[A[x]] + 1]) ++ans;
}
--cnt[A[x]];
A[x] = y;
++cnt[A[x]];
if(A[x] - cnt[A[x]] + 1 >= 1) {
if(!cov[A[x] - cnt[A[x]] + 1]++) --ans;
}
out(ans);enter;
}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

D - Game on Tree

一个点的sg函数值显然是0,而一个树加一条边一个点的sg函数值是这棵树的sg函数值+1

证明,设新加的边为\(u,v\),\(u\)是\(v\)的祖先,若断掉新加的边,则sg值是0

否则断树中的边,sg函数值为\([0,sg[v] - 1]\),从小到大取,使得\(v\)为根游戏状态为0的那条边,断了之后,由于断掉新边游戏状态是0,则这个状态给\(u\)为根的贡献是\(1\)

使得\(v\)为根贡献为1的断边状态,子游戏中断边为0的状态可以转化为1,再填上断掉新边的状态是0,则这个对\(u\)的贡献变成了2

以此类推,这种情况游戏状态就是\(sg[v] + 1\)

#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 100005
#define eps 1e-10
//#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;
struct node {
int to,next;
}E[MAXN * 2];
int sumE,sg[MAXN],head[MAXN];
void add(int u,int v) {
E[++sumE].to = v;
E[sumE].next = head[u];
head[u] = sumE;
}
void dfs(int u,int fa) {
sg[u] = 0;
for(int i = head[u]; i ; i = E[i].next) {
int v = E[i].to;
if(v != fa) {
dfs(v,u);
sg[u] ^= (sg[v] + 1);
}
}
}
void Solve() {
read(N);
int x,y;
for(int i = 1 ; i < N ; ++i) {
read(x);read(y);
add(x,y);add(y,x);
}
dfs(1,0);
if(sg[1]) puts("Alice");
else puts("Bob");
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

E - Jigsaw

把连在地面上的高度设为正数,不连在地面上的高度设为负数

然后一个点相当于一条边\((l,r)\)

相当于把整个图拆成负数点到正数点的若干路径

只要判断一个弱联通图,负数点是否全为度数是否全负,正数点度数是否全正,然后至少有一个点点度不为0

证明就是欧拉回路,两两匹配负数点和正数点,一定会有欧拉回路,断掉这些边就是答案

#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 10005
#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 g[405][405],f[405][405],ind[405],H,col[405],all;
int N,A[100005],B[100005],C[100005],D[100005],cnt;
bool vis[405],flag,has[405];
void dfs(int u) {
all += ind[u];
if(ind[u]) flag = 1;
vis[u] = 1;
for(int i = 1 ; i <= 2 * H ; ++i) {
if(f[u][i] && !vis[i]) dfs(i);
}
}
void Solve() {
read(N);read(H);
for(int i = 1 ; i <= N ; ++i) {
read(A[i]);read(B[i]);read(C[i]);read(D[i]);
int s,t;
if(C[i]) s = C[i];
else s = A[i] + H;
if(D[i]) t = D[i] + H;
else t = B[i];
g[s][t]++;ind[t]++;ind[s]--;
f[s][t]++;f[t][s]++;
has[s] = has[t] = 1;
}
for(int i = 1 ; i <= H ; ++i) {
if(ind[i] < 0) {puts("NO");return;}
}
for(int i = H + 1 ; i <= 2 * H ; ++i) {
if(ind[i] > 0) {puts("NO");return;}
}
for(int i = 1 ; i <= 2 * H ; ++i) {
if(!has[i]) continue;
if(!vis[i]) {
flag = 0;
dfs(i);
if(all != 0 || !flag) {puts("NO");return;}
}
}
puts("YES");
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

F - Zigzag

dp[i][j][mask]表示第i条边走了第j步,左边界是什么

根据限制和每一步的选择修改左边界即可

复杂度\(O(n^{2}2^{n})\)

#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);
}
const int MOD = 1000000007;
int N,M,K;
int A[405],B[405],C[405],w[25][25];
int dp[2][21][(1 << 19) + 5];
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 lowbit(int x) {
return x & (-x);
}
void Solve() {
read(N);read(M);read(K);
memset(w,-1,sizeof(w));
for(int i = 1 ; i <= K ; ++i) {
read(A[i]);read(B[i]);read(C[i]);
w[A[i]][B[i]] = C[i];
}
int cur = 0;
dp[0][1][0] = 1;
for(int i = 1 ; i <= M ; ++i) {
for(int j = 1 ; j < N ; ++j) {
for(int s = 0 ; s < (1 << N - 1) ; ++s) {
if(!dp[cur][j][s]) continue;
if(w[i][j] != 1 && !(s >> (j - 1) & 1)) update(dp[cur][j + 1][s],dp[cur][j][s]);
if(w[i][j] != 0) {
if(s >> (j - 1) & 1) update(dp[cur][j + 1][s],dp[cur][j][s]);
else {
int t = s - (s & (1 << j) - 1);
t -= t & (-t);
t ^= (1 << j - 1);
t += s & (1 << j) - 1;
update(dp[cur][j + 1][t],dp[cur][j][s]);
}
}
}
}
memset(dp[cur ^ 1],0,sizeof(dp[cur ^ 1]));
for(int s = 0 ; s < (1 << N - 1) ; ++s) dp[cur ^ 1][1][s] = dp[cur][N][s];
cur ^= 1;
}
int ans = 0;
for(int s = 0 ; s < (1 << N - 1) ; ++s) ans = inc(ans,dp[cur][1][s]);
out(ans);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

【AtCoder】AGC017的更多相关文章

  1. 【AtCoder】ARC092 D - Two Sequences

    [题目]AtCoder Regular Contest 092 D - Two Sequences [题意]给定n个数的数组A和数组B,求所有A[i]+B[j]的异或和(1<=i,j<=n ...

  2. 【Atcoder】CODE FESTIVAL 2017 qual A D - Four Coloring

    [题意]给定h,w,d,要求构造矩阵h*w满足任意两个曼哈顿距离为d的点都不同色,染四色. [算法]结论+矩阵变换 [题解] 曼哈顿距离是一个立着的正方形,不方便处理.d=|xi-xj|+|yi-yj ...

  3. 【AtCoder】ARC 081 E - Don't Be a Subsequence

    [题意]给定长度为n(<=2*10^5)的字符串,求最短的字典序最小的非子序列字符串. http://arc081.contest.atcoder.jp/tasks/arc081_c [算法]字 ...

  4. 【AtCoder】AGC022 F - Leftmost Ball 计数DP

    [题目]F - Leftmost Ball [题意]给定n种颜色的球各k个,每次以任意顺序排列所有球并将每种颜色最左端的球染成颜色0,求有多少种不同的颜色排列.n,k<=2000. [算法]计数 ...

  5. 【AtCoder】AGC005 F - Many Easy Problems 排列组合+NTT

    [题目]F - Many Easy Problems [题意]给定n个点的树,定义S为大小为k的点集,则f(S)为最小的包含点集S的连通块大小,求k=1~n时的所有点集f(S)的和取模92484403 ...

  6. 【AtCoder】ARC067 F - Yakiniku Restaurants 单调栈+矩阵差分

    [题目]F - Yakiniku Restaurants [题意]给定n和m,有n个饭店和m张票,给出Ai表示从饭店i到i+1的距离,给出矩阵B(i,j)表示在第i家饭店使用票j的收益,求任选起点和终 ...

  7. 【AtCoder】ARC095 E - Symmetric Grid 模拟

    [题目]E - Symmetric Grid [题意]给定n*m的小写字母矩阵,求是否能通过若干行互换和列互换使得矩阵中心对称.n,m<=12. [算法]模拟 [题解]首先行列操作独立,如果已确 ...

  8. 【Atcoder】AGC022 C - Remainder Game 搜索

    [题目]C - Remainder Game [题意]给定n个数字的序列A,每次可以选择一个数字k并选择一些数字对k取模,花费2^k的代价.要求最终变成序列B,求最小代价或无解.n<=50,0& ...

  9. 【Atcoder】AGC 020 B - Ice Rink Game 递推

    [题意]n个人进行游戏,每轮只保留最大的a[i]倍数的人,最后一轮过后剩余2人,求最小和最大的n,或-1.n<=10^5. [算法]递推||二分 [题解]令L(i),R(i)表示第i轮过后的最小 ...

随机推荐

  1. Easyui comboxgrid弹出窗增加搜索功能

    效果如上图所示 <input id="q_item" name="q_item" style="width:200px" toolba ...

  2. Vue Admin - 基于 Vue & Bulma 后台管理面板

    Vue Admin 是一个基于 Vue 2.0 & Bulma 0.3 的后台管理面板(管理系统),相当于是 Vue 版本的 Bootstrap 管理系统,提供了一组通用的后台界面 UI 和组 ...

  3. C# 对图片加水印

    using System; using System.Collections; using System.Data; using System.Linq; using System.Web; usin ...

  4. [C++]指针与引用(应用辨析)

    1.指针变量允许将一个整数经强制转换后赋值给指针变量    Eg:      float *fp;      fp = (float *)5000;//意义:将5000作为一个地址赋给指针变量fp 2 ...

  5. 基于vue-cli的eslint常用设置

    .editorconfig 文件详细备注 # 最顶级的配置,相当于根 editorconfig 直到查找到root=true 才会停止查找不然会一直向上查找 root = true # 通配符 表示匹 ...

  6. 终端命令行开启和关闭mac隐藏文件

    defaults write com.apple.finder AppleShowAllFiles -bool true 此命令显示隐藏文件defaults write com.apple.finde ...

  7. vscode常用快捷键和插件(持续更新),以及一些常用设置的坑和技巧

    一 常用快捷键 ctrl+shift+p:  打开命令面板,最常用了 ctrl+p: 搜索窗口: 直接输入文件名,跳转到文件 > 可以进入 Ctrl+Shift+P 模式 ? 列出当前可执行的动 ...

  8. SpringBoot PUT请求

    (1)配置HiddenHttpMethodFilter(SpringMVC需要配置,SpringBoot已经为我们自动配置了) (2)在视图页面创建一个Post Form表单,在表单中创建一个inpu ...

  9. 【转】Python之xml文档及配置文件处理(ElementTree模块、ConfigParser模块)

    [转]Python之xml文档及配置文件处理(ElementTree模块.ConfigParser模块) 本节内容 前言 XML处理模块 ConfigParser/configparser模块 总结 ...

  10. linux内核中链表代码分析---list.h头文件分析(一)【转】

    转自:http://blog.chinaunix.net/uid-30254565-id-5637596.html linux内核中链表代码分析---list.h头文件分析(一) 16年2月27日17 ...