Codeforces Round #328 div2
Problem_A(592A):
题意:
在一个8*8的棋盘上有黑白两种棋子,'W'代表白色,'B'代表黑色。
玩家A执白子,先走。 白子只能向上走,黑子只能向下走。如果有障碍物则不能走, 比如白色的上方有一个黑子,那么白子不能走。
谁先走到边界谁就赢了。 求解谁会赢
思路:
白子只能往上走, 黑子只能往下走。
所以只要找出最上面的白子和最下面的白子, 求距离边界最小值就可以了。
代码:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define eps 1e-6
#define MAXN 10
#define MAXM 100
#define dd {cout<<"debug"<<endl;}
#define pa {system("pause");}
#define p(x) {printf("%d\n", x);}
#define pd(x) {printf("%.7lf\n", x);}
#define k(x) {printf("Case %d: ", ++x);}
#define s(x) {scanf("%d", &x);}
#define sd(x) {scanf("%lf", &x);}
#define mes(x, d) {memset(x, d, sizeof(x));}
#define do(i, x) for(i = 0; i < x; i ++)
#define dod(i, x, l) for(i = x; i >= l; i --)
#define doe(i, x) for(i = 1; i <= x; i ++)
int n = ;
int row[MAXN][MAXN];
int read_ch()
{
char ch;
while(ch = getchar())
{
if(ch == 'B') return ;
if(ch == 'W') return ;
if(ch == '.') return ;
}
} int main()
{
mes(row, );
for(int i = ; i <= n; i ++)
for(int j = ; j <= n; j ++)
row[i][j] = read_ch(); int min_a = INF, min_b = INF; for(int j = ; j <= n; j ++)
{
for(int i = ; i <= n; i ++)
{
if(row[i][j] == ) break;
if(row[i][j] == )
{
min_a = min(min_a, i - );
break;
}
}
for(int i = n; i >= ; i --)
{
if(row[i][j] == ) break;
if(row[i][j] == )
{
min_b = min(min_b, n - i);
break;
}
}
}
printf("%c\n", min_a <= min_b ? 'A' : 'B');
return ;
}
Problem_B(592B):
题意:
给n个点, 依旧如下的规则划线:
1:先按顺时针将所有的点标号 1~n
2:从第一个点开始, 对其他n-1个点做一条射线
3:如果射线延长的过程中遇到其他线段, 则停止延长。
求这个n-1多边形内的区域被分成了多少块。
思路:
手动模拟一下n = 4和n = 6的情况,就能发现一个规律:
第一个点将区域划分成了 n - 2块区域。
第二个点又增加了 n - 3个区域。
第三个点增加了 n - 4 个区域。
.....
第n - 1个点增加了n - (n - 1) 块区域。
第n个点增加了n - 2块区域。
然后就能得到一个式子:
Sn = n - 2 + n - 3 + n - 4 + ... + n - (n - 1) + n - 2
= n * n - (2 + 3 + 4 + ... + (n - 1)) - 2
= n * n - (1 + 2 + 3 + ... + (n - 1)) - 1
= n * n - (1 + (n - 1)) * (n - 1) / 2 - 1
So 答案就出来了。
代码:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define eps 1e-6
#define MAXN 1000000
#define MAXM 100
#define dd {cout<<"debug"<<endl;}
#define pa {system("pause");}
#define p(x) {printf("%d\n", x);}
#define pd(x) {printf("%.7lf\n", x);}
#define k(x) {printf("Case %d: ", ++x);}
#define s(x) {scanf("%d", &x);}
#define sd(x) {scanf("%lf", &x);}
#define mes(x, d) {memset(x, d, sizeof(x));}
#define do(i, x) for(i = 0; i < x; i ++)
#define dod(i, x, l) for(i = x; i >= l; i --)
#define doe(i, x) for(i = 1; i <= x; i ++)
LL n;
LL get_ans(LL x)
{
return (n - ) + * (n - ) + (n - ) * (n - );
} int main()
{
scanf("%I64d", &n);
printf("%I64d\n", get_ans(n));
return ;
}
Codeforces Round #328 div2的更多相关文章
- Codeforces Round #539 div2
Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...
- 【前行】◇第3站◇ Codeforces Round #512 Div2
[第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...
- Codeforces Round#320 Div2 解题报告
Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...
- Codeforces Round #564(div2)
Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...
- Codeforces Round #361 div2
ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...
- Codeforces Round #626 Div2 D,E
比赛链接: Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) D.Present 题意: 给定大 ...
- Codeforces Round #328(Div2)
CodeForces 592A 题意:在8*8棋盘里,有黑白棋,F1选手(W棋往上-->最后至目标点:第1行)先走,F2选手(B棋往下-->最后至目标点:第8行)其次.棋子数不一定相等,F ...
- CodeForces Round 192 Div2
This is the first time I took part in Codeforces Competition.The only felt is that my IQ was contemp ...
- Codeforces Round #328 (Div. 2) D. Super M
题目链接: http://codeforces.com/contest/592/problem/D 题意: 给你一颗树,树上有一些必须访问的节点,你可以任选一个起点,依次访问所有的必须访问的节点,使总 ...
随机推荐
- PHP免费API调用,使用(CURL)
<?phpclass GetApiModel{//获取第三方API //获取身份证信息 //返回json /*{ "errNum": 0, "retMsg" ...
- APK downloader
APK Downloader Android apk (2016-08-25发现) Apk pure 好像提供免费的FQ工具哟 发现一个Android richtext RichEditor for ...
- xml的语法与创建
xml语法很简单,但很严格,如果出现错误则不能正常解析,而HTML如果出现局部的错误,照样解析 xml第一行必须写xml头<?xml version='1.0' encoding='utf8'? ...
- ThinkPHP的配置
ThinkPHP配置:conf目录下 'URL_PATHINFO_DEPR'=>'-',//修改URL的分隔符, 'TMPL_L_DELIM'=>'<{', //修改左定界符 'TM ...
- 注册Model类
根据username查找是否存在相同的用户名的方法 自动填充功能填充注册时间字段 如果两次输入的密码一直则写入数据库的方法 userModel.class.php <?php /**** 燕十八 ...
- java基础之Java变量命名规范
本文介绍的是java中的变量的命名规则,对于初学者来说,还是很重要的.希望对你有帮助,一起来看. Java是一种区分字母的大小写(case-sensitive)的语言,下面谈谈Java语言中包.类.变 ...
- cocos2d-x实战 C++卷 学习笔记--第7章 动作、特效(一)
前言: 介绍cocos2d-x中的动作.特效. 动作: 动作(action)包括基本动作和基本动作的组合,这些基本动作有缩放.移动.旋转等,而且这些动作变化的速度也可以设定. 动作类是 Action. ...
- [jquery]高级篇--获取div子元素
参考: http://zhidao.baidu.com/link?url=IfeQQBn1xMLqWvwdkKbQYJ8mC6ciGi_8M1NYkm6iQ-kXBMX2f2ylN-ckzFLiynn ...
- 学习C++ Primer 的个人理解(三)
第三章,主要内容是字符串和数组.感觉作者的意图是希望读者可以早一点可以写出简单的小程序,并且可以早点接触迭代器这种思想. 在我看来,这种内容的难度并不大. 对于编程来说,最重要的应该是思想,类似vec ...
- QtSQL学习笔记(4)- 使用SQL Model类
除了QSqlQuery,Qt提供了3个高级类用于访问数据库.这些类是QSqlQueryModel.QSqlTableModel和QSqlRelationalTableModel. 这些类是由QAbst ...