AtCoder Regular Contest 80
C. 4-adjacent
给定序列$a_i$,询问是否存在一个排列,满足$a_{p[i]}* a_{p[i + 1]}$是4的倍数
贪心构造
首先把只是2的倍数的数拿出来,放在最右边
前面把是1的倍数的数和是4的倍数的数交替放置即可
之后随意判断即可
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std; extern inline char gc() {
static char RR[], *S = RR + , *T = RR + ;
if(S == T) fread(RR, , , stdin), S = RR;
return *S ++;
}
inline int read() {
int p = , w = ; char c = gc();
while(c > '' || c < '') { if(c == '-') w = -; c = gc(); }
while(c >= '' && c <= '') p = p * + c - '', c = gc();
return p * w;
} #define ri register int
int n, n2, n4, flag; int main() {
n = read();
for(ri i = ; i <= n; i ++) {
int x = read();
if(x % == ) n4 ++;
else if(x % == ) n2 ++;
}
n -= n2;
if(n & ) {
if(n2) flag = (n4 > n / );
else flag = (n4 >= n / );
}
else flag = (n4 >= n / );
if(flag) printf("Yes\n");
else printf("No\n");
return ;
}
D.Grid Coloring
对$R*W$的格子进行染色,需要使颜色$i$的出现次数为$c_i$
且同一颜色形成联通块,询问是否可行并给出一组方案
S形涂色即可
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; #define ri register int
#define sid 105 int H, W, n, id;
int col[sid][sid], ord[sid * sid]; int main() {
scanf("%d%d%d", &H, &W, &n);
for(ri i = ; i <= n; i ++) {
int x; scanf("%d", &x);
while(x --) ord[++ id] = i;
}
id = ;
for(ri i = ; i <= H; i ++)
for(ri j = ; j <= W; j ++)
col[i][j] = ord[++ id];
for(ri i = ; i <= H; i += )
reverse(col[i] + , col[i] + W + );
for(ri i = ; i <= H; i ++, printf("\n"))
for(ri j = ; j <= W; j ++)
printf("%d ", col[i][j]);
return ;
}
E.Young Maids
题意略复杂,直接看原题面吧...
从前往后去贪心
每次选择的一定是某个区间中的奇(偶)最小值后其后的偶(奇)最小值
注意奇偶的判断即可
复杂度$O(n \log n)$
一开始表示平衡树裸题,然后点开题解,还是打st表吧
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; extern inline char gc() {
static char RR[], *S = RR + , *T = RR + ;
if(S == T) fread(RR, , , stdin), S = RR;
return *S ++;
}
inline int read() {
int p = , w = ; char c = gc();
while(c > '' || c < '') { if(c == '-') w = -; c = gc(); }
while(c >= '' && c <= '') p = p * + c - '', c = gc();
return p * w;
} #define sid 200050
#define inf 1e9
#define ri register int int n;
int bit[sid], l_g[sid];
int st[sid][][], v[sid][], arc[sid]; void Init() {
for(ri i = ; i <= ; i ++) bit[i] = << i;
for(ri i = ; i <= n; i ++) l_g[i] = l_g[i >> ] + ;
for(ri o = ; o <= ; o ++)
for(ri i = ; i <= n; i ++) st[i][][o] = v[i][o];
for(ri o = ; o <= ; o ++)
for(ri j = ; bit[j] <= n; j ++)
for(ri i = ; i + bit[j] - <= n; i ++)
st[i][j][o] = min(st[i][j - ][o], st[i + bit[j - ]][j - ][o]);
} inline int rmq(int l, int r, int o) {
int lg = l_g[r - l + ];
return min(st[l][lg][o], st[r - bit[lg] + ][lg][o]);
} struct Seg {
int v, l, r;
friend bool operator < (Seg a, Seg b)
{ return a.v > b.v; }
};
priority_queue <Seg> q; int main() {
n = read();
for(ri i = ; i <= n; i ++) {
int w = (v[i][(i ^ ) & ] = read());
v[i][i & ] = inf; arc[w] = i;
}
Init();
q.push({ rmq(, n, ), , n });
while(!q.empty()) {
Seg tmp = q.top(); q.pop();
int w1 = tmp.v, pw1 = arc[w1];
int w2 = rmq(pw1 + , tmp.r, pw1 & ), pw2 = arc[w2];
printf("%d %d ", w1, w2);
if(tmp.l != pw1) q.push({ rmq(tmp.l, pw1 - , (tmp.l + ) & ), tmp.l, pw1 - });
if(pw1 + != pw2) q.push({ rmq(pw1 + , pw2 - , pw1 & ), pw1 + , pw2 - });
if(pw2 != tmp.r) q.push({ rmq(pw2 + , tmp.r, pw2 & ), pw2 + , tmp.r });
}
return ;
}
F.Prime Flip
有$n$个位置的牌向上,
每次可以选定一段长为$p$($p$为奇质数)的区间,翻转这个区间
询问最少几次能使所有牌向下
考虑构造新序列$e_i = [a_i = a_{i + 1}]$,$a_i$表示向上还是向下
当$e_i$全部为0时,原序列全部向下
那么,原题的区间操作转化为同时对两个点翻转
两个点匹配有3种情况
1.相差为奇质数,需要1次
2.相差为偶数,需要2次
3.否则,需要3次
对于第一种情况,做二分图匹配
第二种情况,讨论
第三种情况,讨论
对我而言是神题,不会做.....
然而有一堆AK的神仙....
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; #define ri register int
#define ssd 10000010
#define sid 205 int n, N = 1e7;
int pr[ssd / ], tot;
int nj, no, js[sid], os[sid];
bool nop[ssd], e[ssd]; int tim, vis[sid], mat[sid];
bool ex[sid][sid]; inline void Init() {
nop[] = ;
for(ri i = ; i <= N + ; i ++) {
if(!nop[i]) pr[++ tot] = i;
for(ri j = ; j <= tot; j ++) {
int nx = i * pr[j]; if(nx > N + ) break;
nop[nx] = ; if(i % pr[j] == ) break;
}
}
nop[] = ;
} inline int dfs(int o) {
for(int i = ; i <= no; i ++)
if(ex[o][i] && vis[i] != tim) {
vis[i] = tim;
if(!mat[i] || dfs(mat[i]))
return mat[i] = o, ;
}
return ;
} int main() {
Init();
cin >> n;
for(ri i = ; i <= n; i ++) { int x; cin >> x; e[x] = ; } for(ri i = ; i <= N + ; i ++)
if(e[i] != e[i - ]) {
if(i & ) js[++ nj] = i;
else os[++ no] = i;
} for(ri i = ; i <= nj; i ++)
for(ri j = ; j <= no; j ++)
if(!nop[abs(js[i] - os[j])]) ex[i][j] = ; int num = , ans = ; for(ri i = ; i <= nj; i ++)
++ tim, num += dfs(i); nj -= num; no -= num;
ans = num + nj / * + no / * + (nj & ) * ;
printf("%d\n", ans);
return ;
}
AtCoder Regular Contest 80的更多相关文章
- AtCoder Regular Contest 061
AtCoder Regular Contest 061 C.Many Formulas 题意 给长度不超过\(10\)且由\(0\)到\(9\)数字组成的串S. 可以在两数字间放\(+\)号. 求所有 ...
- AtCoder Regular Contest 094 (ARC094) CDE题解
原文链接http://www.cnblogs.com/zhouzhendong/p/8735114.html $AtCoder\ Regular\ Contest\ 094(ARC094)\ CDE$ ...
- AtCoder Regular Contest 092
AtCoder Regular Contest 092 C - 2D Plane 2N Points 题意: 二维平面上给了\(2N\)个点,其中\(N\)个是\(A\)类点,\(N\)个是\(B\) ...
- AtCoder Regular Contest 093
AtCoder Regular Contest 093 C - Traveling Plan 题意: 给定n个点,求出删去i号点时,按顺序从起点到一号点走到n号点最后回到起点所走的路程是多少. \(n ...
- AtCoder Regular Contest 094
AtCoder Regular Contest 094 C - Same Integers 题意: 给定\(a,b,c\)三个数,可以进行两个操作:1.把一个数+2:2.把任意两个数+1.求最少需要几 ...
- AtCoder Regular Contest 095
AtCoder Regular Contest 095 C - Many Medians 题意: 给出n个数,求出去掉第i个数之后所有数的中位数,保证n是偶数. \(n\le 200000\) 分析: ...
- AtCoder Regular Contest 102
AtCoder Regular Contest 102 C - Triangular Relationship 题意: 给出n,k求有多少个不大于n的三元组,使其中两两数字的和都是k的倍数,数字可以重 ...
- AtCoder Regular Contest 096
AtCoder Regular Contest 096 C - Many Medians 题意: 有A,B两种匹萨和三种购买方案,买一个A,买一个B,买半个A和半个B,花费分别为a,b,c. 求买X个 ...
- AtCoder Regular Contest 097
AtCoder Regular Contest 097 C - K-th Substring 题意: 求一个长度小于等于5000的字符串的第K小子串,相同子串算一个. K<=5. 分析: 一眼看 ...
随机推荐
- 【BZOJ】4358: permu 莫队算法
[题意]给定长度为n的排列,m次询问区间[L,R]的最长连续值域.n<=50000. [算法]莫队算法 [题解]考虑莫队维护增加一个数的信息:设up[x]表示数值x往上延伸的最大长度,down[ ...
- 转:国内优秀npm镜像推荐及使用
原文:http://riny.net/2014/cnpm/ npm全称Node Package Manager,是node.js的模块依赖管理工具.由于npm的源在国外,所以国内用户使用起来各种不方便 ...
- 【leetcode 简单】第三十二题 买卖股票的最佳时机Ⅱ
给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格. 设计一个算法来计算你所能获取的最大利润.你可以尽可能地完成更多的交易(多次买卖一支股票). 注意:你不能同时参与多笔交易(你必须在再次 ...
- N-gram语言模型与马尔科夫假设关系(转)
1.从独立性假设到联合概率链朴素贝叶斯中使用的独立性假设为 P(x1,x2,x3,...,xn)=P(x1)P(x2)P(x3)...P(xn) 去掉独立性假设,有下面这个恒等式,即联合概率链规则 P ...
- 监控MYSQL主从同步配置中监控从库运行状态的脚本
代码如下: #!/bin/bash #Check MySQL Slave's Runnning Status #Crontab time 00:10 MYSQLPORT=`netstat -na|gr ...
- Python 库汇总中文版
这又是一个 Awesome XXX 系列的资源整理,由 vinta 发起和维护.内容包括:Web框架.网络爬虫.网络内容提取.模板引擎.数据库.数据可视化.图片处理.文本处理.自然语言处理.机器学习. ...
- IntelliJ IDEA 创建maven项目一次后,然后删除,再次保存到此目录下,提供此目录已经被占用的问题。
-------------------2017-02-14补充: 你看既然是创建过一次 不允许再次创建了,那么请问 第一次创建的 跑哪里去了,不仅仅是保存到了你指定的目录里,其实也默认安装到了 mav ...
- 三十分钟理解博弈论“纳什均衡” -- Nash Equilibrium
欢迎转载,转载请注明:本文出自Bin的专栏blog.csdn.net/xbinworld. 技术交流QQ群:433250724,欢迎对算法.技术感兴趣的同学加入. 纳什均衡(或者纳什平衡),Nash ...
- 深度学习方法(七):最新SqueezeNet 模型详解,CNN模型参数降低50倍,压缩461倍!
欢迎转载,转载请注明:本文出自Bin的专栏blog.csdn.net/xbinworld. 技术交流QQ群:433250724,欢迎对算法.技术感兴趣的同学加入. 继续前面关于深度学习CNN经典模型的 ...
- csu 1555(线段树经典插队模型-根据逆序数还原序列)
1555: Inversion Sequence Time Limit: 2 Sec Memory Limit: 256 MBSubmit: 469 Solved: 167[Submit][Sta ...