洛谷 题解 P2645 【斯诺克】
吐槽一下这道题:
数据太水了!!!
请注意,这题如果你考虑了犯规的情况,那么你的分数。。。可能会和我一样,只有40分。
也就是说,这是一篇AC不了这道题的题解!!!
现在,我来讲一下这道题的正解:
- 两个变量
less
和color
:less
记录剩余颜色为color
的球的个数,且场上没有颜色比less
小的球。 - 由题意,当场上没有红球时,第单数个球必须是红球
- 当场上有红球时,第双数个球必须是彩球,且击打不消耗个数。
- 当
less
为0
时,less = 0, color++;
给出处理某一个人的伪代码:
执行 n 次 {
记录上次球的颜色
读入这次球的颜色
如果 (这次球的颜色为 0) {
直接给对方加 4 分
} 否则 如果 (这是第单数个球 并且 红球没有打完) {
如果 (这次球的颜色不是 1) {
如果 (这次球的颜色对应的分数比 4 大) {
给对方加上这次球的颜色对应的分数
} 否则 {
给对方加 4 分
}
} 否则 {
给自己加 1 分
红球个数减 1
如果 (已经没有红球了) {
颜色加 1
该颜色个数置为 1
}
}
} else {
if ((上次打的不是红球 && 这次打的颜色比应该打的颜色大) || 这次打了红球) {
如果 (这次球的颜色对应的分数比 4 大) {
给对方加上这次球的颜色对应的分数
} 否则 {
给对方加 4 分
}
} else {
给自己加 这次球的颜色对应的分数 分
如果 (这个不是红球后面紧随的球) 该球个数减 1;
如果 (已经没有 color 颜色的球了) {
颜色加 1
该颜色个数置为 1
}
}
}
}
最终代码
/*
Name: Z*** Y* (H***Z*** J***L** Middle School, China)
Copyright: 航空信奥
Author: 航空信奥
Date: 2018-10-19
Description: the program that can solve snooker
*/
#include <queue>
#include <vector>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
using std::max;
using std::min;
using std::cerr;
using std::endl;
using std::sort;
using std::queue;
using std::vector;
using std::priority_queue;
struct fast_IO {
#define fast_IO_all_DEBUG 0
#define fast_IO_read_DEBUG 0
#define fast_IO_write_DEBUG 0
bool __read_sign_LowThan0;
char __read_buf_ch;
template <typename type>
void read(type &res)
{
__read_sign_LowThan0 = 0;
__read_buf_ch = getchar();
while (__read_buf_ch > '9' || __read_buf_ch < '0') {
__read_buf_ch = getchar();
if (__read_buf_ch == '-') {
__read_sign_LowThan0 = 1;
__read_buf_ch = getchar();
break;
}
}
res = (__read_buf_ch & 15);
__read_buf_ch = getchar();
while (__read_buf_ch <= '9' && __read_buf_ch >= '0') {
res = (res << 3) + (res << 1) + (__read_buf_ch & 15);
__read_buf_ch = getchar();
}
if (__read_sign_LowThan0) {
res = ((~res) + 1);
}
#if fast_IO_all_DEBUG || fast_IO_read_DEBUG
printf("[TEST $ read %d $ ]", res);
#endif
}
} io;
#define read io.read
#define write io.write
#define passing() fprintf(stderr, "passing line [%d] in function %s.\n", __LINE__, __FUNCTION__)
#define debug(x) cerr << "[debug] " << #x << " = " << x << endl
#define Max_N (107)
#define Max_M
#define Max_K
#define Max_LogN
#define Max_LogM
#define Max_LogK
int n, m, k;
#define P 10007
int a[Max_N] = {0};
bool used[Max_N] = {false};
#define FILE
int color = 1;
int less = 15;
void doit(int &n, int &mine, int &your)
{
int t, las;
for (int i = 1; i <= n; i++) {
las = t;
read(t);
if (!t) {
your += 4;
} else if ((i & 1) && color == 1) {
if (t != 1) {
if (t > 4) {
your += t;
} else {
your += 4;
}
} else {
mine++;
less--;
if (less == 0) {
color++;
less = 1;
}
}
} else {
if ((las != 1 && t > color) || t == 1) {
if (t > 4) {
your += t;
} else {
your += 4;
}
} else {
mine += t;
if (las != 1 && color != 1) less--;
if (less == 0) {
color++;
less = 1;
}
}
}
// printf("ball %d: %d:%d [color = %d eith %d in low]\n", t, mine, your, color, less);
}
}
int main()
{
#ifdef FILE
freopen("snooker.in", "r", stdin);
freopen("snooker.out", "w", stdout);
#endif
read(n);
read(m);
int ansa(0), ansb(0);
doit(n, ansa, ansb);
doit(m, ansb, ansa);
printf("%d %d", ansa, ansb);
return 0;
}
洛谷 题解 P2645 【斯诺克】的更多相关文章
- P2645 斯诺克 题解
P2645 斯诺克 题目背景 镇海中学开设了很多校本选修课程,有体育类.音乐类.美术类.无线电测向.航空航海航天模型制作等,力争使每位学生高中毕业后,能学到一门拿得出手的兴趣爱好,为将来的终身发展打下 ...
- 洛谷 题解 UVA572 【油田 Oil Deposits】
这是我在洛谷上的第一篇题解!!!!!!!! 这个其实很简单的 我是一只卡在了结束条件这里所以一直听取WA声一片,详细解释代码里见 #include<iostream> #include&l ...
- 洛谷 题解 P1600 【天天爱跑步】 (NOIP2016)
必须得说,这是一道难题(尤其对于我这样普及组205分的蒟蒻) 提交结果(NOIP2016 天天爱跑步): OJ名 编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间 Libre ...
- 洛谷题解P4314CPU监控--线段树
题目链接 https://www.luogu.org/problemnew/show/P4314 https://www.lydsy.com/JudgeOnline/problem.php?id=30 ...
- 洛谷题解 CF777A 【Shell Game】
同步题解 题目翻译(可能有童鞋没读懂题面上的翻译) 给你三张牌0,1,2. 最初选一张,然后依次进行n次交换,交换规则为:中间一张和左边的一张,中间一张和右边一张,中间一张和左边一张...... 最后 ...
- 洛谷题解 CF807A 【Is it rated?】
同步题解 题目 好吧,来说说思路: 1.先读入啦~(≧▽≦)/~啦啦啦 2.判断a[i]赛前赛后是否同分数,如果分数不同,则输出,return 0 . 3.如果同分数,则判断a[i]赛前(或赛后)是否 ...
- 洛谷题解 P1138 【第k小整数】
蒟蒻发题解了 说明:此题我用的方法为桶排(我翻了翻有人用了桶排只不过很难看出来,可能有些重复的,这个题只是作为一个专门的桶排来讲解吧) (不会算抄袭吧 ‘QWaWQ’) 简单来说(会的人跳过就行): ...
- 【洛谷题解】P2303 [SDOi2012]Longge的问题
题目传送门:链接. 能自己推出正确的式子的感觉真的很好! 题意简述: 求\(\sum_{i=1}^{n}gcd(i,n)\).\(n\leq 2^{32}\). 题解: 我们开始化简式子: \(\su ...
- 洛谷题解 P2865 【[USACO06NOV]路障Roadblocks】
链接:https://www.luogu.org/problemnew/show/P2865 题目描述 Bessie has moved to a small farm and sometimes e ...
随机推荐
- java本地缓存
1.为什么要使用缓存 由于服务器.数据库.网络等资源有限,无法支撑越来越多的请求与计算量,所以将一部分数据放在缓存中,以此减小薄弱环节的计算量和请求流程. 网站中缓存的应用场景: 1:可 ...
- 深入理解 DNS
深入理解 DNS 简介 DNS(Domain Name System)域名系统,它是一个将域名和 IP 地址相互映射的一个分布式数据库,把容易记忆的主机名转换成主机 IP 地址. DNS使用 TCP ...
- java编程思想第四版第十四章 类型信息总结
1. Class 对象: 所有的类都是在对其第一次使用的时候,动态加载到JVM中的.当程序创建第一个对类的静态成员的引用时,就会加载这个类.这说明构造器也是类的静态方法.即使在构造器之前并没有stat ...
- 移动端自动化测试Appium环境搭建(part1-2-3)
Appium移动端自动化测试相信大家都不陌生,appium的铁哥们是selenium,不管是selenium还是appium,都是调用webdriver来做自动化测试.今天关于appium的介绍我们不 ...
- Nginx 匹配流程一览
在 nginx server 模块中,location 的定义长被用来匹配一个标准的 URI, 并根据 URI 的不同做出相应的服务方案. nginx location 匹配的优先级 在 locati ...
- 带你涨姿势的认识一下 Kafka 消费者
之前我们介绍过了 Kafka 整体架构,Kafka 生产者,Kafka 生产的消息最终流向哪里呢?当然是需要消费了,要不只产生一系列数据没有任何作用啊,如果把 Kafka 比作餐厅的话,那么生产者就是 ...
- Centos下安装PHP ldap扩展
Centos下安装PHP ldap扩展,有两种方法,仅供参考. 一.在线安装 执行下面命令: 1 yum install PHP-ldap 可能出现的问题: Error: php70w-common- ...
- PHP安全之道学习笔记2:编码安全指南
编码安全指南 编程本身就应该是一门艺术,而安全编程更是一种在刀尖上舞蹈的艺术,不仅要小心脚下的锋利寒刃,更要小心来自网络黑客或攻击者的狂轰乱炸. - by code artist 1.hash比较的缺 ...
- vue 安装指令
vue init webpack 项目名 创建项目cd 项目名 打开项目 npm install vuex --save 安装vuex在一个模块化的打包系统中,您必须显式地通过 Vue.use() 来 ...
- es6 map的用法
let arr =[ {title:'aaaa',read:100,hot:true}, {title:'bbbb',read:50,hot:false}, {title:'ccc',read:100 ...