Codeforces Beta Round #29 (Div. 2, Codeforces format)

http://codeforces.com/contest/29

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 maxn 1000005
typedef long long ll;
typedef unsigned long long ull;
const ull MOD=;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
int n;
cin>>n;
int a[],b[];
for(int i=;i<=n;i++){
cin>>a[i]>>b[i];
}
int flag=;
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(i!=j){
if(a[i]+b[i]==a[j]&&a[j]+b[j]==a[i]){
flag=;
}
}
}
}
if(flag) cout<<"YES"<<endl;
else cout<<"NO"<<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 maxn 1000005
typedef long long ll;
typedef unsigned long long ull;
const ull MOD=;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
double l,d,v,g,r;
cin>>l>>d>>v>>g>>r;
double ans=;
if(v*g>d) ans=l/v;
else{
l-=d;
double t=d/v;
ans=t;
double tt=g+r;
int flag=;
while(t>=){
t-=g;
if(t>=){
t-=r;
}
if(t<) flag=;
}
// cout<<t<<endl;
if(flag==){
ans-=t;
}
ans+=l/v;
}
printf("%.7f\n",ans);
}

C

找出一个度为1的点,然后跑dfs。因为值为1e9,所以需要离散化

 #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 maxn 1000005
typedef long long ll;
typedef unsigned long long ull;
const ull MOD=;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int n;
vector<int>ve;
int a[];
int b[];
int d[];
vector<int>V[]; int getid(int x){
return lower_bound(ve.begin(),ve.end(),x)-ve.begin()+;
} void dfs(int pos,int pre){
cout<<ve[pos-]<<" ";
for(int i=;i<V[pos].size();i++){
if(V[pos][i]!=pre){
dfs(V[pos][i],pos);
}
}
} int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>n;
for(int i=;i<=n;i++){
cin>>a[i]>>b[i];
ve.pb(a[i]);
ve.pb(b[i]);
}
sort(ve.begin(),ve.end());
ve.erase(unique(ve.begin(),ve.end()),ve.end());
int pos,pos1,pos2;
for(int i=;i<=n;i++){
pos1=getid(a[i]);
pos2=getid(b[i]);
d[pos1]++,d[pos2]++;
V[pos1].pb(pos2);
V[pos2].pb(pos1);
}
for(int i=;i<=n;i++){
pos1=getid(a[i]);
pos2=getid(b[i]);
if(d[pos1]==){
pos=pos1;
break;
}
if(d[pos2]==){
pos=pos2;
break;
}
}
dfs(pos,);
}

D

跑两个叶子结点的最短路,看看最后的个数是不是2*n-1

 #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 maxn 1000005
typedef long long ll;
typedef unsigned long long ull;
const ull MOD=;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int n;
vector<int>ve[];
int vis[];
int d[];
vector<int>ans; void dfs(int pos,int pre,int last,vector<int>tmp){
vis[pos]=;
if(pre!=) {
tmp.pb(pos);
}
if(pos==last){
for(int i=;i<tmp.size();i++){
ans.pb(tmp[i]);
}
return;
}
for(int i=;i<ve[pos].size();i++){
if(!vis[ve[pos][i]]&&ve[pos][i]!=pre){
dfs(ve[pos][i],pos,last,tmp);
}
}
} int main(){
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>n;
int u,v;
for(int i=;i<n;i++){
cin>>u>>v;
ve[u].pb(v);
ve[v].pb(u);
d[u]++,d[v]++;
}
int co=;
for(int i=;i<=n;i++){
if(d[i]==){
co++;
}
}
vector<int>son;
son.pb();
for(int i=;i<=co;i++){
cin>>u;
son.pb(u);
}
son.pb();
ans.pb();
for(int i=;i<son.size()-;i++){
memset(vis,,sizeof(vis));
vector<int>tmp;
tmp.clear();
dfs(son[i],,son[i+],tmp);
}
if(ans.size()==*n-){
for(int i=;i<ans.size();i++){
cout<<ans[i]<<" ";
}
cout<<endl;
}
else{
cout<<-<<endl;
}
}

E

bfs搜索,思路很有趣

标记是用A和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 maxn 1000005
typedef long long ll;
typedef unsigned long long ull;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */
int n,m;
vector<int>ve[];
int pre[][][];
bool book[][];
vector<int>ans[]; bool bfs(){
pre[][n][]=-;
pair<int,int>p,pp;
p=make_pair(,n);
queue<pair<int,int> >Q;
Q.push(p);
while(!Q.empty()&&pre[n][][]==){
p=Q.front();
Q.pop();
int p1=p.first,p2=p.second;
for(int i=;i<ve[p1].size();i++){
if(!book[ve[p1][i]][p2]){
book[ve[p1][i]][p2]=;
for(int j=;j<ve[p2].size();j++){
if(ve[p1][i]!=ve[p2][j]){
if(pre[ve[p1][i]][ve[p2][j]][]==){
pre[ve[p1][i]][ve[p2][j]][]=p1;
pre[ve[p1][i]][ve[p2][j]][]=p2;
pp=make_pair(ve[p1][i],ve[p2][j]);
Q.push(pp);
}
}
}
}
}
}
if(pre[n][][]==) return false;
int x=n,y=,z;
while(x>){
ans[].pb(x);
ans[].pb(y);
z=x;
x=pre[x][y][];
y=pre[z][y][];
}
return true;
} int main(){
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>n>>m;
int u,v;
for(int i=;i<=m;i++){
cin>>u>>v;
ve[u].pb(v);
ve[v].pb(u);
}
if(bfs()){
cout<<ans[].size()-<<endl;
for(int i=;i<;i++){
for(int j=ans[i].size()-;j>=;j--){
cout<<ans[i][j]<<" ";
}
cout<<endl;
}
}
else{
cout<<-<<endl;
} }

Codeforces Beta Round #29 (Div. 2, Codeforces format)的更多相关文章

  1. Codeforces Beta Round #29 (Div. 2, Codeforces format) C. Mail Stamps 离散化拓扑排序

    C. Mail Stamps Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem ...

  2. Codeforces Beta Round #29 (Div. 2, Codeforces format) C. Mail Stamps 拓扑排序

    C. Mail Stamps     One day Bob got a letter in an envelope. Bob knows that when Berland's post offic ...

  3. Codeforces Beta Round #32 (Div. 2, Codeforces format)

    Codeforces Beta Round #32 (Div. 2, Codeforces format) http://codeforces.com/contest/32 A #include< ...

  4. Codeforces Beta Round #31 (Div. 2, Codeforces format)

    Codeforces Beta Round #31 (Div. 2, Codeforces format) http://codeforces.com/contest/31 A #include< ...

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

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

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

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

  7. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  8. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

  9. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

随机推荐

  1. vue全局变量定义和修改

    1. 只读的全局变量 对于只读的全局变量,知道的有以下两种使用方式: 1)global.js 模块中定义:其他模块import后再使用即可 1.1)定义 import Vue from 'vue'; ...

  2. office2016系列产品关闭时卡顿

    关闭Print Spooler服务其方法如下: win+r键–>输入services.msc点击确定如下图 单击word中的文件-选项-加载项-COM加载项-转到,将所有加载项前面的勾都去掉(不 ...

  3. 让linux每天定时备份MySQL数据库并删除五天前的备份文件

    MYSQL定期备份是一项重要的工作,但人工操作太繁琐,也难避免有所疏漏,使用下面的方法即可让系统定期备份数据.利用系统crontab来定时执行备份文件,按日期对备份结果进行保存,达到备份的目的. 1. ...

  4. day19-高阶函数、匿名函数

    map 函数 map 是一个在 Python 里非常有用的高阶函数.它接受一个函数和一个序列(迭代器)作为输入,然后对序列(迭代器)的每一个值应用这个函数,返回一个序列(迭代器),其包含应用函数后的结 ...

  5. 本地项目 共享 到github仓库

    一.安装git客户端 Window下安装Git客户端. 二.配置Intellij idea中的Git/ GitHub 选择Github,填写Host.Login和Password,然后Test是否成功 ...

  6. inno setup 安装前判断进程是否存在,以及停止相应进程<转>

    打包的时候遇到了这样的需求:假似用户都是傻瓜                  式操作,如果更新安装程序的时候,之前的老程序还在运行这个时候如果你去提示让用户吧老程序手动退掉也不现实. 所以当遇到这种 ...

  7. Dictionary转为Model实例

    Dictionary<string, object> dic = new Dictionary<string, object>(); dic.Add(); dic.Add(&q ...

  8. sublime text 3 build 3143 安装详解

    sublime text 3 build 3143 安装详解   环境:ubuntu 16 (x64) 0x00 下载   官网下载地址   下载的文件是个压缩包,笔者解压之后将整个sublime-t ...

  9. zabbix 监控端口

    监控HTTPD端口的shell #!/bin/bash #2019年4月19日18:: ####### httpd=` netstat -tnlp|grep httpd|awk '{print $4} ...

  10. CentOS6.5安装MySQL5.7详细教程(本人6.3也行)

    本文参考http://www.cnblogs.com/lzj0218/p/5724446.html 主要参考博文: https://segmentfault.com/a/119000000304949 ...