NYOJ 215 Sum
Sum
- 描述
-
Consider the natural numbers from 1 to N. By associating to each number a sign (+ or -) and calculating the value of this expression we obtain a sum S. The problem is to determine for a given sum S the minimum number N for which we can obtain S by associating signs for all numbers between 1 to N.
For a given S, find out the minimum value N in order to obtain S according to the conditions of the problem.
- 输入
-
The input consists N test cases.
The only line of every test cases contains a positive integer S (0< S <= 100000) which represents the sum to be obtained.
A zero terminate the input.
The number of test cases is less than 100000. - 输出
- The output will contain the minimum number N for which the sum S can be obtained.
- 样例输入
-
3 12 0
- 样例输出
-
2 7
-
AC码:
-
#include<stdio.h> int main() {int n,i,t;while(scanf("%d",&n)&&n){i=1;t=1;while(t!=n){i++;t=i*(i+1)/2;if(t>n){if((t-n)%2==0)t=n;}}printf("%d\n",i);}return 0; }
NYOJ 215 Sum相关推荐
- JAVA第一个GUI程序---计算器
想想自己以前学过很多内容,但都是光理论不操作导致上机很少,一事无成,如今做了一个计算器的小程序练练手吧.花了两天的时间终于完成了.以后肯定要多做项目多实践! 下面是代码,写的不简洁,不规范. View ...
- 洛谷P4319 变化的道路
题意:给定图,每条边都有一段存在时间.求每段时间的最小生成树. 解:动态MST什么毒瘤...洛谷上还是蓝题... 线段树分治 + lct维护最小生成树. 对时间开线段树,每条边的存在时间在上面会对应到 ...
- hdu3339 In Action(Dijkstra+01背包)
1 /* 2 题意:有 n 个站点(编号1...n),每一个站点都有一个能量值,为了不让这些能量值连接起来,要用 3 坦克占领这个站点!已知站点的 之间的距离,每个坦克从0点出发到某一个站点,1 un ...
- while循环练习23
练习一,逐一显示指定列表中的所有元素: //方法一 In [25]: l1 Out[25]: [1, 2, 3, 4]In [26]: while l1:....: print l1[0]....: ...
- NYOJ 640 Geometric Sum
Geometric Sum 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 Compute (a + a^2 + - + a^n) mod m. 输入 Three int ...
- NYOJ 927 The partial sum problem 【DFS】+【剪枝】
The partial sum problem 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描写叙述 One day,Tom's girlfriend give him a ...
- NYOJ 30 Gone Fishing JAVA+解析
Gone Fishing这道题目运用的多次折合成一次这种思想我首次见,我想的一个思路是,每次算一下鱼量和时间代价比,这个代码我没有敲,下面的代码是一位仁兄敲得,我研读了一下,做了一个注释,应该有利于后 ...
- hdu-2204 Eddy's爱好 nyoj 526
hdu : http://acm.hdu.edu.cn/showproblem.php?pid=2204 nyoj : http://acm.nyist.net/JudgeOnline/proble ...
- NYOJ 762 第k个互质数(二分 + 容斥)
第k个互质数 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 两个数的a,b的gcd为1,即a,b互质,现在给你一个数m,你知道与它互质的第k个数是多少吗?与m互质的数按 ...
最新文章
- ADO.NET之一:连接层
- Makefile与Shell的问题
- what is the meaning of bring you up to speed?
- 用java实现 两个工具和一个copy功能
- Java如何连接openvas_gas: chinese Gui for openvAS(GAS)
- windows7 安装IIS没有default web site 解决方法
- NET中class与struct的区别简析
- 汽车软件开发的8种颠覆性趋势及国产自主可控的多领域全数字实时仿真平台SkyEye
- HDU 5908 Abelian Period 可以直接用multiset
- atitit.ajax上传文件的实现原理 与设计
- 一位挪威博士的PolarDB资深架构师之路
- java俄罗斯方块程序设计报告_java课程设计实验报告俄罗斯方块
- 你不知道网络安全有多严峻
- 三阶科赫雪花PYTHON
- [江枫]用Amoeba构架MySQL分布式数据库环境
- Barcode Producer for Mac(创建条形码软件)
- 【容斥】2017 ACM Arabella Collegiate Programming Contest
- Binding几种绑定方式
- openflow交换机 ryu_ryu(示例代码)
- 【Vue源码解读】万行源码详细解读