Codeforces Beta Round #16 (Div. 2 Only)
Codeforces Beta Round #16 (Div. 2 Only)
http://codeforces.com/contest/16
A
水题
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define maxn 500005
typedef long long ll;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int n,m;
string str[]; int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
cin>>n>>m;
int flag=;
map<int,int>mp;
for(int i=;i<n;i++) cin>>str[i];
for(int i=;i<n;i++){
if(str[i][]==str[i-][]) flag=;
}
if(!flag){
if(m==){
cout<<"YES"<<endl;
}
else{
for(int k=;k<n;k++){
for(int i=;i<m;i++){
if(str[k][i]!=str[k][i-]) flag=;
}
}
if(flag) cout<<"NO"<<endl;
else cout<<"YES"<<endl;
}
}
else{
cout<<"NO"<<endl;
}
}
B
贪心
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define maxn 500005
typedef long long ll;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ struct sair{
ll num,val;
}a[]; bool cmp(sair a,sair b){
return a.val>b.val;
} int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
ll n,m;
cin>>n>>m;
for(int i=;i<=m;i++){
cin>>a[i].num>>a[i].val;
}
sort(a+,a+m+,cmp);
ll ans=;
for(int i=;i<=m;i++){
if(n>=a[i].num){
ans+=a[i].num*a[i].val;
n-=a[i].num;
}
else if(n<a[i].num){
ans+=a[i].val*n;
n=;
}
if(!n) break;
}
cout<<ans<<endl;
}
C
gcd
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define maxn 500005
typedef long long ll;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ ll gcd(ll a,ll b){
if(b==) return a;
return gcd(b,a%b);
}
int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
ll a,b,c,d;
cin>>a>>b>>c>>d;
ll x=gcd(c,d);
c/=x;
d/=x;
x=min(a/c,b/d);
cout<<c*x<<" "<<d*x<<endl;
}
D
模拟
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define maxn 500005
typedef long long ll;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */
string str; int Change(char ch1,char ch2){
return (ch1-'')*+(ch2-'');
} int main(){
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif
// std::ios::sync_with_stdio(false);
int n;
scanf("%d%*c",&n);
int pres=,pref=;
int ans=;
int co=;
for(int i=;i<=n;i++){
getline(cin,str);
// cout<<str<<" "<<i<<endl;
char flag=str[];
int shi=Change(str[],str[]);
int fen=Change(str[],str[]);
if(flag=='p') shi+=;
if(shi==&&flag=='a') shi=;
if(shi==&&flag=='p') shi=;
// cout<<pres<<" "<<pref<<" "<<shi<<" "<<fen<<endl;
if(shi==pres&&fen==pref) co++;
else {
co=;
}
if(co>) {
co=;
ans++;
}
if(shi<pres||(shi==pres&&fen<pref)){
ans++;
}
pres=shi;
pref=fen;
}
cout<<ans<<endl;
}
E
状压DP
dp(i吃掉j)=dp(i和j同时存在)∗p(i战胜j)的概率∗prob(i和j相遇)的概率
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define maxn 500005
typedef long long ll;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int n;
double a[][]; double dp[<<]; int main(){
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>n;
for(int i=;i<n;i++){
for(int j=;j<n;j++){
cin>>a[i][j];
}
}
dp[(<<n)-]=;///所有鱼都存在的情况
for(int i=(<<n)-;i;i--){
int num=;
for(int j=;j<n;j++){
if(i&(<<j)) num++;///判断存活鱼的个数
}
for(int j=;j<n;j++){
if(i&(<<j)){///j存活
for(int k=j+;k<n;k++){
if(i&(<<k)){///k存活
dp[i-(<<k)]+=dp[i]*a[j][k]*1.0/(num*(num-)/); ///j吃k
dp[i-(<<j)]+=dp[i]*a[k][j]*1.0/(num*(num-)/); ///k吃j
}
}
}
}
}
for(int i=;i<n;i++){
cout<<dp[<<i]<<" ";
}
cout<<endl;
}
Codeforces Beta Round #16 (Div. 2 Only)的更多相关文章
- Codeforces Beta Round #16 div 2 C.Monitor最大公约数
C. Monitor time limit per test 0.5 second memory limit per test 64 megabytes input standard input ou ...
- Codeforces Beta Round #16 E. Fish (状压dp)(概率dp)
Codeforces Beta Round #16 (Div. 2 Only) E. Fish 题目链接:## 点击打开链接 题意: 有 \(n\) 条鱼,每两条鱼相遇都会有其中一只吃掉对方,现在给你 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #70 (Div. 2)
Codeforces Beta Round #70 (Div. 2) http://codeforces.com/contest/78 A #include<bits/stdc++.h> ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
- Codeforces Beta Round #75 (Div. 2 Only)
Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...
随机推荐
- 机器学习进阶-图像梯度计算-scharr算子与laplacian算子(拉普拉斯) 1.cv2.Scharr(使用scharr算子进行计算) 2.cv2.laplician(使用拉普拉斯算子进行计算)
1. cv2.Scharr(src,ddepth, dx, dy), 使用Scharr算子进行计算 参数说明:src表示输入的图片,ddepth表示图片的深度,通常使用-1, 这里使用cv2.CV_6 ...
- django 之manytomany
https://www.cnblogs.com/changbaishan/p/8056762.html https://blog.csdn.net/hpu_yly_bj/article/details ...
- Delphi TMemoryStream写入到字符串和字符串写入到流
一.TMemoryStream数据写入到字符串里 var lvStream:TMemoryStream; s:AnsiString; p: PAnsiChar; begin lvStream:= TM ...
- mysql 的sleep线程过多处理方法
php程序不要使用长连接:java程序调整连接池 什么是长连接? 其实长连接是相对于通常的短连接而说的,也就是长时间保持客户端与服务端的连接状态. 通常的短连接操作步骤是: 连接->数据传输-& ...
- How to Pronounce the Word ARE
How to Pronounce the Word ARE Share Tweet Share Tagged With: ARE Reduction Study the ARE reduction. ...
- webstorm添加多个项目
在webstorm工作目录下,添加其他项目,不用每个项目打开一个webstorm,刚开始使用webstorm的时候,每次打开一个项目的时,都要打开一个开发界面,在这几个窗口之间来回的切换,有一天真的感 ...
- 钩子函数mounted:
1.钩子函数 钩子函数是Windows消息处理机制的一部分,通过设置“钩子”,应用程序可以在系统级对所有消息.事件进行过滤,访问在正常情况下无法访问的消息.钩子的本质是一段用以处理系统消息的程序,通过 ...
- MongoDB模糊查询,以及MongoDB模糊查询时带有括号的情况
模糊查询 记录如下: { "_id" : ObjectId("5c3d486d24aa9a000526367b"), "name" : &q ...
- @Component单例与并发(未解决)
今天用websocket记录连接的个数: 模拟少量请求到服务器端的websocket,@Component默认是单例的,让其注解到MyWebSocket类上: 每次请求过来都是相同的MyWebSock ...
- idea gradle卡主问题
http://services.gradle.org/distributions/ 首先下载 all 版本 ,解压 ,再d盘, 并保留zip 文件 ,新建环境变量 GRADLE_HOME 指向 ...