hdu 2828 Buy Tickets

来源:http://www.cnblogs.com/ygtzds/archive/2017/10/06/7631781.html
-Advertisement-
Play Games

Buy Tickets Problem Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queu ...


Buy Tickets

Time Limit : 8000/4000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 31   Accepted Submission(s) : 15
Problem Description

Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue…

The Lunar New Year was approaching, but unluckily the Little Cat still had schedules going here and there. Now, he had to travel by train to Mianyang, Sichuan Province for the winter camp selection of the national team of Olympiad in Informatics.

It was one o’clock a.m. and dark outside. Chill wind from the northwest did not scare off the people in the queue. The cold night gave the Little Cat a shiver. Why not find a problem to think about? That was none the less better than freezing to death!

People kept jumping the queue. Since it was too dark around, such moves would not be discovered even by the people adjacent to the queue-jumpers. “If every person in the queue is assigned an integral value and all the information about those who have jumped the queue and where they stand after queue-jumping is given, can I find out the final order of people in the queue?” Thought the Little Cat.

 

 

Input <p>There will be several test cases in the input. Each test case consists of <i>N</i> + 1 lines where <i>N</i> (1 ≤ <i>N</i> ≤ 200,000) is given in the first line of the test case. The next <i>N</i> lines contain the pairs of values <i>Pos<sub>i</sub></i> and <i>Val<sub>i</sub></i> in the increasing order of <i>i</i> (1 ≤ <i>i</i> ≤ <i>N</i>). For each <i>i</i>, the ranges and meanings of <i>Pos<sub>i</sub></i> and <i>Val<sub>i</sub></i> are as follows:</p><ul><li><i>Pos<sub>i</sub></i> ∈ [0, <i>i</i> − 1] — The <i>i</i>-th person came to the queue and stood right behind the <i>Pos<sub>i</sub></i>-th person in the queue. The booking office was considered the 0th person and the person at the front of the queue was considered the first person in the queue.</li><li><i>Val<sub>i</sub></i> ∈ [0, 32767] — The <i>i</i>-th person was assigned the value <i>Val<sub>i</sub></i>.</li></ul><p>There no blank lines between test cases. Proceed to the end of input.</p>  

 

Output <p>For each test cases, output a single line of space-separated integers which are the values of people in the order they stand in the queue.</p>  

 

Sample Input 4 0 77 1 51 1 33 2 69 4 0 20523 1 19243 1 3890 0 31492  

 

Sample Output 77 33 69 51 31492 20523 3890 19243  

 

Source PKU     還是線段樹的新手,做完才恍然線段樹只是可供利用的一種數據結構,具體怎麼用要發揮自己的想象力。。 一開始還在想用lowbit()之類的常用函數。 這道題目的中心在,逆序插入的最後一人位置不變。在結點用ksum表示空位數量。    
#include <iostream>
#include <cstdio>
#include <algorithm>
#include<vector>
#include<cstring>
using namespace std;
int a[200005],b[200005],ans[200005];
int tem,t;
struct node
{
    int l,r,ksum;
}tr[200005<<2];
void build(int n,int l,int r)
{
    tr[n].l=l;
    tr[n].r=r;
    tr[n].ksum=r-l+1;
    if(l==r)
        return;
    int m=(l+r)>>1;
    build(n<<1,l,m);
    build(n<<1|1,m+1,r);
}
void f(int k,int v,int n)
{
    int m=(tr[n].l+tr[n].r)>>1;
    if(tr[n].l==tr[n].r)
    {
        tr[n].ksum=0;
        ans[tr[n].l]=v;
        return;
    }
    if(tr[n<<1].ksum>=k)
        f(k,v,n<<1);
    else
        f(k-tr[n<<1].ksum,v,n<<1|1);
    tr[n].ksum=tr[n<<1].ksum+tr[n<<1|1].ksum;
}


int main()
{

    while(~scanf("%d",&t))
    {
        build(1,1,t);
        tem=0;
        for(int i=1;i<=t;i++)
            scanf("%d%d",&a[i],&b[i]);
        for(int i=t;i>0;i--)
            f(a[i]+1,b[i],1);
        for(int i=1;i<t;i++)
            cout<<ans[i]<<" ";
            cout<<ans[t]<<endl;
    }
}

  


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 1、MVC:非Java獨有,所有的B/S的結構都在使用它。 M——Model模式(自己寫代碼) V——View 視圖(jsp) C——Controller 控制器(Servlet) 2、JavaWeb三層框架 Web層-->與Web相關的內容(Servlet,JSP,Servlet相關API:req ...
  • 一、創建自定義標簽基本步驟 1、步驟 標簽處理類(標簽也是一個對象,那麼就需要先有類!) tld文件,它是一個xml 頁面中使用<%@taglib%>來指定tld文件的位置 2、標簽處理類 SimpleTag介面 void doTag():每次執行標簽時都會調用這個方法; JspTag getPar ...
  • Python 協程爬取妹子圖~~~ async aiohttp scrapy ...
  • 首先分析一下集合與數組的區別:1.java中的數組一般用於存儲基本數據類型,而且是靜態的,即長度固定不變,這就不適用於元素個數未知的情況;2.集合只能用於存儲引用類型,並且長度可變,適用於大多數情況,可用toArray()方法轉換成數組。 java語言提供了多種集合類的介面,如List、Set、Ma ...
  • 方法一: Toolkit.getDefaultToolkit().beep(); 方法二: System.out.println('\007');//八進位數 ...
  • package com.swift;//可以不要這句 import java.io.IOException; public class Shutdown100 { public static void main(String[] args) { try { Runtime.getRuntime().... ...
  • Doing Homework HDU - 1074 題意: 有n個作業,每個作業有一個截止時間和完成所需時間,如果完成某個作業的時間超出了截止時間就扣完成時間-截止時間的分。求按怎樣的順序完成作業扣分最少。 方法:狀壓dp。ans[S]表示完成集合S的作業最少的扣分(集合S用一個數字表示)。pre[ ...
  • 一、JSTL的概述 1、Apache開發與維護,依賴EL表達式 2、Apache Tomcat安裝JSTL 庫步驟如下: 從Apache的標準標簽庫中下載的二進包(jakarta-taglibs-standard-current.zip)。 官方下載地址:http://archive.apache. ...
一周排行
    -Advertisement-
    Play Games
  • 前言 本文介紹一款使用 C# 與 WPF 開發的音頻播放器,其界面簡潔大方,操作體驗流暢。該播放器支持多種音頻格式(如 MP4、WMA、OGG、FLAC 等),並具備標記、實時歌詞顯示等功能。 另外,還支持換膚及多語言(中英文)切換。核心音頻處理採用 FFmpeg 組件,獲得了廣泛認可,目前 Git ...
  • OAuth2.0授權驗證-gitee授權碼模式 本文主要介紹如何筆者自己是如何使用gitee提供的OAuth2.0協議完成授權驗證並登錄到自己的系統,完整模式如圖 1、創建應用 打開gitee個人中心->第三方應用->創建應用 創建應用後在我的應用界面,查看已創建應用的Client ID和Clien ...
  • 解決了這個問題:《winForm下,fastReport.net 從.net framework 升級到.net5遇到的錯誤“Operation is not supported on this platform.”》 本文內容轉載自:https://www.fcnsoft.com/Home/Sho ...
  • 國內文章 WPF 從裸 Win 32 的 WM_Pointer 消息獲取觸摸點繪製筆跡 https://www.cnblogs.com/lindexi/p/18390983 本文將告訴大家如何在 WPF 裡面,接收裸 Win 32 的 WM_Pointer 消息,從消息裡面獲取觸摸點信息,使用觸摸點 ...
  • 前言 給大家推薦一個專為新零售快消行業打造了一套高效的進銷存管理系統。 系統不僅具備強大的庫存管理功能,還集成了高性能的輕量級 POS 解決方案,確保頁面載入速度極快,提供良好的用戶體驗。 項目介紹 Dorisoy.POS 是一款基於 .NET 7 和 Angular 4 開發的新零售快消進銷存管理 ...
  • ABP CLI常用的代碼分享 一、確保環境配置正確 安裝.NET CLI: ABP CLI是基於.NET Core或.NET 5/6/7等更高版本構建的,因此首先需要在你的開發環境中安裝.NET CLI。這可以通過訪問Microsoft官網下載並安裝相應版本的.NET SDK來實現。 安裝ABP ...
  • 問題 問題是這樣的:第三方的webapi,需要先調用登陸介面獲取Cookie,訪問其它介面時攜帶Cookie信息。 但使用HttpClient類調用登陸介面,返回的Headers中沒有找到Cookie信息。 分析 首先,使用Postman測試該登陸介面,正常返回Cookie信息,說明是HttpCli ...
  • 國內文章 關於.NET在中國為什麼工資低的分析 https://www.cnblogs.com/thinkingmore/p/18406244 .NET在中國開發者的薪資偏低,主要因市場需求、技術棧選擇和企業文化等因素所致。歷史上,.NET曾因微軟的閉源策略發展受限,儘管後來推出了跨平臺的.NET ...
  • 在WPF開發應用中,動畫不僅可以引起用戶的註意與興趣,而且還使軟體更加便於使用。前面幾篇文章講解了畫筆(Brush),形狀(Shape),幾何圖形(Geometry),變換(Transform)等相關內容,今天繼續講解動畫相關內容和知識點,僅供學習分享使用,如有不足之處,還請指正。 ...
  • 什麼是委托? 委托可以說是把一個方法代入另一個方法執行,相當於指向函數的指針;事件就相當於保存委托的數組; 1.實例化委托的方式: 方式1:通過new創建實例: public delegate void ShowDelegate(); 或者 public delegate string ShowDe ...