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 现在你已经有一 ...
随机推荐
- AS3 - 对文件和目录的操作
1,写入到文件 1 2 3 4 5 var fileObj:File = File.documentsDirectory.resolvePath("hangge.txt"); va ...
- Delphi 修改本地日期和时间
procedure TForm1.ModifySysdate(D: Double); var systemtime:Tsystemtime; DateTime:TDateTime; begin Set ...
- kafka无法消费数据
遇到一个问题,使用Python kafka客户端和kafka命令行都无法消费数据,但是在kafka命令行后面添加--partition 0后就可以消费数据. bin/kafka-console-con ...
- 在postgresqlz中查看与删除索引
查看索引 select * from pg_indexes where tablename='tbname'; 或者 select * from pg_statio_all_inde ...
- [CI]CodeIgniter快速开发指南
---------------------------------------------------------------------------------------------------- ...
- 30.SSH配置文件模板和类库.md
目录 1.struts2 4.类库 1.struts2 1.<?xml version="1.0" encoding="UTF-8"?>2.< ...
- <assert.h>库学习
assert的初步认识 assert宏指令是用来诊断程序是否有误的,函数原型如下 void assert(int expression) 那为什么我们要使用assert而不用printf呢?因为ass ...
- canvas画布内部重复画圆
<!DOCTYPE html><html><head> <title>canvas example</title> <meta cha ...
- php导出excel不知道列数 php26进制函数
function num2Letter($num) { $num = intval($num); if ($num <= 0) return false; $letterArr = array( ...
- SSM框架简介及整合教程
1.Spring Spring 框架是 Java 应用最广的框架,它的成功来源于理念,而不是技术本身,它的理念包括 IoC (控制反转) 和 A面向切面编程).Spring框架是个轻量级的Java E ...