女人被狂躁到高潮视频免费无遮挡,内射人妻骚骚骚,免费人成小说在线观看网站,九九影院午夜理论片少妇,免费av永久免费网址

當(dāng)前位置:首頁(yè) > > 充電吧
[導(dǎo)讀]題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=5071 題面: Chat Time Limit: 2000/1000 MS (Java/Others

題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=5071


題面:

Chat Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 2195????Accepted Submission(s): 465


Problem Description As everyone knows, DRD has no girlfriends. But as everyone also knows, DRD’s friend ATM’s friend CLJ has many potential girlfriends. One evidence is CLJ’s chatting record.


CLJ chats with many girls all the time. Sometimes he begins a new conversation and sometimes he ends a conversation. Sometimes he chats with the girl whose window is on the top.

You can imagine CLJ’s windows as a queue. The first girl in the queue is the top girl if no one is “always on top ”.

Since CLJ is so popular, he begins to assign a unique positive integer as priority for every girl. The higher priority a girl has, the more CLJ likes her. For example, GYZ has priority 109, and JZP has priority 108 while Sister Soup has priority 1, and Face Face has priority 2.

As a famous programmer, CLJ leads a group to implement his own WM(window manager). The WM will log CLJ’s operations. Now you are supposed to implement the log system. The general logging format is “Operation #X: LOGMSG.”, where X is the number of the operation and LOGMSG is the logging message.

There are several kinds of operations CLJ may use:

1.Add u: CLJ opens a new window whose priority is u, and the new window will be the last window in the window queue. This operation will always be successful except the only case in which there is already a window with priority u. If it is successful, LOGMSG will be “success”. Otherwise LOGMSG will be “same priority”.

2.Close u: CLJ closes a window whose priority is u. If there exists such a window, the operation will be successful and LOGMSG will be “close u with c”, where u is the priority and c is the number of words CLJ has spoken to this window. Otherwise, LOGMSG will be “invalid priority”. Note that ANY window can be closed.

3.Chat w: CLJ chats with the top window, and he speaks w words. The top window is the first window in the queue, or the “always on top” window (as described below) instead if there exists. If no window is in the queue, LOGMSG will be “empty”, otherwise the operation can be successful and LOGMSG will be “success”.

4.Rotate x: CLJ performs one or more Alt-Tabs to move the x-th window to the first one in the queue. For example, if there are 4 windows in the queue, whose priorities are 1, 3, 5, 7 respectively and CLJ performs “Rotate 3”, then the window’s priorities in the queue will become 5, 1, 3, 7. Note that if CLJ wants to move the first window to the head, this operation is still considered “successful”. If x is out of range (smaller than 1 or larger than the size of the queue), LOGMSG will be “out of range”. Otherwise LOGMSG should be “success”.

5.Prior: CLJ finds out the girl with the maximum priority and then moves the window to the head of the queue. Note that if the girl with the maximum priority is already the first window, this operation is considered successful as well. If the window queue is empty, this operation will fail and LOGMSG must be “empty”. If it is successful, LOGMSG must be “success”.

6.Choose u: CLJ chooses the girl with priority u and moves the window to the head of the queue.This operation is considered successful if and only if the window with priority u exists. LOGMSG for the successful cases should be “success” and for the other cases should be “invalid priority”.

7.Top u: CLJ makes the window of the girl with priority u always on top. Always on top is a special state, which means whoever the first girl in the queue is, the top one must be u if u is always on top. As you can see, two girls cannot be always on top at the same time, so if one girl is always on top while CLJ wants another always on top, the first will be not always on top any more, except the two girls are the same one. Anyone can be always on top. LOGMSG is the same as that of the Choose operation.

8.Untop: CLJ cancels the “always on top” state of the girl who is always on top. That is, the girl who is always on top now is not in this special state any more. This operation will fail unless there is one girl always on top. If it fails, LOGMSG should be “no such person”, otherwise should be “success”.

As a gentleman, CLJ will say goodbye to every active window he has ever spoken to at last, “active” here means the window has not been closed so far. The logging format is “Bye u: c” where u is the priority and c is the number of words he has ever spoken to this window. He will always say good bye to the current top girl if he has spoken to her before he closes it. ?
Input The first line contains an integer T (T ≤ 10), denoting the number of the test cases.

For each test case, the first line contains an integer n(0 < n ≤ 5000), representing the number of operations. Then follow n operations, one in a line. All the parameters are positive integers below 109. ?
Output Output all the logging contents. ?
Sample Input
1
18
Prior
Add 1
Chat 1
Add 2
Chat 2
Top 2
Chat 3
Untop
Chat 4
Choose 2
Chat 5
Rotate 2
Chat 4
Close 2
Add 3
Prior
Chat 2
Close 1

?

Sample Output
Operation #1: empty.
Operation #2: success.
Operation #3: success.
Operation #4: success.
Operation #5: success.
Operation #6: success.
Operation #7: success.
Operation #8: success.
Operation #9: success.
Operation #10: success.
Operation #11: success.
Operation #12: success.
Operation #13: success.
Operation #14: close 2 with 8.
Operation #15: success.
Operation #16: success.
Operation #17: success.
Operation #18: close 1 with 11.
Bye 3: 2

HintThis problem description does not relate to any real person in THU. 

?

Source 2014 Asia AnShan Regional Contest


解題:

??? 之前一直覺得很煩,沒(méi)敢寫,沒(méi)想到居然能1A,還是比較驚喜的!

??? 對(duì)應(yīng)8種操作,我采用的數(shù)據(jù)結(jié)構(gòu)是兩個(gè)map。第一個(gè)map為<(int)pos,(node)n>,其中pos為位置,n為節(jié)點(diǎn),節(jié)點(diǎn)中包含兩個(gè)值u(優(yōu)先級(jí)權(quán)值),w(單詞數(shù)量)。第二個(gè)map為<(int)u,(int)pos>其中u為優(yōu)先級(jí)權(quán)值,pos為位置,topp存儲(chǔ)的是被top的那個(gè)對(duì)象的優(yōu)先級(jí),如果為-1,則說(shuō)明,沒(méi)有對(duì)象處在top狀態(tài),sz為當(dāng)前節(jié)點(diǎn)數(shù)量。topp和sz都需要時(shí)時(shí)更新。

??? 1.添加操作,先看是否已經(jīng)存在(map.count判斷),若沒(méi)有,則添加,否則顯示錯(cuò)誤信息。

??? 2.關(guān)閉操作,看是否存在,若不存在,顯示錯(cuò)誤信息,否則刪除當(dāng)前節(jié)點(diǎn),并將后面的往上順移一位。

??? 3.聊天操作,看sz是否為0,若為0,則顯示錯(cuò)誤信息。若不為0,則看topp是否為-1,若不為-1,則通過(guò)map2找到對(duì)應(yīng)位置,更新map1中的值,若為-1,則更新位置為1的map1中的值。

??? 4.置頂操作,首先判斷是否越界,不越界則將該位置提到首位即可,其實(shí)應(yīng)該寫成函數(shù)供下面功能使用,不過(guò)好在代碼都是差不多的,拷貝下就好了。

??? 5.優(yōu)先級(jí)置頂,循環(huán)遍歷,然后將該位置置頂,與上同。

??? 6.通過(guò)map2找到對(duì)應(yīng)位置,并置頂。

??? 7.將topp值改成此時(shí)的u值。

??? 8.將topp還原為-1。

??? 最后要注意還要輸出和剩下的沒(méi)關(guān)閉的窗口聊天的數(shù)量,若為0,則不需輸出,同時(shí)要將優(yōu)先級(jí)最高的先輸出。

坑點(diǎn):

??? 1.topp值和sz值需時(shí)時(shí)維護(hù)。

??? 2.數(shù)量應(yīng)用long long保存。

??? 3.輸出答案時(shí),最后是有'.'的。

??? 4.最后輸出窗口要先輸出處于top狀態(tài)的,沒(méi)有就按順序即可。


代碼:

#include 
#include 
#include 
#include 
#define LL long long 
using namespace std;
struct node
{
   node (int x,LL y)
   {
	   u=x;
	   w=y;
   }
   node ()
   {
	   u=0;
	   w=0;
   }
   node (const node &xx)
   {
	   u=xx.u;
	   w=xx.w;
   }
   //u優(yōu)先級(jí)權(quán)值,w數(shù)量
   int u;
   LL w;
};
map  store;
map  refl;
int main()
{
    int t,n,val,sz,pos,topp,uu,maxn;
	LL amt,ww;
	char oper[10];
	scanf("%d",&t);
	node tmp;
	for(int i=1;i<=t;i++)
	{
		store.clear();
		refl.clear();
		sz=0;
		topp=-1;
		scanf("%d",&n);
		for(int j=1;j<=n;j++)
		{
			printf("Operation #%d: ",j);
			getchar();
			scanf("%s",oper);
			//加操作
			if(oper[0]=='A')
			{
				scanf("%d",&val);
                if(!refl.count(val))
				{
					printf("success.n");
                    tmp.w=0;
					tmp.u=val;
                    pos=++sz;
                    refl[val]=pos;
					store[pos]=tmp;
				}
				else
				printf("same priority.n");
			}
			//關(guān)閉操作
			else if(oper[0]=='C'&&oper[1]=='l')
			{
				scanf("%d",&val);
				if(!refl.count(val))
				  printf("invalid priority.n");
				else
				{
                  if(val==topp)
					  topp=-1;
                  pos=refl[val];
				  amt=store[pos].w;
                  refl.erase(val);
				  for(int k=pos+1;k<=sz;k++)
				  {
					  uu=store[k].u;
					  store[k-1].u=store[k].u;
					  store[k-1].w=store[k].w;
					  refl[uu]=k-1;
				  }
				  store.erase(sz);
				  sz--;
                  printf("close %d with %d.n",val,amt);
				}
			}
			//聊天功能
			else if(oper[0]=='C'&&oper[2]=='a')
			{
				scanf("%d",&val);
				if(sz==0)
					printf("empty.n");
				else
				{
					printf("success.n");
					if(topp==-1)
						store[1].w+=val;
					else
					{
						pos=refl[topp];
						store[pos].w+=val;
					}
				}
			}
			//置頂操作
			else if(oper[0]=='R')
			{
				scanf("%d",&val);
				if(val<1||val>sz)
					printf("out of range.n");
				else
				{
				   printf("success.n");
                   uu=store[val].u;
				   ww=store[val].w;
				   for(int k=val-1;k>=1;k--)
				   {
                     store[k+1].u=store[k].u;
					 store[k+1].w=store[k].w;
					 refl[store[k+1].u]=k+1;
				   }
				   store[1].u=uu;
				   store[1].w=ww;
				   refl[uu]=1;
				}
			}
			//優(yōu)先級(jí)置頂
			else if(oper[0]=='P')
			{
               if(sz==0)
				   printf("empty.n");
			   else
			   {
				   printf("success.n");
				   maxn=0;
				   for(int k=1;k<=sz;k++)
				   {
					   if(store[k].u>maxn)
						   maxn=store[k].u;
				   }
				   val=refl[maxn];
				   uu=store[val].u;
				   ww=store[val].w;
				   for(int k=val-1;k>=1;k--)
				   {
                     store[k+1].u=store[k].u;
					 store[k+1].w=store[k].w;
					 refl[store[k+1].u]=k+1;
				   }
				   store[1].u=uu;
				   store[1].w=ww;
				   refl[uu]=1;
			   }
			}
			//選擇置頂
			else if(oper[0]=='C')
			{
				scanf("%d",&val);
				if(!refl.count(val))
			      printf("invalid priority.n");
				else
				{
					printf("success.n");
					val=refl[val];
 				    uu=store[val].u;
				    ww=store[val].w;
				    for(int k=val-1;k>=1;k--)
				    {
                      store[k+1].u=store[k].u;
					  store[k+1].w=store[k].w;
					  refl[store[k+1].u]=k+1;
				    }
				    store[1].u=uu;
				    store[1].w=ww;
				    refl[uu]=1;
				}
			}
			//top操作
			else if(oper[0]=='T')
			{
				scanf("%d",&val);
				if(!refl.count(val))
                  printf("invalid priority.n");
				else
				{
					printf("success.n");
					topp=val;
				}
			}
			//untop操作
			else if(oper[0]=='U')
			{
                if(topp==-1)
					printf("no such person.n");
				else
				{
					printf("success.n");
					topp=-1;
				}
			}
		}
		//特殊優(yōu)先級(jí)優(yōu)先
		if(topp!=-1&&store[refl[topp]].w)
			printf("Bye %d: %I64dn",topp,store[refl[topp]].w);
		for(int i=1;i<=sz;i++)
		{
			//優(yōu)先級(jí)只需輸出一次
			if(store[i].u!=topp&&store[i].w>0)
				printf("Bye %d: %I64dn",store[i].u,store[i].w);
		}
	}
	return 0;
}


本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除。
換一批
延伸閱讀

LED驅(qū)動(dòng)電源的輸入包括高壓工頻交流(即市電)、低壓直流、高壓直流、低壓高頻交流(如電子變壓器的輸出)等。

關(guān)鍵字: 驅(qū)動(dòng)電源

在工業(yè)自動(dòng)化蓬勃發(fā)展的當(dāng)下,工業(yè)電機(jī)作為核心動(dòng)力設(shè)備,其驅(qū)動(dòng)電源的性能直接關(guān)系到整個(gè)系統(tǒng)的穩(wěn)定性和可靠性。其中,反電動(dòng)勢(shì)抑制與過(guò)流保護(hù)是驅(qū)動(dòng)電源設(shè)計(jì)中至關(guān)重要的兩個(gè)環(huán)節(jié),集成化方案的設(shè)計(jì)成為提升電機(jī)驅(qū)動(dòng)性能的關(guān)鍵。

關(guān)鍵字: 工業(yè)電機(jī) 驅(qū)動(dòng)電源

LED 驅(qū)動(dòng)電源作為 LED 照明系統(tǒng)的 “心臟”,其穩(wěn)定性直接決定了整個(gè)照明設(shè)備的使用壽命。然而,在實(shí)際應(yīng)用中,LED 驅(qū)動(dòng)電源易損壞的問(wèn)題卻十分常見,不僅增加了維護(hù)成本,還影響了用戶體驗(yàn)。要解決這一問(wèn)題,需從設(shè)計(jì)、生...

關(guān)鍵字: 驅(qū)動(dòng)電源 照明系統(tǒng) 散熱

根據(jù)LED驅(qū)動(dòng)電源的公式,電感內(nèi)電流波動(dòng)大小和電感值成反比,輸出紋波和輸出電容值成反比。所以加大電感值和輸出電容值可以減小紋波。

關(guān)鍵字: LED 設(shè)計(jì) 驅(qū)動(dòng)電源

電動(dòng)汽車(EV)作為新能源汽車的重要代表,正逐漸成為全球汽車產(chǎn)業(yè)的重要發(fā)展方向。電動(dòng)汽車的核心技術(shù)之一是電機(jī)驅(qū)動(dòng)控制系統(tǒng),而絕緣柵雙極型晶體管(IGBT)作為電機(jī)驅(qū)動(dòng)系統(tǒng)中的關(guān)鍵元件,其性能直接影響到電動(dòng)汽車的動(dòng)力性能和...

關(guān)鍵字: 電動(dòng)汽車 新能源 驅(qū)動(dòng)電源

在現(xiàn)代城市建設(shè)中,街道及停車場(chǎng)照明作為基礎(chǔ)設(shè)施的重要組成部分,其質(zhì)量和效率直接關(guān)系到城市的公共安全、居民生活質(zhì)量和能源利用效率。隨著科技的進(jìn)步,高亮度白光發(fā)光二極管(LED)因其獨(dú)特的優(yōu)勢(shì)逐漸取代傳統(tǒng)光源,成為大功率區(qū)域...

關(guān)鍵字: 發(fā)光二極管 驅(qū)動(dòng)電源 LED

LED通用照明設(shè)計(jì)工程師會(huì)遇到許多挑戰(zhàn),如功率密度、功率因數(shù)校正(PFC)、空間受限和可靠性等。

關(guān)鍵字: LED 驅(qū)動(dòng)電源 功率因數(shù)校正

在LED照明技術(shù)日益普及的今天,LED驅(qū)動(dòng)電源的電磁干擾(EMI)問(wèn)題成為了一個(gè)不可忽視的挑戰(zhàn)。電磁干擾不僅會(huì)影響LED燈具的正常工作,還可能對(duì)周圍電子設(shè)備造成不利影響,甚至引發(fā)系統(tǒng)故障。因此,采取有效的硬件措施來(lái)解決L...

關(guān)鍵字: LED照明技術(shù) 電磁干擾 驅(qū)動(dòng)電源

開關(guān)電源具有效率高的特性,而且開關(guān)電源的變壓器體積比串聯(lián)穩(wěn)壓型電源的要小得多,電源電路比較整潔,整機(jī)重量也有所下降,所以,現(xiàn)在的LED驅(qū)動(dòng)電源

關(guān)鍵字: LED 驅(qū)動(dòng)電源 開關(guān)電源

LED驅(qū)動(dòng)電源是把電源供應(yīng)轉(zhuǎn)換為特定的電壓電流以驅(qū)動(dòng)LED發(fā)光的電壓轉(zhuǎn)換器,通常情況下:LED驅(qū)動(dòng)電源的輸入包括高壓工頻交流(即市電)、低壓直流、高壓直流、低壓高頻交流(如電子變壓器的輸出)等。

關(guān)鍵字: LED 隧道燈 驅(qū)動(dòng)電源
關(guān)閉