soj1047.Super Snooker(转换思路+二路求和)
That year the Super Snooker Championship was contested by two experienced Snooks universally ac-claimed as the best players on the planet: Stephanie McHendry and Joanna McHiggins. The game involved an immense rectangular table covered with green cloth and lined by edges two inches high, except in the four corners and in the middle of the longer sides where there were holes. On it were put a number of balls (from 6 up to as many as 25), each representing a value or certain number of points (anywhere from 2 to 1000, but numbered consecutively). Each player in turn tried to nudge the lowest valued ball left on the table into one of the holes on the edges of the table using a strange limb called a “kew”. If one succeeded, she was said to have “podded” the ball and the value of the podded ball was added to her score.
But here is the strange thing: the object of the game was not to finish with more points than the opponent. No, being a people who loved peace above all else, the object for both players was to end up with an equal number of points. This presented a bit of a problem. It was very important to them to know if it was possible to finish equal given the score of both players and the values of the balls left on the table. For instance, with a score-line of 56–34 and three balls left with values 13, 14 and 15, it is impossible to reach equal end-scores. If there are five balls left with values 20–24, it is possible: 56 + 20 + 24 = 34 + 21 + 22 + 23 = 100. You are asked to write a program that helps the Snooks by calculating whether it is possible for two Super Snooker players to win their game by finishing equal, given a score-line and the range of values of the range of the remaining balls.
5
56 34 13 15
56 34 20 24
0 0 500 519
0 0 500 520
0 0 500 521
not possible
possible
possible
not possible
not possible
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int N;
cin >> N;
while(N--)
{
int a,b,c,d;
cin >> a >> b >> c >> d;
int len = d - c + 1;
int sum = (c + d)*len/2;
if(a > b)
swap(a,b);
if((b - a + sum) % 2 == 1 || (a + b + sum) % 2 == 1 || b > a + sum)
cout << "not possible" << endl;
else
{
bool flag = false;
int i;
int Min,Max;
int x = (b - a + sum) / 2;
for(i = 1; i <= len ;i++)
{
Min = (c + c + i - 1)* i / 2;
Max = (d - i + 1 + d)* i / 2;
if(x >= Min && x <= Max)
{
flag = true;
break;
}
}
if(flag == true)
cout << "possible" << endl;
else
cout << "not possible" << endl;
}
}
return 0;
}
soj1047.Super Snooker(转换思路+二路求和)的更多相关文章
- 看JQ时代过来的前端,如何转换思路用Vue打造选项卡组件
前言 在Vue还未流行的时候,我们都是用JQuery来封装一个选项卡插件,如今Vue当道,让我们一起来看看从JQ时代过来的前端是如何转换思路,用数据驱动DOM的思想打造一个Vue选项卡组件. 接下来, ...
- java从命令行接受多个数字求和输出
一·设计思路 1.定义一个整型变量sum,用于接收和 2.利用循环将命令行数字求和 3.输出参数个数以及参数之和 二·流程图 三·程序源代码 public class JavaAppArguments ...
- 一个简单的XML与数组之间的转换
xml是网络使用最多的数据交换格式,所以,不掌握怎么操作它,又有蛋疼的了. php中可以操作xml的类/函数很多,个人认为最简单的是SimpleXMLElement这个类,它的使用就跟其名字一样:简单 ...
- [POJ1220]NUMBER BASE CONVERSION (高精,进制转换)
题意 任意进制之间的高进的转换 思路 相模倒排,高精处理 代码 我太弱了,下面附一个讨论里发的maigo思路的代码 ],A[]; ],d[]; main(){ for(scanf("%d&q ...
- 文件在线预览doc,docx转换pdf(一)
文件在线预览doc,docx转换pdf(一) 1. 前言 文档转换是一个是一块硬骨头,但是也是必不可少的,我们正好做的知识库产品中,也面临着同样的问题,文档转换,精准的全文搜索,知识的转换率,是知识库 ...
- Spark2.0 特征提取、转换、选择之一:数据规范化,String-Index、离散-连续特征相互转换
数据规范化(标准化) 在数据预处理时,这两个术语可以互换使用.(不考虑标准化在统计学中有特定的含义). 下面所有的规范化操作都是针对一个特征向量(dataFrame中的一个colum)来操作的. 首先 ...
- 将HTML元素转换成图片供用户下载(html2canvas + canvas2Image)
这是项目中遇到的一个问题,起初觉得把一个html元素生成图片,提供给用户下载的需求挺容易实现的,毕竟看过一些截图的插件,但是在真正操作中遇到了各种各样的问题,比如移动端上截图显示不清晰,html元素中 ...
- 九度OJ 1208:10进制 VS 2进制 (进制转换)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2040 解决:612 题目描述: 对于一个十进制数A,将A转换为二进制数,然后按位逆序排列,再转换为十进制数B,我们乘B为A的二进制逆序数. ...
- HTML连载18-id选择器与class区别&class选择器使用思路&后代选择器
一.id选择器和classable选择器的区别 选择器 CSS中的开头 HTML标签可以绑定几个 是否可重复 用途 id选择器 # 仅能一个 不可以重复(一个标签里仅有一个) 一般情况下是给JS用的, ...
随机推荐
- 浅谈iOS内存管理机制
iOS内存管理机制的原理是引用计数,引用计数简单来说就是统计一块内存的所有权,当这块内存被创建出来的时候,它的引用计数从0增加到1,表示有一个对象或指针持有这块内存,拥有这块内存的所有权,如果这时候有 ...
- 关于es6箭头函数
1 基本用法 ES6 允许使用 “ 箭头 ” (=>)定义函数. var f = v => v; //上面的箭头函数等同于: var f = function(v) { return v ...
- php $_SERVER['HTTP_USER_AGENT'] 2
//mobile false pc true no pc function is_mobile(){ $agent = strtolower($_SERVER['HTTP_U ...
- mysql 时间格式化参数表笔记
DATE_FORMAT() 函数用于以不同的格式显示日期/时间数据. 语法: DATE_FORMAT(date,format) 实例: DATE_FORMAT(NOW(),'%b %d %Y %h:% ...
- crosses initialization of “XXX” 的问题
在switch-case中定义了变量,用g++编译的时候报错crosses initialization of “XXX” ,在网上一查,说是gcc要求变量的定义不能位于goto之后 将变量定义放在s ...
- maven执行"mvn clean package" 命令报错
昨天利用mvn打包,执行程序'mvn clean package' 命令,发现打包失败 问题描述 具体看代码 发信tomcat下的log 清除不掉.为什么呢?忽然想起来我的项目服务还起着,于是我把服务 ...
- Angular js Radio Button
症状: 绑定一个list radio button 老是只能绑定一行,纠结了很久 ,回家发现 原来是 name 用了同一个 ,坑啊,记录下 免得下次再犯. 之前的代码 <ul> & ...
- String、StringBuffer与StringBuilder比较
关于这三个类在字符串处理中的位置不言而喻,那么他们到底有什么优缺点,到底什么时候该用谁呢?下面我们从以下几点说明一下 1.三者在执行速度方面的比较: StringBuilder > St ...
- properties文件读取与写入
将peoperties文件的读取和写入封装成了一个工具类: import java.io.BufferedInputStream; import java.io.FileInputStream; im ...
- 【poj3133】 Manhattan Wiring
http://poj.org/problem?id=3133 (题目链接) 题意 $n*m$的网格里有空格和障碍,还有两个$2$和两个$3$.要求把这两个$2$和两个$3$各用一条折线连起来.障碍里不 ...