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. 字符串md5之后转成int类型, 方便数据库索引

    function hashStringToInt($string){ $stringHash = substr(md5($string), 0, 8); return base_convert($st ...

  2. RabbitMQ系列教程之一:我们从最简单的事情开始!Hello World(转载)

    RabbitMQ系列教程之一:我们从最简单的事情开始!Hello World 一.简介 RabbitMQ是一个消息的代理器,用于接收和发送消息,你可以这样想,他就是一个邮局,当您把需要寄送的邮件投递到 ...

  3. spring使用中ModelAttribute的内容被覆盖

    在前台以get方式向后台提交数据: 后台接收: 后台接收参数的时候,由于user里面也有一个属性为id,后台在接收参数的时候,User里面的id会被重新赋值,这是一个大坑.如果后续继续用User来做操 ...

  4. VPS 相关

    1.一键测试 wget http://soft.laozuo.org/tools/cpu-io.shsh cpu-io.sh 2.锐速破解 wget -N --no-check-certificate ...

  5. mysql 远程 ip访问

    默认情况下Linux内的mysql数据库mysql,user表内的用户权限只是对localhost即本机才能登陆.需要更改权限: 如下的方式确认: root#mysql -h localhost-u  ...

  6. SQL调用C# dll(第二中DLL,强名称密匙)

    参考:微软官网 https://msdn.microsoft.com/zh-cn/library/ms345106(es-es).aspx 1.新建项目 SQLDllTestUsingNew Clas ...

  7. Windows组件下载地址

    Windows下载中心 http://www.microsoft.com/zh-cn/download/default.aspx IE10下载地址 http://www.microsoft.com/z ...

  8. requests库的文档--快速上手

    快速上手 迫不及待了吗?本页内容为如何入门 Requests 提供了很好的指引.其假设你已经安装了 Requests.如果还没有,去安装一节看看吧. 首先,确认一下: Requests 已安装 Req ...

  9. Android Studio SVN配置

    一 . 原文链接:忽略文件[转]    https://blog.csdn.net/buaaroid/article/details/51546521 1.用Android Studio创建一个项目, ...

  10. com.android.dx.command.Main with arguments

    Error:Execution failed for task ':jingyeyun:transformClassesWithDexForDebug'.> com.android.build. ...