Codeforces Round #306 (Div. 2) D.E. 解题报告
D题:Regular Bridge
乱搞。
构造
这题乱搞一下即可了。构造一个有桥并且每一个点的度数都为k的无向图。
方法非常多。也不好叙述。。
代码例如以下:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#define INF 0x3f3f3f3f
#define LL long long
const int mod=1e9+7;
using namespace std ;
int main()
{
int k, i, j;
while(scanf("%d",&k)!=EOF){
if(k==1){
puts("YES\n2 1\n1 2");
continue ;
}
if(!(k&1)) {
puts("NO");
continue ;
}
puts("YES");
printf("%d %d\n",2*k+4,(k+2)*k);
printf("1 2\n1 %d\n",k+2);
for(i=1;i<=(k-3)/2;i++){
printf("1 %d\n1 %d\n",i+2,k+2-i);
}
for(i=2;i<=k+2;i++){
for(j=i+1;j<=k+2;j++){
if(i==2&&j==k+2) continue ;
if(i<=(k-3)/2+2&&i>=3&&i+j==k+4) continue ;
printf("%d %d\n",i,j);
}
}
printf("%d %d\n%d %d\n",k+3,k+4,k+3,2*k+4);
for(i=1;i<=(k-3)/2;i++){
printf("%d %d\n%d %d\n",k+3,k+4+i,k+3,2*k+4-i);
}
for(i=k+4;i<=2*k+4;i++){
for(j=i+1;j<=2*k+4;j++){
if(i==k+4&&j==2*k+4) continue ;
if(i>=k+5&&i<=k+4+(k-3)/2&&j+i==3*k+8) continue ;
printf("%d %d\n",i,j);
}
}
printf("1 %d\n",k+3);
}
return 0 ;
}
E题:Brackets in Implications
乱搞。
构造。
首先能够注意到仅仅有1->0的结果为0.所以必需要构造出一个1->0来,所以最后一个必须为0,否则不管怎样也构造不出最后的0.然后仅仅要在最后一位的0前面构造出一个1就能够了,由于不管前面的结果是什么,仅仅要加上这个1。结果肯定为1,就能够跟最后一位的0构造出0来了。
然后再看第n-1位,第n-1位假设是1。那么就直接按原样输出就能够了。
这时候第n-1位为0.然后能够注意到第n-1位的前面仅仅要有1个0就能够了。由于0加上随意一个数都是1,所以能够变成这样的形式(0->(1->(1->(1……0))…)->0。
假如前面没有0的话,那么就是全是1。那么不管怎么构造也都是变成1->0->0。所曾经面必须有个0,而仅仅要有一个0,构造方法就出来了。
代码例如以下:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#define INF 0x3f3f3f3f
#define LL long long
const int mod=1e9+7;
using namespace std ;
int a[1100000];
int main()
{
int n, i, pos, flag;
while(scanf("%d",&n)!=EOF){
for(i=1;i<=n;i++){
scanf("%d",&a[i]);
}
if(a[n]){
puts("NO");
continue ;
}
if(n==1){
puts("YES\n0\n");
continue ;
}
if(a[n-1]){
puts("YES\n");
for(i=1;i<=n;i++){
printf("%d",a[i]);
if(i!=n) printf("->");
}
continue ;
}
if(n==2){
puts("NO");
continue ;
}
flag=0;
for(i=n-2;i>=1;i--){
if(!a[i]){
flag=1;
pos=i;
break;
}
}
if(!flag) {
puts("NO");
continue ;
}
puts("YES");
for(i=1;i<pos;i++){
printf("%d->",a[i]);
}
for(i=pos;i<=n-2;i++){
printf("(%d->",a[i]);
}
printf("%d",a[n-1]);
for(i=pos;i<=n-2;i++){
printf(")");
}
printf("->%d\n",a[n]);
}
return 0 ;
}
Codeforces Round #306 (Div. 2) D.E. 解题报告的更多相关文章
- 数学/找规律/暴力 Codeforces Round #306 (Div. 2) C. Divisibility by Eight
题目传送门 /* 数学/暴力:只要一个数的最后三位能被8整除,那么它就是答案:用到sprintf把数字转移成字符读入 */ #include <cstdio> #include <a ...
- DFS Codeforces Round #306 (Div. 2) B. Preparing Olympiad
题目传送门 /* DFS: 排序后一个一个出发往后找,找到>r为止,比赛写了return : */ #include <cstdio> #include <iostream&g ...
- 水题 Codeforces Round #306 (Div. 2) A. Two Substrings
题目传送门 /* 水题:遍历一边先找AB,再BA,再遍历一边先找BA,再AB,两种情况满足一种就YES */ #include <cstdio> #include <iostream ...
- Codeforces Round #306 (Div. 2) E. Brackets in Implications 构造
E. Brackets in Implications Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...
- Codeforces Round #306 (Div. 2) D. Regular Bridge 构造
D. Regular Bridge Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/pro ...
- Codeforces Round #306 (Div. 2) C. Divisibility by Eight 暴力
C. Divisibility by Eight Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...
- Codeforces Round #306 (Div. 2) B. Preparing Olympiad dfs
B. Preparing Olympiad Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550 ...
- Codeforces Round #306 (Div. 2) A. Two Substrings 水题
A. Two Substrings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/pro ...
- Codeforces Round #306 (Div. 2) 550A Two Substrings
链接:http://codeforces.com/contest/550/problem/A 这是我第一次玩cf这种比赛,前面做了几场练习,觉得div2的前面几个还是比较水的. 所以看到这道题我果断觉 ...
随机推荐
- WAMP多站点配置,更改服务器端口
修改apache.conf的配置文件 设置保存路径 原本的路径:DocumentRoot "D:/wamp/www/" 修改为自己定义的路径:D:\all_code\php 查询: ...
- HDU2527:Safe Or Unsafe(哈弗曼树)
Problem Description Javac++ 一天在看计算机的书籍的时候,看到了一个有趣的东西!每一串字符都可以被编码成一些数字来储存信息,但是不同的编码方式得到的储存空间是不一样的!并且当 ...
- HDU 5025Saving Tang Monk BFS + 二进制枚举状态
3A的题目,第一次TLE,是因为一次BFS起点到终点状态太多爆掉了时间. 第二次WA,是因为没有枚举蛇的状态. 解体思路: 因为蛇的数目是小于5只的,那就首先枚举是否杀死每只蛇即可. 然后多次BFS, ...
- Ural 1001 - Reverse Root
The problem is so easy, that the authors were lazy to write a statement for it! Input The input stre ...
- 转:python中函数curry化
1 柯里化(Currying) 一个函数有多个参数,我们希望能固定其中几个参数的值. from functools import partial def foo(a,b,c): return a+b+ ...
- The connection to adb is down, and a severe error has occured.问题解决
遇到问题描述: 运行android程序控制台输出 [2013-06-25 11:10:32 - MyWellnessTracker] The connection to adb is down, an ...
- 【Linux】Linux 自己主动挂载NTFS格式移动硬盘
1.首先下载ntfs-3g http://www.tuxera.com/community/ntfs-3g-download/ 2.解压 $tar zxvf ntfs-3g_ntfsprogs-201 ...
- 第三方系统打开EAFC的实现
前言:EAFC是我们公司的一个框架,一个项目上,客户的OA系统要调用我们推送过去的代办任务,希望能打开我们的代办处理界面,我们的代办处理界面是winform的.引出给出了以下的一个方案.在此备存. - ...
- Linux -FHS 标准
FHS (Filesystem Hierarchy Standard),其目的是让用户可以了解以安装软件通常放在那个文件下面. /bin 放置的是单用户维护模式下,能够被调用的命令.主要有cat,ch ...
- Thread.sleep还是TimeUnit.SECONDS.sleep
转http://stevex.blog.51cto.com/4300375/1285767/ 刚看到TimeUnit.SECONDS.sleep()方法时觉得挺奇怪的,这里怎么也提供sleep方法? ...