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用的, ...
随机推荐
- Vue.js——60分钟webpack项目模板快速入门
概述 browserify是一个 CommonJS风格的模块管理和打包工具,上一篇我们简单地介绍了Vue.js官方基于browserify构筑的一套开发模板.webpack提供了和browserify ...
- PHP 常用函数总结(一)
重点: 看函数的 ‘参数’ 和 ‘返回值’ 文档:http://www.w3school.com.cn/php/php_ref_array.asp http://www.w3school.com.cn ...
- 2013南京网赛1003 hdu 4750 Count The Pairs
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4750 题意:给出一个无向图,f(a,b)表示从点a到点b的所有路径中的每条路径的最长边中的最小值,给出 ...
- get mobile http request in PC & fiddler4
get mobile http request in PC 如何在 pc 上抓取 手机的 http 请求 Fiddler 提琴手 https://www.telerik.com/download/fi ...
- ubuntu 16.04 部署 pypy+nginx+uwsgi+django(详细)
1.nginx ...
- BZOJ3504 CQOI2014危桥(最大流)
如果只有一个人的话很容易想到最大流,正常桥连限流inf双向边,危桥连限流2双向边即可.现在有两个人,容易想到给两起点建超源两汇点建超汇,但这样没法保证两个人各自到达自己要去的目的地.于是再超源连一个人 ...
- Sort HDU - 5884(优先队列+二分)
Sort Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- Be the Winner HDU - 2509(反博弈。。这样叫应该没错吧。。)
就是 好几堆苹果 每堆苹果排成一条线 可以任意从每堆拿苹果 如果一堆苹果里拿了之后 则有两种情况 1.从不是边缘拿 拿完这一堆变成两堆 2.从边缘拿 拿完还是一堆 题目还要求 谁 ...
- MT【136】一道三次函数的最佳逼近问题
已知函数\(f(x)=-x^3-3x^2+(1+a)x+b(a<0,b\in R)\), 若\(|f(x)|\)在\([-2,0]\)上的最大值为\(M(a,b)\),求\(M(a,b)\)的最 ...
- C++11并发编程个人小结
thread_local变量在每个线程第一次执行到时初始化(类似static),并在每个线程各自累加,并在线程结束时释放. std::condition_variable:: wait(std::un ...