Codeforces Beta Round #49 (Div. 2)

http://codeforces.com/contest/53

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 pb push_back
#define eb emplace_back
#define maxn 1000005
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef unsigned long long ull; string s[]; int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
string str;
cin>>str;
int n;
cin>>n;
for(int i=;i<=n;i++){
cin>>s[i];
}
string ans=str;
int flag=;
for(int i=;i<=n;i++){
if(s[i].find(str)==){
if(!flag) ans=s[i],flag=;
else ans=min(ans,s[i]);
}
}
cout<<ans<<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 pb push_back
#define eb emplace_back
#define maxn 1000005
#define rep(k,i,j) for(int k=i;k<j;k++)
#define eps 1e-8
typedef long long ll;
typedef unsigned long long ull; ///w/h>=0.8&&w/h<=1.25 ll num[];
ll h,w; int sgn(double x){
if(x<) return -;
if(x<eps) return ;
return ;
}
vector<double>tmp; bool Check1(ll mid,ll h){
double zhi=(mid*1.0)/(h*1.0);
if(sgn(zhi-0.8)>=&&sgn(1.25-zhi)>=) return true;
return false;
} bool Check2(ll h,ll mid){
double zhi=(mid*1.0)/(h*1.0);
if(sgn(zhi-0.8)>=&&sgn(1.25-zhi)>=) return true;
return false;
} int main(){
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>h>>w;
num[]=;
ll l,r,mid;
ll ans=;
ll ansh,answ;
for(int i=;i<=;i++) num[i]=num[i-]*;
for(int i=;i<=;i++){
if(h>=num[i]){
l=ll(ceil(num[i]*0.8)); if(ll(num[i]*1.25)<=w) r=num[i]*1.25;
else r=w;
// if(h==5&&w==5) cout<<l<<" "<<r<<endl;
if(l>r) continue;
while(l<=r){
mid=l+r>>;
if(Check1(mid,num[i])) l=mid+;
else r=mid-;
}
if(ans<=r*num[i]){
ans=r*num[i];
ansh=num[i],answ=r;
}
}
}
for(int i=;i<=;i++){
if(w>=num[i]){
/* l=ll(ceil(num[i]/0.8));
if(ll(num[i]/1.25)<=w) r=num[i]*1.25;
else r=h;*/
l=ceil(num[i]*1.0/1.25);
r=min(h,ll(num[i]*1.0/0.8));
// cout<<l<<" "<<r<<endl;
// if(h==5&&w==5) cout<<l<<" "<<r<<endl;
if(l>r) continue;
while(l<=r){ mid=l+r>>;//cout<<mid<<endl;
if(Check2(num[i],mid)) l=mid+;
else r=mid-;
}
if(ans<=r*num[i]){
ans=r*num[i];
answ=num[i],ansh=r;
}
}
}
if(ansh<answ){
if(answ<=h) swap(ansh,answ);
}
cout<<ansh<<" "<<answ<<endl;
}

C

找规律

 #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 pb push_back
#define eb emplace_back
#define maxn 1000005
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef unsigned long long ull; int main(){
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
int n;
cin>>n;
int L=,R=n;
for(int i=;i<=n;i++){
if(i%){
cout<<L++<<" ";
}
else{
cout<<R--<<" ";
}
} }

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 pb push_back
#define eb emplace_back
#define maxn 1000005
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef unsigned long long ull; int a[],b[];
vector<pair<int,int> >ve; int main(){
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
int n;
cin>>n;
for(int i=;i<=n;i++) cin>>a[i];
for(int i=;i<=n;i++) cin>>b[i];
int j;
for(int i=;i<=n;i++){
if(a[i]!=b[i]){
for(j=i+;j<=n;j++){
if(a[i]==b[j]){
break;
}
}
for(;j>i;j--){
ve.pb(make_pair(j-,j));
swap(b[j],b[j-]);
}
}
}
cout<<ve.size()<<endl;
for(int i=;i<ve.size();i++){
cout<<ve[i].first<<" "<<ve[i].second<<endl;
}
}

E

状压DP

这题思路很奇妙,有些细节还没理解清楚

参考博客:https://www.luogu.org/problemnew/solution/CF53E

 #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 pb push_back
#define eb emplace_back
#define maxn 1000005
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef unsigned long long ull; int n,m,k;
int g[][];
int dp[][];
int ans; int main(){
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>n>>m>>k;
int u,v,x;
rep(i,,m){
cin>>u>>v;
u--,v--;
x=(<<u)|(<<v);
g[u][v]=g[v][u]=;
dp[x][x]=;
}
rep(i,,<<n){
rep(j,,<<n){
if(i&j==j&&dp[i][j]){
rep(k,,n){
rep(w,,n){
if (g[k][w]&&(i&(<<k))&&(~i&(<<w))&&(!(((j&(~(<<k)))|(<<w))>>(w+)))){
dp[i|(<<w)][(j&(~(<<k)))|((<<w))]+=dp[i][j];
}
}
}
}
}
}
int nn=(<<n)-;
rep(i,,<<n){
if(__builtin_popcount(i)==k){
ans+=dp[nn][i];
}
}
cout<<ans<<endl;
}

Codeforces Beta Round #49 (Div. 2)的更多相关文章

  1. Codeforces Beta Round #46 (Div. 2)

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

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

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

  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 #79 (Div. 2 Only)

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

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

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

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

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

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

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

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

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

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

    Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...

随机推荐

  1. 初识AutoMapper

    在开始本篇文章之前,先来思考一个问题:一个项目分多层架构,如显示层.业务逻辑层.服务层.数据访问层.层与层访问需要数据载体,也就是类.如果多层通用一个类,一则会暴露出每层的字段,二者会使类字段很多,而 ...

  2. 跨域(一)——CORS机制

    Ajax是严格遵守同源策略的,既不能从另一个域读取数据,也不能发送数据到另一个域.但是,W3C的新标准中CORS(Cross Origin Resource Sharing)推进浏览器支持这样的跨域方 ...

  3. PRC远程过程调用

    RPC(Remote Promote Call) 一种进程间通信方式.允许像调用本地服务一样调用远程服务. RPC框架的主要目标就是让远程服务调用更简单.透明.RPC框架负责屏蔽底层的传输方式(TCP ...

  4. 记一个pg连接数过多的异常

    java中使用数据库连接池,如果在部署的时候,操作不慎,可能出现典型的连接池爆满的问题 org.postgresql.util.PSQLException: FATAL: sorry, too man ...

  5. pip安装提示PermissionError: [WinError 5]错误问题解决

    操作环境   Python3.6 + Winodws7 问题现象 新安装python3.6版本后使用pip安装第三方模块失败,报错信息如下: C:\Users\linyfeng>pip inst ...

  6. 2.Servlet基础.md

    目录 1.定义 2.特点 3.手动编写一个Servlet 3.1创建一个Servlet类 3.2找到编写类的class文件,将这个类的整个包拷贝到一个web应用中的WEB-INF/classes目录下 ...

  7. Arcgis Runtime 100.3开发实例源代码调试日志

    Arcgis Runtime 100.3开发实例源代码调试日志 路径: "D:\arcgis runtime1003\arcgis-runtime-samples-dotnet-master ...

  8. android资讯类软件框架《IT蓝豹》

    android资讯类软件框架 android资讯类软件框架,支持侧滑,并且首页viewpager切换tab,tab滑动到最右侧的时候提示滑动结束, 滑动到最左侧的时候切换滑动侧滑menu.左滑和侧滑处 ...

  9. SpringBoot整合RabbitMQ,实现消息发送和消费以及多个消费者的情况

    下载安装Erlang和RabbitMQ Erlang和RabbitMQ:https://www.cnblogs.com/theRhyme/p/10069611.html AMQP协议 https:// ...

  10. 关于H5唤醒APP的功能实现(千辛万苦啊!)

    首先,我是个后端,写java的,甚至不是搞移动端的,所以js这方面有点底子但不专业,对于出现的错误也请见谅,原来项目要求有个H5页面打开APP的功能就强行要做,没办法就想办法搞一下,网上的教程基本都是 ...