zoukankan      html  css  js  c++  java
  • Lightoj 1088

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1088

    题意: 有一维的n个点和q条线段。询问每条线段上的点有多少个。

    思路:寻找这些点中对于每条线段的上下界就可以。

    代码:

    #include <stdio.h>
    #include <ctime>
    #include <math.h>
    #include <limits.h>
    #include <complex>
    #include <string>
    #include <functional>
    #include <iterator>
    #include <algorithm>
    #include <vector>
    #include <stack>
    #include <queue>
    #include <set>
    #include <map>
    #include <list>
    #include <bitset>
    #include <sstream>
    #include <iomanip>
    #include <fstream>
    #include <iostream>
    #include <ctime>
    #include <cmath>
    #include <cstring>
    #include <cstdio>
    #include <time.h>
    #include <ctype.h>
    #include <string.h>
    #include <assert.h>
    
    using namespace std;
    
    int n, q;
    int a[100010];
    int x, y;
    int ok;
    
    int query(int t,int &ok)
    {
        ok = 0;
        int left = 1;
        int right = n;
        int mid;
        while (left <= right)
        {
            int mid = (left + right) / 2;
            if (a[mid] >= t)
            {
                if (a[mid] == t)
                    ok = 1;
                right = mid - 1;
            }
            else
                left = mid + 1;
        }
        return left;
    }
    
    int main()
    {
        int t;
        scanf("%d",&t);
        int cases = 1;
        while (t--)
        {
            scanf("%d%d",&n,&q);
            for (int i = 1; i <= n; i++)
                scanf("%d",&a[i]);
            printf("Case %d:
    ", cases++);
            while (q--)
            {
                scanf("%d%d", &x, &y);
                int ok1 = 0, ok2 = 0, tmp = 0;
                int t1 = query(x,ok1);
                int t2 = query(y,ok2);
                if (ok2) tmp = 1;
                //printf("      %d %d
    ",t1,t2);
                printf("%d
    ", t2 - t1 + tmp);
            }
        }
        return 0; 
    }
    
  • 相关阅读:
    010editor爆破与注册机
    [FlareOn4]notepad
    [FlareOn6]Snake(NES逆向)
    [FlareOn6]Memecat Battlestation
    [FlareOn6]FlareBear
    回车符和换行符之间的区别
    docker配置搭建elasticsearch集群
    docker部署安装harbor
    ansible的get_url模块
    ansible的lineinfile与blockinfile模块
  • 原文地址:https://www.cnblogs.com/mthoutai/p/7224547.html
Copyright © 2011-2022 走看看