zoukankan      html  css  js  c++  java
  • 2019 年百度之星·程序设计大赛

    1001

    #pragma comment(linker, "/STACK:36777216")
    
    #include <bits/stdc++.h>
    
    #define REP(i,n) for(int i=0;i<int(n);++i)
    #define FOR(i,a,b) for(int i=int(a);i<int(b);++i)
    #define DWN(i,b,a) for(int i=int(b);i>=int(a);--i)
    
    /// type define
    typedef double DB;
    typedef long long LL;
    typedef std::vector<int>VI;
    typedef std::vector<LL>VLL;
    typedef std::pair<int, int>PII;
    typedef std::pair<LL, LL>PLL;
    typedef std::vector<PII >VPII;
    
    /// const
    static const double eps = 1e-8;
    static const double pi = acos(-1.0);
    static const int inf = 0x3f3f3f3f;
    static const LL INF = 0x3f3f3f3f3f3f3f3f;
    
    /// common statement
    #define PB push_back
    #define MP std::make_pair
    #define fi first
    #define se second
    
    /****************************************************************/
    
    const int maxn = 2e6 + 7;
    const LL MOD = 1e9 + 7;
    
    int a[maxn],b[maxn];
    
    void solve() {
      /*********** start your code here. ************/
      int n;
      std::cin >> n;
      REP(i,n) std::cin >> a[i];
      REP(i,n) std::cin >>b[i];
      for(int i = n-1; i >= 0; --i) {
        int x = a[i],y = b[i];
        if(a[i] || b[i]) {
          if(!x)
            puts("0/1");
          else if(!y)
            puts("1/0");
          else {
            int z = std::__gcd(x,y);
            x /= z,y /= z;
            std::cout << x << "/" << y << "
    ";
          }
          break;
        }
      }
    }
    
    void init() {
    
    }
    
    int main() {
      std::ios::sync_with_stdio(false);
      std::cin.tie(0);
      init();
      int T;
      std::cin >>T;
      while(T--)
        solve();
      return 0;
    }
    

    1002 Game

    将每次移动都考虑成从区间到区间的变换。

    不妨设当前所在的区间为 [l,r] ,下一个要到的区间为 [a,b]。那么,有以下 3 种情况

    1. [l,r] 和 [a,b] 有交集,那么取交集即可(因为起点是可选的),步数为 0
    2. [l,r] 在 [a,b] 的左侧,那么最小的步数就是从 a 走到 r ,由于一次可选走一步或者两步,最后一步的奇偶就影响的落点,可一步可两步就结果就是一个长为 2 的新区间(这个新区间必须在 [a,b] 内部,这里要判断)
    3. [l,r] 在 [a,b] 的右侧,类似情况 2,换成了从 b 走到 r
    #include<bits/stdc++.h>
    
    using namespace std;
    
    const int inf = 0x3f3f3f3f;
    
    void init() {
    
    }
    
    int n, l, r;
    
    int transfer(int a, int b) {
      int res(0);
      int _l = max(l, a), _r = min(r, b);
      if(_l <= _r) {
        l = _l, r = _r;
        return 0;
      }
      if(b < l) {
        /// [a,b] [l,r]
        int res = (l - b + 1) / 2;
        r = b;
        l = b - ((l - b & 1) && a < b ? 1 : 0);
        return res;
      } else {
        /// [l,r] [a,b]
        res = (a - r + 1) / 2;
        l = a;
        r = a + (((a - r & 1) && b > a) ? 1 :0);
        return res;
      }
    }
    
    void solve() {
      int ans = 0;
      l = 1, r = inf;
      std::cin >> n;
      for(int i = 0, a, b; i < n; ++i) {
        std::cin >> a >> b;
        ans += transfer(a, b);
      }
      std::cout << ans << "
    ";
    }
    
    int main() {
      ios::sync_with_stdio(false);
      cin.tie(0);
      int T;
      cin >> T;
      while(T--)
        solve();
      return 0;
    }
    
    

    1005

    #pragma comment(linker, "/STACK:36777216")
    
    #include <bits/stdc++.h>
    
    #define REP(i,n) for(int i=0;i<int(n);++i)
    #define FOR(i,a,b) for(int i=int(a);i<int(b);++i)
    #define DWN(i,b,a) for(int i=int(b);i>=int(a);--i)
    
    /// type define
    typedef double DB;
    typedef long long LL;
    typedef std::vector<int>VI;
    typedef std::vector<LL>VLL;
    typedef std::pair<int, int>PII;
    typedef std::pair<LL, LL>PLL;
    typedef std::vector<PII >VPII;
    
    /// const
    static const double eps = 1e-8;
    static const double pi = acos(-1.0);
    static const int inf = 0x3f3f3f3f;
    static const LL INF = 0x3f3f3f3f3f3f3f3f;
    
    /// common statement
    #define PB push_back
    #define MP std::make_pair
    #define fi first
    #define se second
    
    /****************************************************************/
    
    const int maxn = 2e6 + 7;
    const LL MOD = 1e9 + 7;
    
    LL C(LL x){
      LL step[] = {3,4,3,1,6,1};
      LL b[] = {0,1,1,0,3,0};
    
        return b[x%6]+x/6*step[x%6];
    }
    
    void solve() {
      /*********** start your code here. ************/
      LL n;std::cin >>n;
      std::cout << C(n) << "
    ";
    }
    
    
    
    void init() {
    
    }
    
    int main() {
      std::ios::sync_with_stdio(false);
      std::cin.tie(0);
      //init();
      int T;
      std::cin >>T;
      while(T--)
        solve();
      return 0;
    }
    
  • 相关阅读:
    list去重
    安装go与nebula-importer遇见的问题
    2.安装docker后运行其他镜像
    2.绝对路径Linux和Windows上的写法
    1.SpringBoot 读取配置文件的值 赋给静态变量
    04747JAVA语言程序设计练习题(第一章)
    Revit文件加载到arcgis pro中调整位置并生成slpk包
    新部署arcgis javascript api 服务器添加的两个mime
    转发博客园中的文章
    【转】使用ArcGIS Pro编辑在线三维服务图层
  • 原文地址:https://www.cnblogs.com/Forgenvueory/p/11374092.html
Copyright © 2011-2022 走看看