码迷,mamicode.com
首页 > 其他好文 > 详细

【水】vijosP1141 最小非负值

时间:2014-10-02 00:31:21      阅读:398      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   strong   sp   div   

P1141最小非负值

描述

输入一个自然数n(n<1e10000),表示1到n共n个自然数排成一列,你要在每一个数前添上+或-,要使得添加符号后这个代数式的值最小且非负.

输入格式

一个数,n.

输出格式

一个数,即最小非负值。

样例

样例输入

5

样例输出

1

限制

各个测试点1s

思路

听说是高精度,我很开心地进去看了一下……卧槽……

还是有一点点用的,如下

注意

getline函数不一定要fstream才可以用

正常getline函数用法:

#include<iostream>

getline(cin,st);

这里不要写什么infile outfile了,直接写cin经验证无错

代码

//我对代码长度不是很在意,短码写着累看着也累啊(我也写不好……)
#include<iostream>
#include<cstring>  

using namespace std;
int a,lon;
string k;
int main()
{
    getline (cin,k);
    lon=k.length();
    a=(int(k[lon-1])-int(0));
    if (lon>1) {a=a+( int(k[lon-2])-int(0) )*10 ;}
    if  ( ((a%4)==1)||((a%4)==2) ) cout<<1<<endl; else cout<<0<<endl;
    return 0;
}

结果

bubuko.com,布布扣

 

 

【水】vijosP1141 最小非负值

标签:style   blog   http   color   io   os   strong   sp   div   

原文地址:http://www.cnblogs.com/seekdreamer/p/4003666.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!