M-SOLUTIONS Programming Contest
A.(n-2)*180
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std; int n; int main(){
scanf("%d",&n); printf("%d\n",(n-)*);
return ;
}
B.已确定的输局<=7
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std; int n,x;
char s[]; int main(){
scanf("%s",s+); n=strlen(s+);
rep(i,,n) if (s[i]=='x') x++;
if (x>) puts("NO"); else puts("YES");
return ;
}
C.现只考虑A最后胜的情况,B同理。枚举A赢第n局之前B赢了多少局i,那么若不考虑平局概率则这种情况的发生概率为A^n*B^i*C(n-1+i,i),由期望显然可以得到,一场非平局的出现概率为1-C则期望1/(1-C)会出现一场非平局,共有n+i个非平局,则期望局数为(n+i)/(1-C)。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std; const int N=,mod=1e9+;
int n,A,B,C,ans,fac[N],inv[N]; int ksm(int a,int b){
int res=;
for (; b; a=1ll*a*a%mod,b>>=)
if (b & ) res=1ll*res*a%mod;
return res;
} int cc(int n,int m){ return n<m ? : 1ll*fac[n]*inv[m]%mod*inv[n-m]%mod; } int main(){
scanf("%d%d%d%d",&n,&A,&B,&C); int ii=ksm(,mod-);
A=1ll*A*ii%mod; B=1ll*B*ii%mod; C=1ll*C*ii%mod;
int a=1ll*ksm(A+B,mod-)*A%mod,b=1ll*ksm(A+B,mod-)*B%mod;
fac[]=; rep(i,,n+n) fac[i]=1ll*fac[i-]*i%mod;
inv[n+n]=ksm(fac[n+n],mod-); for (int i=n+n; i; i--) inv[i-]=1ll*inv[i]*i%mod;
rep(i,,n-){
ans=(ans+1ll*ksm(b,i)*ksm(a,n)%mod*cc(n-+i,i)%mod*ksm(-C+mod,mod-)%mod*(n+i))%mod;
ans=(ans+1ll*ksm(a,i)*ksm(b,n)%mod*cc(n-+i,i)%mod*ksm(-C+mod,mod-)%mod*(n+i))%mod;
}
printf("%d\n",ans);
return ;
}
D.能取到最大值=总和-最大点权。于是把c从大到小排序,按DFS序分配即可。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
#define For(i,x) for (int i=h[x],k; i; i=nxt[i])
typedef long long ll;
using namespace std; const int N=;
int n,u,v,tot,ans,cnt,c[N],s[N],h[N],to[N<<],nxt[N<<];
struct E{ int u,v; }e[N];
void add(int u,int v){ to[++cnt]=v; nxt[cnt]=h[u]; h[u]=cnt; }
bool cmp(int a,int b){ return a>b; } void dfs(int x,int fa){
s[x]=c[++tot];
For(i,x) if ((k=to[i])!=fa) dfs(k,x);
} int main(){
scanf("%d",&n);
rep(i,,n) scanf("%d%d",&u,&v),e[i]=(E){u,v},add(u,v),add(v,u);
rep(i,,n) scanf("%d",&c[i]);
sort(c+,c+n+,cmp); dfs(,);
rep(i,,n) ans+=min(s[e[i].u],s[e[i].v]);
printf("%d\n",ans);
rep(i,,n) printf("%d ",s[i]);
return ;
}
E.答案等于(x/d)*(x/d+1)*...*(x/d+(n-1))*d^n,这就是个阶乘乘上快速幂。注意特判d=0或x/d~x/d+n-1中出现0的情况。
#include<cstdio>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
using namespace std; const int mod=1e6+;
int x,d,n,T,fac[mod+]; int ksm(int a,int b){
int res=;
for (; b; a=1ll*a*a%mod,b>>=)
if (b & ) res=1ll*res*a%mod;
return res;
} int main(){
fac[]=; rep(i,,mod-) fac[i]=1ll*fac[i-]*i%mod;
for (scanf("%d",&T); T--; ){
scanf("%d%d%d",&x,&d,&n);
if (!d){ printf("%d\n",ksm(x,n)); continue; }
x=1ll*x*ksm(d,mod-)%mod;
if (!x || x+n->=mod) puts("");
else printf("%lld\n",1ll*fac[x+n-]*ksm(fac[x-],mod-)%mod*ksm(d,n)%mod);
}
return ;
}
M-SOLUTIONS Programming Contest的更多相关文章
- The Ninth Hunan Collegiate Programming Contest (2013) Problem J
Problem J Joking with Fermat's Last Theorem Fermat's Last Theorem: no three positive integers a, b, ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem L
Problem L Last Blood In many programming contests, special prizes are given to teams who solved a pa ...
- Gym 100952E&&2015 HIAST Collegiate Programming Contest E. Arrange Teams【DFS+剪枝】
E. Arrange Teams time limit per test:2 seconds memory limit per test:64 megabytes input:standard inp ...
- The 15th UESTC Programming Contest Preliminary M - Minimum C0st cdoj1557
地址:http://acm.uestc.edu.cn/#/problem/show/1557 题目: Minimum C0st Time Limit: 3000/1000MS (Java/Others ...
- Programming Contest Problem Types
Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...
- ZOJ 3703 Happy Programming Contest
偏方记录背包里的物品.....每个背包的价值+0.01 Happy Programming Contest Time Limit: 2 Seconds Memory Limit: 65536 ...
- Happy Programming Contest(ZOJ3703)(01背包+路径储存)
Happy Programming Contest ZOJ3703 老实说:题目意思没看懂...(希望路过的大神指点) 最后那个the total penalty time是什么意思啊!!! 还是学 ...
- The 2015 China Collegiate Programming Contest A. Secrete Master Plan hdu5540
Secrete Master Plan Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Othe ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Capture the Flag
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5503 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494 The 12th Zhejiang Provincial ...
随机推荐
- 小数据池/is和==/再谈编码作业
# 1,老男孩好声选秀大赛评委在打分的时候呢, 可以输入分数. 假设, 老男孩有10个评委. 让10个评委进行打分, 要求, 分数必须高于5分, 低于10分.将每个评委的打分情况保存在列表中. pin ...
- 原创:协同过滤之spark FP-Growth树应用示例
上一篇博客中,详细介绍了UserCF和ItemCF,ItemCF,就是通过用户的历史兴趣,把两个物品关联起来,这两个物品,可以有很高的相似度,也可以没有联系,比如经典的沃尔玛的啤酒尿布案例.通过Ite ...
- IDEA 重新 build Project
- ES6 数组方法 forEach map filter find every some reduce
1. forEach const colors = ['red', 'blue', 'green'] colors.forEach(function (params) { console.log(pa ...
- Eclipse安装jbpm插件
1.1 eclipse mar 和neon有什么区别? Eclipse 是一个开放源代码的.基于Java的可扩展开发平台.就其本身而言,它只是一个框架和一组服务,用于通过插件组件构建开发环境. . ...
- Goroutine调度器
前言 并发(并行)一致都是编程语言的核心主题,不同于其他语言,例如C/C++语言用户序自行借助pthread创建线程,Golang天然就给出了并发解决方案:goroutine. Goroutine 写 ...
- tensorflow build failed on Centos with Error: suffix or operands invalid for ""
在redhat6.5的机器上编译tensorflow1.10,局部环境配好gcc4.8.2后,发现了如题的错误.这是关于AVX指令集识别问题.虽然gcc版本足够高,能够编出使用AVX的汇编代码,但是b ...
- HIDL概述【转】
本文转载自:https://blog.csdn.net/u013357557/article/details/84561457 HIDL背景Treble 是 Google Android 团队的一项重 ...
- locust参数化(数据库取值)
locust参数化(数据库取值) 基于上一篇参数化的梳理,本篇用另一种方法从数据库中取出这100个用户来登录 思路:在 TaskSet 中的 on_start 方法表示执行任务前的操作,可以将数据库取 ...
- 方法名同类名相同如果没有__construct,会被当做构造函数。
简介本文主要罗列些例子,看看当php类名和函数名重名时,php是如何处理的例子<?php class TestObject{ public $subject; private $message ...