CodeForces - 1102A(思维题)
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(思维题)的更多相关文章
- Codeforces 424A (思维题)
Squats Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Statu ...
- Vova and Trophies CodeForces - 1082B(思维题)
Vova has won nn trophies in different competitions. Each trophy is either golden or silver. The trop ...
- CodeForces - 417B (思维题)
Crash Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Status ...
- CodeForces - 417A(思维题)
Elimination Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit ...
- B - Sonya and Exhibition CodeForces - 1004B (思维题)
B. Sonya and Exhibition time limit per test 1 second memory limit per test 256 megabytes input stand ...
- codeforces ~ 1009 B Minimum Ternary String(超级恶心的思维题
http://codeforces.com/problemset/problem/1009/B B. Minimum Ternary String time limit per test 1 seco ...
- 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas
题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...
- C. Nice Garland Codeforces Round #535 (Div. 3) 思维题
C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- CodeForces - 631C ——(思维题)
Each month Blake gets the report containing main economic indicators of the company "Blake Tech ...
随机推荐
- 初始WebApi(1)
如果你要问我WebApi是干嘛,我只能说它是的给数据.哈哈哈哈哈,这几天也才刚刚了解了解关于WebApi的知识,今天就来谈谈吧. 1.创建WebApi项目 第一步:选择ASP.NET Web应用程序 ...
- jvm入门及理解(二)——类加载器子系统
一.类加载子系统的作用 类加载子系统负责从文件系统或者网络中加载Class文件,class文件在文件开头有特定的文件标识: ClassLoader只负责class文件的加载,至于它是否可以运行,则由E ...
- hadoop(七)集群配置同步(hadoop完全分布式四)|9
前置配置:rsync远程同步|xsync集群分发(hadoop完全分布式准备三)|9 1. 分布式集群分配原则 部署分配原则 说明Namenode和secondarynamenode占用内存较大,建议 ...
- tomcat通过tomcat 安装根目录下的conf-Catalina-localhost目录发布项目详解
tomcat通过conf-Catalina-localhost目录发布项目详解 Tomcat发布项目的方式大致有三种,但小菜认为通过在tomcat的conf/Catalina/localhost目 ...
- pinpoint php 使用不当引发棘手的问题 --psid sid tid pname ptype ah
Pinpoint 简单介绍 Pinpoint 是用 Java 编写的 APM(应用性能管理)工具,用于大规模分布式系统,以帮助分析系统的总体结构以及分布式应用程序的组件之间是如何进行数据互联的. 安装 ...
- Web 如何搭建自己的个人网站
如何搭建自己的个人技术博客网站 学习目标 1.[了解]搭建网站需要的web构件和网站运行原理 2.[掌握]如何搭建个人博客网站 学习前言 大家都是学习开发的,相信都接触过百度,新浪,淘宝,京东...等 ...
- Tcxgrid使用例子
1.更改某个单元格的值后,其他单元格的值也相应改变 直接点击单元格进行更改值,然后在改单元格增加相应的事件: procedure Tfrm_BarCode_makecl5.gdtv_1select_t ...
- Chrome 浏览器安装 ChroPath 插件
1.下载地址 http://www.cnplugins.com/devtool/chropath/download.html 2.安装方法 a.把下载的文件更改后缀名变为压缩包,然后解压到本地:如下图 ...
- [Laravel框架学习一]:Laravel框架的安装以及 Composer的安装
1.先下载Composer-Setup.exe,下载地址:下载Composer .会自动搜索PHP.exe的安装路径,如果没有,就手动找到php路径下的php.exe. 2.在PHP目录下,打开php ...
- STL入门大全(待编辑)
前言:这个暑假才接触STL,仿佛开启了新世界的大门(如同学完结构体排序一般的快乐\(≧▽≦)/),终于彻底领悟了大佬们说的“STL大法好”(虽然我真的很菜www现在只学会了一点点...)这篇blog主 ...