题解

151 条题解

  • 2
    @ 2017-05-08 09:05:41
    /*
    找规律~    其实可以直接找规律然后就能发现答案有周期性
    当n=1,2,3,4,5,6,7,8……时,对应的输出是1,1,0,0,1,1,0,0……
    下面给出数学证明
    {
    我们知道,连续的四个整数可以让其和为0。-n+(n+1)+(n+2)-(n+3)=0。
    所以我们把1到n个数从后往前分成n div 4份。若n为5则1(-2+3+4-5)=1
    N=10则-1+2(-3+4+5-6)(-7+8+9-10)=1
    当然n mod 4=0时和就为0。
    于是我们要计算出n mod 4的值,只要计算1..n mod 4的最小非负值
    (n mod 4+1…n这些数的和为0,不用管它们)。那么需要高精度除法吗?
    不!若n>=100,我们设n=100a+b|b<100,前面的100a mod 4必=0,不用考虑,于是要计算n mod 4,
    只要计算n的最后两位(就是b)mod 4就行了!最后在根据mod出来的余数进行特判:
    N mod 4=0:ans=0
    N mod 4=1:ans=1
    N mod 4=2:ans=-1+2=1
    N mod 4=3:ans=-1-2+3=0
    }
    然后直接搞就行了
    */
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    using namespace std;
    
    long long n;
    
    int main()
    {
        scanf("%d",&n);
        if(n%4==1||n%4==2)
            cout<<1<<endl;
        else
            cout<<0<<endl;
        return 0;
    }
         
    
  • 2
    @ 2016-11-14 09:36:08

    一个整数若能被四整除,则其后两位数也能被四整除(若不足两位,仅看各位即可),反之亦然。
    (Tips:100%4==0)
    理解:存在这样一个公式n-(n+1)-(n+2)+(n+3)=0 ()
    若n%==0,自然最小非负值为0;
    若n%==1,将1提出,剩下数列可满足n个公式(
    ),故最小非负值为1
    若n%==2,将1,2提出,剩下数列可满足n个公式(),故最小非负值为2-1=1
    若n%==3,将1,2,3提出,剩下数列可满足n个公式(
    ),故最小非负值为3-2-1=0

  • 1
    @ 2023-05-19 21:54:06

    /*范围1e10000用高精度*/
    /*规律:1,1,0,0,1,1,0,0,1,1,0,0,1,1......*/
    #include<iostream>
    #include<cstring>
    using namespace std;
    int main()
    {
    char a[10001]={};
    int n[10001]={},len,ans;
    cin>>a;
    len=strlen(a);/*求a长度*/
    for(int j=0;j<10001;j++){
    n[j]=a[j]-'0';/*char换int*/
    }
    ans=n[len-2]*10+n[len-1];/*4的整除特性,看末两位*/
    if(ans%4==1||ans%4==2) cout<<"1";
    else{ cout<<"0"; }
    }

  • 1
    @ 2019-10-23 16:00:34
    //%楼上大佬
    //大佬分析的很清楚,这里就只粘个代码
    #include<iostream>
    #include<cstring>
    using namespace std;
    char a[10010];
    int main()
    {
        std::ios::sync_with_stdio(false);
        int len,i,ha;
        cin>>a;
        len=strlen(a);
        if(len==1)
         ha=a[0]-'0';
        else
         ha=10*(a[len-2]-'0')+a[len-1]-'0';
        if(ha%4==0)
         cout<<0;
        if(ha%4==1)
         cout<<1;
        if(ha%4==2)
         cout<<1;
        if(ha%4==3)
         cout<<0;
        return 0;
    }
    
  • 0
    @ 2024-09-07 11:28:30

    #include <bits/stdc++.h>
    using namespace std;
    int main(){
    string s;
    cin >> s;
    int t = s.size()-1;

    string ss = "";
    if(t < 1){
    ss = s;
    }else{
    ss += s[t];
    ss += s[t-1];
    }
    int tt = stoi(ss);
    if(tt % 4 == 0 || tt % 4 == 3){
    cout << 0 << endl;
    }else{
    cout << 1 << endl;
    }

    }//这是一道找规律的题哦!也是我对的第二道题!!!

  • 0
    @ 2015-10-26 19:32:16

    分为两种情况
    当数的位数为1位时,直接提取那一位,否则提取个位和十位
    新得到的数对4取余,当余数为1和2时输出1否则输出0,原因是,当n=1,2,3,4,5,6,7,8时程序输出结果为1,1,0,0,1,1,0,0,可见输出结果具有周期性,周期为4
    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 520 KiB, score = 20
    测试数据 #1: Accepted, time = 0 ms, mem = 528 KiB, score = 20
    测试数据 #2: Accepted, time = 15 ms, mem = 524 KiB, score = 20
    测试数据 #3: Accepted, time = 15 ms, mem = 524 KiB, score = 20
    测试数据 #4: Accepted, time = 5 ms, mem = 528 KiB, score = 20
    Accepted, time = 35 ms, mem = 528 KiB, score = 100
    代码
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <string>
    #include <string.h>
    #include <algorithm>
    #include <functional>
    using namespace std;
    int main()
    {
    string s;
    int n;
    cin >> s;
    if (s.length() > 1)
    {
    n = (s[s.length() - 2] - 48) * 10 + (s[s.length() - 1] - 48);
    }
    else
    {
    n = s[0] - 48;
    }
    if ((n % 4) >= 1 && (n % 4) <= 2)
    {
    cout << 1 << endl;
    }
    else
    {
    cout << 0 << endl;
    }
    return 0;
    }

  • 0
    @ 2015-08-18 20:16:45

    var
    n:ansistring;
    k:integer;
    begin
    readln(n);
    if length(n)=1 then k:=ord(n[length(n)])-48 else
    k:=(ord(n[length(n)-1])-48)*10+ord(n[length(n)]);
    if (k mod 4=0)or(k mod 4=3) then writeln(0)
    else writeln(1);
    end.

  • 0
    @ 2015-07-05 17:15:41

    var
    s:ansistring;
    n,i:longint;
    begin
    readln(s);
    delete(s,1,length(s)-2);
    val(s,n,i);
    n:=n mod 4;
    case n of
    0,3:writeln('0');
    1,2:writeln('1');
    end;
    end.

  • 0
    @ 2015-06-03 21:48:38

    main(i){scanf("%d",&i);puts(2&--i?"0":"1");}
    怕不

  • 0
    @ 2015-02-06 17:00:22

    这样还好一点了。
    #include<iostream>
    #include<string.h>
    #include<math.h>
    #include<stdio.h>
    using namespace std;

    char a[10004];
    int n[10004];
    int len;
    int mod4(){
    int i;
    int dif=0;
    for (i = len+2; i >= 0; i--){
    dif *= 10;
    dif += n[i];
    dif %= 4;
    }

    return dif;
    }
    int main(){

    cin >> a;
    memset(n, 0, sizeof(n));
    int i=0;
    while (a[i])i++;
    len = i;
    for (i = 0; i < len; i++){
    n[i] = a[len - 1 - i] - '0';
    }
    if (mod4()==3||mod4()==0)
    cout << 0 << endl;
    else cout << 1 << endl;
    return 0;
    }
    这样还是太麻烦,判断能不能被4整除,直接看后两位就可以了。

  • 0
    @ 2015-02-06 16:47:35

    我又想麻烦了,我真傻,真的。
    #include<iostream>
    #include<string.h>
    #include<math.h>
    #include<stdio.h>
    using namespace std;

    char a[10004];
    int n[10004];
    int n1[10004];
    int len;
    bool mod4(int m[]){
    if (m[0] % 2)return false;
    int i;
    int dif=0;
    for (i = len+2; i >= 0; i--){
    dif *= 10;
    dif += m[i];
    dif %= 4;
    }
    return dif == 0;
    }
    int main(){

    freopen("in.txt", "r", stdin);

    cin >> a;
    memset(n, 0, sizeof(n));
    memset(n1, 0, sizeof(n1));
    int i=0;
    while (a[i])i++;
    len = i;
    for (i = 0; i < len; i++){
    n[i] =n1[i]= a[len - 1 - i] - '0';
    }
    i = 0;
    while (n1[i]=='9')i++;
    n1[i]++;
    if (mod4(n)){
    cout << 0 << endl;
    }
    else if (mod4(n1)){
    cout << 0 << endl;
    }
    else if (n[0] % 2 == 0 && n[1] % 2 == 0){
    cout << 0 << endl;
    }
    else cout << 1 << endl;
    return 0;
    }

  • 0
    @ 2015-01-01 16:57:52

    a=int(raw_input())
    print (a+1)%4/2

  • 0
    @ 2014-11-23 13:08:51

    其实规律很简单,当n=1,2,3,4,5,6,7,8……时,对应的输出是1,1,0,0,1,1,0,0……
    #include <stdio.h>
    unsigned int i;
    int main()
    {
    scanf("%d",&i);
    if(i%4==1||i%4==2)printf("1");
    else if(i%4==3||i%4==0)printf("0");
    return 0;
    }

  • 0
    @ 2014-09-03 23:10:27

    P1141最小非负值
    Accepted
    记录信息
    评测状态 Accepted
    题目 P1141 最小非负值
    递交时间 2014-09-03 23:08:36
    代码语言 C++
    评测机 VijosEx
    消耗时间 15 ms
    消耗内存 284 KiB
    评测时间 2014-09-03 23:08:39
    评测结果

    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 284 KiB, score = 20

    测试数据 #1: Accepted, time = 0 ms, mem = 284 KiB, score = 20

    测试数据 #2: Accepted, time = 15 ms, mem = 284 KiB, score = 20

    测试数据 #3: Accepted, time = 0 ms, mem = 280 KiB, score = 20

    测试数据 #4: Accepted, time = 0 ms, mem = 280 KiB, score = 20

    Accepted, time = 15 ms, mem = 284 KiB, score = 100
    代码

    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <algorithm>
    #include <math.h>

    using namespace std;

    char n[ 10000 + 10 ];
    int i;
    int s;

    int main()
    {
    memset( n , 0 , sizeof( n ) );
    while( cin >> n )
    {
    for( i = 0 ; n[i] != 0 ; i++ )
    ;
    if( i >= 3 )
    {
    i -= 3;
    s = ( n[i] - '0' ) * 100 + ( n[i + 1] - '0' ) * 10 + ( n[i + 2] - '0' );
    }
    else if( i == 2 )
    s = ( n[i - 2] - '0' ) * 10 + ( n[i - 1] - '0' );
    else if( i == 1 )
    s = ( n[i - 1] - '0' );
    else if( i == 0 )
    s = 0;
    s %= 8;
    if( s == 1 || s == 2 || s == 5 || s == 6 )
    s = 1;
    else if( s == 0 || s == 3 || s == 4 || s == 7 )
    s = 0;
    memset( n , 0 , sizeof( n ) );
    cout << s << endl;
    }
    return 0;
    }

    不要怕那个n的取值范围。。。。。。

  • 0
    @ 2014-07-30 18:12:36

    其实规律很简单,当n=1,2,3,4,5,6,7,8……时,对应的输出是1,1,0,0,1,1,0,0……

  • 0
    @ 2014-03-20 19:08:01

    水水水 5行秒杀 仅供参考
    var s:ansistring;f,k:longint;
    begin
    readln(s);f:=length(s);s:=copy(s,f-1,2);val(s,k);
    if(k mod 4)in[1..2]then writeln(1)else writeln(0);
    end.

    • @ 2014-03-20 19:09:32

      抱歉 没想到 发上去就这样了 请大家用;来分句吧!!!
      sorrysorrysorrysorrysorrysorrysorrysorrysorry
      sorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorrysorry

  • 0
    @ 2013-10-28 12:44:29

    program num;
    var
    s:ansistring;
    c1,c2:char;
    n,x:integer;
    begin
    readln(s);
    x:=length(s);
    c1:=s[x-1];
    c2:=s[x];
    if x>1 then n:=(ord(c1)-48)*10+ord(c2)-48
    else n:=ord(c2)-48;
    if (n mod 4=1) or (n mod 4=2) then write(1)
    else write(0);end.

  • 0
    @ 2013-10-08 14:39:27

    一上来忘记高精了,汗啊。害我两次WA。
    简单题。

    C++ Code:
    #include <iostream>
    using namespace std;
    int main(){
    char a[10000];
    for(int i=0;i<10000;i++){
    a[i]=NULL;
    }
    cin>>a;
    int b=0;
    for(int i=9999;i>=0;i--){
    if(a[i]!=NULL){
    if(i==0){
    b=(int)a[i];
    b-='0';
    break;
    }else{
    b=(int)a[i];
    b-='0';
    int temp=(int)a[i-1];
    temp-='0';
    temp*=10;
    b+=temp;
    break;
    }
    }
    }
    b=b%4;
    if(b==0){
    cout<<0;
    }
    if(b==1){
    cout<<1;
    }
    if(b==2){
    cout<<1;
    }
    if(b==3){
    cout<<0;
    }
    }

  • 0
    @ 2010-04-08 12:38:16

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    Flag   Accepted

    题号   P1141

    类型(?)   数论 / 数值

    通过   3337人

    提交   10000次

    通过率   33%

    难度   1

    庆祝第10000次提交

  • 0
    @ 2010-04-07 21:43:38

    #include

    #include

    int main(void) {

    char c1,c2='0',c;

    while(isdigit(c=getchar())&&(c1=c2,c2=c));

    printf("%d\n",!((c1-'0')*10+(c2-'0')-1&2));

    return 0;

    }

信息

ID
1141
难度
5
分类
高精度 | 其他 点击显示
标签
(无)
递交数
4260
已通过
1416
通过率
33%
被复制
13
上传者