【AtCoder】M-SOLUTIONS Programming Contest
M-SOLUTIONS Programming Contest
A - Sum of Interior Angles
#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 ba 47
//#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;
void Solve() {
read(N);
out((N - 2) * 180);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
B - Sumo
#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 ba 47
//#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 L;
char s[20];
void Solve() {
scanf("%s",s + 1);
L = strlen(s + 1);
int ans = 15 - L;
for(int i = 1 ; i <= L ; ++i) {
if(s[i] == 'o') ++ans;
}
if(ans >= 8) puts("YES");
else puts("NO");
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
C - Best-of-(2n-1)
就是有\(C\)的概率往下摁,否则就停止,这样的期望次数是\(\frac{C}{1 - C}\)
我们枚举最终情况走了\(i\)个\(A\)和\(N\)个\(B\)(反过来同理),这个时候\(A\)胜的概率是\(\frac{A}{A+ B}\),\(B\)胜的概率是\(\frac{B}{A+ B}\),期望次数就是\((N + i)(\frac{C}{1 - C} + 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 100005
#define ba 47
//#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 fac[1000005],invfac[1000005];
int N,A,B,C;
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;
}
void update(int &a,int b) {
a = inc(a,b);
}
int cnm(int n,int m) {
if(n < m) return 0;
else return mul(fac[n],mul(invfac[m],invfac[n - m]));
}
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;
}
void Solve() {
read(N);read(A);read(B);read(C);
A = mul(A,fpow(100,MOD - 2));
B = mul(B,fpow(100,MOD - 2));
C = mul(C,fpow(100,MOD - 2));
int iv = fpow(inc(1,MOD - C),MOD - 2);
C = mul(C,iv);
int k = fpow(inc(A,B),MOD - 2);
A = mul(A,k);B = mul(B,k);
fac[0] = 1;
for(int i = 1 ; i <= 2 * N ; ++i) {
fac[i] = mul(fac[i - 1],i);
}
invfac[2 * N] = fpow(fac[2 * N],MOD - 2);
for(int i = 2 * N - 1 ; i >= 0 ; --i) {
invfac[i] = mul(invfac[i + 1],i + 1);
}
int ans = 0;
for(int i = 0 ; i < N ; ++i) {
int h = inc(mul(fpow(A,N),fpow(B,i)),mul(fpow(B,N),fpow(A,i)));
int t = mul(cnm(i + N - 1,N - 1),mul(C + 1,i + N));
t = mul(t,h);
update(ans,t);
}
out(ans);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
D - Maximum Sum of Minimum
大胆猜想一下发现就是除了最大值都加一遍,如果一个值加了两遍会占一个比它大的值得位置,不优,构造的话就是随便选一个根然后按dfs序从大到小填数
#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 10005
#define ba 47
//#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 sumE,head[MAXN],N;
int c[MAXN],ans;
int p[MAXN],tot;
void add(int u,int v) {
E[++sumE].to = v;
E[sumE].next = head[u];
head[u] = sumE;
}
void dfs(int u,int fa) {
p[u] = c[tot--];
for(int i = head[u] ; i ; i = E[i].next) {
int v = E[i].to;
if(v != fa) {
dfs(v,u);
}
}
}
void Solve() {
read(N);
int a,b;
for(int i = 1 ; i < N ; ++i) {
read(a);read(b);add(a,b);add(b,a);
}
for(int i = 1 ; i <= N ; ++i) read(c[i]);
sort(c + 1,c + N + 1);
for(int i = 1 ; i < N ; ++i) ans += c[i];
tot = N;
dfs(1,0);
out(ans);enter;
for(int i = 1 ; i <= N ; ++i) {
out(p[i]);space;
}
enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
E - Product of Arithmetic Progression
没做出来的我真是降智
如果d=0,那么答案是\(x^{n}\)
如果d不为0,都除上一个d,然后发现是一段连续的数相乘,可以用前缀乘积的一个除另一个,特判掉\(x = 0\)和\(\frac{x}{d} + n - 1 >= P\)的情况,最后再乘上\(d^{n}\)
#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 10005
#define ba 47
//#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 = 1000003;
int pre[MOD + 5];
int mul(int a,int b) {
return 1LL * a * b % MOD;
}
int inc(int a,int b) {
return a + b >= MOD ? a + b - MOD : a + b;
}
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;
}
void Solve() {
pre[0] = 1;
for(int i = 1 ; i < MOD ; ++i) pre[i] = mul(pre[i - 1],i);
int Q,x,d,n;
read(Q);
for(int i = 1 ; i <= Q ; ++i) {
read(x);read(d);read(n);
if(d == 0) {out(fpow(x,n));enter;continue;}
x = mul(x,fpow(d,MOD - 2));
if(x + n - 1 >= MOD || x == 0) {puts("0");continue;}
int res = mul(pre[x + n - 1],fpow(pre[x - 1],MOD - 2));
res = mul(res,fpow(d,n));
out(res);enter;
}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
F - Random Tournament
设\(dpl[i][j]\)表示这个区间\([i,j]\)有一种方式是\(i\)能打败所有人
\(dpr[i][j]\)表示有一种方式\(j\)能打败所有人
答案就是\(dpr[1][x] = 1\)并且\(dpl[x][N] = 1\)的所有位置
然后\(dpr[l][r]\)为1的条件是存在\(k\)使得\(dpr[l][k] = 1\)并且\(dpl[k][r - 1] = 1\)并且\(a_{r,k} = 1\)
\(dpl[l][r]\)是存在\(k\)使得\(dpr[l + 1][k] = 1\)并且\(dpl[k][r] = 1\)并且\(a_{l,k} = 1\)
这个可以用bitset优化,所以复杂度是\(O(\frac{N^{3}}{w})\)
#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 10005
#define ba 47
//#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);
}
bitset<2005> a[2005],dpr[2005],dpl[2005],tmp;
int N;
char s[2005][2005];
void Solve() {
read(N);
for(int i = 2 ; i <= N ; ++i) {
scanf("%s",s[i] + 1);
for(int j = 1 ; j < i ; ++j) {
if(s[i][j] == '1') a[i][j] = 1;
else a[j][i] = 1;
}
}
for(int i = 1 ; i <= N ; ++i) dpr[i][i] = 1,dpl[i][i] = 1;
for(int d = 2 ; d <= N ; ++d) {
for(int l = 1 ; l <= N ; ++l) {
int r = l + d - 1;
if(r > N) break;
if((dpr[l] & dpl[r - 1] & a[r]).any()) {
dpr[l][r] = 1;
}
if((dpl[r] & dpr[l + 1] & a[l]).any()) {
dpl[r][l] = 1;
}
}
}
out((dpr[1] & dpl[N]).count());enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
【AtCoder】M-SOLUTIONS Programming Contest的更多相关文章
- 【AtCoder】diverta 2019 Programming Contest 2
diverta 2019 Programming Contest 2 A - Ball Distribution 特判一下一个人的,否则是\(N - (K - 1) - 1\) #include &l ...
- 【AtCoder】diverta 2019 Programming Contest
diverta 2019 Programming Contest 因为评测机的缘故--它unrated了.. A - Consecutive Integers #include <bits/st ...
- 【题解】CF1056F Write the Contest(三分+贪心+DP)
[题解]CF1056F Write the Contest(三分+贪心+DP) 最优化问题的三个解决方法都套在一个题里了,真牛逼 最优解应该是怎样的,一定存在一种最优解是先完成了耗时长的任务再干别的( ...
- 【AtCoder】ARC092 D - Two Sequences
[题目]AtCoder Regular Contest 092 D - Two Sequences [题意]给定n个数的数组A和数组B,求所有A[i]+B[j]的异或和(1<=i,j<=n ...
- 【AtCoder】ARC 081 E - Don't Be a Subsequence
[题意]给定长度为n(<=2*10^5)的字符串,求最短的字典序最小的非子序列字符串. http://arc081.contest.atcoder.jp/tasks/arc081_c [算法]字 ...
- 【Atcoder】CODE FESTIVAL 2017 qual A D - Four Coloring
[题意]给定h,w,d,要求构造矩阵h*w满足任意两个曼哈顿距离为d的点都不同色,染四色. [算法]结论+矩阵变换 [题解] 曼哈顿距离是一个立着的正方形,不方便处理.d=|xi-xj|+|yi-yj ...
- 【枚举】Southwestern Europe Regional Contest H - Sheldon Numbers
https://vjudge.net/contest/174235#problem/H [题意] 求[x,y]之间有多少个Sheldon Number Sheldon Number是二进制满足以下条件 ...
- 【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 ...
随机推荐
- Java进阶知识20 Spring的代理模式
本文知识点(目录): 1.概念 2.代理模式 2.1.静态代理 2.2.动态代理 2.3.Cglib子类代理 1.概念 1.工厂模式 2. 单例模式 代理(Proxy ...
- 2019牛客暑期多校训练营(第六场)E 构造、原图是补图的同构图
https://ac.nowcoder.com/acm/contest/886#question 题意 问是否存在某个n个点的无向图G是其补图H的同构图,若存在输出G的邻接矩阵以及H关于G的映射. ...
- Ajax请求如何设置csrf_token
1. 方式一 通过获取隐藏的input标签中的csrfmiddlewaretoken值,放置在data中发送. $.ajax({ url: "/cookie_ajax/", typ ...
- VSCode-VUE模板文件
编辑自己的代码片段 ctrl+shift+p 输入snippet 选择 'Preferences: Configure User Snippets' 输入vue 选择vue.json,会打开vue.j ...
- 常见的RuntimeException
一般面试中java Exception(runtimeException )是必会被问到的问题常见的异常列出四五种,是基本要求.更多的....需要注意积累了 常见的几种如下: NullPointerE ...
- OpenFOAM 中的边界条件(一)【转载】
链接:http://xiaopingqiu.github.io/2016/04/02/Boundary-conditions-in-OpenFOAM1/ 本系列解读 OpenFOAM 中边界条件的实现 ...
- centos7的网络配置参考
<鸟哥的Linux私房菜>中的相关介绍和配置:http://linux.vbird.org/linux_basic/0610hardware.php 修改链接(connection)的名字 ...
- pwn学习日记Day8 基础知识积累
知识杂项 aslr:是一种针对缓冲区溢出的安全保护技术,通过对堆.栈.共享库映射等线性区布局的随机化,通过增加攻击者预测目的地址的难度,防止攻击者直接定位攻击代码位置,达到阻止溢出攻击的目的的一种技术 ...
- iOS App的几种安全防范
虽然公司的项目目前还不算健壮,安全问题对于大部分小公司来说似乎并没什么必要,不过要攻击的话,我有十足的把握,我们是无法承受冲击的.嘿嘿嘿~不过带着一颗入坑iOS的心思,搜集了一下资料后,还是做了一些尝 ...
- K-Means算法及代码实现
1.K-Means算法 K-Means算法,也被称为K-平均或K-均值算法,是一种广泛使用的聚类算法.K-Means算法是聚焦于相似的无监督的算法,以距离作为数据对象间相似性度量的标准,即数据对象间的 ...