【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轮过后的最小 ...
随机推荐
- 【线性代数】5-2:置换和余因子(Permutations and Cofactors)
title: [线性代数]5-2:置换和余因子(Permutations and Cofactors) categories: Mathematic Linear Algebra keywords: ...
- AE开发之默认滚轮缩放功能反置(C#修改注册表数据)
ArcMap默认的滚轮缩放是向下放大,向上缩小 如果想修改成向上放大,向下缩小,直接在ArcMap-Customize-ArcMap Options里, 将最下面的Mouse Wheel and Co ...
- ORM SQLAlchemy 简介
对象关系映射(Object Relational Mapping,简称ORM使用DB-API访问数据库,需要懂 SQL 语言,能够写 SQL 语句,如果不想懂 SQL,又想使用关系型数据库,可以使用 ...
- THREE.js(一)
//创建场景 var scene = new THREE.Scene(); //透视摄像机(视野角度,长宽比,远剪切面,进剪切面,) var camera = new THREE.Perspectiv ...
- kotlin之map委托
fun main(arg: Array<String>) { val map = mapOf("name" to "tom", ) val user ...
- Editplus的运行JAVA的配置
工具--->参数设置
- Java 正则判断一个字符串中是否包含中文
使用正则判断一个字符串中是否包含中文或者中文字符 代码实现如下: import java.util.regex.Matcher; import java.util.regex.Pattern; /** ...
- Sql 中常用日期转换Convert(Datetime) convert datetime
Convert(data_type,expression[,style]) Convert(varchar(10),字段名,转换格式) 说明:此样式一般在时间类型(datetime,smalldate ...
- laravel 自带消息notification通知
原文地址:https://blog.csdn.net/zhangxh1013/article/details/53130490
- Mysql按照设计顺序获得某个表的字段名称,字段类型,字段描述!!!!!
编写sql语句 select column_name,data_type ,column_comment from information_schema.columns where table_nam ...