Sum

时间限制:1000 ms  |  内存限制:65535 KB
难度:2
描述
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相关推荐

  1. JAVA第一个GUI程序---计算器

    想想自己以前学过很多内容,但都是光理论不操作导致上机很少,一事无成,如今做了一个计算器的小程序练练手吧.花了两天的时间终于完成了.以后肯定要多做项目多实践! 下面是代码,写的不简洁,不规范. View ...

  2. 洛谷P4319 变化的道路

    题意:给定图,每条边都有一段存在时间.求每段时间的最小生成树. 解:动态MST什么毒瘤...洛谷上还是蓝题... 线段树分治 + lct维护最小生成树. 对时间开线段树,每条边的存在时间在上面会对应到 ...

  3. hdu3339 In Action(Dijkstra+01背包)

    1 /* 2 题意:有 n 个站点(编号1...n),每一个站点都有一个能量值,为了不让这些能量值连接起来,要用 3 坦克占领这个站点!已知站点的 之间的距离,每个坦克从0点出发到某一个站点,1 un ...

  4. while循环练习23

    练习一,逐一显示指定列表中的所有元素: //方法一 In [25]: l1 Out[25]: [1, 2, 3, 4]In [26]: while l1:....: print l1[0]....: ...

  5. NYOJ 640 Geometric Sum

    Geometric Sum 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 Compute (a + a^2 + - + a^n) mod m. 输入 Three int ...

  6. NYOJ 927 The partial sum problem 【DFS】+【剪枝】

    The partial sum problem 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描写叙述 One day,Tom's girlfriend give him a ...

  7. NYOJ 30 Gone Fishing JAVA+解析

    Gone Fishing这道题目运用的多次折合成一次这种思想我首次见,我想的一个思路是,每次算一下鱼量和时间代价比,这个代码我没有敲,下面的代码是一位仁兄敲得,我研读了一下,做了一个注释,应该有利于后 ...

  8. hdu-2204 Eddy's爱好 nyoj 526

    hdu : http://acm.hdu.edu.cn/showproblem.php?pid=2204 nyoj :  http://acm.nyist.net/JudgeOnline/proble ...

  9. NYOJ 762 第k个互质数(二分 + 容斥)

    第k个互质数 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 两个数的a,b的gcd为1,即a,b互质,现在给你一个数m,你知道与它互质的第k个数是多少吗?与m互质的数按 ...

最新文章

  1. ADO.NET之一:连接层
  2. Makefile与Shell的问题
  3. what is the meaning of bring you up to speed?
  4. 用java实现 两个工具和一个copy功能
  5. Java如何连接openvas_gas: chinese Gui for openvAS(GAS)
  6. windows7 安装IIS没有default web site 解决方法
  7. NET中class与struct的区别简析
  8. 汽车软件开发的8种颠覆性趋势及国产自主可控的多领域全数字实时仿真平台SkyEye
  9. HDU 5908 Abelian Period 可以直接用multiset
  10. atitit.ajax上传文件的实现原理 与设计
  11. 一位挪威博士的PolarDB资深架构师之路
  12. java俄罗斯方块程序设计报告_java课程设计实验报告俄罗斯方块
  13. 你不知道网络安全有多严峻
  14. 三阶科赫雪花PYTHON
  15. [江枫]用Amoeba构架MySQL分布式数据库环境
  16. Barcode Producer for Mac(创建条形码软件)
  17. 【容斥】2017 ACM Arabella Collegiate Programming Contest
  18. Binding几种绑定方式
  19. openflow交换机 ryu_ryu(示例代码)
  20. 【Vue源码解读】万行源码详细解读

热门文章

  1. 大型分布式C++框架《四:netio之请求包中转站 上》
  2. 虚拟机中RedHat Linux系统安装
  3. JavaFX学习之道:JavaFX之TableView
  4. [EULAR文摘] 在总人群中监测ACPA能否预测早期关节炎
  5. js在客户端创建文件——ActiveXObject
  6. [转]android之Apache Http——向服务器发送请求的同时发送参数
  7. linux批量备份服务器配置文件和目录的脚本
  8. js如何往div里写div
  9. Cambridge partner
  10. modnet是一个无需绿幕,扣人像,笔记本上跑到10-20帧