日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

CodeForces - 1102A(思维题)

發布時間:2023/12/15 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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(思维题)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。