1. 程式人生 > >pat1026 Table Tennis

pat1026 Table Tennis

1.當有多個乒乓球檯空閒時,vip顧客到了會使用最小id的vip球檯,而不是最小id的球檯,測試以下用例:

2
10:00:00 30 1
12:00:00 30 1
5 1
3

輸出正確結果應為:
10:00:00 10:00:00 0
12:00:00 12:00:00 0
0 0 2 0 0
2.題目要求每對顧客玩的時間不超過2小時,那麼當顧客要求玩的時間>2小時的時候,應該截斷控制,測試以下用例:
2
18:00:00 180 1
20:00:00 60 1
1 1
1
輸出的正確結果應為:
18:00:00 18:00:00 0
20:00:00 20:00:00 0
2
3.雖然題目中保證客戶到達時間在08:00:00到21:00:00之間,但是根據最後的8個case來看,裡面還是有不在這個時間區間內到達的顧客,所以建議還是稍加控制,測試以下用例:
1
21:00:00 80 1
1 1
1
輸出的正確結果應為:
0
4.題目中說的round up to an integer minutes是嚴格的四捨五入,需要如下做:
wtime = (stime - atime + 30) / 60
而不是:
wtime = (stime - atime + 59) / 60
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstring>
#include<cmath>
using namespace std;
struct node
{
	int arr,l,f;
}p[10005];
struct result
{
	int t1,t2,wait;
}res[10005];
vector<node>v[2];
int ok[105],vip[105],serve[105];
int n,m,k;
const bool cmp(const node &x,const node &y)
{
	return x.arr<y.arr;
}
const bool cmp1(const result &x,const result &y)
{
	return x.t2<y.t2;
}
int find(int tm,int f)
{
	int ret = 1000000,ans = 0;
	for(int i = 1;i<=m;i++)
	{
	    if(f&&!vip[i])continue;
		if(ok[i]<tm)
		{
			    ans = i;
                break;
		}
		else if(ok[i]<ret)
		{
			ans = i;
			ret = ok[i];
		}
	}
	return ans;
}
int main()
{
    int i,j,a,b,c,num;
	while(scanf("%d",&n)!=EOF)
	{
		num = 0;
		memset(serve,0,sizeof(serve));
		for(i = 0;i<n;i++)
		{
			scanf("%d:%d:%d %d %d",&a,&b,&c,&p[i].l,&p[i].f);
			p[i].arr = a*60*60+b*60+c;
			if(p[i].f)v[1].push_back(p[i]);
			else v[0].push_back(p[i]);
		}
		p[n].arr = p[n+1].arr = 1e8;
		v[0].push_back(p[n]);
		v[1].push_back(p[n+1]);
        sort(v[0].begin(),v[0].end(),cmp);
		sort(v[1].begin(),v[1].end(),cmp);
		scanf("%d%d",&m,&k);
		for(i = 1;i<=m;i++)ok[i] = 8*60*60;
		for(i = 1;i<=k;i++)
		{
			scanf("%d",&a);
			vip[a] = 1;
		}
		i = j = 0;
		while(1)
		{
			int tm1 = v[0][i].arr,tm2 = v[1][j].arr;
			int id = find(min(tm1,tm2),0),who;
			int vip_table = find(tm2,1);
			if(ok[id]>=21*60*60||min(tm1,tm2)>=21*60*60)break;
			if(!vip[id])who = v[0][i].arr<v[1][j].arr?0:1;
			else who = v[1][j].arr<max(ok[id],v[0][i].arr)?1:0;
			int pos = who == 0?i:j;
			if(who == 1&&vip_table&&ok[vip_table]<=v[1][pos].arr)id = vip_table;
			res[num].t1 = v[who][pos].arr;
			res[num].t2 = max(ok[id],v[who][pos].arr);
			res[num].wait = res[num].t2-res[num].t1;
			ok[id] = res[num].t2+min(v[who][pos].l,120)*60;
			serve[id]++;
			if(who == 0)i++;
			else j++;
			num++;
		}
		sort(res,res+num,cmp1);
		for(i = 0;i<num;i++)printf("%02d:%02d:%02d %02d:%02d:%02d %d\n",res[i].t1/3600,res[i].t1%3600/60,res[i].t1%60,res[i].t2/3600,res[i].t2%3600/60,res[i].t2%60,(res[i].wait+30)/60);
		for(i = 1;i<m;i++)printf("%d ",serve[i]);
		printf("%d\n",serve[m]);
	}
    return 0;
}


相關推薦

pat1026 Table Tennis

1.當有多個乒乓球檯空閒時,vip顧客到了會使用最小id的vip球檯,而不是最小id的球檯,測試以下用例:2 10:00:00 30 1 12:00:00 30 1 5 1 3 輸出正確結果應為: 10:00:00 10:00:00 0 12:00:00 12:00:00

Pat(Advanced Level)Practice--1026(Table Tennis)

ros turn card 沒有 use gb2312 [] ng- undefined Pat1026代碼 題目描寫敘述: A table tennis club has N tables available to the public. The

@@443 B. Table Tennis

layers -s clip oar inpu tinc ren for each n people are standing in a line to play table tennis. At first, the first two players in the

PAT 1026 Table Tennis[比較難]

i++ amp min contains logical must first tdi color 1026 Table Tennis (30)(30 分) A table tennis club has N tables available to the publi

PAT 1026 Table Tennis

rst pat esp out his cal != output urn A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For

1026 Table Tennis (30 分)C++實現(已AC)

題目: 題目連結:https://pintia.cn/problem-sets/994805342720868352/problems 思路: 感覺我的思路比較清奇, 導致程式碼寫的比較長… 我的思路是: 建立一個客戶列表,時間按照秒儲存,按照到達時間排序; 桌子放入一個列表

1026 Table Tennis (30 分)模擬排列問題

題目 A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For any pair of players, if there are some t

PAT-ADVANCED1026——Table Tennis

題目描述: 題目翻譯: 1026 乒乓球桌 一個乒乓球俱樂部有N張乒乓球桌對外開放。乒乓球桌編號為1 ~ N。對任何一對運動員,如果他們到達時有空餘的乒乓球桌,他們會被分配到可用的編號最小的那張乒乓球桌。如果所有的桌子都被佔了,他們必須在佇列中等待。假設任何

1026 Table Tennis (PAT Advanced) 坑點

A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For any pair of players, if there are some tables open

PAT甲級 1026 Table Tennis(30 分)模擬,排序 ----------

1026 Table Tennis(30 分) A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For any pair of

PAT 1026. Table Tennis

第一篇blog : p 測試點4考察的是"It is assumed that every pair of players can play for at most 2 hours." 測試點8則是"The waiting time must be rounded up

1026. Table Tennis (30)

1.整體思路為:先遍歷vip桌子和vip玩家,如果有匹配成功的,進行匹配;然後再遍歷一輪所有的桌子和等候的玩家,有匹配的進行匹配; 2.被卡的地方: 1)關於秒的四捨五入,是按照大於等於30秒,進一分鐘,小於30秒則捨去的原則;最後的一個測試用例就是檢驗這個30秒的 2)在

PAT-1026 Table Tennis (30)

牛客網上過了,pat練題 18 分。所以關於題目大意和解題思路可能有些不對。。。吐槽下:這題坑好多,有多個方面的細節題目都沒說清。真心花了很多時間,但還是不知道自己哪錯了。。。#include <iostream> #include &

table tennis ╮(╯▽╰)╭

Problem Description There are N table tennis, and only one of them has quality problem which is lighter than a normal ball. Give you a

PAT 1026. Table Tennis (30)

題意:1.當前無vip使用者時,普通使用者按照空餘桌子的號碼依次就坐。2.當前有vip使用者,沒有空餘的vip桌子時,vip當做普通使用者進入佇列排序;                有空餘的vip桌子時,應該先就做vip座位; 基本演算法:類似於mergeSort的方法,

[CSS] Showing horizontal scrollbar always for the table

nbsp overflow tab spl spa horizon clas pre idt table { display: block; overflow: scroll; width: 200px; height:95vh;

依賴於angular的table組件

down 拖拽排序 ces onmouseup app 寬度調整 還需 記錄 ble 組件實現了以下功能 1. 列寬可動態拖動 2. 列數據排序 3. 列過濾 4. 列位置自由調整 除了需要引入angular.js(我用的是1.4.6版本),還需要引用一個angular衍生

selenium處理table表格

處理 輸入 table 所有 指定 固定 pat 你會 driver 在UI自動化測試中經常會遇到表格的處理,下面是一點心得。 假設網頁頁面有一個表格,如何獲取這個table的指定cell的值?你會說我們可以根據xpath定位到這個cell的行列,然後getText(),不

mysql錯誤【一】[ERROR] Missing system table mysql.proxies_priv

mysql錯誤 環境:mysql一主一從架構,主庫是mysql5.1,從庫是mysql5.6;系統均為CentOS6.2 問題: 在主庫上面執行的SQL語句 1.創建表 CREATE TABLE `app_versions` ( `date` date NO

修復mysql:[ERROR] Native table ‘performance_schema’

data- 驗證 eve nbsp mar usr rwlock wait 地址 轉: http://www.amznz.com/error-native-table-performance_schema/ mysql數據庫出現如下錯誤,主要是因為升級了mysql軟件包