【#1】【The2014ACM-ICPC亚洲区广州站】训练赛

【A-Dog's Candies】【HDU5127】

Far far away, there live a lot of dogs in the forest. Unlike other dogs, those dogs love candies much more than bones.Every candy has two attributes: the sweetness degree p and the sourness degree q. Different dogs like different candies. A dog also has two attributes: the fondness degree for sweetness x and the fondness degree for sourness y. So the deliciousness degree of a candy for a dog is defined as p×x + q×y.The dog king has a huge candy box. At first, the box is empty. The king can add candies to the box or take some candies from the box and eat them. There are always some dogs who want to know which candies in the box are the most delicious for them. Please help the king to answer their questions.

【Input】

The input consists of at most 10 test cases. For each test case, the first line contains an integer n indicating that there are n candy box operations(1 <= n <= 50000).The following n lines describe the n operations.Each operation contains three integers t, x and y( 0 <= |x|, |y| <= 1e9). The first integer t may be -1, 0, or 1.If t equals -1, it means that a candy in the box with sweetness degree x and sourness degree y is eaten by the dog king.If t equals 1, it means that a candy with sweetness degree x and sourness degree y is added to the candy box.If t equals 0, it means that a dog with sweetness fondness degree x and sourness fondness degree y wants to know the maximal deliciousness degree of the candies in the box for him. It is guaranteed that every candy is unique in the box. The input ends by n = 0.

【Output】

For each operation in which t equals to 0, you should print the maximal deliciousness degree of the best candy for the dog.

题目大意:狗狗们爱吃糖果,糖果有2个属性,甜度值p和酸度值q.狗狗们对糖果的喜爱程度为嗜甜度x和嗜酸度y,那么糖果的美味程度定义为px+qy.现在有3种操作,-1,0,1.-1 x y表示删除甜度x酸度y的糖,1 x y表示增添甜度x酸度y的糖,0 x y 表示属性为x,y的狗狗查询于他而言最好吃的糖果是哪一个。

【题解】注意到本题的时限为30秒,所以vector暴力模拟即可。

int n;

struct node{

long long x,y;

};

inline long long mul(node a,node b){return a.xb.x+a.yb.y;}

inline bool same(node a,node b){return a.x==b.x && a.y==b.y;}

vectorv;

int main(){

while(1){

   scanf("%d",&n);if(n==0) break;

   int op,i;node p;

   while(n--){

       scanf("%d %lld %lld",&op,&p.x,&p.y);

       if(op==1) v.push_back(p);

       if(op==0){

          long long ans=-999999999999999999ll;

          for(i=0;i

           printf("%lld\n",ans);

       }

       if(op==-1)

          for(vector::iterator it=v.begin();it!=v.end();it++){

              node tp=*it; if(same(tp,p)){v.erase(it);break;}

          }

   }

   while(!v.empty()) v.pop_back();

}

return 0;

}

【B - The E-pang Palace】【HDU - 5128】

E-pang Palace was built in Qin dynasty by Emperor Qin Shihuang in Xianyang, Shanxi Province. It was the largest palace ever built by human. It was so large and so magnificent that after many years of construction, it still was not completed. Building the great wall, E-pang Palace and Qin Shihuang's tomb cost so much labor and human lives that people rose to fight against Qin Shihuang's regime.Xiang Yu and Liu Bang were two rebel leaders at that time. Liu Bang captured Xianyang -- the capital of Qin. Xiang Yu was very angry about this, and he commanded his army to march to Xianyang. Xiang Yu was the bravest and the strongest warrior at that time, and his army was much more than Liu Bang's. So Liu Bang was frighten and retreated from Xianyang, leaving all treasures in the grand E-pang Palace untouched. When Xiang Yu took Xianyang, he burned E-pang Palce. The fire lasted for more than three months, renouncing the end of Qin dynasty.Several years later, Liu Bang defeated Xiangyu and became the first emperor of Han dynasty. He went back to E-pang Palace but saw only some pillars left. Zhang Liang and Xiao He were Liu Bang's two most important ministers, so Liu Bang wanted to give them some awards. Liu Bang told them: "You guys can make two rectangular fences in E-pang Palace, then the land inside the fences will belongs to you. But the corners of the rectangles must be the pillars left on the ground, and two fences can't cross or touch each other." To simplify the problem, E-pang Palace can be consider as a plane, and pillars can be considered as points on the plane. The fences you make are rectangles, and you MUST make two rectangles. Please note that the rectangles you make must be parallel to the coordinate axes. The figures below shows 3 situations which are not qualified(Thick dots stands for pillars): Zhang Liang and Xiao He wanted the total area of their land in E-pang Palace to be maximum. Please bring your computer and go back to Han dynasty to help them so that you may change the history.

【Input】

There are no more than 15 test case. For each test case: The first line is an integer N, meaning that there are N pillars left in E-pang Palace(4 <=N <= 30). Then N lines follow. Each line contains two integers x and y (0 <= x,y <= 200), indicating a pillar's coordinate. No two pillars has the same coordinate. The input ends by N = 0.

【Output】

For each test case, print the maximum total area of land Zhang Liang and Xiao He could get. If it was impossible for them to build two qualified fences, print "imp".

【题目大意】:前文废话极多,大意为,阿房宫烧毁后地面留下n个木桩,给出坐标信息。现在两个人圈地,要求圈地为矩形,且矩形的边不能相“触碰“,即如果共有某个木桩也认为是”触碰“的。现在求最大占地面积,如果找不到输出imp。

【题解】暴力搜索点即可,但注意到:矩形的嵌套是不违规的,而且面积只计算外圈大矩形的面积。其他的普通做即可.

int n,m[202][202];

struct node

{

int x,y;

}point[33];

bool cmp(node a, node b)

{

if(a.x < b.x)return true;

if(a.x > b.x)return false;

if(a.y < b.y)return true;

return false;

}

bool judge(node a,node b,node c,node d)

{

if(a.x>=b.x || a.y>=b.y || c.x>=d.x || c.y>=d.y)return false;

if(m[a.x][b.y]==0 || m[b.x][a.y]==0 || m[c.x][d.y]==0 || m[d.x][c.y]==0)return false;

if(c.xb.x &&d.y >b.y

|| c.x>a.x&&c.y>a.y &&d.x

if(c.x <= b.x && c.y<=b.y)return false;

return true;

}

inline int size(node a,node b,node c,node d)

{

int ans=0;

   if(c.xb.x &&d.y >b.y

|| c.x>a.x&&c.y>a.y &&d.x

ans+=(b.x-a.x)*(b.y-a.y);

ans+=(d.x-c.x)*(d.y-c.y);

return ans;

}

int main(){

int i,j,k,l,ans;

while(true)   {

   scanf("%d",&n);

   if(n==0)break;

   ans=-1;memset(m,0,sizeof(m));

   for(i=1;i<=n;i++){

       scanf("%d%d",&point[i].x,&point[i].y);

       m[point[i].x][point[i].y]=1;

   }

   for(i=1;i<=n;i++)

       for(j=1;j<=n;j++)

          for(k=1;k<=n;k++)

              for(l=1;l<=n;l++)

                 if(judge(point[i],point[j],point[k],point[l]))

                     ans=max(ans,size(point[i],point[j],point[k],point[l]));

   if(ans==-1)printf("imp\n");

   else printf("%d\n",ans);

}

}

【D - Signal Interference】【HDU - 5130】

http://blog.sina.com.cn/s/blog_be010f940102ylne.html

【E - Song Jiang's rank list】【HDU - 5131】

《Shui Hu Zhuan》,also 《Water Margin》was written by Shi Nai'an -- an writer of Yuan and Ming dynasty. 《Shui Hu Zhuan》is one of the Four Great Classical Novels of Chinese literature. It tells a story about 108 outlaws. They came from different backgrounds (including scholars, fishermen, imperial drill instructors etc.), and all of them eventually came to occupy Mout Liang(or Liangshan Marsh) and elected Song Jiang as their leader. In order to encourage his military officers, Song Jiang always made a rank list after every battle. In the rank list, all 108 outlaws were ranked by the number of enemies he/she killed in the battle. The more enemies one killed, one's rank is higher. If two outlaws killed the same number of enemies, the one whose name is smaller in alphabet order had higher rank. Now please help Song Jiang to make the rank list and answer some queries based on the rank list.

【Input】There are no more than 20 test cases. For each test case:

The first line is an integer N (0

【Output】For each test case, print the rank list first. For this part in the output ,each line contains an outlaw's name and the number of enemies he killed. Then, for each name in the query of the input, print the outlaw's rank. Each outlaw had a major rank and a minor rank. One's major rank is one plus the number of outlaws who killed more enemies than him/her did.One's minor rank is one plus the number of outlaws who killed the same number of enemies as he/she did but whose name is smaller in alphabet order than his/hers. For each query, if the minor rank is 1, then print the major rank only. Or else Print the major rank, blank , and then the minor rank. It's guaranteed that each query has an answer for it.

【题目大意】水浒好汉排座次,杀人多的排前面,相同杀人看名字,按字典序排序。先输出座次,然后根据名称输出排名,如果有并列的输出并列后第几。

【题解】结构体排序

struct node

{

char s[60];

int x,rk1,rk2;

}a[210];

bool cmp(node x,node y)

{

if (x.x!=y.x) return x.x>y.x;

return (strcmp(x.s,y.s)<0)?1:0;

}

int main()

{

int n,m,i,num,cnt;char c[60];

while (1)

{

   scanf("%d",&n);

   if (n==0) break;

   for (i=1;i<=n;i++)

    cin>>a[i].s>>a[i].x;

   sort(a+1,a+1+n,cmp);

   for (i=1;i<=n;i++)

    cout<<a[i].s<<" "<<a[i].x<<endl;

   num=cnt=a[1].rk1=a[1].rk2=1;

   for (i=2;i<=n;i++)

    if (a[i].x!=a[i-1].x) {num+=cnt;a[i].rk1=num;a[i].rk2=cnt=1;}

    else {a[i].rk1=num;a[i].rk2=++cnt;}

   scanf("%d",&m);

   while (m--)

   {

       cin>>c;

       for (i=1;i<=n;i++)

        if (strcmp(c,a[i].s)==0) break;

       if (a[i].rk2==1) printf("%d\n",a[i].rk1);

       else printf("%d %d\n",a[i].rk1,a[i].rk2);     

   }

}

return 0;

}

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,099评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,828评论 3 387
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 158,540评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,848评论 1 285
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,971评论 6 385
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,132评论 1 291
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,193评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,934评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,376评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,687评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,846评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,537评论 4 335
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,175评论 3 317
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,887评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,134评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,674评论 2 362
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,741评论 2 351

推荐阅读更多精彩内容