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. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

    转自:https://www.zhihu.com/question/20948649?sort=created 我最近也遇到这个问题了,用传统的快捷方式加参数并没有用,不知道是不是和chrome版本有 ...

  2. html to docx

    public static void main(String[] args) throws Exception{ //创建 POIFSFileSystem 对象 POIFSFileSystem poi ...

  3. 微信、陌陌等著名IM软件设计架构详解(转)

    对微信.陌陌等进行了分析,发出来分享一下(时间有些久了) 电量:对于移动设备最大的瓶颈就是电量了.因为用户不可能随时携带电源,充电宝.所以必须考虑到电量问题.那就要检查我们工程是不是有后台运行,心跳包 ...

  4. 尚硅谷redis学习11-jedis操作redis

    前面学习了redis的知识后,下面学习一下如何在java中通过jedis操作redis. 所需jar包:commons-pool-xxxx.jar,jedis-xxx.jar 下面看一下常用操作: 1 ...

  5. 直接在浏览器运行jsx及高版本的js代码

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...

  6. Ubuntu下的LNMP环境

    保证联网的情况下,直接参照http://lnmp.org/install.html进行安装,以下花括号内为原文引用: { 1.使用putty或类似的SSH工具登陆VPS或服务器: 登陆后运行:scre ...

  7. hibernate criteria Restrictions工具类用法

    CriteriaQuery cq = new CriteriaQuery(TSUser.class, dataGrid); // 查询条件组装器 org.jeecgframework.core.ext ...

  8. HTML+CSS基础课程三

    1.文字排版--字体 我们可以使用css样式为网页中的文字设置字体.字号.颜色等样式属性.下面我们来看一个例子,下面代码实现:为网页中的文字设置字体为宋体. body{font-family:&quo ...

  9. H5做的商城客户端,效果很不错

    H5做的商城客户端,效果很不错 H5做的商城客户端,效果和android原生客户端没多大区别,现在h5是越来越火了, android的小伙伴们又遇到一个新的挑战了.本项目只能学习一下WebViewAc ...

  10. 函数练习以及 if else 三元运算