Codeforces Beta Round #9 (Div. 2 Only)

http://codeforces.com/contest/9

A

gcd水题

 #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 1000010
typedef long long ll;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */
int gcd(int a,int b){
if(b==) return a;
return gcd(b,a%b);
} int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
int n,m;
cin>>n>>m;
n=max(n,m);
int fz=-n+;
int fm=;
int d=gcd(fz,fm);
// cout<<fz<<" "<<fm<<endl;
cout<<fz/d<<"/"<<fm/d<<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 1000010
typedef long long ll;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */
struct Point{
ll x,y;
}a[]; double dist[][]; int main(){
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif
ll n,vb,vs;
cin>>n>>vb>>vs;
for(int i=;i<=n;i++){
cin>>a[i].x;
a[i].y=;
}
ll sx,sy;
cin>>sx>>sy;
for(int i=;i<=n;i++){
dist[][i]=sqrt(sqr(a[].x-a[i].x)+sqr(a[].y-a[i].y));
}
for(int i=;i<=n;i++){
dist[i][]=sqrt(sqr(a[i].x-sx)+sqr(a[i].y-sy));
}
double ans=1e18;
ll pos=;
for(int i=;i<=n;i++){
if(a[i].x!=){
double t1=dist[][i]/vb;
double t2=dist[i][]/vs;
if(ans>=t1+t2){
ans=t1+t2;
pos=i;
}
}
}
cout<<pos<<endl;
}

C

dfs

 #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 1000010
typedef long long ll;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */
map<ll,int>mp;
ll n;
int ans; void dfs(int pos){
if(pos>n) return;
if(!mp[pos]){
ans++;
mp[pos]=;
}
else return;
dfs(pos*);
dfs(pos*+);
} int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
cin>>n;
dfs();
cout<<ans<<endl;
}

D

参考博客:http://www.cnblogs.com/qscqesze/p/5414271.html

DP

dp[i][j]表示当前用了i个节点,高度小于等于j的方案数

dp[i][j] = sigma(dp[k][j-1]*dp[i-k-1][j-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 maxn 1000010
typedef long long ll;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ long long dp[][]; int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
int n,h;
cin>>n>>h;
for(int i=;i<=n;i++){
dp[][i-]=;
for(int j=;j<=n;j++){
for(int k=;k<j;k++){
dp[j][i]+=dp[k][i-]*dp[j-k-][i-];
}
}
}
cout<<dp[n][n]-dp[n][h-]<<endl;
}

E

题意:给出n个点,m条边,问是否能通过加一些边,使得n个点构成有且仅有n条边的单个环

直接构造就好

 #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 1000010
typedef long long ll;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */
int fa[];
int d[];
vector<pair<int,int> > ve,ans;
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;
}
void join(int x,int y)
{
int xx=Find(x);
int yy=Find(y);
if(xx!=yy) fa[xx]=yy;
}
int main(){
int n,m;
cin>>n>>m;
int v,u;
for(int i=;i<=n;i++) fa[i]=i;
for(int i=;i<=m;i++){
cin>>u>>v;
ve.push_back(make_pair(u,v));
join(u,v);
d[v]++,d[u]++;
if(d[u]>||d[v]>){
cout<<"NO"<<endl;
return ;
}
}
for(int i=;i<=n;i++){
for(int j=;j<i;j++){
if(d[j]<=&&d[i]<=&&Find(i)!=Find(j))
{
ans.push_back(make_pair(j,i));
join(i,j);
d[i]++,d[j]++;
}
}
}
for(int i=;i<=n;i++){
if(d[i]!=){
for(int j=;j<i;j++){
if(d[j]==){
ans.push_back(make_pair(j,i));
join(i,j);
d[i]++,d[j]++;
}
}
}
}
for(int i=;i<=n;i++)
if(d[i]==)ans.push_back(make_pair(i,i));
int p = Find();
for(int i=;i<=n;i++)
if(Find(i)!=p){
cout<<"NO"<<endl;
return ;
}
cout<<"YES"<<endl;
cout<<ans.size()<<endl;
for(int i=;i<ans.size();i++)
cout<<ans[i].first<<" "<<ans[i].second<<endl;
}

Codeforces Beta Round #9 (Div. 2 Only)的更多相关文章

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

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

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

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

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

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

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

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

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

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

  6. Codeforces Beta Round #75 (Div. 2 Only)

    Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...

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

    Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...

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

    Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...

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

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

  10. Codeforces Beta Round #70 (Div. 2)

    Codeforces Beta Round #70 (Div. 2) http://codeforces.com/contest/78 A #include<bits/stdc++.h> ...

随机推荐

  1. 杂项-性能测试工具:LoadRunner

    ylbtech-杂项-性能测试工具:LoadRunner LoadRunner,是一种预测系统行为和性能的负载测试工具.通过以模拟上千万用户实施并发负载及实时性能监测的方式来确认和查找问题,LoadR ...

  2. 转载-MyBatis学习总结

    MyBatis学习总结(八)——Mybatis3.x与Spring4.x整合 孤傲苍狼 2015-02-07 00:09 阅读:89825 评论:54     MyBatis学习总结(七)——Myba ...

  3. Spark学习笔记3:键值对操作

    键值对RDD通常用来进行聚合计算,Spark为包含键值对类型的RDD提供了一些专有的操作.这些RDD被称为pair RDD.pair RDD提供了并行操作各个键或跨节点重新进行数据分组的操作接口. S ...

  4. Dividing Infinity - Distributed Partitioning Schemes

    This is the second post in a series discussing the architecture and implementation of massively para ...

  5. 【Python编程:从入门到实践】chapter10 文件和异常

    chapter10 文件和异常 10.1 从文件中读取数据 10.1.1 读取整个文件 with open("pi.txt") as file_object: contents = ...

  6. 测试运行kafka的时候缺少包的错误

    把kafka安装好了,在开启Kafka producer生产者,消费者的时候报这个错误 解决方法: 下载slf4j-1.7.6.ziphttp://www.slf4j.org/dist/slf4j-1 ...

  7. PyCharm License Activation激活码失效问题的解决方法

    自己的小Python项目好几天没有写了,今天打开PyCharm准备继续写,突然发现之前的激活码被取消不能用了,本来激情满满的准备干活啦!之前搜的这个激活码本来说的是可以用到18年1月份的呢,哎…心情是 ...

  8. 【Flutter】Flutter 一些常用库

    Flutter社区和资源传送门 新: 慕课网<Flutter入门与案例实战>   |   中文网<Flutter实战>电子书 字体图标生成 http://fluttericon ...

  9. Redis 在 LINUX 系统下 安装, 启动

    01, 下载  http://www.redis.cn/ ,  这里下再下来的是 redis-4.0.1.tar.gz 这个压缩包 02, 将压缩包放到 linux 系统中,  一般放在 usr/lo ...

  10. leetcode401

    public class Solution { /// <summary> /// 将二进制字符串转为十进制数字 /// </summary> /// <param na ...