https://vjudge.net/problem/2135388/origin
Describe

You are given an integer sequence 1,2,…,n. You have to divide it into two sets A and B in such a way that each element belongs to exactly one set and |sum(A)−sum(B)| is minimum possible.

The value |x| is the absolute value of x and sum(S) is the sum of elements of the set S.

Input

The first line of the input contains one integer n (1≤n≤2⋅109).

Output

Print one integer — the minimum possible value of |sum(A)−sum(B)| if you divide the initial sequence 1,2,…,n into two sets A and B.

Examples

Input
3
Output
0
Input
5
Output
1
Input
6
Output
1
Note

Some (not all) possible answers to examples:

In the first example you can divide the initial sequence into sets A={1,2} and B={3} so the answer is 0.

In the second example you can divide the initial sequence into sets A={1,3,4} and B={2,5} so the answer is 1.

In the third example you can divide the initial sequence into sets A={1,4,5} and B={2,3,6} so the answer is 1.

这是一道思维题,刚拿到题的时候毛了,这是什么题,DP背包容量为1/2值的和;不难发现这个题是个防爆零的送分题。
在表格中不难看出,当数字个数为偶数个时,要平分到两个组合,如果平分后个数为奇数肯定数组中间的两个值被分开,最小差值唯一,123456 分1 / 6 分2 / 5 分3 /4,差值为1; 当个数为奇数个时便有如下方法如果去掉最大之后,按照偶数分析。
AC代码如下

#include<iostream>
#include<cstdio>
#include<map>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
#define mst(a,b) memset((a),(b),sizeof(a))
#define inf 0x3f3f3f3f
#define maxn 100
#define Abs(a) ((a)>0?(a):-(a))
int main()
{int n;cin>>n;if(n%2==1) {n=n-1;n/=2;if(n%2==1) cout<<'0'<<endl;else cout<<'1'<<endl;return 0;}else{n=n/2;if(n%2==0) cout<<'0'<<endl;else cout<<'1'<<endl;return 0;}
}

CodeForces - 1102A(思维题)相关推荐

  1. codeforces - 1315C - 思维题

    原题链接:https://codeforces.com/problemset/problem/1315/C 翻译: 这是一个猜谜游戏,你需要猜中一个序列,谜题是一个序列,我们设为b,长度为n.你需要根 ...

  2. Codeforces 1077B Disturbed People(思维题)

    Codeforces 1077B Disturbed People(思维题) There is a house with nn flats situated on the main street of ...

  3. codeforces 有意思的思维题 1 ~ 15

    codeforces 思维题 1.给定数组,求满足i < j and ai * aj = i + j的数对数量 2.第 i 步向前跳 i 步或后退 1 步 3.给两个点,求正方形的另两个点 4. ...

  4. CF--思维练习-- CodeForces - 215C - Crosses(思维题)

    ACM思维题训练集合 There is a board with a grid consisting of n rows and m columns, the rows are numbered fr ...

  5. ☆【CodeForces - 764C】Timofey and a tree (思维题,树的性质)

    题干: Each New Year Timofey and his friends cut down a tree of n vertices and bring it home. After tha ...

  6. Educational Codeforces Round 67 (Rated for Div. 2)(D思维题 线段树/E树形dp(换根dp) 二次扫描与换根法)

    心得 D写了个假算法被hack了wtcl- E据涛神说是二次扫描与换根法,看了看好像和树形dp差不多 F概率dp G费用流 回头再补 思路来源 马老师 归神 贤神等代码 http://www.mami ...

  7. ACM思维题训练 Section A

    题目地址: 选题为入门的Codeforce div2/div1的C题和D题. 题解: A:CF思维联系–CodeForces -214C (拓扑排序+思维+贪心) B:CF–思维练习-- CodeFo ...

  8. little w and Soda(思维题)

    链接:https://ac.nowcoder.com/acm/contest/297/A 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言5242 ...

  9. ZOJ 3829 贪心 思维题

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ...

最新文章

  1. java.sql.Exception:setString 只能处理少于 32766 个字符的字符串
  2. redis 3.0 集群__数据迁移和伸缩容
  3. Android绘制自定义控件,Android自定义控件绘制基本图形基础入门
  4. android layout过程分析,Andriod 从 0 开始自定义控件之 View 的 layout 过程 (八)
  5. 如何提取明细表头_如何在实际操作中应用偏移修剪?
  6. #pragma once 和 #ifndef ... #define ... #endif 的区别
  7. STC15W408读取HX711称重数据串口发送
  8. 离散信号内插matlab,离散信号和系统实验报告.doc
  9. 获取编译学习笔记 (十一年)—— 内的中间
  10. 11、quiver(x,y,u,v)
  11. php 生成xls解决乱码,怎么解决php导出excel文件乱码问题
  12. 转载:洛克菲勒家族参与投资土豆网
  13. OpenCL快速入门教程
  14. CenOS 6.0 安装NVIDIA GeFore GT 440 显卡驱动
  15. 域名购买以及云解析DNS
  16. 渗透测试 | UserInfo信息收集
  17. 学习强国-为中华崛起而学习
  18. 《少年pi》:每个人心中都有一只孟…
  19. html加载背景图片
  20. 解决one-stage目标检测正负样本不均衡的另类方法--Gradient Harmonized

热门文章

  1. mac电脑访问另一台mac共享文件
  2. mac地址容量的作用_S6520X+MAC地址容量检查命令
  3. 这5个要点让你看清“Salesforce+AWS”
  4. loadrunner-3-3场景计划方式与运行模式
  5. 笨笨图片批量下载器 V0.3 beta[C# | WinForm | 正则表达式 | HttpWebRequest | Async异步编程] new...
  6. C++内存分配与对象构造的分离
  7. simplexml和xpath
  8. [原创] Android SDK 安装全记录
  9. 如何在ESX下抓取数据包
  10. qpython3可视图形界面_PySide——Python图形化界面入门教程(三)