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. 浅谈如何避免内存泄漏(out of memory)

    1.在涉及使用Context时,对于生命周期比Activity长的对象应该使用Application的Context.凡是使用Context优先考虑Application的Context,当然它并不是 ...

  2. 网关、子网掩码、DHCP, DNS

    都跟ip地址相关,IP地址构成:网络地址+主机地址 子网掩码可以确定网络地址,例如某IP:192.168.1.102 子网掩码:255.255.255.0, 那么网络地址就是192.168.1,主机地 ...

  3. jquery接触初级-----juqery DOM操作 之一

    1. DOM 分为三个部分:DOM core ,HTML_DOM,CSS_DOM: 1.1.document.getElementById(),document.getElementsByTagNam ...

  4. 1047A_Little C Loves 3 I(构造)

    A. Little C Loves 3 I time limit per test 1 second memory limit per test 256 megabytes input standar ...

  5. Lazarus下改变DBGrid记录的颜色,与Delphi不同了。

    功能:根据一条记录满足特定条件,使用不同的颜色进行显示. 来源:http://www.aliyagoo.com/blog 主要事件是在PrepareCanvas 不是DrawColumnCell 而且 ...

  6. Grafana+Zabbix使用配置

    官方提供的网友分享的图形面板,可以自行选择使用下载---  https://grafana.com/dashboards   Grafana 是 Graphite 和 InfluxDB 仪表盘和图形编 ...

  7. python笔记之强制函数以关键字参数传参

    最近学习python,学到了函数传参,看到了以下这个特殊情况,特此来做个笔记 def add(*, x, y): print(x, y) 以上函数定义后,该怎么传参?前面的那个*号是做什么用的? 我们 ...

  8. 遍历DOM树,each()遍历

    在<jQuery教程/理解选取更新范围>一节中,我们知道:当选择器返回了多个元素时,可以使用一个方法来更新所有的元素,不再需要使用循环. 然后有的时候需要遍历元素,怎么办? 使用each( ...

  9. C++随记

    1.const限定符 const限定变量的值不可变,并且const对象必须要初始化 const int buf = 512; //正确,表明buf的值为512 buf = 400;  //错误,buf ...

  10. 使用navigator对象,输出当前浏览器的信息

    <script type="text/javascript"> with(document) { write("你的浏览器信息:<ol>" ...