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. jeecg好用吗,看看大家的评价

    大家都会有个疑问,jeecg好用吗? 看看大家的评价

  2. day06-三元表达式

    python中没有其他语言中的三元表达式,不过有类似的实现方法 其他语言中,例如java的三元表达式是这样int a = 1;String b = "";b = a > 1? ...

  3. Linux 删除指定时间的文件

    find /root/demo -mmin +10 -type f -name '*.png' -exec rm -rf {} \; find 相关:http://man.linuxde.net/fi ...

  4. html表单中get与post之间的区别

    当用户在 HTML 表单 (HTML Form) 中输入信息并提交之后,有两种方法将信息从浏览器传送到 Web 服务器 (Web Server). 一种方法是通过 URL,另外一种是在 HTTP Re ...

  5. javascript:解决两个小数相乘出现无限小数

    两个小数相乘,会出现无限小数:先把小数乘以10或100或1000(小数点后有多少位就乘以多少),再相乘,最后再除以10或100或1000

  6. C语言复习:结构体

    结构体专题 01.结构体类型定义及结构体变量定义     char c1,char c2, char name[62]; int age     char name[62]; int age,char ...

  7. 软件工程github使用小结

    1.在 https://github.com/join 这个网址处申请注册一个Github账号,申请成功后可在https://github.com/login 处利用刚刚注册的账号进行登录,才能开始在 ...

  8. 使用__slots__限制实例的属性

    1.给实例化的对象添加新的属性 看下面一段代码,然后给实例化的对象s添加或者修改属性 class Student(object): name='china' s = Student() s1=Stud ...

  9. ArcGIS案例学习笔记-手动编辑擦除挖空挖除相减

    ArcGIS案例学习笔记-手动编辑擦除挖空挖除相减 联系方式:谢老师,135-4855-4328,xiexiaokui#qq.com 目的:手动编辑擦除.挖空.挖除.相减 1. 选中内部要素 2. c ...

  10. 用git bash 传数据到远程出错:git push origin master 出错:error: failed to push some refs to

    https://blog.csdn.net/qq_28055429/article/details/51007453