A - Biscuits

题目:

给出 \(n\) 个物品,每个物品有一个权值。

问有多少种选取方式使得物品权值之和 \(\bmod\space 2\) 为 \(p\).

\(n \leq 50\)

题解:

记录一下 \(n\) 个物品中权值是奇数的数的个数.

分类讨论一下喽...

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
x=0;static char ch;static bool flag;flag = false;
while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
#define rg register int
#define rep(i,a,b) for(rg i=(a);i<=(b);++i)
#define per(i,a,b) for(rg i=(a);i>=(b);--i)
const int maxn = 128;
int n,p,x,a,b;
int main(){
read(n);read(p);
rep(i,1,n){
read(x);
if(x & 1) ++a;
else ++b;
}
if(a == 0){
if(p == 0) printf("%lld\n", 1LL << n);
else puts("0");
}else printf("%lld\n", 1LL <<n-1);
return 0;
}

B - Moderate Differences

题目:

一个长为 \(n\) 的序列,给出左右两端的元素,问能否在中间的 \(n-2\) 个位置之中填入一些元素使得所有相邻元素的差的绝对值在 \([c,d]\) 内。

\(n \leq 500000, a,b,c,d \leq 10^9\)

题解:

我们将所有的填入与前一项差在某一范围内的元素视作将这个元素改变的限制。

我们知道这个元素一定是经过若干次上升和若干次下降后到达右端。

所以我们可以枚举上升多少次,相应的就知道了下降多少次。

这样我们可以计算出来上升的区间范围和下降的区间范围。

计算一下就好了.

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(ll &x){
x=0;static char ch;static bool flag;flag = false;
while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
#define rg register int
#define rep(i,a,b) for(rg i=(a);i<=(b);++i)
#define per(i,a,b) for(rg i=(a);i>=(b);--i)
int main(){
ll n,a,b,c,d;read(n);read(a);read(b);read(c);read(d);
if(n == 1){
if(a != b) puts("NO");
else puts("YES");
}else{-- n;
for(ll i = 0, j;i <= n;++i){
j = n - i;
ll x = i*c, y = i*d;
ll X = j*c + b-a, Y = j*d + b-a;
if(y < X) continue;
if(Y < x) continue;
puts("YES");return 0;
}puts("NO");
}
return 0;
}

C - Snuke and Spells

题目:

在一个长度为 \(i\) 的序列中施展咒语会消掉所有的值为 \(i\) 的项。

带动态修改某一点元素值地查询需要改掉多少数才能使得序列可以通过不断施展咒语而消掉。

\(n,m \leq 200000\)

题解:

我们分别考虑每个元素。

我们发现如果第 \(i\) 个元素有 \(s_i\) 中。

那么当长度到达 \(i\) 时下一步就会到达 \(i - s_i\)。

我们用一条 \([i-s_i,i]\) 的线段来表示这么一个数。

容易发现只有当所有 \([0,n]\) 的所有点之间的线段都被覆盖的时候才可行。

那么一次修改的话我们又最多只能多覆盖一条线段。

(最多使\([i-s_i,i] \to [i-s_i-1,i]\))

所以最小的修改此时就是没有被覆盖的线段条数。

记录一下 \(num_i\) 表示覆盖了 \([i-1,i]\) 的线段条数即可。

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
x=0;static char ch;static bool flag;flag = false;
while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
#define rg register int
#define rep(i,a,b) for(rg i=(a);i<=(b);++i)
#define per(i,a,b) for(rg i=(a);i>=(b);--i)
const int maxn = 200010;
int a[maxn],ws[maxn],num[maxn];
int main(){
int n,m;read(n);read(m);
rep(i,1,n) read(a[i]),ws[a[i]] ++ ;
int ans = 0;
rep(i,1,n) if(ws[i]){
num[max(i-ws[i]+1,1)] ++ ;
num[min(i+1,n+1)] -- ;
}
rep(i,1,n) num[i] += num[i-1],ans += (num[i] == 0);
while(m--){
int t,y,x;read(t);read(y);
x = a[t];a[t] = y;
if((x-ws[x]+1) >= 1 && (x-ws[x]+1) <= n){
if(-- num[x-ws[x]+1] == 0) ++ ans;
}-- ws[x];++ ws[y];
if((y-ws[y]+1) >= 1 && (y-ws[y]+1) <= n){
if(++ num[y-ws[y]+1] == 1) -- ans;
}printf("%d\n",ans);
}
return 0;
}

D - Game on Tree

题目:

给定一个 \(n\) 个点的树。Alice和Bob在上面玩游戏。

一次操作切断一条边,没有 \(1\) 节点的部分被删掉

无法操作就输. \(n \leq 100000\)

题解:

雅礼集训讲课原题。

考虑子树的合并就好了。

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
x=0;static char ch;static bool flag;flag = false;
while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
#define rg register int
#define rep(i,a,b) for(rg i=(a);i<=(b);++i)
#define per(i,a,b) for(rg i=(a);i>=(b);--i)
const int maxn = 100010;
struct Edge{
int to,next;
}G[maxn<<1];
int head[maxn],cnt;
void add(int u,int v){
G[++cnt].to = v;
G[cnt].next = head[u];
head[u] = cnt;
}
int fa[maxn],g[maxn];
void dfs(int u){
g[u] = 0;
for(rg i = head[u],v;i;i=G[i].next){
v = G[i].to;if(v == fa[u]) continue;
fa[v] = u;dfs(v);
g[u] ^= (g[v] + 1);
}
}
int main(){
int n;read(n);
int u,v;
rep(i,2,n){
read(u);read(v);
add(u,v);add(v,u);
}dfs(1);
puts(g[1] == 0 ? "Bob" : "Alice");
return 0;
}

E - Jigsaw

题目:

叙述不清,自己看题.

\(link\space to\space Atcoder\)

题解:

很容易想到接口什么的。

每个物品实际上都有两个接口。

考虑都没一段物品两端一定都是落地的。

我们考虑让所有左端落地的左端接口参数为正。反之为负。

所有右端落地的右端接口参数为负,反之为正。

我们发现所有右端接口参数等于左端接口参数的两个物品可以拼接。

考虑转化模型:

抽象出 \(2H\) 个点 \(-H,-(H-1), ... , -1 , 1 , 2 , ... ,H\)

那么对于我们物品设左端接口参数为 \(u\) 右端接口参数为 \(v\).

我们就连接一条 \((u,v)\) 的边。

那么现在的问题就是是否能够将所有的边拆分成若干条路径并且边不重复使用。

使得所有的路径都是从正数节点开始,负数节点结束。

对于这个判断,我们直接判断一下:

  • 所有正数节点是否都满足 \(出度 \geq 入度\)
  • 所有负数节点是否都满足 \(入读 \geq 出度\)
  • 所有弱连通分量中至少存在一个满足 \(出度 \neq 入读\) 的点

如果都满足那么可行。

不难发现这样是对的。

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
x=0;static char ch;static bool flag;flag = false;
while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
#define rg register int
#define rep(i,a,b) for(rg i=(a);i<=(b);++i)
#define per(i,a,b) for(rg i=(a);i>=(b);--i)
const int maxn = 512;
const int zero = 250;
int fa[maxn],siz[maxn],oud[maxn],ind[maxn];bool h[maxn];
int find(int x){return fa[x] == x ? x : fa[x] = find(fa[x]);}
inline void Union(int x,int y){
x = find(x);y = find(y);
if(x == y) {++siz[x];return ;}
fa[x] = y;siz[y] += siz[x] + 1;
}
int main(){
int n,H;read(n);read(H);
rep(i,1,H) fa[i+zero] = i+zero,siz[i+zero] = 1;
rep(i,-H,-1)fa[i+zero] = i+zero,siz[i+zero] = 1;
int a,b,c,d;
rep(i,1,n){
int x,y;
read(a);read(b);read(c);read(d);
if(c == 0) x = a;else x = -c;
if(d == 0) y = -b;else y = d;
++ oud[x + zero];++ ind[y + zero];
Union(x+zero,y+zero);
}
rep(i,1,H) if(oud[i+zero] < ind[i+zero]) return puts("NO"),0;
rep(i,-H,-1)if(ind[i+zero] < oud[i+zero]) return puts("NO"),0;
rep(i,1,H) h[find(i+zero)] |= (ind[i+zero]!=oud[i+zero]);
rep(i,-H,-1)h[find(i+zero)] |= (ind[i+zero]!=oud[i+zero]);
rep(i,1,H) if(siz[find(i+zero)] > 1 && (find(i+zero) == i+zero) && (h[i+zero] == false)) return puts("NO"),0;
rep(i,-H,-1)if(siz[find(i+zero)] > 1 && (find(i+zero) == i+zero) && (h[i+zero] == false)) return puts("NO"),0;
puts("YES");
return 0;
}

AtCoder Grand Contest 017 题解的更多相关文章

  1. AtCoder Grand Contest 017题解

    传送门 \(A\) 直接转移就是了 typedef long long ll; const int N=55; ll f[N][2];int a[N],n,p; int main(){ scanf(& ...

  2. 题解——ATCoder AtCoder Grand Contest 017 B - Moderate Differences(数学,构造)

    题面 B - Moderate Differences Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Stat ...

  3. AtCoder Grand Contest 017 F - Zigzag

    题目传送门:https://agc017.contest.atcoder.jp/tasks/agc017_f 题目大意: 找出\(m\)个长度为\(n\)的二进制数,定义两个二进制数的大小关系如下:若 ...

  4. AtCoder Grand Contest 017 (VP)

    contest link Official Editorial 比赛体验--之前做题的时候感觉 AtCoder 挺快的,现在打了VP之后发现还是会挂的--而且不是加载缓慢或者载不出来,直接给你一个无法 ...

  5. Atcoder Grand Contest 054 题解

    那天晚上由于毕业晚会与同学吃饭喝酒没打 AGC,第二天稍微补了下题,目前补到了 E,显然 AGC 的 F 对于我来说都是不可做题就没补了(bushi A 简单题,不难发现如果我们通过三次及以上的操作将 ...

  6. AtCoder Grand Contest 017

    noi前橙名计划失败.全程搞C而gg…… A - Biscuits 题意:背包,求价值为奇/偶的方案数. #include<cstdio> #include<queue> #i ...

  7. AtCoder Grand Contest 030题解

    第一次套刷AtCoder 体验良好 传送门 Poisonous Cookies cout<<b+min(c,a+b+); Tree Burning 难度跨度有点大啊 可以证明当第一次转向之 ...

  8. AtCoder Grand Contest 031题解

    题面 传送门 题解 比赛的之后做完\(AB\)就开始发呆了--简直菜的一笔啊-- \(A - Colorful\ Subsequence\) 如果第\(i\)个字母选,那么它前面任意一个别的字母的选择 ...

  9. AtCoder Grand Contest 017 迟到记

    晚上去操场上浪. 回来以后看到好几个人开着 \(AtCoder\) 在打代码. ... ... 今天有 \(AtCoder\) 比赛 ? 管它呢, \(Kito\) 在切西瓜,先吃西瓜... 然后看 ...

随机推荐

  1. iptables配置顺序-两条规则会忽略后边的

    oracle在centos本机能够正常访问,关闭防火墙也能够远程访问,但是一旦开启防火墙则不能远程访问 尝试添加规则iptables -A INPUT -m state --state NEW -m ...

  2. 使用mysqldump迁移数据

    1. 先停止业务,使用MySQLdump的数据导出工具,将您线下原有数据库数据导出为数据文件 mysqldump -hlocalhost -uroot --default-character-set= ...

  3. Java通过JDBC操作Hive

    http://www.cnblogs.com/netbloomy/p/6688670.html 0.概述 使用的都是CLI或者hive –e的方式仅允许使用HiveQL执行查询.更新等操作.然而Hiv ...

  4. 配置可对外链接的Redis

    链接服务器的Redis telnet 192.168.1.200 6379 Trying 192.168.1.200... telnet: Unable to connect to remote ho ...

  5. scala学习手记27 - 下划线与参数

    在Scala里,下划线(_)可以表示函数值的参数.如果某个参数在函数里仅使用一次,就可以用下划线表示.每次在函数里用下划线,都表示随后的参数. val arr = Array(1, 2, 3, 4, ...

  6. 入门教程:.NET开源OpenID Connect 和OAuth解决方案IdentityServer v3 介绍 (一)

    现代的应用程序看起来像这样: 典型的交互操作包括: 浏览器与 web 应用程序进行通信 Web 应用程序与 web Api (有时是在他们自己的有时代表用户) 通信 基于浏览器的应用程序与 web A ...

  7. d2.js学习笔记(七)——动态SVG坐标空间

    目标 在这一章,我们将学习如何使SVG坐标空间是动态的,这样我们的数据可视化不论数据是什么,都始终是可见的. 我们会使得SVG坐标空间尺度上调或下调来适于我们的数据. 三个SVG长方形 我们就从三个长 ...

  8. 调用http接口的工具类

    网上面有很多,但是我们项目怎么也调不到结果,试了差不多很多案例,都是报connection reset 后来,我发现是有一个验证,需要跳过验证.然后才能调接口.所以找了一个忽略https的方法.进行改 ...

  9. Django进阶Admin篇 - admin基本配置

    django admin 是django自带的一个后台app,提供了后台的管理功能. 基础知识点: 一.认识ModelAdmin 管理界面的定制类,如需扩展特定的model界面,需要从该类继承 二.注 ...

  10. 八 web爬虫讲解2—urllib库爬虫—ip代理—用户代理和ip代理结合应用

    使用IP代理 ProxyHandler()格式化IP,第一个参数,请求目标可能是http或者https,对应设置build_opener()初始化IPinstall_opener()将代理IP设置成全 ...