Codeforces Round #306 (Div. 2) D-E
来源:互联网 发布:jquery遍历json数组 编辑:程序博客网 时间:2024/04/29 19:26
D构造
首先我们想到的是做一个对称的图形,如同哑铃一般,中间的就是桥,两侧的就是双连通块。
那么我们想到的是构造一个双连通块,使得这个双连通块有一个点的度数为
接着想到了完全图,对于一个完全图来说,每个点的度数为
此时发现当
奇数的时候,构造方法很多,随便画一下就行了。
我的方法是:将它连成一个环,然后除去最大的那个值(当做桥的接口),从
// whn6325689// Mr.Phoebe// http://blog.csdn.net/u013007900#include <algorithm>#include <iostream>#include <iomanip>#include <cstring>#include <climits>#include <complex>#include <fstream>#include <cassert>#include <cstdio>#include <bitset>#include <vector>#include <deque>#include <queue>#include <stack>#include <ctime>#include <set>#include <map>#include <cmath>#include <functional>#include <numeric>#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;#define eps 1e-9#define PI acos(-1.0)#define INF 0x3f3f3f3f#define LLINF 1LL<<62#define speed std::ios::sync_with_stdio(false);typedef long long ll;typedef unsigned long long ull;typedef long double ld;typedef pair<ll, ll> pll;typedef complex<ld> point;typedef pair<int, int> pii;typedef pair<pii, int> piii;typedef vector<int> vi;#define CLR(x,y) memset(x,y,sizeof(x))#define CPY(x,y) memcpy(x,y,sizeof(x))#define clr(a,x,size) memset(a,x,sizeof(a[0])*(size))#define cpy(a,x,size) memcpy(a,x,sizeof(a[0])*(size))#define debug(a) cout << #a" = " << (a) << endl;#define debugarry(a, n) for (int i = 0; i < (n); i++) { cout << #a"[" << i << "] = " << (a)[i] << endl; }#define mp(x,y) make_pair(x,y)#define pb(x) push_back(x)#define lowbit(x) (x&(-x))#define MID(x,y) (x+((y-x)>>1))#define getidx(l,r) (l+r|l!=r)#define ls getidx(l,mid)#define rs getidx(mid+1,r)#define lson l,mid#define rson mid+1,rtemplate<class T>inline bool read(T &n){ T x = 0, tmp = 1; char c = getchar(); while((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar(); if(c == EOF) return false; if(c == '-') c = getchar(), tmp = -1; while(c >= '0' && c <= '9') x *= 10, x += (c - '0'),c = getchar(); n = x*tmp; return true;}template <class T>inline void write(T n){ if(n < 0) { putchar('-'); n = -n; } int len = 0,data[20]; while(n) { data[len++] = n%10; n /= 10; } if(!len) data[len++] = 0; while(len--) putchar(data[len]+48);}//-----------------------------------int k;vector<int> g[222];int main(){ scanf("%d",&k); if(k==1) { puts("YES"); printf("%d %d\n",2,1); printf("%d %d\n",1,2); } else if(k&1) { puts("YES"); for(int i=1; i<=k+1; i++) for(int j=i+1; j<=k+1; j++) g[i].push_back(j); for(int i=1; i<=k/2; i++) for(int j=0; j<g[i].size(); j++) if(g[i][j]==(k+1)-i+1) { g[i][j]=k+2; g[(k+1)-i+1].push_back(k+2); } printf("%d %d\n",(k+2)*2,(k+2)*k); for(int i=1; i<=k+1; i++) for(int j=0; j<g[i].size(); j++) printf("%d %d\n",i,g[i][j]); for(int i=1; i<=k+1; i++) for(int j=0; j<g[i].size(); j++) printf("%d %d\n",k+2+i,k+2+g[i][j]); printf("%d %d\n",k+2,(k+2)*2); } else puts("NO"); return 0;}
E也是构造,题目不太好做,但是如果看了数据的话,很快就可以出来。
从给的四个式子中可以发现如果结果要为0,最后一位必须是0,现在要做的就是再最后一个0之前构造1,我们可以发现如果最后一个0的前面一个是1,那么不管这个1之前是什么最后答案都是1,因为0 ->1=1,1 ->1=1,即与前面的值无关,所以我们转过来考虑不可能的情况,考虑最后一个0的前面是0,因为要构1,又0->0=0,1->0=0也就是说这个0前面不能是1,依次类推可以得到,如果倒数第二个0的前面都是1,那必然无解,否则就有解
// whn6325689// Mr.Phoebe// http://blog.csdn.net/u013007900#include <algorithm>#include <iostream>#include <iomanip>#include <cstring>#include <climits>#include <complex>#include <fstream>#include <cassert>#include <cstdio>#include <bitset>#include <vector>#include <deque>#include <queue>#include <stack>#include <ctime>#include <set>#include <map>#include <cmath>#include <functional>#include <numeric>#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;#define eps 1e-9#define PI acos(-1.0)#define INF 0x3f3f3f3f#define LLINF 1LL<<62#define speed std::ios::sync_with_stdio(false);typedef long long ll;typedef unsigned long long ull;typedef long double ld;typedef pair<ll, ll> pll;typedef complex<ld> point;typedef pair<int, int> pii;typedef pair<pii, int> piii;typedef vector<int> vi;#define CLR(x,y) memset(x,y,sizeof(x))#define CPY(x,y) memcpy(x,y,sizeof(x))#define clr(a,x,size) memset(a,x,sizeof(a[0])*(size))#define cpy(a,x,size) memcpy(a,x,sizeof(a[0])*(size))#define debug(a) cout << #a" = " << (a) << endl;#define debugarry(a, n) for (int i = 0; i < (n); i++) { cout << #a"[" << i << "] = " << (a)[i] << endl; }#define mp(x,y) make_pair(x,y)#define pb(x) push_back(x)#define lowbit(x) (x&(-x))#define MID(x,y) (x+((y-x)>>1))#define getidx(l,r) (l+r|l!=r)#define ls getidx(l,mid)#define rs getidx(mid+1,r)#define lson l,mid#define rson mid+1,rtemplate<class T>inline bool read(T &n){ T x = 0, tmp = 1; char c = getchar(); while((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar(); if(c == EOF) return false; if(c == '-') c = getchar(), tmp = -1; while(c >= '0' && c <= '9') x *= 10, x += (c - '0'),c = getchar(); n = x*tmp; return true;}template <class T>inline void write(T n){ if(n < 0) { putchar('-'); n = -n; } int len = 0,data[20]; while(n) { data[len++] = n%10; n /= 10; } if(!len) data[len++] = 0; while(len--) putchar(data[len]+48);}//-----------------------------------const int MAXN=100010;int a[MAXN],n;int main(){ scanf("%d",&n); for(int i=1; i<=n; i++) scanf("%d",&a[i]); if(a[n]) { puts("NO"); return 0; } if(n==1) printf("YES\n0\n"); else if(a[n-1]) { puts("YES"); for(int i=1; i<=n; i++) printf("%d%s",a[i],i==n?"\n":"->"); } else if(n==2) printf("NO\n"); else { int las=n-2; while(las && a[las]) las--; if(las==0) puts("NO"); else { puts("YES"); for(int i=1; i<las; i++) printf("%d->",a[i]); printf("(0->("); for(int i=las+1; i<=n-2; i++) printf("1->"); printf("0))->0\n"); } } return 0;}
0 0
- Codeforces Round #306 (Div. 2) D-E
- Codeforces Round #184 (Div. 2) D、E
- Codeforces Round #283 (Div. 2) D,E
- Codeforces Round #345 (Div. 2) D,E
- Codeforces Round #368 (Div. 2) D &E
- Codeforces Round #443 (Div. 2) D,E
- Codeforces Round #306 (Div. 2) D.E. 解题报告
- Codeforces Round #186 (Div. 2)A、B、C、D、E
- Codeforces Round #237 (Div. 2) E. Maze 1D
- Codeforces Round #258 (Div. 2)-(A,B,C,D,E)
- Codeforces Round #261 (Div. 2) A,B,C,D,E
- Codeforces Round #263 (Div. 2) A,B,C,D,E
- Codeforces Round #264 (Div. 2) A,B,C,D,E
- Codeforces Round #274 (Div. 2) 解题报告 (C D E)
- Codeforces Round #277 (Div. 2) A,B,C,D,E
- Codeforces Round #280 (Div. 2 A,B,C,D,E)
- Codeforces Round #287 (Div. 2) A、B、C、D、E
- Codeforces Round #287 (Div. 2)A,B,C,D,E
- hdu 5037 Frog(贪心)
- 错误Unable to load native-hadoop library for your platform...
- 方便的任意处使用UI线程的工具类分享
- JAVA 遍历Map的四种方法
- 9.17学习笔记 java和python交互,java8位UUID,mac闪电接口高清线导购
- Codeforces Round #306 (Div. 2) D-E
- GitHub基础学习—简单分支处理
- 反复校验用户输入的日期,直到年、月、日都合法,计算该日在本年中为第几天?(注意考虑闰年问题)
- PHP数据存储与检索
- HttpClient结合Structs2进行文件上传(Action返回字符串)
- Android服务器主动推送之百度云推送
- 谱聚类matlab
- 行为模式:观察者模式
- 中文编码过滤器2: post和get方式都有效