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 ...
随机推荐
- C语言 文件操作(四)
1.fprintf int fprintf(FILE *stream, const char *format, ...) stream -- 这是指向 FILE 对象的指针,该 FILE 对象标识了流 ...
- Linux bash篇(三 数据流重定向)
1> 以覆盖的方式将正确的数据输出到文件或设备上 1>> 以追加的方式将正确的数据输出到文件或设备上 2> 以覆盖的方式将错误的数据输 ...
- openpyxl 模块 读写Excel
import openpyxl #写到execl中def write_execl(): book=openpyxl.Workbook() sheet=book.active #获取默认sheet # ...
- 搭建环境-Eclipse配置Tomcat创建Servlet总结
Descripton:Web开发:Eclipse的下载与安装,Tomcat下载和结合Eclipse的使用,Eclipse使用Servlet[记录下总结下] 一.Eclipse的下载与安装 下载地址 注 ...
- CSS 布局水平 & 垂直对齐
元素居中对齐 margin: auto; 文本居中对齐 text-align: center; 图片居中对齐 要让图片居中对齐, 可以使用 margin: auto; 并将它放到 块 元素中 左右对齐 ...
- 22.1 Extends 继承的 方法重写、@Override的使用、
/* * 继承中成员方法的特点 * 子类中没有这个方法,调用父类的 * 子类中重写了这个方法,调用子类的 * 方法的重写:在子父类当中,子类的方法和父类的完全一样,子类重写了父类的方法(覆盖),当子类 ...
- HTTPS工作流程
HTTPS工作流程 RSA算法 RSA的密钥分成两个部分: PublicKey 加密数据 验证签名 不能解密 任何人都可以获得 Private Key 数据签名(摘要算法) 解密 加密(不用此功能) ...
- 用threejs 实现3D物体在浏览器展示
用threejs 实现3D物体在浏览器展示,通过鼠标平移,缩放,键盘箭头按钮左右移动等功能展示. <!DOCTYPE html> <html> <head> < ...
- Salesforce元数据入门指南,管理员必看!
元数据是Salesforce基础架构的核心,是Salesforce中的核心组件或功能.没有元数据,大部分功能都无法实现. 但是,某些Salesforce管理员仍然很难掌握元数据的整个范围,并且无法充分 ...
- 教你如何安装和使用Python pip
前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:Starshot PS:如有需要Python学习资料的小伙伴可以加点击 ...