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

  1. 【AtCoder】ARC092 D - Two Sequences

    [题目]AtCoder Regular Contest 092 D - Two Sequences [题意]给定n个数的数组A和数组B,求所有A[i]+B[j]的异或和(1<=i,j<=n ...

  2. 【Atcoder】CODE FESTIVAL 2017 qual A D - Four Coloring

    [题意]给定h,w,d,要求构造矩阵h*w满足任意两个曼哈顿距离为d的点都不同色,染四色. [算法]结论+矩阵变换 [题解] 曼哈顿距离是一个立着的正方形,不方便处理.d=|xi-xj|+|yi-yj ...

  3. 【AtCoder】ARC 081 E - Don't Be a Subsequence

    [题意]给定长度为n(<=2*10^5)的字符串,求最短的字典序最小的非子序列字符串. http://arc081.contest.atcoder.jp/tasks/arc081_c [算法]字 ...

  4. 【AtCoder】AGC022 F - Leftmost Ball 计数DP

    [题目]F - Leftmost Ball [题意]给定n种颜色的球各k个,每次以任意顺序排列所有球并将每种颜色最左端的球染成颜色0,求有多少种不同的颜色排列.n,k<=2000. [算法]计数 ...

  5. 【AtCoder】AGC005 F - Many Easy Problems 排列组合+NTT

    [题目]F - Many Easy Problems [题意]给定n个点的树,定义S为大小为k的点集,则f(S)为最小的包含点集S的连通块大小,求k=1~n时的所有点集f(S)的和取模92484403 ...

  6. 【AtCoder】ARC067 F - Yakiniku Restaurants 单调栈+矩阵差分

    [题目]F - Yakiniku Restaurants [题意]给定n和m,有n个饭店和m张票,给出Ai表示从饭店i到i+1的距离,给出矩阵B(i,j)表示在第i家饭店使用票j的收益,求任选起点和终 ...

  7. 【AtCoder】ARC095 E - Symmetric Grid 模拟

    [题目]E - Symmetric Grid [题意]给定n*m的小写字母矩阵,求是否能通过若干行互换和列互换使得矩阵中心对称.n,m<=12. [算法]模拟 [题解]首先行列操作独立,如果已确 ...

  8. 【Atcoder】AGC022 C - Remainder Game 搜索

    [题目]C - Remainder Game [题意]给定n个数字的序列A,每次可以选择一个数字k并选择一些数字对k取模,花费2^k的代价.要求最终变成序列B,求最小代价或无解.n<=50,0& ...

  9. 【Atcoder】AGC 020 B - Ice Rink Game 递推

    [题意]n个人进行游戏,每轮只保留最大的a[i]倍数的人,最后一轮过后剩余2人,求最小和最大的n,或-1.n<=10^5. [算法]递推||二分 [题解]令L(i),R(i)表示第i轮过后的最小 ...

随机推荐

  1. 「CF716D」Complete The Graph「最短路」

    题意 给定一个\(n\)个点\(m\)条边的无向图,有一些边权暂时为\(0\),你需要分配一个\([1, 10^{18}]\)的数.最终使得\(s\)到\(t\)最短路为\(L\),输出一个可行的分配 ...

  2. (转)实验文档3:在kubernetes集群里集成Apollo配置中心

    使用ConfigMap管理应用配置 拆分环境 主机名 角色 ip HDSS7-11.host.com zk1.od.com(Test环境) 10.4.7.11 HDSS7-12.host.com zk ...

  3. 1-4CMYK色彩模式

    http://www.missyuan.com/thread-350717-1-1.html CMYK也称作印刷色彩模式,顾名思义就是用来印刷的. 只要是在印刷品上看到的图像,就是CMYK模式表现的 ...

  4. nginx 部署php

    一:nginx安装: yum install nginx 安装完成即可,在/usr/sbin/目录下是nginx命令所在目录,在/etc/nginx/目录下是nginx所有的配置文件,用于配置ngin ...

  5. js/jQuery中的宽高

    一.和window有关的宽高 window.innerWidth:浏览器窗口宽度 window.innerHeight:浏览器窗口高度(不包括导航,工具栏等的高度) window.outerWidth ...

  6. Colab 实用教程

    Google Colab 是什么? Google Colab 是一个免费的云服务,现在它还支持免费的 GPU! 你可以: 提高你的 Python 语言的编码技能. 使用 Keras.TensorFlo ...

  7. 黑马vue---61、为什么vue组件的data要是一个函数

    黑马vue---61.为什么vue组件的data要是一个函数 一.总结 一句话总结: 因为js中以函数为变量作用域,所以这样可以保证每个组件的数据不互相影响 二.why components data ...

  8. nodeJS 项目如何运行

    nodeJS 项目如何运行 一.总结 一句话总结: nodejs项目根目录中用node xx.js 或是 node xx运行 打开 window的 cmd 命令窗口,使用 cd 命令跳转到 nodeJ ...

  9. geth 新建账户

    使用geth的account命令管理账户,例如创建新账户.更新账户密码.查询账户等: geth account <command> [options...] [arguments...] ...

  10. Infralution.Localization.Wpf

    WPF Localization Using RESX Files Once you have downloaded the source code and built it, add a refer ...