链接

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的更多相关文章

  1. AtCoder Regular Contest 061

    AtCoder Regular Contest 061 C.Many Formulas 题意 给长度不超过\(10\)且由\(0\)到\(9\)数字组成的串S. 可以在两数字间放\(+\)号. 求所有 ...

  2. AtCoder Regular Contest 094 (ARC094) CDE题解

    原文链接http://www.cnblogs.com/zhouzhendong/p/8735114.html $AtCoder\ Regular\ Contest\ 094(ARC094)\ CDE$ ...

  3. AtCoder Regular Contest 092

    AtCoder Regular Contest 092 C - 2D Plane 2N Points 题意: 二维平面上给了\(2N\)个点,其中\(N\)个是\(A\)类点,\(N\)个是\(B\) ...

  4. AtCoder Regular Contest 093

    AtCoder Regular Contest 093 C - Traveling Plan 题意: 给定n个点,求出删去i号点时,按顺序从起点到一号点走到n号点最后回到起点所走的路程是多少. \(n ...

  5. AtCoder Regular Contest 094

    AtCoder Regular Contest 094 C - Same Integers 题意: 给定\(a,b,c\)三个数,可以进行两个操作:1.把一个数+2:2.把任意两个数+1.求最少需要几 ...

  6. AtCoder Regular Contest 095

    AtCoder Regular Contest 095 C - Many Medians 题意: 给出n个数,求出去掉第i个数之后所有数的中位数,保证n是偶数. \(n\le 200000\) 分析: ...

  7. AtCoder Regular Contest 102

    AtCoder Regular Contest 102 C - Triangular Relationship 题意: 给出n,k求有多少个不大于n的三元组,使其中两两数字的和都是k的倍数,数字可以重 ...

  8. AtCoder Regular Contest 096

    AtCoder Regular Contest 096 C - Many Medians 题意: 有A,B两种匹萨和三种购买方案,买一个A,买一个B,买半个A和半个B,花费分别为a,b,c. 求买X个 ...

  9. AtCoder Regular Contest 097

    AtCoder Regular Contest 097 C - K-th Substring 题意: 求一个长度小于等于5000的字符串的第K小子串,相同子串算一个. K<=5. 分析: 一眼看 ...

随机推荐

  1. NB二人组(二)----归并排序

    归并排序的思路: 归并算法程序(配合下图进行思考): def merge(li,low,mid,high): i = low j = mid + 1 ltmp=[] while i <= mid ...

  2. CAD启动提示"是否关闭命令行"不管点击什么,都会闪退的解决办法

    AutoCAD splash screen starts up and then closes   AutoCAD splash screen starts up and then closes (S ...

  3. 64_q2

    qt3-3.3.8b-69.fc26.x86_64.rpm 13-Feb-2017 01:37 3591906 qt3-MySQL-3.3.8b-69.fc26.i686.rpm 13-Feb-201 ...

  4. linux配置samba服务【原创】

    转载请注明出处http://www.cnblogs.com/paul8339/p/7509981.html 需求,windows服务器访问linux的共享文件,需要linux服务器安装并配置samba ...

  5. URAL 2078~2089

    URAL 2078~2089 A - Bowling game 题目描述:给出保龄球每一局击倒的球数,按照保龄球的规则,算出总得分的最小值和最大值. solution 首先是最小值:每一局第一球击倒\ ...

  6. 003iptables 命令介绍

    http://www.cnblogs.com/wangkangluo1/archive/2012/04/19/2457072.html iptables 防火墙可以用于创建过滤(filter)与NAT ...

  7. C# 怎么显示中文格式的日期、星期几

    //该语句显示的为英文格式DateTime.Now.DayOfWeek.ToString(); //显示中文格式星期几 "星期" + DateTime.Now.ToString(& ...

  8. HDU 1255 覆盖的面积(线段树:扫描线求面积并)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1255 题目大意:给你若干个矩形,让你求这些矩形重叠两次及以上的部分的面积. 解题思路:模板题,跟HDU ...

  9. 20165301 2017-2018-2 《Java程序设计》第八周学习总结

    20165301 2017-2018-2 <Java程序设计>第八周学习总结 教材学习内容总结 第十二章:Java多线程机制 进程与线程 操作系统与进程:进程是程序的一次动态执行过程. 进 ...

  10. JAVA邻接矩阵实现拓扑排序

    由于一直不适用邻接表 ,现在先贴一段使用邻接矩阵实现图的拓扑排序以及判断有无回路的问题.自己做的图.将就看吧. package TopSort; import java.util.LinkedList ...