Codeforces Beta Round #9 (Div. 2 Only)
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)的更多相关文章
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- 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 #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
- Codeforces Beta Round #75 (Div. 2 Only)
Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...
- Codeforces Beta Round #74 (Div. 2 Only)
Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...
- Codeforces Beta Round #73 (Div. 2 Only)
Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...
- Codeforces Beta Round #72 (Div. 2 Only)
Codeforces Beta Round #72 (Div. 2 Only) http://codeforces.com/contest/84 A #include<bits/stdc++.h ...
- Codeforces Beta Round #70 (Div. 2)
Codeforces Beta Round #70 (Div. 2) http://codeforces.com/contest/78 A #include<bits/stdc++.h> ...
随机推荐
- [C#][MVC]DropDownListFor 默认值无法选中的 BUG
本文来自:https://www.cnblogs.com/craze/p/6124575.html 关于mvc中@Html.DropDownListFor和@Html.DropDownList默认值无 ...
- VS2005常用快捷键
Visual C++ 2005有很多种快捷键的映射方案,有适合 Emacs 用户的,有适合 Visual C++ 6.0 用户的,也有 Visual Studio 2005的,下面的快捷键符合IDE默 ...
- JVM的DirectMemory设置
转载http://blog.csdn.net/zshake/article/details/46785469 几台服务器的JVM占用内存总是持续增长,大大超过-Xmx设定的值,服务器物理内存几乎被耗尽 ...
- apache 服务器在ubuntu上图片无法显示解决
很简单的一段代码实例: <!DOCTYPE html> <html> <body> <h2>Welcome here!</h2> <i ...
- 关于win时间同步的解决方案
将以下的批处理执行:net stop w32time sc config w32time start= auto net start w32time w32tm /config /update /ma ...
- 推荐一个lamp的一键安装包
本来我是一直用的nginx的,现在安全者的服务器是用的tengine,稳定性就不用多说了! 前段时间用thinkphp写了两个两个项目,刚开始放到了国外的服务器上,环境也是lnmp的,最后发现ngin ...
- Storm存储结果至Redis
原有的事务支持使用MemcachedState来进行,现在需要将其迁移至Redis,并且需要记录所有key值列表,因为在redis中虽然可以使用keys *操作,但不是被推荐的方式,所以把所有结果 ...
- 自己写的jQuery颜色插件
界面效果: 插件js代码: ;(function ($) { //122种颜色 var aColors = [ "ff0000", "ffff00", &quo ...
- OpenGL 多线程共享纹理
1:opengl 多线程共享纹理纹理: //解码时候使用opengl进行绘制,需要构建队列和两个线程,分别用于解码数据并且填充纹理和渲染. 主线程常见两个共享上下文: main() { ⋯⋯⋯⋯ gH ...
- 35. oracle中instr在平台上的转换用法
//INSTR('15,17,29,3,30,4',a.femployee) var instrSql = fun.funHelper.charIndex('a.femployee',"'& ...