【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個(gè)屬性,甜度值p和酸度值q.狗狗們對(duì)糖果的喜愛程度為嗜甜度x和嗜酸度y收夸,那么糖果的美味程度定義為px+qy.現(xiàn)在有3種操作,-1,0,1.-1 x y表示刪除甜度x酸度y的糖践惑,1 x y表示增添甜度x酸度y的糖妙痹,0 x y 表示屬性為x,y的狗狗查詢于他而言最好吃的糖果是哪一個(gè)寇荧。
【題解】注意到本題的時(shí)限為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個(gè)木樁,給出坐標(biāo)信息●桑現(xiàn)在兩個(gè)人圈地爽撒,要求圈地為矩形,且矩形的邊不能相“觸碰“响蓉,即如果共有某個(gè)木樁也認(rèn)為是”觸碰“的∷段穑現(xiàn)在求最大占地面積,如果找不到輸出imp枫甲。
【題解】暴力搜索點(diǎn)即可源武,但注意到:矩形的嵌套是不違規(guī)的扼褪,而且面積只計(jì)算外圈大矩形的面積。其他的普通做即可.
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.
【題目大意】水滸好漢排座次迎捺,殺人多的排前面,相同殺人看名字查排,按字典序排序。先輸出座次抄沮,然后根據(jù)名稱輸出排名跋核,如果有并列的輸出并列后第幾。
【題解】結(jié)構(gòu)體排序
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;
}