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. 浅谈JSONObject与JSONArray的区别

    例如:一个json字符串如下: { "type":[{"a","1"},{"a","2"},{&qu ...

  2. Directshow 采集与FFDshow 冲突

    在使用Directshow 进行视频采集的时候,发现与本地安装的一个ffdshow有冲突. 见下图: 经过测试发现dshow 在设置采集媒体类型的时候,如果设置RGB32就会崩溃,如果设置RGB24就 ...

  3. js的非空校验

    利用TagName获取元素名称,进行批量非空校验 var input = document.getElementsByTagName("input"); for (var i=0; ...

  4. git rebase 合并提交 解决超过100M文件的提交不能推送问题

    git log 现在可以看到有3个提交: change 1.mp4 size to small //发现不能推送,又改回小于100M add 1.mp4 big 改变为超过100M add 1.mp4 ...

  5. Statemnet和PerparedStstemnent有哪些区别

    Statement 和 PreparedStatement之间的关系和区别.     关系:PreparedStatement继承自Statement,都是接口     区别:PreparedStat ...

  6. [jPlayer]一分钟部署jPlayer

    ---------------------------------------------------------------------------------------------------- ...

  7. [PHP]PHP定时任务的实现

    ---------------------------------------------------------------------------------------------------- ...

  8. Java基本语法知识要点

    0x00   一个源文件中有多少个类,在用javac编译后,在同一目录下将产生多少个对应的字节码文件(.class ).类里面不一定要有public static void main(String[] ...

  9. python 小整数池 和intern 【整理】

    小整数对象池 (在python内置了) 整数在程序中的使用非常广泛,Python为了优化速度,使用了小整数对象池,避免为整数频繁申请和销毁内存空间. Python对小整数的定义是[-5,257]这些整 ...

  10. C#自制Web 服务器开发:mysql免安装版配置步骤详解分享

    mysql免安装版配置步骤详解分享 1.准备工作 下载mysql的最新免安装版本mysql-noinstall-5.1.53-win32.zip,解压缩到相关目录,如:d:\ mysql-noinst ...