我是從三點多才知道有比賽的,所以只剩下不到兩個多小時,中間肚子疼,又上廁所一次,真是的。。參加吧,撿到哪到是哪到~
不吉利的數字
- 描述
-
一些普通的數字在很多人眼里是不吉利。如數字4,諧音“死”,所以很多地方都沒有帶4的數字:比如新校區澡堂衣櫃編號及沒有4;再如數字13,在西方人眼中代表着壞運氣,也是不吉利的數字,13不出遠門,樓層不設第13層等等。
假如某些人認為0是不吉利的數字,並且在他們以后的生活中,記錄數據都在不在使用含有0的自然數。
他們記錄數的序列是1,2,3,4,5,6,7,8,9,11,12,13,14,15,16,17,18,19,21,22.......n,由於不使用數字0,他們記錄的數和我們實際使用的自然數有一定的差別,如他們的11,實際就是第10個數,21就是第19個數,以此類推。。。
現在給你一個數n,請判斷在不不含0的序列中的,如果在,求n是第幾個數,不在,輸出Unlucky。
Hint: 105,10523等等,都是含有0的
- 輸入
-
有多組測試數據<5000
每組數據占一行,每行有一個數n(0<=n<=1000000)。
以EOF結尾 - 輸出
- 每組輸出占一行,如果n在不含0的序列中,輸出是第幾個。如果不在不含0的序列中,輸出Unlucky;
- 樣例輸入
-
11 9 21 10
- 樣例輸出
-
10 9 19 Unlucky
【我的代碼】這道題非常簡單,5分鍾AC:1 import java.util.Scanner; 2 3 4 public class Main3 { 5 static int t=1000001; 6 static int a[]=new int[t]; 7 public static void main(String args[]){ 8 Scanner cin=new Scanner(System.in); 9 String str=""; 10 int sum=1; 11 12 13 for(int i=1;i<t;i++){ 14 str=i+""; 15 boolean f=false; 16 for(int j=0;j<str.length();j++){ 17 if(str.charAt(j)=='0') { 18 f=true; 19 break; 20 } 21 } 22 if(!f) 23 a[i]=sum++; 24 } 25 while(cin.hasNext()){ 26 int num=cin.nextInt(); 27 if(a[num]==0) 28 System.out.println("Unlucky"); 29 else 30 System.out.println(a[num]); 31 } 32 } 33 }
數棋盤
時間限制: 1000 ms | 內存限制: 65535 KB- 描述
-
一個有N×N個格子的正方形棋盤,每個格子可以用C種不同顏色來染色,一共可以得到多少種不同的棋盤。如果一個棋盤,經過任意旋轉,反射后變成另一個棋盤,這兩個棋盤就是屬於同一種棋盤。
比如當N=C=2的時候,有下面六種不同的棋盤:
現在告訴你N和C,請你算算,到底有多少種不同的棋盤.
輸入-
本題目包含多組測試,請處理到文件結束。
每組測試數據包含兩個正整數N和C(0<N,C,<31),分別表示棋盤的大小是N×N,用C種顏色來進行染色。 - 輸出
- 對於每組測試,在一行里輸出答案。
- 樣例輸入
-
2 2 3 1
- 樣例輸出
-
6 1
以前看過相關的解題報告,好在我記住了,不過中間還是忘了一些,又回憶了一下,證明了一下:
【我的代碼】1 import java.util.*; 2 import java.math.*; 3 public class Main { 4 5 6 public static void main(String[] args) { 7 Scanner cin= new Scanner(System.in); 8 while(cin.hasNextInt()) 9 { 10 11 BigInteger sum=BigInteger.ZERO; 12 int n=cin.nextInt(); 13 int m=cin.nextInt(); 14 BigInteger M=BigInteger.valueOf(m); 15 sum=sum.add(M.pow(n*n)); 16 sum=sum.add(M.pow((n*n+3)/4)); 17 sum=sum.add(M.pow((n*n+1)/2)); 18 sum=sum.add(M.pow((n*n+3)/4)); 19 if(n%2 == 0) 20 { 21 sum=sum.add(M.pow(n*n/2).add(M.pow(n*(n-1)/2+n)).multiply(BigInteger.valueOf(2))); 22 } 23 else 24 sum=sum.add(M.pow(n*(n-1)/2+n).multiply(BigInteger.valueOf(4))); 25 System.out.println(sum.divide(BigInteger.valueOf(8))); 26 } 27 28 } 29 }
太空飛行計划
時間限制: 1000 ms | 內存限制: 65535 KB- 描述
-
W 教授正在為國家航天中心計划一系列的太空飛行。每次太空飛行可進行一系列商業性實驗而獲取利潤。現已確定了一個可供選擇的實驗集合E={E1,E2,…,Em},和進行這些實驗需要使用的全部儀器的集合I={I1,I2,…In}。實驗Ej需要用到的儀器是I的子集Rj 。配置儀器Ik的費用為ck美元。實驗Ej的贊助商已同意為該實驗結果支付pj美元。W教授的任務是找出一個有效算法,確定在一次太空飛行中要進行哪些實驗並因此而配置哪些儀器才能使太空飛行的凈收益最大。這里凈收益是指進行實驗所獲得的全部收入與配置儀器的全部費用的差額。對於給定的實驗和儀器配置情況,編程找出凈收益最大的試驗計划。
- 輸入
-
多組測試數據(不超過500組)
每組數據第1行有2 個正整數m和n(m,n <= 100)。m是實驗數,n是儀器數。接下來的m 行,每行是一個實驗的有關數據。第一個數贊助商同意支付該實驗的費用f(f < 10000);接着是該實驗需要用到的儀器的個數t,接着是t個儀器的編號。最后一行的n個數是配置每個儀器的費用pi(pi <=100)。 - 輸出
- 每組數據輸出占一行,輸出最大的凈收益(如果無法收益,輸出0)。
- 樣例輸入
-
2 3 10 2 1 2 25 2 2 3 5 6 7
- 樣例輸出
-
17
【我的代碼】第一次想的太簡單:c-wrong:1 import java.util.*; 2 public class Mainflyplan { 3 public static void main(String args[]){ 4 Scanner cin=new Scanner(System.in); 5 int m=cin.nextInt(); //實驗數 6 int n=cin.nextInt(); //儀器數 7 8 Sy a[]=new Sy[m]; 9 for(int i=0;i<m;i++){ 10 Sy sy=new Sy(); 11 sy.fi=cin.nextInt(); 12 sy.num=cin.nextInt(); 13 sy.init(); 14 for(int j=0;j<sy.num;j++) 15 sy.a[j]=cin.nextInt(); 16 17 a[i]=sy; 18 } 19 int fi[]=new int[n+1]; 20 for(int i=1;i<n+1;i++) //輸入儀器費用 21 fi[i]=cin.nextInt(); 22 23 int sum=0; //總盈利 24 int old=-1; //判斷每次循環是否最大值有變化,無變化則挑出 25 26 int oldenum=-1; 27 int equnum=0; 28 boolean euse[]=new boolean[n+1]; //n個儀器是否被選擇 29 int tmpe=0; 30 31 while(oldenum!=equnum|old!=sum){ //條件應當是 儀器數沒有改變,最大值也沒有改變的時候 32 33 34 old=sum; 35 36 37 // tmpe=0; 38 // for(int i=1;i<=n;i++) 39 // if(euse[i]) tmpe++; 40 41 oldenum=equnum; 42 for(int i=0;i<m;i++){ //對實驗個數進行遍歷 43 if(!a[i].flag){ //沒有被收錄 44 int ecost=0;//當前循環加入該實驗所需要配置儀器的總費用 45 for(int j=0;j<a[i].num;j++){ 46 int now=a[i].a[j]; 47 if(euse[now]) 48 ecost+=0; //已經被收錄則無需費用 49 else{ 50 ecost+=fi[now]; 51 } 52 } 53 54 a[i].benfit=a[i].fi-ecost; //當前循環加入該實驗的收益 55 if(a[i].benfit>=0){ //如果收益大於0 等於0也應當收錄,這樣為后來有更多的儀器有保證 56 sum+=a[i].benfit; 57 a[i].flag=true; 58 59 for(int k=0;k<a[i].num;k++){ 60 int now=a[i].a[k]; 61 euse[now]=true; 62 } 63 64 tmpe=0; //更新儀器數 65 for(int p=1;p<=n;p++) 66 if(euse[p]) tmpe++; 67 equnum=tmpe; //更新儀器數 68 } 69 } 70 } 71 } 72 System.out.println(sum); 73 74 } 75 76 77 } 78 class Sy 79 { 80 boolean flag=false; //是否被收錄 81 int fi=0; 82 int num=0; 83 int a[]; 84 int benfit=0; 85 public void init(){ 86 a=new int[num]; 87 } 88 }
【我的代碼】 修改后:
1 import java.util.*; 2 public class Main { 3 public static void main(String args[]){ 4 Scanner cin=new Scanner(System.in); 5 int m=cin.nextInt(); //實驗數 6 int n=cin.nextInt(); //儀器數 7 8 Sy a[]=new Sy[m]; 9 for(int i=0;i<m;i++){ 10 Sy sy=new Sy(); 11 sy.fi=cin.nextInt(); 12 sy.num=cin.nextInt(); 13 sy.init(); 14 for(int j=0;j<sy.num;j++) 15 sy.a[j]=cin.nextInt(); 16 17 a[i]=sy; 18 } 19 int fi[]=new int[n+1]; 20 for(int i=1;i<n+1;i++) //輸入儀器費用 21 fi[i]=cin.nextInt(); 22 23 int sum=0; //總盈利 24 25 boolean euse[]=new boolean[n+1]; //n個儀器是否被選擇 26 27 28 29 for(int i=0;i<m;i++){ //對實驗個數進行遍歷 30 int s=0; 31 for(int j=0;j<m;j++){ 32 if(a[j].flag) s++; 33 } 34 if(s==m) break; 35 36 //找到最大應該加入的方案 37 38 int max=-1,maxp=0; 39 40 for(int k=0;k<m;k++){ 41 if(!a[k].flag){ 42 int ecost=0;//當前循環加入該實驗所需要配置儀器的總費用 43 for(int j=0;j<a[k].num;j++){ 44 int now=a[k].a[j]; 45 if(euse[now]) 46 ecost+=0; //已經被收錄則無需費用 47 else{ 48 ecost+=fi[now]; 49 } 50 } 51 52 a[k].benfit=a[k].fi-ecost; //當前循環加入該實驗的收益 53 54 if(a[k].num==0) {max=a[k].benfit;maxp=k; break;} 55 else 56 if(a[k].benfit==0){max=a[k].benfit;maxp=k;} 57 else 58 if(a[maxp].benfit!=0&&max<a[k].benfit) {max=a[k].benfit;maxp=k;} 59 } 60 } 61 62 if(!a[maxp].flag){ 63 sum+=a[maxp].benfit; 64 a[maxp].flag=true; 65 66 for(int k=0;k<a[maxp].num;k++){ 67 int now=a[maxp].a[k]; 68 euse[now]=true; 69 } 70 71 } 72 73 74 75 76 } 77 78 79 80 System.out.println(sum); 81 82 } 83 84 85 } 86 class Sy 87 { 88 boolean flag=false; //是否被收錄 89 int fi=0; 90 int num=0; 91 int a[]; 92 int benfit=0; 93 public void init(){ 94 a=new int[num]; 95 } 96 }
南開AC:
1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #include<iostream> 5 #include<algorithm> 6 #define maxn 500 7 #define maxm 1000 8 #define inf 1000000000 9 using namespace std; 10 11 int gap[maxn],dis[maxn],pre[maxn],cur[maxn]; 12 int NV,n,m; 13 14 struct Edge { 15 int v,next,val; 16 Edge(){} 17 Edge( int V , int NEXT , int VAL ):v(V),next(NEXT),val(VAL){} 18 }edge[maxm]; 19 int cnt_edge,head[maxn]; 20 bool vis[maxn]; 21 22 void Insert_Edge( int u , int v , int flow = 0 ) { 23 //printf("%d->%d,%d\n",u,v,flow); 24 edge[cnt_edge] = Edge(v,head[u],flow); 25 head[u] = cnt_edge++; 26 edge[cnt_edge] = Edge(u,head[v],0); 27 head[v] = cnt_edge++; 28 } 29 30 void Init() { 31 cnt_edge = 0; 32 memset(head,-1,sizeof(int)*NV); 33 memset(vis,false,sizeof(vis)); 34 } 35 36 int Sap( int st , int en ) { 37 for( int i = 0 ; i < NV ; i++ ) { 38 dis[i] = gap[i] = 0; 39 cur[i] = head[i]; 40 } 41 int u = pre[st] = st, maxflow = 0,aug = inf; 42 gap[0] = NV; 43 while( dis[st] < NV ) { 44 loop: for( int &i = cur[u] ; i != -1 ; i = edge[i].next ) { 45 int v = edge[i].v; 46 if( edge[i].val && dis[u] == dis[v] + 1 ) { 47 aug = aug<edge[i].val?aug :edge[i].val; 48 pre[v] = u; 49 u = v; 50 if( v == en ) { 51 maxflow += aug; 52 for( u = pre[u] ; v != st ; v = u , u = pre[u] ) { 53 edge[ cur[u] ].val -= aug; 54 edge[ cur[u]^1 ].val += aug; 55 } 56 aug = inf; 57 } 58 goto loop; 59 } 60 } 61 int mindis = NV; 62 for( int i = head[u] ; i != -1 ; i = edge[i].next ) { 63 int v = edge[i].v; 64 if( edge[i].val && mindis > dis[v] ) { 65 cur[u] = i; 66 mindis = dis[v]; 67 } 68 } 69 if( --gap[dis[u]] == 0 ) break; 70 gap[ dis[u] = mindis + 1 ]++; 71 u = pre[u]; 72 } 73 return maxflow; 74 } 75 76 void Dfs( int u ) { 77 vis[u] = true; 78 //printf("u = %d\n",u); 79 int v; 80 for( int i = head[u] ; i != -1 ; i = edge[i].next ) { 81 //printf("i = %d\n",i); 82 v = edge[i].v; 83 //printf("v=%d\n",v); 84 if( !vis[v] && edge[i].val ) Dfs(v); 85 } 86 } 87 88 int main() { 89 while( scanf("%d%d",&m,&n) != EOF ) { 90 NV = n + m + 2; 91 Init(); 92 int st = 0; 93 int en = NV - 1; 94 int w,num,tp,sum = 0; 95 char cc; 96 for( int i = 1 ; i <= m ; i++ ) { 97 scanf("%d",&w); 98 sum += w; 99 Insert_Edge(st,i,w); 100 while(scanf("%d%c",&tp,&cc)) { 101 //printf("~%c~",cc); 102 Insert_Edge(i,tp+m,inf); 103 if( cc == '\n' ) break; 104 } 105 } 106 for( int i = 1 ; i <= n ; i++ ) { 107 scanf("%d",&tp); 108 Insert_Edge(i+m,en,tp); 109 } 110 //for( int i = head[0] ; i != -1 ; i = edge[i].next ) { 111 // printf("i = %d\n",i); 112 // printf("v=%d\n",edge[i].v); 113 //} 114 int res = sum - Sap(st,en); 115 Dfs(st); 116 int id; 117 for( id = 1 ; id <= m ; id++ ) { 118 if( vis[id] ) { 119 printf("%d",id); 120 break; 121 } 122 } 123 for( id++ ; id <= m ; id++ ) { 124 if( vis[id] ) printf(" %d",id); 125 } 126 puts(""); 127 for( id = 1 ; id <= n ; id++ ) { 128 if( vis[id+m] ) { 129 printf("%d",id); 130 break; 131 } 132 } 133 for( id++ ; id <= n ; id++ ) { 134 if( vis[id+m] ) printf(" %d",id); 135 } 136 puts(""); 137 138 printf("%d\n",res); 139 } 140 return 0; 141 }
南陽的系統有問題,第三題所有的都沒有結果。但是在南開就AC了。。
后面三道題在做其中一道時候,已經沒有時間了,都讀完了題目,分析了一下,郁悶。。才進入狀態就。。評測系統就關閉了。。。
flip這道題是原題。。
hotel這道題用數組應該比較好過的。
比賽結束復制了一下全部比賽提交AC結果:
Problem A 不吉利的數字 35 % (22/62) Problem B 數棋盤 44 % (4/9) Problem C 太空飛行計划 0 % (0/28) Problem D flip 76 % (16/21) Problem E move 21 % (3/14) Problem F K steps 0 % (0/2) Problem G hotel 0 % (0/0) 感覺這次還是蠻有意思的,可能是熱身賽吧,感覺容易題還是蠻容易的。。flip
時間限制: 1000 ms | 內存限制: 65535 KB- 描述
-
Give you a non-negative integer x and an operation. The only operation you can do is to reverse one bit in binary form of xonce(i.e 1->0, 0->1).your goal is to turn x into x+1.Calculate the minimum times of operations you need to do.
- 輸入
-
The first line of the input is an integer T indicates the test cases.
Then follow T lines. Each line is a non-negative integer x as described above, note that 0<=x<10^9. - 輸出
- Output the minimum times of operations you need to do to reach the goal.
- 樣例輸入
-
3 1 2 3
- 樣例輸出
-
2 1 3
題目翻譯:flip
時間限制:1000 ms | 內存限制:65535 KB
描述
給你一個非負的正整數x和一種操作。你只能做將二進制格式的x的某一位反轉這樣一個操作。
一次(例如1->0,0->1)
你的目的是 返回令x變成x+1
計算達到目標最小的操作次數。輸入
第一行輸入是一個正整數T代表測試的數據組數。
隨后的T行,每一行是一個從上描述的非負正整數x,注意0<=x<10^9.
輸出
輸入達到目標最小的操作次數
樣例輸入
3
1
2
3
樣例輸出
2
1
3
【朋友的代碼】我們是單獨分開做的,我在寢室,他在實驗室,他做出來兩道,時間和我差不多,他的代碼:1 #include<iostream> 2 3 using namespace std; 4 5 int main() 6 { 7 int t; 8 cin>>t; 9 while(t--) 10 { 11 int n,i=0,j=0,a[32],b[32],sum,k=0,g; 12 cin>>n; 13 sum=n+1; 14 while(true) 15 { 16 if(n==1) 17 { 18 a[i]=1; 19 i++; 20 break; 21 } 22 else 23 { 24 a[i]=n%2; 25 n=n/2; 26 i++; 27 } 28 } 29 while(true) 30 { 31 if(sum==1) 32 { 33 b[j]=1; 34 j++; 35 break; 36 } 37 else 38 { 39 b[j]=sum%2; 40 sum=sum/2; 41 j++; 42 } 43 } 44 if(i==j) 45 { 46 for(g=0;g<i;g++) 47 { 48 if(a[g]!=b[g]) 49 { 50 k++; 51 } 52 } 53 } 54 else 55 { 56 for(g=0;g<i;g++) 57 { 58 if(a[g]!=b[g]) 59 { 60 k++; 61 } 62 } 63 k++; 64 } 65 cout<<k<<endl; 66 } 67 }
move
時間限制: 10000 ms | 內存限制: 65535 KB- 描述
-
Do you ever become frustrated with television because you keep seeing the same things, recycled over and over again? Well I personally don't care about television, but I do sometimes feel that way about numbers.
Let's say a pair of distinct positive integers (n, m) is recycled if you can obtain m by moving some digits from the back of n to the front without changing their order. For example, (12345, 34512) is a recycled pair since you can obtain 34512 by moving 345 from the end of 12345 to the front. Note that n and m must have the same number of digits in order to be a recycled pair. Neither n nor m can have leading zeros.
Given integers A and B with the same number of digits and no leading zeros, how many distinct recycled pairs (n, m) are there with A ≤ n < m ≤ B?
- 輸入
- The first line of the input gives the number of test cases, T(1 ≤ T ≤ 50.). T test cases follow. Each test case consists of a single line containing the integers A and B.(1 ≤ A ≤ B ≤ 2000000)
- 輸出
- For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1), and y is the number of recycled pairs (n, m) with A ≤ n < m ≤ B.
- 樣例輸入
-
4 1 9 10 40 100 500 1111 2222
- 樣例輸出
-
Case #1: 0 Case #2: 3 Case #3: 156 Case #4: 287
題目翻譯:
move
時間限制:10000 ms | 內存限制:65535 KB
描述
你曾今是否為電視節目的反復出現總是看到同樣的東西而感到沮喪?當然我個人並不關心電視,而是關心與其具有同樣性質的數字。讓我們來說一說以相互不同的正整數組成的一對(n,m)“往復數”,如果一對數(n,m),其中你能夠通過移動n的后面幾位數字到它的前面得到m,則我們稱這對數為“往復數”。舉例來說,由於可以通過移動12345的345到12的前面來得到34512, (12345, 34512) 就是一對“往復數”。值得注意的是,n和m必須是同樣位數的數才可以成為“往復數”。n和m都不能以0開頭。
給你一對具有相同位數並且都不以0開頭的整數A和B,你能夠找到多少個互不相同的“往復數”組合(n,m),且它們都滿足A ≤ n < m ≤ B?
輸入
第一行是測試數據的組數T。T(1 ≤ T ≤ 50.)
隨后T行測試數據,每一行是一組測試數據,包含正整數A和B(1 ≤ A ≤ B ≤ 2000000)
輸出
對於每一組測試數據,輸出一行包含"Case #x: y",x代表為第幾組測試數據(從1開始),y是計算出的滿足A ≤ n < m ≤ B的“往復數”對數。 (一個(n,m)算一對)
K steps時間限制: 2000 ms | 內存限制: 65535 KB- 描述
-
Here are n beautiful towns and m roads(directional edge). yjx wants to visit these towns for relaxation when he suddenlygot a question. He wants to know the number of schemes to walk from town A to town B in exactly k steps.A road can bevisited more then once. It takes exactly one step to walk from one town to another if they are directly connected by a road.yjx is very entangled with this matter, please help him.
- 輸入
-
First line is a number T, the number of the cases.
Each case is as follows:
First line includes four number: n, m, k, l which means n(1 <= n <= 100)towns, m(1 <= m<=1000)roads, k(1<=k<=1000)steps,
and l (1<=l<=1000) lines test data.
Then there are m lines, and each line is made up of two number u, v (u != v, 1<= u,v <= n) which means one road from u to v.
Then l lines test data, and each line is made up of two number p, q (so you must help yjx to know the number of the scheme that just walk k steps from town p to town q).
hint: maybe there are more than one road from u to v . - 輸出
- For each test data, output the number of the scheme(the number is big, so you must make the number mod 1991).
- 樣例輸入
-
2 2 2 1 2 1 2 2 1 1 2 2 1 3 2 2 1 1 2 2 3 1 3
- 樣例輸出
-
1 1 1
題目翻譯:K steps
時間限制:2000 ms | 內存限制:65535 KB
描述
這里有n個漂亮的城鎮和m條道路(直接相連),yjx想要在這幾個城鎮之間游玩,但是他突然遇到一個問題。他想知道使用K步從城鎮A到城鎮B一共有幾種走法。一條路能夠被走多次,並且從一個城鎮到達另一個城鎮(如果他們之間是被路直接相連的)只需要一步即到。
yjx對這個問題非常抓狂,所以請求你幫助。
輸入
第一行是T,代表測試數據的組數。
每一組測試用例:第一行包括四個數字 n, m, k, l ,它們分別代表n(1 <= n <= 100)城鎮,m(1 <= m<=1000)道路, k(1<=k<=1000)步,l (1<=l<=1000) 行測試數據。
隨后的m行,每一行是由 u, v (u != v, 1<= u,v <= n) 兩個數構成的,代表一條從u到v的路
隨后的l行測試數據,每一行由p, q兩個數組成,這是yjx想知道從p城鎮到q城鎮走k步的不同走法數。提示:從u到v可能有大於1條道路。
輸出
對於每組測試數據,輸出總的方案數(這個數是非常大的,所以你必須使這個數mod1991再輸出)
樣例輸入
2
2 2 1 2
1 2
2 1
1 2
2 1
3 2 2 1
1 2
2 3
1 3
樣例輸出
1
1
1
hotel
時間限制: 1000 ms | 內存限制: 65535 KB- 描述
-
The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and enjoy a vacation on the sunny shores of Lake Superior. Bessie, ever the competent travel agent, has named the Bullmoose Hotel on famed Cumberland Street as their vacation residence. This immense hotel has N (1 ≤ N ≤ 50,000) rooms all located on the same side of an extremely long hallway (all the better to see the lake, of course).
The cows and other visitors arrive in groups of size Di (1 ≤ Di ≤ N) and approach the front desk to check in. Each group i requests a set of Di contiguous rooms from Canmuu, the moose staffing the counter. He assigns them some set of consecutive room numbers r..r+Di-1 if they are available or, if no contiguous set of rooms is available, politely suggests alternate lodging. Canmuu always chooses the value of r to be the smallest possible.
Visitors also depart the hotel from groups of contiguous rooms. Checkout i has the parameters Xi and Di which specify the vacating of rooms Xi ..Xi +Di-1 (1 ≤ Xi≤ N-Di+1). Some (or all) of those rooms might be empty before the checkout.
Your job is to assist Canmuu by processing M (1 ≤ M < 50,000) checkin/checkout requests. The hotel is initially unoccupied.
- 輸入
-
* Line 1: Two space-separated integers: N and M
* Lines 2..M+1: Line i+1 contains request expressed as one of two possible formats: (a) Two space separated integers representing a check-in request: 1 and Di (b) Three space-separated integers representing a check-out: 2, Xi, and Di - 輸出
- * Lines 1.....: For each check-in request, output a single line with a single integer r, the first room in the contiguous sequence of rooms to be occupied. If the request cannot be satisfied, output 0.
- 樣例輸入
-
10 6 1 3 1 3 1 3 1 3 2 5 5 1 6
- 樣例輸出
-
1 4 7 0 5
題目翻譯:hotel
時間限制:1000 ms | 內存限制:65535 KB
描述
cows一路向北到的加拿大Thunder Bay來豐富自己的文化和享受陽光海岸度假。Bessie曾建是一家旅行社的主管,現在被任命為著名的位於Cumberland 街道的Bullmoose 酒店的總管。這間巨大的酒店擁有N (1 ≤ N ≤ 50,000) 個房間,房間都位於湖的同一側的(當然這些房間都能夠很好的欣賞湖的美景)。cows和其他的參觀者以Di (1 ≤ Di ≤ N)個人這樣的群體到達,並且到前台來登記入住,每第i一群人請求Canmuu(酒店員工)分配Di數目的連續的房間給他們這群人入住。如果空房間數允許,Canmuu將分配 r..r+Di-1給這群人,如果沒有他們請求的號碼的連續的房間,則建議他們選擇候選的由酒店分配的號碼,Canmuu 總是選擇最小的r來分配給客戶。
旅游者同樣也按照連續的方式進行入住。第i群人登出(住完走人)參數 Xi和Di代表房間Xi ..Xi +Di-1 (1 ≤ Xi≤ N-Di+1)不住了。在他們到台前辦理登出之前,這些房間中的一些(或者所有)也許是空的。
你的工作就是幫助Canmuu 處理M (1 ≤ M < 50,000) 的入住/登出請求,酒店初始是空的。
輸入
第一行:兩個以空格分開的整數:N和M
第二行到第M+1行:第i+1行包含兩種可能的請求格式:(a) 兩個以空格分開的整數 1 and Di代表入住請求 (b)三個以空格分開的整數代表一個登出請求:2, Xi, and Di
輸出
對於每一個入住請求輸出一行,這一行包含一個整數r,r代表連續入住房間的第一個房間號。如果請求不能夠滿足,輸出0樣例輸入
10 6
1 3
1 3
1 3
1 3
2 5 5
1 6
樣例輸出
1