Codeforces Beta Round #25 (Div. 2 Only)
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)的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #49 (Div. 2)
Codeforces Beta Round #49 (Div. 2) http://codeforces.com/contest/53 A #include<bits/stdc++.h> ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
随机推荐
- python内置函数使用
print(abs(1)) #绝对值,正数就是自己 ",''])) #计算可迭代对象中是否为真,其中一个为假,就显示为假 print(all('')) # If the iterable i ...
- STM32F103C8开发板原理图和管脚图
- Django中MEDIA_ROOT和MEDIA_URL
在django上传图片前端使用动态的配置方法 MEDIA_ROOT 代表着 要上传的路径会和你在models中写的上传的路径进行拼节形成最终文件上传的路径 MEDIA_URL主要就是映射了 在前端使用 ...
- selenium初次接触-1
10月30日 web自动化测试的两种方式:模拟整个http客户端(压力测试,取代浏览器和人,直接和服务端进行交互),模拟用户操作(功能测试,取代人) selenium是自动化浏览器的工具包,可以用于各 ...
- Cmake 编译opengl开源库glfw工程及使用
使用的是cmake gui进行编译的,路径输入好之后,点configure配置vs版本,这里是vs2013版本,然后如果画面出现红色的 需要再点击一下 Generate 然后直接点open proje ...
- openGL-------------别人的博客
https://blog.csdn.net/dcrmg/article/category/6505957 OpenGL(一)绘制圆.五角星.正弦曲线 ========================= ...
- self, super理解
self是方法参数列表中的第一个参数,是运行时决定的. super是编译器符号,是编译时决定的.super的含义为从父类开始寻找相应的方法,父类在编译的时候就已经决定了. 一个关键点:super并不代 ...
- cordova-config.xml 配置记录
<?xml version='1.0' encoding='utf-8'?> <widget id="come.gs.webapp1" version=" ...
- js 对象创建设计模式
创建js对象可以使用多种模式,每种模式有着不同的特点:如下: 1.工厂模式:创建一个函数,在函数中实例化一个对象,当每次调用函数时,就实例化一个对象,并返回这个对象: 我们知道,对象是引用形式的,每次 ...
- css 的pointer-events 属性
1.css 有好多属性,可以让你感觉到不可思议,关键是可以解决一些难以实现的问题,今天遇到一个,就是 point-enevts属性 支持 pointer-events 属性 的浏览器版本 2. 1 ...