Codeforces Beta Round #25 (Div. 2 Only)

http://codeforces.com/contest/25

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;
int a[];
map<int,int>mp; int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
int n;
cin>>n;
int d=,s=;
int posd,poss;
for(int i=;i<=n;i++){
cin>>a[i];
if(a[i]%) d++,posd=i;
else s++,poss=i;
}
if(d>s) cout<<poss<<endl;
else cout<<posd<<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 */ int n;
int a[];
map<int,int>mp; int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
int n;
cin>>n;
string str;
cin>>str;
int co=;
while(n){
if(n>){
n-=;
cout<<str[co]<<str[co+]<<'-';
co+=;
}
else{
if(n==)
cout<<str[co]<<str[co+]<<str[co+]<<endl;
else
cout<<str[co]<<str[co+]<<endl;
n=;
}
}
}

C

用floyd跑,类似DP的思想

 #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 dp[][]; int main(){
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif
//std::ios::sync_with_stdio(false);
int n;
cin>>n;
for(int i=;i<n;i++){
for(int j=;j<n;j++){
cin>>dp[i][j];
}
}
int m;
cin>>m;
ll u,v,c;
while(m--){
cin>>u>>v>>c;
u--,v--;
ll ans=;
for(int i=;i<n;i++){
for(int j=;j<n;j++){
dp[i][j]=min(dp[i][j],min(dp[i][u]+c+dp[v][j],dp[i][v]+c+dp[u][j]));
ans+=dp[i][j];
}
}
cout<<ans/<<" ";
}
}

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 */ int fa[]; int Find(int x){
int r=x,y;
while(x!=fa[x]){
x=fa[x];
}
while(r!=x){
y=fa[r];
fa[r]=x;
r=y;
}
return x;
} bool join(int x,int y){
int xx=Find(x);
int yy=Find(y);
if(xx!=yy){
fa[xx]=yy;
return true;
}
return false;
} int main(){
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif
//std::ios::sync_with_stdio(false);
int n;
cin>>n;
int u,v;
vector<pair<int,int> >ve;
for(int i=;i<=;i++) fa[i]=i;
for(int i=;i<n;i++){
cin>>u>>v;
if(!join(u,v)) ve.push_back(make_pair(u,v));
}
vector<pair<pair<int,int>,pair<int,int> > >ans;
for(int i=;i<ve.size();i++){
u=ve[i].first;
for(int j=;j<=n;j++){
if(join(u,j)){
ans.push_back(make_pair(make_pair(u,ve[i].second),make_pair(u,j)));
break;
}
}
}
cout<<ans.size()<<endl;
for(int i=;i<ans.size();i++){
cout<<ans[i].first.first<<" "<<ans[i].first.second<<" "<<ans[i].second.first<<" "<<ans[i].second.second<<endl;
}
}

E

字符串hash 找到一个前缀和另一个后缀最长相同的长度,也可以用kmp做

 #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;
typedef unsigned long long ull;
const ull MOD=;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */
int Check(string s1,string s2){
int len=;
if(s1.find(s2)!=-) return s1.length();
if(s2.find(s1)!=-) return s2.length();
int len1=s1.length();
int len2=s2.length();
int ans=len1+len2;
int i=len1-,j=;
ull aa=,bb=;
ull flag=;
// cout<<s1<<" "<<s2<<endl;
while(i>=&&j<len2){
aa=s1[i]*flag+aa;
flag=flag*MOD;
bb=bb*MOD+s2[j];
// cout<<s1[i]<<" "<<s2[j]<<" "<<aa<<" "<<bb<<endl;
if(aa==bb){
len=j+;
}
i--,j++;
}
return ans-len;
} int main(){
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif
//std::ios::sync_with_stdio(false);
string s1,s2,s3;
cin>>s1>>s2>>s3;
int len1=s1.length(),len2=s2.length(),len3=s3.length();
// cout<<len1<<" "<<len2<<" "<<len3<<" "<<len1+len2+len3<<endl;
int ans=0x3f3f3f3f;
ans=min(ans,(Check(s1,s2)+Check(s2,s3)-len2));
ans=min(ans,Check(s1,s3)+Check(s3,s2)-len3);
ans=min(ans,Check(s2,s1)+Check(s1,s3)-len1);
ans=min(ans,Check(s2,s3)+Check(s3,s1)-len3);
ans=min(ans,Check(s3,s1)+Check(s1,s2)-len1);
ans=min(ans,Check(s3,s2)+Check(s2,s1)-len2);
cout<<ans<<endl;
}

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

  1. codeforces水题100道 第十七题 Codeforces Beta Round #25 (Div. 2 Only) A. IQ test (brute force)

    题目链接:http://www.codeforces.com/problemset/problem/25/A题意:在n个书中找到唯一一个奇偶性和其他n-1个数不同的数.C++代码: #include ...

  2. Codeforces Beta Round #25 (Div. 2)--A. IQ test

    IQ test time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...

  3. Codeforces Beta Round #25 (Div. 2 Only) A. IQ test【双标记/求给定数中唯一的奇数或偶数】

    A. IQ test time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

  4. Codeforces Beta Round #25 (Div. 2 Only)E. Test

    E. Test time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...

  5. Codeforces Beta Round #25 (Div. 2 Only)D. Roads not only in Berland

    D. Roads not only in Berland time limit per test 2 seconds memory limit per test 256 megabytes input ...

  6. Codeforces Beta Round #25 (Div. 2 Only) C. Roads in Berland

    C. Roads in Berland time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  7. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  8. Codeforces Beta Round #49 (Div. 2)

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

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

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

随机推荐

  1. 火狐Firefox浏览器所有历史版本下载地址

    Mozilla Firefox 频繁的更新,导致许多好用的插件在更新后不能兼容,而且想换回低版本还不容易啊,官网上只看到最新版本和前一个版本的下载. 这里为大家提供了一个下载链接,是来自Mozilla ...

  2. Java的反射机制与泛型擦除

    实现方式 反编译:.class–>.java 通过反射机制访问java对象的属性,方法,构造方法等涉及类 java.lang.Class; java.lang.reflect.Construct ...

  3. JSONArray 遍历

    JSONArray 遍历   刚遇到一个接接口任务,发现其中返回数据中,是个字符串数组,数组中就是单个json形式的内容,其实应该也可以称这种数据叫做json数组吧,只不过是字符串形式.而我需要的是将 ...

  4. kafka无法消费数据

    遇到一个问题,使用Python kafka客户端和kafka命令行都无法消费数据,但是在kafka命令行后面添加--partition 0后就可以消费数据. bin/kafka-console-con ...

  5. JavaScript:几种常用循环

    ##循环数组的方法 1.for循环 for(let i = 0;i < ary.length;i++){ console.log(ary[i]); } 2.forEach ary.forEach ...

  6. Indy 10.5.8 for Delphi and Lazarus 修改版(2011)

    Indy 10.5.8 for Delphi and Lazarus 修改版(2011)    Internet Direct(Indy)是一组开放源代码的Internet组件,涵盖了几乎所有流行的I ...

  7. Haskell语言学习笔记(80)req

    req req 是一个好用,类型安全,可扩展,上层的HTTP客户端的库. $ cabal install req Installed req-1.1.0 Prelude> :m +Network ...

  8. numpy.distutils.system_info.NotFoundError: no lapack/blas resources found问题解决

    操作环境 Python3.6 + Windows7 问题现象   利用pip自动安装seaborn/numpy/scipy(pip install seaborn)模块失败,提示numpy.distu ...

  9. delphi注册热键方法(一)

    uses windows,menus; ..... //声明 HotKey_Key: Word; HotKey_Shift: Word; procedure WMHotKey(var msg : Tm ...

  10. Uni2D入门

    转载 http://blog.csdn.net/kakashi8841/article/details/17558059 开始 Uni2D增加了一些新的便利的特性给Unity,它们用于推动你2D工作流 ...