zoukankan      html  css  js  c++  java
  • HDU

    Fast Arrangement

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 3563    Accepted Submission(s): 1024


    Problem Description
    Chinese always have the railway tickets problem because of its' huge amount of passangers and stations. Now goverment need you to develop a new tickets query system.
    One train can just take k passangers. And each passanger can just buy one ticket from station a to station b. Each train cannot take more passangers any time. The one who buy the ticket earlier which can be sold will always get the ticket.
     

    Input
    The input contains servel test cases. The first line is the case number. In each test case:
    The first line contains just one number k( 1 ≤ k ≤ 1000 ) and Q( 1 ≤ Q ≤ 100000 )
    The following lines, each line contains two integers a and b, ( 1 ≤ a < b ≤ 1000000 ), indicate a query.
    Huge Input, scanf recommanded.
     

    Output
    For each test case, output three lines:
    Output the case number in the first line.
    If the ith query can be satisfied, output i. i starting from 1. output an blank-space after each number.
    Output a blank line after each test case.
     

    Sample Input
    1 3 6 1 6 1 6 3 4 1 5 1 2 2 4
     

    Sample Output
    Case 1: 1 2 3 5
     

    Author
    Louty (Special Thanks Nick Gu)
     

    Source
     

    Recommend
    zhouzeyong


    题意:设计一个卖票系统,已经卖出的位置在乘车区间内不能再卖出,输出第几条输入的票可以卖出

    思路:用线段树,每卖出一张票就修改指定区间的票数,最后检查总票数即可

    #include<cstdio>
    #include<cstring>
    #define MAXN 1000010
    struct node{
    	int l, r,tag,num;
    }tree[MAXN<<2];
    int k,q, a, b,cas,len,cnt[MAXN];
    int max(int a, int b)
    {
    	return a > b ? a : b;
    }
    void build(int k, int l, int r)
    {
    	tree[k].tag = 0; tree[k].num = 0;
    	tree[k].l = l; tree[k].r = r;
    	if (l == r)
    		return;
    	int mid = (l + r) >> 1;
    	build(k << 1, l, mid);
    	build(k << 1 | 1, mid + 1, r);
    }
    void pushup(int k)
    {
    	tree[k].num = max(tree[k << 1].num, tree[k << 1 | 1].num);
    }
    void pushdown(int k)
    {
    	tree[k << 1].num += tree[k].tag;
    	tree[k << 1 | 1].num += tree[k].tag;
    	tree[k << 1].tag += tree[k].tag;
    	tree[k << 1 | 1].tag += tree[k].tag;
    	tree[k].tag = 0;
    
    }
    void update(int k, int l, int r, int x)
    {
    	if (tree[k].l == l&&tree[k].r == r)
    	{
    		tree[k].num += x;
    		tree[k].tag += x;
    		return;
    	}
    	if (tree[k].tag)
    		pushdown(k);
    	int mid = (tree[k].l + tree[k].r) >> 1;
    	if (r <= mid)
    		update(k << 1, l, r, x);
    	else if (l >= mid + 1)
    		update(k << 1 | 1, l, r, x);
    	else
    	{
    		update(k << 1, l, mid, x);
    		update(k << 1 | 1, mid + 1, r, x);
    	}
    	pushup(k);
    }
    int query(int k, int l, int r)
    {
    	
    	if (tree[k].l == l&&tree[k].r == r)
    		return tree[k].num;
    	if (tree[k].tag)
    		pushdown(k);
    	int mid = (tree[k].l + tree[k].r) >> 1;
    	if (r <= mid)
    		return query(k << 1, l, r);
    	else if (l >= mid + 1)
    		return query(k << 1 | 1, l, r);
    	else
    		return max(query(k << 1, l, mid) , query(k << 1 | 1, mid + 1, r));
    }
    
    int main()
    {
    	int t;
    	cas = 1;
    	scanf("%d", &t);
    	while (t--)
    	{
    		memset(cnt, 0, sizeof(cnt));
    		len = 1;
    		scanf("%d%d", &k, &q);	
    		build(1, 1, 1000010);
    		for (int i = 1; i <= q; i++)
    		{
    			scanf("%d%d", &a, &b);
    			b--;
    			if (query(1, a, b) < k)
    			{
    				cnt[len++] = i;
    				update(1, a, b, 1);
    			}
    		}
    		printf("Case %d:
    ", cas++);
    		for (int i = 1; i < len; i++)
    		{
    			printf("%d ", cnt[i]);
    		}
    		printf("
    
    ");
    
    	}
    	return 0;
    }

  • 相关阅读:
    ethereum(以太坊)(六)--整型(int)
    pycharm升级pip20版本后,还是显示pip10的版本的问题
    Django2.2.7 邮箱重置密码
    django重置密码,填哪个用户的注册邮箱,就是重置的哪个用户的密码,和登陆记录没有关系。
    Django:重置用户密码,用第三方库Django-password-reset
    python_django_views文件中return render("XXXX/XXX.html") 显示 Template file not found
    Django添加templates目录
    django2.2 版本static静态文件路径配置出错的问题解决方案。
    pycharm无法新建django项目,报错timed out,需先建立pure项目,进入后建立django项目,最后调整目录层级。
    python读取大文件和普通文件
  • 原文地址:https://www.cnblogs.com/csu-lmw/p/9124421.html
Copyright © 2011-2022 走看看