AGC032

A - Limited Insertion

这题就是从后面找一个最靠后而且当前可以放的,可以放的条件是它的前面正好放了它的数值-1个数

如果不符合条件就退出

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
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 a[MAXN],N,cnt[MAXN];
bool vis[MAXN];
void Solve() {
read(N);
for(int i = 1 ; i <= N ; ++i) read(a[i]);
for(int i = 1 ; i <= N ; ++i) {
int cnt = 0;
for(int j = 1 ; j < i ; ++j) {
if(a[j] <= a[i]) ++cnt;
}
if(cnt + 1 < a[i]) {puts("-1");return;}
}
for(int i = 1 ; i <= N ; ++i) {
cnt[0] = 0;
for(int j = 1 ; j <= N ; ++j) cnt[j] = cnt[j - 1] + vis[j];
for(int j = N ; j >= 1 ; --j) {
if(!vis[j] && cnt[j - 1] + 1 == a[j]) {
vis[j] = 1;
out(a[j]);enter;
break;
}
}
}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}

B - Balanced Neighbors

如果是偶数个,分成和相等的\(\frac{N}{2}\)份

如果是奇数个,最后一个点单独为一组,前\(N - 1\)个两个一组分成和相等的\(\frac{N - 1}{2}\)份

然后把一组作为一个点,建一个完全图,两组(一组1,2,一组3,4)之间连边就是

1-2,1-4,2-3,2-4

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
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;
vector<pii > v;
void Solve() {
read(N);
if(N & 1) {
for(int i = 1 ; i < N ; ++i) {
v.pb(mp(i,N));
}
--N;
}
for(int i = 1 ; i <= N ; ++i) {
for(int j = i + 1 ; j <= N ; ++j) {
if(i + j != N + 1) v.pb(mp(i,j));
}
}
out(v.size());enter;
for(auto t : v) {
out(t.fi);space;out(t.se);enter;
}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}

C - Three Circuits

必定存在一个欧拉回路

如果一个点有六个或以上点度必定存在

如果有三个点以上有四个点度必定存在

如果只有两个点有四个点度

那么如果这四条路都在这两个点之间,那么就无解

否则有解

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
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);
}
struct node {
int to,next;
}E[MAXN * 2];
int head[MAXN],sumE;
int N,M;
int cnt[MAXN];
bool vis[MAXN];
void add(int u,int v) {
E[++sumE].to = v;
E[sumE].next = head[u];
head[u] = sumE;
}
void dfs(int u) {
vis[u] = 1;
for(int i = head[u] ; i ; i = E[i].next) {
int v = E[i].to;
if(!vis[v]) dfs(v);
}
}
void Solve() {
read(N);read(M);
int a,b;
for(int i = 1 ; i <= M ; ++i) {
read(a);read(b);
cnt[a]++;cnt[b]++;
add(a,b);add(b,a);
}
for(int i = 1 ; i <= N ; ++i) {
if(cnt[i] & 1) {puts("No");return;}
}
int t = 0;
int p = 0,q = 0;
for(int i = 1 ; i <= N ; ++i) {
if(cnt[i] >= 6) {puts("Yes");return;}
if(cnt[i] >= 4) {
++t;
if(!p) p = i;
else if(!q) q = i;
}
}
if(t > 2) {puts("Yes");return;}
if(t == 2) {
vis[p] = 1;
dfs(q);
for(int i = 1 ; i <= N ; ++i) {
if(!vis[i]) {puts("Yes");return;}
}
}
puts("No");
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}

D - Rotation Sort

把操作改成数轴上,我可以把一个点移动到左边或右边任意一个位置上,可以不必要是整数点

显然对于每个点操作只进行一次

然后拆成\((-\infty,1),(1,2),(2,3),(3,4)....(N - 1,N),(N,+\infty)\)和整数点\(1,2,3,4,5,6..N\)

然后根据位置dp即可

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 5005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
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,B;
int64 dp[MAXN][2 * MAXN],s[MAXN][2 * MAXN];
int p[MAXN],pos[MAXN];
void Solve() {
read(N);read(A);read(B);
for(int i = 1 ; i <= N ; ++i) {read(p[i]);pos[p[i]] = i;}
for(int i = 1 ; i <= N ; ++i) {
s[i][0] = 1e18;
for(int j = 1 ; j <= 2 * N + 1 ; ++j) {
if(j & 1) {
dp[i][j] = s[i - 1][j] + (j < pos[i] * 2 ? B : A);
}
else {
dp[i][j] = s[i - 1][j - 1] + (j != pos[i] * 2 ? (j < pos[i] * 2 ? B : A): 0);
}
s[i][j] = min(s[i][j - 1],dp[i][j]);
}
}
out(s[N][2 * N + 1]);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}

E - Modulo Pairing

用蓝色表示相加小于M的,红色表示大于M的

然后就会变成前面是蓝的,后面是红的

简单分析发现蓝的越小越好,红的越大越好,所以求出能向左最长的红色序列

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
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;
int a[MAXN];
void Solve() {
read(N);read(M);
for(int i = 1 ; i <= 2 * N ; ++i) read(a[i]);
sort(a + 1,a + 2 * N + 1);
int r = -1;
for(int i = 2 * N ; i >= 1 ; --i) {
int t = lower_bound(a + 1,a + 2 * N + 1,M - a[i]) - a;
if((t & 1) == (i & 1)) ++t;
if(r == -1) r = i + t;
else r = max(r,i + t);
}
if(r == -1) r = 4 * N + 1;
int ans = 0;
for(int i = 2 * N ; i >= 1 ; --i) {
if(r - i < i) ans = max(ans,(a[i] + a[r - i]) % M);
else break;
}
r = 1 + r - 2 * N - 1;
for(int i = 1 ; i <= 2 * N ; ++i) {
if(i < r - i) ans = max(ans,a[i] + a[r - i]);
else break;
}
out(ans);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}

F - One Third

切一刀,画一条红线,然后正120画一条蓝线,反120画一条绿线

我们要求的就是任意1/3中最短两个颜色不同之间的线的角度大小

然后我们取第一刀红线和蓝线之间的 1/3区间,然后里面被分成了\(N\)份,我们递推一个\(f(i)\),表示有\(i\)份左右两边区间颜色不同的概率

然后\(g(i)\)表示\(i\)份中最短的一段的期望长度,\(\frac{1}{3}\)长度里\(N\)份中选\(i\)份期望长度是\(\frac{i}{3N}\),可以认为分成\(N\)份中选\(i\)份每个点被选中的概率是\(\frac{i}{N} = \frac{\binom{i - 1}{N - 1}}{\binom{i}{N}}\)

那\(i\)段中的期望最小长度呢

是\(E(min) = \int_{t = 0}^{1/i}P(min \geq t) dt = \int_{t = 0}^{1/i}(1 - it)^{i - 1}dt = \int_{t = 0}^{1}\frac{t^{i - 1}}{i} dt = \frac{1}{i^2}\)

所以\(g(i) = \frac{1}{3iN}\)

答案就是所有的\(f(i)g(i)\)的和

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 1000005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
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);
}
const int MOD = 1000000007;
int N;
int f[MAXN][3],g[MAXN],fac[MAXN],invfac[MAXN],inv[MAXN];
int inc(int a,int b) {
return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
return 1LL * a * b % MOD;
}
int fpow(int x,int c) {
int res = 1,t = x;
while(c) {
if(c & 1) res = mul(res,t);
t = mul(t,t);
c >>= 1;
}
return res;
}
int C(int n,int m) {
if(n < m) return 0;
return mul(fac[n],mul(invfac[m],invfac[n - m]));
}
void Solve() {
read(N);
fac[0] = 1;
for(int i = 1 ; i <= N; ++i) fac[i] = mul(fac[i - 1],i);
invfac[N] = fpow(fac[N],MOD - 2);
for(int i = N - 1 ; i >= 0 ; --i) invfac[i] = mul(invfac[i + 1],i + 1);
inv[1] = 1;
for(int i = 2 ; i <= 1000000 ; ++i) inv[i] = mul(inv[MOD % i],MOD - MOD / i);
f[0][0] = 1;
int iv3= fpow(inv[3],N - 1);
int ans = 0;
for(int i = 1 ; i <= N ; ++i) {
f[i][1] = inc(f[i - 1][0],f[i - 1][2]);
f[i][0] = inc(f[i - 1][1],f[i - 1][2]);
f[i][2] = inc(f[i - 1][0],f[i - 1][1]);
g[i] = mul(mul(inv[3],inv[N]),inv[i]);
int p = mul(mul(f[i][1],C(N,i)),iv3);
ans = inc(ans,mul(g[i],p));
}
out(ans);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

【AtCoder】AGC032的更多相关文章

  1. 【Atcoder】 AGC032赛后总结

    比赛前 emmm,今天是场AGC,想起上次我的惨痛经历(B都不会),这次估计要凉,可能A都不会Flag1 比赛中 看场看了波\(A\),咦,这不是很呆的题目吗?倒着扫一遍就好了. 然后切了就开始看B, ...

  2. 【AtCoder】ARC092 D - Two Sequences

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. E: The package code needs to be reinstalled, but I can't find an archive for it.

    ubuntu安装软件时报错: E: The package code needs to be reinstalled, but I can't find an archive for it. 解决方法 ...

  2. UML教程

    1.前言 1.1 前言   本资料对UML1.5各种模型图的构成和功能进行说明,通过本资料的学习达到可以读懂UML模型图的目的.本资料不涉及模型图作成的要点等相关知识. 1.2 UML概述 1.2.1 ...

  3. 如何去掉li标签的重叠边框

    当我们的li标签设置了border的时候就会出现重叠边框,如何去掉呢,见代码 html代码 <ul class="friendLink_list"> <li> ...

  4. CSS margin属性取值

    margin表示一个元素的外边距.取值为正值时,表示相对于正常流离邻近元素更远,而取负值时,使其更近 但是,设置margin后,四个方向的表现形式不同 自身发生移动:top.left margin-t ...

  5. 分享一份非常强势的Android面试题

    马上步入金九银十了,是时候看一些面试题去鹅厂了,接下来我将分享一些面试题,每天总结一点点,希望对大家有所帮助! ListView和RecyclerView区别 参考链接: https://blog.c ...

  6. Confluence 6 订阅所应用的所有小工具

    你可以从你的 Jira, Bamboo,FishEye 或 Crucible 站点中订阅所有的小工具到你的 Confluence 小工具目录中.用户可以为他们的页面查找和选择小工具. 希望订阅其他站点 ...

  7. Confluence 6 外部小工具在其他应用中设置可信关系

    为了在你的 Confluence 中与其他应用建立外部小工具,我们建议你在 2 个应用之间设置 OAuth 或者信任的应用连接关系.在这个例子中,外部应用为小工具的服务器(服务器提供者)和 Confl ...

  8. ob_start用法详解

    用PHP的ob_start(); 一. 相关函数简介:1.Flush:刷新缓冲区的内容,输出.函数格式:flush()说明:这个函数经常使用,效率很高.2.ob_start :打开输出缓冲区函数格式: ...

  9. SpringMVC文件下载与JSON格式

    点击查看上一章 现在JSON这种数据格式是被使用的非常的广泛的,SpringMVC作为目前最受欢迎的框架,它对JSON这种数据格式提供了非常友好的支持,可以说是简单到爆. 在我们SpringMVC中只 ...

  10. ActiveMQ消息的持久化策略

    持久化消息和非持久化消息的存储原理: 正常情况下,非持久化消息是存储在内存中的,持久化消息是存储在文件中的.能够存储的最大消息数据在${ActiveMQ_HOME}/conf/activemq.xml ...