• 两行虐杀儒略历


    CSP2020-S T1

    儒略历(julian)

    小猪国杀, 送走了一大批人, 也包括

    特地将翻车的考场代码改对, 以报仇雪恨

    考场代码((0pts) - (40pts))

    ((255)行)

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

    就是这里写挂了, CSP2020 惨爆零

    剩下这些有 (40pts)

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <map>
    #include <queue>
    using namespace std;
    inline long long RD() {
      long long Itmp(0), Isig(1);
      char Ichr(getchar());
      while ((Ichr != '-')&&((Ichr > '9')||(Ichr < '0'))) {
        Ichr = getchar();
      }
      if (Ichr == '-') {
        Isig = -1;
        Ichr = getchar();
      }
      while (Ichr >= '0' && Ichr <= '9') {
        Itmp = Itmp * 10 + Ichr - '0';
        Ichr = getchar();
      }
      return Itmp * Isig;
    }
    long long Q, R;
    long long Mth[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    long long BC(1721424)/*1720245 + 1179*/, year4(1461), year100(36524), year400(146097), _1582(577738)/*577460 + 273 + 4*/, year3(1095);
    long long tmpy4, tmpy, ans, tmpy100, tmpy400;
    void Clr () {
      ans = 0;
    }
    void Gtmd (int x) {
      for (register int i(1); i <= 12; ++i) {
        if (x > Mth[i]) {
          x -= Mth[i];
          continue;
        } else {
          printf("%d %d ", x, i);
          return;
        }
      }
      return;
    }
    int main() {
      freopen("julian3.in", "r", stdin);
      freopen("julian.out", "w", stdout);
      Q = (int)RD();
      for (register int i(1); i <= Q; ++i) {
        //printf("%d
    ", i - 1);
        Clr();
        R = RD();
        R++;
        if(R <= BC) {
          tmpy4 = (R - 1) / year4;
          R -= year4 * tmpy4;
          tmpy = (R - 2) / 365;
          R -= 365 * tmpy;
          //printf("%d
    ", R);
          ans += tmpy;
          ans += tmpy4 * 4;
          //printf("%d
    ", ans);
          if (ans % 4 == 0) {
            if (R < 60) {
              Gtmd(R);
              printf("%d BC
    ", 4713 - ans);
            }
            if (R == 60) {
              printf("29 2 %d BC
    ", 4713 - ans);
            }
            if (R > 60) {
              Gtmd(R - 1);
              printf("%lld BC
    ", 4713 - ans);
            }
          } else {
            //printf("faq
    ");
            Gtmd(R - 1);
            printf("%lld BC
    ", 4713 - ans);
          }
        } else {
          R -= BC;
          if (R >= _1582) {
            // printf("ops
    ");
            R += 288;
            R -= _1582;
            //Gtmd(R);
            //printf("%d
    ", R);
            if(R <= 365) {//1582
              Gtmd(R);
              printf("1582
    ");
              continue;
            }
            R -= 365;
            if(R <= 365) {
              Gtmd(R);
              printf("1583
    ");
              continue;
            }
            R-=365;
            ans = 1584;
            if (R <= 5844) {
              //printf("here
    ");
              tmpy4 = (R - 1) / year4;
              R -= tmpy4 * year4;
              tmpy = (R - 2) / 365;
              R -= 365 * tmpy;
              ans += tmpy4 * 4 + tmpy;
              if(tmpy) {
                R--;
                Gtmd(R);
                printf("%d
    ", ans);
              } else {
                if (R < 60) {
                  Gtmd(R);
                  printf("%d
    ", ans);
                }
                if (R == 60) {
                  printf("29 2 %d
    ", ans);
                }
                if (R > 60) {
                  Gtmd(R - 1);
                  printf("%lld
    ", ans);
                }
              }
              continue;
            }
            R -= 5844;
            ans = 1600;
            tmpy400 = (R - 1) / year400;//400
            R -= tmpy400 * year400;
            tmpy100 = (R - 2) / year100;//100
            R -= tmpy100 * year100;
            if(tmpy100) {
              R--;
            }
            tmpy4 = R / year4;
            R -= tmpy4 * year4;
            if (tmpy4 && tmpy100) {
              R++;
            }
            tmpy = (R - 2) / 365;
            R -= tmpy * 365;
            if(tmpy) {
              if(tmpy100) {
                if(!tmpy4)
                  R++;
              } else {
                if(tmpy4) {
                  //R--;
                }
              }
            }
            if(tmpy100) {
              if(!tmpy4) {
                if(!tmpy) {
                  R++;
                }
              }
            }
            ans += tmpy + 4 * tmpy4 + 100 * tmpy100 + 400 * tmpy400;
            if(R == 0) {
              ans--;
              printf("31 12 %d
    ", ans);
              continue;
            }
            if (tmpy100 == 0 && tmpy4 == 0 && tmpy == 0) {//400
              ans += tmpy400 * 400;
              if (R < 60) {
                Gtmd(R);
                printf("%d
    ", ans);
              }
              if (R == 60) {
                printf("29 2 %d
    ", ans);
              }
              if (R > 60) {
                if(R == 1) {
                  ans--;
                  printf("31 12 %d
    ", ans);
                  continue;
                }
                Gtmd(R - 1);
                printf("%lld
    ", ans);
              }
              continue;
            }
            if(tmpy4 == 0 && tmpy == 0) {//100
              R--;
              Gtmd(R);
              printf("%d
    ", ans);
              continue;
            }
            if(tmpy == 0) {//4
              if (R < 60) {
                Gtmd(R);
                printf("%d
    ", ans);
              }
              if (R == 60) {
                printf("29 2 %d
    ", ans);
              }
              if (R > 60) {
                if(R == 1) {
                  ans--;
                  printf("31 12 %d
    ", ans);
                  continue;
                }
                Gtmd(R - 1);
                printf("%lld
    ", ans);
              }
              continue;
            }
            R--;
            Gtmd(R);
            printf("%d
    ", ans);
            continue;
    
          } else {
            if (R <= year3) {
              tmpy = (R - 1) / 365;
              R -= 365 * tmpy;
              ans += tmpy;
              Gtmd(R);
              printf("%lld
    ", ans + 1);
            } else {
              R -= year3;
              ans += 3;
              tmpy4 = (R - 1) / year4;
              R -= year4 * tmpy4;
              tmpy = (R - 1) / 365;
              R -= 365 * tmpy;
              //printf("%d
    ", R);
              ans += tmpy;
              ans += tmpy4 * 4;
              //printf("%d
    ", ans);
              if (ans % 4 == 3) {
                if (R < 60) {
                  Gtmd(R);
                  printf("%d
    ", ans + 1);
                }
                if (R == 60) {
                  printf("29 2 %d
    ", ans + 1);
                }
                if (R > 60) {
                  Gtmd(R - 1);
                  printf("%lld
    ", ans + 1);
                }
              } else {
                //printf("faq
    ");
                Gtmd(R - 1);
                printf("%lld
    ", ans + 1);
              }
            }
          }
        }
      }
      return 0;
    }
    

    稍加修改(特判)的正解

    ((274行))

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <map>
    #include <queue>
    using namespace std;
    inline long long RD() {
      long long Itmp(0), Isig(1);
      char Ichr(getchar());
      while ((Ichr != '-')&&((Ichr > '9')||(Ichr < '0'))) {
        Ichr = getchar();
      }
      if (Ichr == '-') {
        Isig = -1;
        Ichr = getchar();
      }
      while (Ichr >= '0' && Ichr <= '9') {
        Itmp = Itmp * 10 + Ichr - '0';
        Ichr = getchar();
      }
      return Itmp * Isig;
    }
    long long Q, R;
    long long Mth[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    long long BC(1721424)/*1720245 + 1179*/, year4(1461), year100(36524), year400(146097), _1582(577738)/*577460 + 273 + 4*/, year3(1095);
    long long tmpy4, tmpy, ans, tmpy100, tmpy400;
    void Clr () {
      ans = 0;
    }
    void Gtmd (int x) {
      //printf("here %d
    ",x);
      for (register int i(1); i <= 12; ++i) {
        if (x > Mth[i]) {
          x -= Mth[i];
          continue;
        } else {
          printf("%d %d ", x, i);
          return;
        }
      }
      return;
    }
    int main() {
      //freopen("julian3.in", "r", stdin);
      //freopen("julian.out", "w", stdout);
      Q = (int)RD();
      for (register int i(1); i <= Q; ++i) {
        //printf("%d
    ", i - 1);
        Clr();
        R = RD();
        R++;
        if(R <= BC) {
          tmpy4 = (R - 1) / year4;
          R -= year4 * tmpy4;
          tmpy = (R - 2) / 365;
          R -= 365 * tmpy;
          //printf("%d
    ", R);
          ans += tmpy;
          ans += tmpy4 * 4;
          //printf("%d
    ", ans);
          if (ans % 4 == 0) {
            if (R < 60) {
              Gtmd(R);
              printf("%d BC
    ", 4713 - ans);
            }
            if (R == 60) {
              printf("29 2 %d BC
    ", 4713 - ans);
            }
            if (R > 60) {
              Gtmd(R - 1);
              printf("%lld BC
    ", 4713 - ans);
            }
          } else {
            //printf("faq
    ");
            Gtmd(R - 1);
            printf("%lld BC
    ", 4713 - ans);
          }
        } else {
          R -= BC;
          if (R >= _1582) {
    
            // printf("ops
    ");
            R += 288;
            R -= _1582;
            //Gtmd(R);
            //printf("%d
    ", R);
            if(R <= 365) {//1582
              Gtmd(R);
              printf("1582
    ");
              continue;
            }
            R -= 365;
            if(R <= 365) {
              Gtmd(R);
              printf("1583
    ");
              continue;
            }
            R-=365;
            ans = 1584;
            if (R <= 5844) {
              //printf("here
    ");
              tmpy4 = (R - 1) / year4;
              R -= tmpy4 * year4;
              tmpy = (R - 2) / 365;
              R -= 365 * tmpy;
              ans += tmpy4 * 4 + tmpy;
              if(tmpy) {
                R--;
                Gtmd(R);
                printf("%d
    ", ans);
              } else {
                if (R < 60) {
                  Gtmd(R);
                  printf("%d
    ", ans);
                }
                if (R == 60) {
                  printf("29 2 %d
    ", ans);
                }
                if (R > 60) {
                  Gtmd(R - 1);
                  printf("%lld
    ", ans);
                }
              }
              continue;
            }
            R -= 5844;
            ans = 1600;
            tmpy400 = (R - 1) / year400;//400
            R -= tmpy400 * year400;
            tmpy100 = (R - 2) / year100;//100
            R -= tmpy100 * year100;
            if(tmpy100) {
              R--;
            }
            tmpy4 = R / year4;
            R -= tmpy4 * year4;
            if (tmpy4 && tmpy100) {
              R++;
            }
            tmpy = (R - 2) / 365;
            R -= tmpy * 365;
            if(tmpy) {
              if(tmpy100) {
                if(!tmpy4)
                  R++;
              } else {
                if(tmpy4) {
                  //R--;
                }
              }
            }
            if(tmpy100) {
              if(!tmpy4) {
                if(!tmpy) {
                  R++;
                }
              }
            }
            ans += tmpy + 4 * tmpy4 + 100 * tmpy100 + 400 * tmpy400;
            if(R == 0) {
              ans--;
              printf("31 12 %d
    ", ans);
              continue;
            }
            if (tmpy100 == 0 && tmpy4 == 0 && tmpy == 0) {//400
              //ans += tmpy400 * 400;
              if (R < 60) {
                Gtmd(R);
                printf("%d
    ", ans);
              }
              if (R == 60) {
                printf("29 2 %d
    ", ans);
              }
              if (R > 60) {
                if(R == 1) {
                  ans--;
                  printf("31 12 %d
    ", ans);
                  continue;
                }
                Gtmd(R - 1);
                printf("%lld
    ", ans);
              }
              continue;
            }
            if(tmpy4 == 0 && tmpy == 0) {//100
              //printf("here
    ");//216155297
              R--;
              if(R == 366) {
                printf("1 1 %d
    ", ans + 1);
                continue;
              }
              Gtmd(R);
              printf("%d
    ", ans);
              continue;
            }
            if(tmpy == 0) {//4
              if (R < 60) {
                Gtmd(R);
                printf("%d
    ", ans);
              }
              if (R == 60) {
                printf("29 2 %d
    ", ans);
              }
              if (R > 60) {
                if(R == 1) {
                  ans--;
                  printf("31 12 %d
    ", ans);
                  continue;
                }
                Gtmd(R - 1);
                printf("%lld
    ", ans);
              }
              continue;
            }
            R--;
            if(R == 366) {
              printf("1 1 %d
    ", ans + 1);
              continue;
            }
            Gtmd(R);
            printf("%d
    ", ans);
            continue;
    
          } else {
            if (R <= year3) {
              tmpy = (R - 1) / 365;
              R -= 365 * tmpy;
              ans += tmpy;
              Gtmd(R);
              printf("%lld
    ", ans + 1);
            } else {
              R -= year3;
              ans += 3;
              tmpy4 = (R - 1) / year4;
              R -= year4 * tmpy4;
              tmpy = (R - 2) / 365;
              R -= 365 * tmpy;
              ans += tmpy;
              ans += tmpy4 * 4;
              if (ans % 4 == 3) {
                if (R < 60) {
                  /*if(R == 0) {
                    printf("1 1 %d
    ", ans + 1);
                    continue;
                  }*/
                  Gtmd(R);
                  printf("%d
    ", ans + 1);
                }
                if (R == 60) {
                  printf("29 2 %d
    ", ans + 1);
                }
                if (R > 60) {
                  Gtmd(R - 1);
                  printf("%lld
    ", ans + 1);
                }
              } else {
                if(R == 1) {
                  /*if (ans % 4 == 0) {
                    printf("here
    ");
                  }*/
                  printf("31 12 %d
    ", ans);
                  continue;
                }
                Gtmd(R - 1);
                printf("%lld
    ", ans + 1);
              }
            }
          }
        }
      }
      return 0;
    }
    

    两行虐杀

    建议改成: 代 码 可 读 性 带 师

    ((2)行)

    #include <cstdio>
    using namespace std;long long Q, R, Mth[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, BC(1721424)/*1720245 + 1179*/, year4(1461), year100(36524), year400(146097), _1582(577738)/*577460 + 273 + 4*/, year3(1095), tmpy4, tmpy, ans, tmpy100, tmpy400;inline void Gtmd (int x) {for (register int i(1); i <= 12; ++i){if(x <= Mth[i]){printf("%d %d ", x, i);return;}x -= Mth[i];}}int main(){scanf("%d", &Q);for (register int i(1); i <= Q; ++i){ans = 0;scanf("%lld", &R);R++;if(R <= BC) {tmpy4 = (R - 1) / year4,R -= year4 * tmpy4,tmpy = (R - 2) / 365,R -= 365 * tmpy,ans += tmpy,ans += tmpy4 * 4;if(ans % 4 == 0) {if (R < 60)Gtmd(R),printf("%d BC
    ", 4713 - ans);if (R == 60)printf("29 2 %d BC
    ", 4713 - ans);if(R > 60)Gtmd(R - 1),printf("%lld BC
    ", 4713 - ans);continue;}Gtmd(R - 1),printf("%lld BC
    ", 4713 - ans);continue;}R -= BC;if (R >= _1582) {R += 288,R -= _1582;if(R <= 365) {Gtmd(R),printf("1582
    ");continue;}R -= 365;if(R <= 365) {Gtmd(R),printf("1583
    ");continue;}R-=365,ans = 1584;if (R <= 5844) {tmpy4 = (R - 1) / year4,R -= tmpy4 * year4,tmpy = (R - 2) / 365,R -= 365 * tmpy,ans += tmpy4 * 4 + tmpy;if(tmpy){R--,Gtmd(R),printf("%d
    ", ans);continue;}if(R < 60)Gtmd(R),printf("%d
    ", ans);if (R == 60)printf("29 2 %d
    ", ans);if(R > 60)Gtmd(R - 1),printf("%lld
    ", ans);continue;}R -= 5844,ans = 1600,tmpy400 = (R - 1) / year400,R -= tmpy400 * year400,tmpy100 = (R - 2) / year100,R -= tmpy100 * year100;if(tmpy100)R--;tmpy4 = R / year4,R -= tmpy4 * year4;if (tmpy4 && tmpy100)R++;tmpy = (R - 2) / 365,R -= tmpy * 365;if(tmpy)if(tmpy100)if(!tmpy4)R++;if(tmpy100)if(!tmpy4)if(!tmpy)R++;ans += tmpy + 4 * tmpy4 + 100 * tmpy100 + 400 * tmpy400;if(R == 0){ans--,printf("31 12 %d
    ", ans);continue;}if (tmpy100 == 0 && tmpy4 == 0 && tmpy == 0) {if(R < 60)Gtmd(R),printf("%d
    ", ans);if (R == 60)printf("29 2 %d
    ", ans);if(R > 60){if(R == 1){ans--,printf("31 12 %d
    ", ans);continue;}Gtmd(R - 1),printf("%lld
    ", ans);}continue;}if(tmpy4 == 0 && tmpy == 0) {R--;if(R == 366){printf("1 1 %d
    ", ans + 1);continue;}Gtmd(R),printf("%d
    ", ans);continue;}if(tmpy == 0) {if (R < 60)Gtmd(R),printf("%d
    ", ans);if (R == 60)printf("29 2 %d
    ", ans);if(R > 60){if(R == 1){ans--,printf("31 12 %d
    ", ans);continue;}Gtmd(R - 1),printf("%lld
    ", ans);}continue;}R--;if(R == 366){printf("1 1 %d
    ", ans + 1);continue;}Gtmd(R),printf("%d
    ", ans);continue;}if(R <= year3){tmpy = (R - 1) / 365,R -= 365 * tmpy,ans += tmpy,Gtmd(R),printf("%lld
    ", ans + 1);continue;}R -= year3,ans += 3,tmpy4 = (R - 1) / year4,R -= year4 * tmpy4,tmpy = (R - 2) / 365,R -= 365 * tmpy,ans += tmpy,ans += tmpy4 * 4;if(ans % 4 == 3) {if (R < 60)Gtmd(R),printf("%d
    ", ans + 1);if (R == 60)printf("29 2 %d
    ", ans + 1);if (R > 60)Gtmd(R - 1),printf("%lld
    ", ans + 1);continue;}if(R == 1){printf("31 12 %d
    ", ans);continue;}Gtmd(R - 1),printf("%lld
    ", ans + 1);}return 0;}}
    
  • 相关阅读:
    java 集合框架(十五)Deque
    java 集合框架(十四)Queue
    java 集合框架(十)List
    java 集合框架(四)Set
    java 集合框架(三)Collection
    java 集合框架(一)概述
    java 集合框架(二)Iterable接口
    java I/O框架 (四)文件流
    全零网络IP地址0.0.0.0表示意义详谈
    windows在cmd执行svn 命令
  • 原文地址:https://www.cnblogs.com/Wild-Donkey/p/13970645.html
Copyright © 2020-2023  润新知