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> ...
随机推荐
- HTML学习-1网页基础知识
HTML超文本标记语言:HyperText Markup Language. 由浏览器运行解析. 它包括了静态页面.html .htm.动态页面.php .aspx .jsp,从数据库提取. 今天 ...
- innosetup 安装前、卸载前判断是否有进程正在运行<转>
[Code] //安装前判断是否有进程正在运行,istask.dll文件与打包的exe文件一起 function RunTask(FileName: string; bFullpath: Boolea ...
- [原]vue - webapp 返回无效 解决方案
- supervisor process management
supervisor是unix like系统的进程管理工具 安装: pip install supervisor 配置文件: echo_supervisord_conf # 打印一个配置文件样例 ec ...
- BroadcastReceiver的使用,动态注册和注销,优先级和中断控制
BroadcastReceiver: BroadcastReceiver(广播接收器)是Android中的四大组件之一,用来通知某些事件的相关信息,如下载完成,设置改变等. 默认的BroadcastR ...
- jquery接触初级-----juqery DOM操作 之二
DOm 操作之: 1.1 children(),这个函数只是查找元素的子元素,而不考虑其他后代元素 <body> <p title="请选择你最喜欢的水果"&g ...
- 【382】利用 namedtuple 实现函数添加属性
namedtuple 能够实现类似类的效果,tuple 的元素可以通过属性的形式返回,如下所示: from collections import namedtuple Student = namedt ...
- 如何使用JDBC查询指定的记录
//连接数据库 public class JdbcDao { private Connection conn=null; private String strSql=null; publi ...
- [C语言]流程控制, 复合赋值, 优先级, 循环控制
---------------------------------------------------------------------------------------- //单一判断 ) { ...
- Glide4 高效加载图片的配置【转】
原文: Glide4 高效加载图片的配置 https://www.jianshu.com/p/a079713f280f