Codeforces Beta Round #49 (Div. 2)

时间:2023-11-10 14:24:08

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;
}