链接

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. TED_Topic1:Why we need to rethink capitalism

    Topic 1:Why we need to rethink capitalism By Paul Tudor Jones II # Background about our speaker      ...

  2. yii2 自动登录解读

    今日遇到一个需要将当前用户,全部登出系统(YII2框架制作)重新登录的需求 仔细回忆一遍,Yii2的登录流程,竟然有些不太明白,于是下午空闲时 重新看了下Yii2的用户登录源码 文件位于YII2项目下 ...

  3. H5调试工具 - weinre远程调试工具

    weinre 简介 weinre 是一款类似于firebug 和Web Inspector的网页调试工具, 它的不同之处在于可以用于进行远程调试,比如调试手机上面的网页. 安装 weinre(运行在n ...

  4. docker 镜像导入和导出

    使用 docker commit 即可把这个容器变为一个镜像 docker commit 8d93082a9ce1 ubuntu:myubuntu 这时候 docker 容器会被创建为一个新的 Ubu ...

  5. 15 - reduce-pratial偏函数-lsu_cache

    目录 介绍 1 reduce方法 2 partial方法(偏函数) 2.1 partial方法基本使用 2.2 partial原码分析 2.3 functools.warps实现分析 3 lsu_ca ...

  6. 读书笔记 effective c++ Item 4 确保对象被使用前进行初始化

    C++在对象的初始化上是变化无常的,例如看下面的例子: int x; 在一些上下文中,x保证会被初始化成0,在其他一些情况下却不能够保证.看下面的例子: class Point { int x,y; ...

  7. linux系统磁盘挂载

    1.查看系统磁盘挂载情况 fdisk -l 2.格式化磁盘 mkfs -t ext3 /dev/sdb 3.挂在磁盘 mount /dev/sdb /disk2 4.查看磁盘挂载情况 df -h 5. ...

  8. Firefox缓存文件夹位置设置及清除缓存方法

    地址栏敲入: about:config, 新建一个"browser.cache.disk.parent_directory", 并设置为你要的缓存文件夹, 例如:  "F ...

  9. str.format() 格式化字符串函数

    语法 它通过{}和:来代替%. “映射”示例 通过位置 In [1]: '{0},{1}'.format('kzc',18) Out[1]: 'kzc,18' In [2]: '{},{}'.form ...

  10. 以应用带动SDN发展(CDN峰会 工信部杨崑)(转)

    以应用带动SDN发展(CDN峰会 工信部杨崑)   SDNAP推荐:这是在亚太全媒体SDN峰会由工信部研究院秘书长杨崑做的关于SDN的一个演讲,本人认为主讲者通过对整 个信息服务体系的精简归纳总结,剥 ...