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.js——60分钟组件快速入门(下篇)

    转自:https://www.cnblogs.com/keepfool/p/5637834.html 概述 上一篇我们重点介绍了组件的创建.注册和使用,熟练这几个步骤将有助于深入组件的开发.另外,在子 ...

  2. node.js 发送邮件

    var nodemailer = require('nodemailer'); var smtpTransport = require('nodemailer-smtp-transport'); // ...

  3. APP-2-Hbuilder开发环境搭建

    1.Hbuilder下载 http://www.dcloud.io/hbuilderx.html 2.夜神模拟器下载 https://www.yeshen.com/ 3.chrome浏览器下载 htt ...

  4. 尚硅谷springboot学习15-日志框架1-入门

    引子 小张:开发一个大型系统 1.System.out.println(""):将关键数据打印在控制台:去掉?写在一个文件? ​ 2.框架来记录系统的一些运行时信息:日志框架 : ...

  5. Eclipse SVN文件冲突及不能直接提交情况

    下图为Eclipse SVN使用过程中存在文件冲突的情形. 以下是三种冲突情形及相应解决办法: 1.简单的文件版本冲突 情形:A改变了文件的头部,B改变了文件的尾部,如果两者改动互不影响,SVN可以智 ...

  6. ajaxfileupload.js上传文件兼容IE7及以上版本

    要兼容IE789,要修改ajaxfileupload.js;要将此处的代码替换掉 if(window.ActiveXObject) { var io = document.createElement( ...

  7. Hibernate学习笔记2.2(Hibernate基础Annotation配置)

    如果数据库表名与类名不一致 可以用使用 @Table(name="_teacher") 来指定表名,没有就会自己创建 也可以在配置文件上修改 为class添加table属性 如果什 ...

  8. 如何设置java环境变量

    以安装目录是E:\Program Files\Java\jDK1.7.0为例:

  9. javascript 中Array.prototype.sort 函数的用法

    来源:http://www.jb51.net/article/5769.htm JavaScript中对变量的操作都是通过引用方式,而对数组也一样. 前两天想要对一个数组进行复制,一直苦于找不到办法( ...

  10. mysql 数据库必备命令操作,入门练习一下

    mysql 数据库必备命令操作 show databases: 查看所有的数据库: create database jfedu: 创建名为jfedu数据库: use nihao: 进入jfedu数据库 ...