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. 分析: 一眼看 ...
随机推荐
- Stat3—因子分析(Factor Analysis)
题注:主成分分析分析与因子分析也有不同,主成分分析仅仅是变量变换,而因子分析需要构造因子模型.主成分分析:原始变量的线性组合表示新的综合变量,即主成分:因子分析:潜在的假想变量和随机影响变量的线性组合 ...
- 51nod 1120 机器人走方格 V3
N * N的方格,从左上到右下画一条线.一个机器人从左上走到右下,只能向右或向下走. 并要求只能在这条线的上面或下面走,不能穿越这条线,有多少种不同的走法? 由于方法数量可能很大,只需要输出Mod 1 ...
- 【BZOJ】1426: 收集邮票 期望DP
[题意]有n种不同的邮票,第i次可以花i元等概率购买到一种邮票,求集齐n种邮票的期望代价.n<=10^4. [算法]期望DP [题解]首先设g[i]表示已拥有i张邮票集齐的期望购买次数,根据全期 ...
- C - Contest Setting Gym - 101982C dp 补题
题目链接:https://vjudge.net/contest/273260#problem/C 学习了一下别人的思路,首先去重,然后离散化. dp数组开二维,每一次更新,状态转移方程,dp[ i ] ...
- 使用showplan.sql分析sql Performance
在HelloDBA网站找到一个分析sql性能的工具-showplan,记录一下 showplan.sql下载路径:http://www.HelloDBA.com/Download/showplan.z ...
- Linux运维常用的几个命令介绍【转】
Linux运维常用的几个命令介绍 1. 查看系统内核版本 [root@funsion geekxa]# cat /etc/issue CentOS release 6.5 (Final) Kerne ...
- UIScrollViewDelegate 方法调用
UIScrollViewDelegate 方法调用 /** 设置缩放的View, 初始化完之后调用此方法告诉scrollView 谁可以缩放操作, 然后进行布局 */ func viewForZoom ...
- TCP的状态兼谈Close_Wait和Time_Wait的状态
原文链接: http://www.2cto.com/net/201208/147485.html TCP的状态兼谈Close_Wait和Time_Wait的状态 一 TCP的状态: 1).LIST ...
- javascript当中的this详解
总结this的3个规则: this是调用上下文,上下文被创建或者初始化时才确定 非严格模式:this是全局对象:严格模式:this是undefined 函数调用 a. 以函数形式调用的函数通常不使用t ...
- 计算 Python (list or array) 相同索引元素相等的个数
上代码: a = [2, 3, 3, 1, 1, 3, 3, 3, 2, 1, 3, 1, 3, 2, 2, 2, 3, 1, 2, 3, 2, 3, 1, 1, 2, 1, 1, 1, 2, 2, ...