HDOJ 5071 Chat 模擬
大模擬:
1》saygoodbye要先對 always on top 的人說
2》對沒有說過話的不要說good bye
3》用long long
Chat
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 337 Accepted Submission(s): 82
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 whZ喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vc2Ugd2luZG93IGlzIG9uIHRoZSB0b3AuPGJyPgo8YnI+CllvdSBjYW4gaW1hZ2luZSBDTEqhr3Mgd2luZG93cyBhcyBhIHF1ZXVlLiBUaGUgZmlyc3QgZ2lybCBpbiB0aGUgcXVldWUgaXMgdGhlIHRvcCBnaXJsIGlmIG5vIG9uZSBpcyChsGFsd2F5cyBvbiB0b3AgobEuPGJyPgo8YnI+ClNpbmNlIENMSiBpcyBzbyBwb3B1bGFyLCBoZSBiZWdpbnMgdG8gYXNzaWduIGEgdW5pcXVlIHBvc2l0aXZlIGludGVnZXIgYXMgcHJpb3JpdHkgZm9yIGV2ZXJ5IGdpcmwuIFRoZSBoaWdoZXIgcHJpb3JpdHkgYSBnaXJsIGhhcywgdGhlIG1vcmUgQ0xKIGxpa2VzIGhlci4gRm9yIGV4YW1wbGUsIEdZWiBoYXMgcHJpb3JpdHkgMTA8c3VwPjk8L3N1cD4sIGFuZCBKWlAgaGFzIHByaW9yaXR5IDEwPHN1cD44PC9zdXA+IHdoaWxlIFNpc3RlciBTb3VwIGhhcwogcHJpb3JpdHkgMSwgYW5kIEZhY2UgRmFjZSBoYXMgcHJpb3JpdHkgMi48YnI+Cjxicj4KQXMgYSBmYW1vdXMgcHJvZ3JhbW1lciwgQ0xKIGxlYWRzIGEgZ3JvdXAgdG8gaW1wbGVtZW50IGhpcyBvd24gV00od2luZG93IG1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bnRlZ2VyIFQgKFQgodwgMTApLCBkZW5vdGluZyB0aGUgbnVtYmVyIG9mIHRoZSB0ZXN0IGNhc2VzLjxicj4KPGJyPgpGb3IgZWFjaCB0ZXN0IGNhc2UsIHRoZSBmaXJzdCBsaW5lIGNvbnRhaW5zIGFuIGludGVnZXIgbigwIDwgbiCh3CA1MDAwKSwgcmVwcmVzZW50aW5nIHRoZSBudW1iZXIgb2Ygb3BlcmF0aW9ucy4gVGhlbiBmb2xsb3cgbiBvcGVyYXRpb25zLCBvbmUgaW4gYSBsaW5lLiBBbGwgdGhlIHBhcmFtZXRlcnMgYXJlIHBvc2l0aXZlIGludGVnZXJzIGJlbG93IDEwPHN1cD45PC9zdXA+LgoKIAo8YnI+CgpPdXRwdXQKCk91dHB1dCBhbGwgdGhlIGxvZ2dpbmcgY29udGVudHMuCgogCjxicj4KClNhbXBsZSBJbnB1dAoKPHByZSBjbGFzcz0="brush:java;">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
#include
#include
#include
#include
#include
using namespace std;
typedef long long int LL;
const int INF=0x3f3f3f3f;
const int HEAD=0;
const int TAIL=6400;
struct CHART
{
int pro,front,back;
LL w;
}chat[6500];
int n,x,id;
int alwayson;
set pc;
char cmd[50];
void init()
{
id=1;pc.clear();alwayson=-1;
memset(chat,0,sizeof(chat));
chat[HEAD].front=HEAD; chat[HEAD].back=TAIL;
chat[TAIL].front=HEAD; chat[TAIL].back=TAIL;
chat[HEAD].pro=-INF-1; chat[TAIL].pro=-INF-1;
}
void Add(int u)
{
if(pc.count(u))
{
puts("same priority.");
return ;
}
pc.insert(u);
chat[id].w=0; chat[id].pro=u;
chat[id].front=chat[TAIL].front;
chat[id].back=TAIL;
chat[chat[TAIL].front].back=id;
chat[TAIL].front=id;
id++;
puts("success.");
}
void Close(int u)
{
if(pc.count(u)==0)
{
puts("invalid priority.");
return ;
}
pc.erase(u);
if(alwayson==u) alwayson=-1;
int pos=HEAD;
for(pos=HEAD;pos!=TAIL;pos=chat[pos].back)
{
if(chat[pos].pro==u) break;
}
int bc=chat[pos].back;
int ft=chat[pos].front;
chat[bc].front=ft;
chat[ft].back=bc;
printf("close %d with %I64d.\n",chat[pos].pro,chat[pos].w);
}
void Chat(int w)
{
if(chat[HEAD].back==TAIL)
{
puts("empty.");
return ;
}
puts("success.");
int u=-1;
if(alwayson!=-1) u=alwayson;
else u=chat[chat[HEAD].back].pro;
int pos=HEAD;
for(pos=HEAD;pos!=TAIL;pos=chat[pos].back)
{
if(chat[pos].pro==u) break;
}
chat[pos].w+=w;
}
void Rotate(int x)
{
if(x<1||x>pc.size())
{
puts("out of range.");
return ;
}
puts("success.");
int pos=HEAD,i=0;
for(pos=HEAD;ichat[mxp].pro)
{
mxp=pos;
}
}
pos=mxp;
///split
int bc=chat[pos].back;
int ft=chat[pos].front;
chat[bc].front=ft;
chat[ft].back=bc;
///merge
chat[pos].front=HEAD;
chat[pos].back=chat[HEAD].back;
chat[chat[HEAD].back].front=pos;
chat[HEAD].back=pos;
}
void Choose(int u)
{
if(pc.count(u)==0)
{
puts("invalid priority.");
return ;
}
puts("success.");
int pos=HEAD;
for(pos=HEAD;pos!=TAIL;pos=chat[pos].back)
{
if(chat[pos].pro==u) break;
}
///split
int bc=chat[pos].back;
int ft=chat[pos].front;
chat[bc].front=ft;
chat[ft].back=bc;
///merge
chat[pos].front=HEAD;
chat[pos].back=chat[HEAD].back;
chat[chat[HEAD].back].front=pos;
chat[HEAD].back=pos;
}
void Top(int u)
{
if(pc.count(u)==0)
{
puts("invalid priority.");
return ;
}
puts("success.");
alwayson=u;
}
void Untop()
{
if(alwayson==-1)
{
puts("no such person.");
return ;
}
alwayson=-1;
puts("success.");
}
void saybyebye()
{
if(alwayson!=-1)
{
int p=HEAD;
for(p=HEAD;p!=TAIL;p=chat[p].back)
{
if(chat[p].pro==alwayson) break;
}
if(chat[p].w) printf("Bye %d: %I64d\n",chat[p].pro,chat[p].w);
}
int pos=HEAD;
for(pos=chat[HEAD].back;pos!=TAIL;pos=chat[pos].back)
{
if(chat[pos].pro!=alwayson&&chat[pos].w)
printf("Bye %d: %I64d\n",chat[pos].pro,chat[pos].w);
}
}
int main()
{
int T_T;
scanf("%d",&T_T);
while(T_T--)
{
init();
scanf("%d",&n);
for(int i=0;i