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)的更多相关文章

  1. 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 ...

  2. Codeforces Beta Round #16 E. Fish (状压dp)(概率dp)

    Codeforces Beta Round #16 (Div. 2 Only) E. Fish 题目链接:## 点击打开链接 题意: 有 \(n\) 条鱼,每两条鱼相遇都会有其中一只吃掉对方,现在给你 ...

  3. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  4. Codeforces Beta Round #70 (Div. 2)

    Codeforces Beta Round #70 (Div. 2) http://codeforces.com/contest/78 A #include<bits/stdc++.h> ...

  5. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  6. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  7. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

  8. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

  9. Codeforces Beta Round #75 (Div. 2 Only)

    Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...

随机推荐

  1. NB-IoT移远BC95使用小结

    移远-BC95-测试前准备 1.  设备连接主串口,串口调试助手波特率使用9600,选择对应的端口号.在串口调试助手上输入AT发送,查看是否有OK返回. 如果想修改波特可以通过下面的AT来修改 AT+ ...

  2. 解决Run As -> Java Application不能运行问题

    转自:https://breakshell.iteye.com/blog/467130 点 Run As -> Java Application 不能运行,报的错误如下: Plug-in org ...

  3. RabbitMq(2) 简单消息队列

    <dependency> <groupId>com.rabbitmq</groupId> <artifactId>amqp-client </ar ...

  4. Linux主机如何用ssh去登录docker容器的步骤

    进入终端,sudo -i,切换root,输入docker -d 打开另一个终端,切换root,输入docker search ubuntu,大概如下结果: NAME                   ...

  5. Unable to locate Spring NamespaceHandler for XML schema namespace

    1. 问题 本文将讨论Spring中最常见的配置问题 —— Spring的一个命名空间的名称空间处理程序没有找到. 大多数情况下,是由于一个特定的Spring的jar没有配置在classpath下,让 ...

  6. 447. Add Strings

    原文题目: 447. Add Strings 解题: 字符串的当做整数来做加法,其实就是大数加法的简化版本 思路: 1)考虑不同位数,如"1234"+“45”,需要先处理低两位,再 ...

  7. android手机 解锁bootloader 刷recovery 线刷rom 卡刷rom

    1 解锁bootloader 为手机安装官方驱动 按相应的组合键使手机进入fastboot模式 执行命令fastboot oem unlock 123456 (123456为厂家提供的解锁码) 手机重 ...

  8. Android事件拦截机制 - 两句话

    模拟情形:ViewGroupA ->ViewGroupB->View False往下走,True就停下.(适用于事件传递和事件处理)

  9. wParam与lParam的区别

    wParam与lParam的区别 lParam 和 wParam 是宏定义,一般在消息函数中带这两个类型的参数,通常用来存储窗口消息的参数. LRESULT CALLBACK WindowProc(H ...

  10. tap news:week5 0.0 create react app

    参考https://blog.csdn.net/qtfying/article/details/78665664 先创建文件夹 安装create react app 这个脚手架(facebook官方提 ...