【AtCoder】ARC079
ARC079题解
C - Cat Snuke and a Voyage
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
res = 0;char c = getchar();T f = 1;
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N,M;
bool vis[MAXN];
vector<int> to[MAXN];
void Solve() {
read(N);read(M);
int a,b;
vis[N] = 1;
for(int i = 1 ; i <= M ; ++i) {
read(a);read(b);
if(a > b) swap(a,b);
if(b == N) vis[a] = 1;
to[a].pb(b);to[b].pb(a);
}
if(vis[1]) {puts("POSSIBLE");return;}
for(auto k : to[1]) {
if(vis[k]) {puts("POSSIBLE");return;}
}
puts("IMPOSSIBLE");
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
D - Decrease (Contestant ver.)
由于发现一个1,2,3,4,5,6,7....N的序列一次操作后可以变成
2,3,4,5,6,7...N,0的序列,这样N次过后,总会得到所有数-1的序列
也就是,我可以进行那么多次,序列可以构造成\(K / N\)开始加1到N的序列,就是可以进行\(\lfloor \frac{K}{N} \rfloor N\)那么多次了
剩下的就从头开始逆着往回加即可
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
res = 0;char c = getchar();T f = 1;
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N;
int64 a[55],K;
void Solve() {
read(K);
N = 50;
a[1] = K / N;
for(int i = 2 ; i <= N ; ++i) {
a[i] = a[i - 1] + 1;
}
int t = K % N;
for(int i = 1 ; i <= t ; ++i) {
a[i] += N;
for(int j = 1 ; j <= N ; ++j) {
if(i != j) a[j]--;
}
}
out(N);enter;
for(int i = 1 ; i <= N ; ++i) {
out(a[i]);space;
}
enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
E - Decrease (Judge ver.)
进行一次操作我们直接把最大的扣到N以下,暴力进行几次复杂度不会太大
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
res = 0;char c = getchar();T f = 1;
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N;
int64 a[55],ans;
void Solve() {
read(N);
for(int i = 1 ; i <= N ; ++i) read(a[i]);
while(1) {
int t = 1;
for(int i = 2 ; i <= N ; ++i) {
if(a[i] > a[t]) t = i;
}
if(a[t] < N) break;
int64 k = (a[t] - (N - 1) - 1) / N + 1;
a[t] -= k * N;
ans += k;
for(int i = 1 ; i <= N ; ++i) {
if(i != t) a[i] += k;
}
}
out(ans);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
F - Namori Grundy
若连通还每个点就一个入度,那这是一个有向的基环外向树
把环上挂着的数给dp完,相当于每次对于儿子取一个未出现过的最小值一样的操作
然后环上的点要么取自己未出现过的最小值,要么取把这个最小值填上之后下一个没出现过的
也就是环上前一个点如果选择下一个点的第一选项,下一个点必须选择第二选项
把环上每个点拆成两个点,按照这种关系连边,出现大小恰好为原来环点数的环时合法,如果无环或有一个二倍点数的环就不合法
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
res = 0;char c = getchar();T f = 1;
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N,p[MAXN],deg[MAXN],val[MAXN];
int id[MAXN][2],tot,cir;
vector<int> t[MAXN],to[MAXN * 2];
vector<int> son[MAXN];
queue<int> q;
int dfn[MAXN * 2],low[MAXN * 2],sta[MAXN * 2],instack[MAXN * 2],idx,top;
bool flag = 0;
void Tarjan(int u) {
dfn[u] = low[u] = ++idx;
sta[++top] = u;instack[u] = 1;
for(auto v : to[u]) {
if(!dfn[v]) {Tarjan(v);low[u] = min(low[v],low[u]);}
else if(instack[u] == 1){
low[u] = min(low[u],dfn[v]);
}
}
if(low[u] == dfn[u]) {
int k = 0;
while(1) {
int x = sta[top--];
++k;
instack[x] = 2;
if(x == u) break;
}
if(k == cir) flag = 1;
}
}
void Solve() {
read(N);
for(int i = 1 ; i <= N ; ++i) {
read(p[i]);
deg[p[i]]++;
}
for(int i = 1 ; i <= N ; ++i) {
if(!deg[i]) q.push(i);
}
while(!q.empty()) {
int u = q.front();q.pop();
sort(son[u].begin(),son[u].end());
son[u].erase(unique(son[u].begin(),son[u].end()),son[u].end());
int m = 0;
while(m < son[u].size()) {
if(son[u][m] != m) break;
++m;
}
son[p[u]].pb(m);
if(!--deg[p[u]]) {
q.push(p[u]);
}
}
for(int i = 1 ; i <= N ; ++i) {
if(deg[i]) {
sort(son[i].begin(),son[i].end());
son[i].erase(unique(son[i].begin(),son[i].end()),son[i].end());
int m = 0,pos = 0;
while(1) {
if(pos >= son[i].size() || son[i][pos] != m) {
t[i].pb(m);
if(t[i].size() < 2) {++m;}
else break;
}
else {pos++;++m;}
}
id[i][0] = ++tot;id[i][1] = ++tot;
++cir;
}
}
for(int i = 1 ; i <= N ; ++i) {
if(deg[i]) {
int f = p[i];
to[id[f][0]].pb(id[i][t[f][0] == t[i][0]]);
to[id[f][1]].pb(id[i][t[f][1] == t[i][0]]);
}
}
for(int i = 1 ; i <= tot ; ++i) {
if(!dfn[i]) Tarjan(i);
}
if(flag) puts("POSSIBLE");
else puts("IMPOSSIBLE");
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
【AtCoder】ARC079的更多相关文章
- 【AtCoder】ARC092 D - Two Sequences
[题目]AtCoder Regular Contest 092 D - Two Sequences [题意]给定n个数的数组A和数组B,求所有A[i]+B[j]的异或和(1<=i,j<=n ...
- 【Atcoder】CODE FESTIVAL 2017 qual A D - Four Coloring
[题意]给定h,w,d,要求构造矩阵h*w满足任意两个曼哈顿距离为d的点都不同色,染四色. [算法]结论+矩阵变换 [题解] 曼哈顿距离是一个立着的正方形,不方便处理.d=|xi-xj|+|yi-yj ...
- 【AtCoder】ARC 081 E - Don't Be a Subsequence
[题意]给定长度为n(<=2*10^5)的字符串,求最短的字典序最小的非子序列字符串. http://arc081.contest.atcoder.jp/tasks/arc081_c [算法]字 ...
- 【AtCoder】AGC022 F - Leftmost Ball 计数DP
[题目]F - Leftmost Ball [题意]给定n种颜色的球各k个,每次以任意顺序排列所有球并将每种颜色最左端的球染成颜色0,求有多少种不同的颜色排列.n,k<=2000. [算法]计数 ...
- 【AtCoder】AGC005 F - Many Easy Problems 排列组合+NTT
[题目]F - Many Easy Problems [题意]给定n个点的树,定义S为大小为k的点集,则f(S)为最小的包含点集S的连通块大小,求k=1~n时的所有点集f(S)的和取模92484403 ...
- 【AtCoder】ARC067 F - Yakiniku Restaurants 单调栈+矩阵差分
[题目]F - Yakiniku Restaurants [题意]给定n和m,有n个饭店和m张票,给出Ai表示从饭店i到i+1的距离,给出矩阵B(i,j)表示在第i家饭店使用票j的收益,求任选起点和终 ...
- 【AtCoder】ARC095 E - Symmetric Grid 模拟
[题目]E - Symmetric Grid [题意]给定n*m的小写字母矩阵,求是否能通过若干行互换和列互换使得矩阵中心对称.n,m<=12. [算法]模拟 [题解]首先行列操作独立,如果已确 ...
- 【Atcoder】AGC022 C - Remainder Game 搜索
[题目]C - Remainder Game [题意]给定n个数字的序列A,每次可以选择一个数字k并选择一些数字对k取模,花费2^k的代价.要求最终变成序列B,求最小代价或无解.n<=50,0& ...
- 【Atcoder】AGC 020 B - Ice Rink Game 递推
[题意]n个人进行游戏,每轮只保留最大的a[i]倍数的人,最后一轮过后剩余2人,求最小和最大的n,或-1.n<=10^5. [算法]递推||二分 [题解]令L(i),R(i)表示第i轮过后的最小 ...
随机推荐
- Django-常用异常
1 from rest_framework.authentication import BasicAuthentication raise AuthenticationFailed(res.dict) ...
- 微服务springboot视频最新SpringBoot2.0.3版本技术视频教程【免费学习】
超火爆的springboot微服务技术怎么学,看这里,springboot超详细的教程↓↓↓↓↓↓https://ke.qq.com/course/179440?tuin=9b386640 01.sp ...
- 1617:转圈游戏 ybt
1617:转圈游戏 时间限制: 1000 ms 内存限制: 524288 KB提交数: 540 通过数: 326 [题目描述] nn 个小伙伴(编号从 00 到 n−1n−1 ...
- PyTricks-How to Sort a Python dict
字典的键值排序 import operator # 1表示按照值排序 xs = {"a": 4, "b": 3, "c": 2, " ...
- Pluck CMS 4.7.10远程代码执行漏洞分析
本文首发于先知: https://xz.aliyun.com/t/6486 0x01漏洞描述 Pluck是用php编写的一款的小型CMS影响版本:Pluck CMS Pluck CMS 4.7.10( ...
- js返回函数, 函数名后带多个括号的用法及join()的注意事项
内容 题目描述 输入 输出 题目描述 实现函数 functionFunction,调用之后满足如下条件: 1.返回值为一个函数 f 2.调用返回的函数 f,返回值为按照调用顺序的参数拼接,拼接字符为英 ...
- Flutter移动电商实战 --(34)列表页_小BUG的修复
当高粱酒的子类没有数据返回的时候就会报错. 解决接口空数据报错的问题 没有数据的时候,给用户一个友好的提示, 我们没有数据的时候还要告诉用户,提示一下他没有数据,在我们的右侧列表的build方法内去判 ...
- 三、Navicat将远程MySql数据库数据导入本地
1.安装本地的MySql.记住用户名和密码,这里以root,root为例. 2.打开Navicat,新建连接(连接),输入连接名,用户名,密码.确定,连接测试.这里连接名为luzhanshi.这样本地 ...
- SQL-W3School-高级:SQL UNIQUE 约束
ylbtech-SQL-W3School-高级:SQL UNIQUE 约束 1.返回顶部 1. SQL UNIQUE 约束 UNIQUE 约束唯一标识数据库表中的每条记录. UNIQUE 和 PRIM ...
- SQL-W3School-高级:SQL 约束(Contraints)
ylbtech-SQL-W3School-高级:SQL 约束(Contraints) 1.返回顶部 1. SQL 约束 约束用于限制加入表的数据的类型. 可以在创建表时规定约束(通过 CREATE T ...