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

【I - Little Zu Chongzhi's Triangles】【HDU - 5135】

Zu Chongzhi (429–500) was a prominent Chinese mathematician and astronomer during the Liu Song and Southern Qi Dynasties. Zu calculated the value ofπ to the precision of six decimal places and for a thousand years thereafter no subsequent mathematician computed a value this precise. Zu calculated one year as 365.24281481 days, which is very close to 365.24219878 days as we know today. He also worked on deducing the formula for the volume of a sphere. It is said in some legend story books that when Zu was a little boy, he liked mathematical games. One day, his father gave him some wood sticks as toys. Zu Chongzhi found a interesting problem using them. He wanted to make some triangles by those sticks, and he wanted the total area of all triangles he made to be as large as possible. The rules were : 1) A triangle could only consist of 3 sticks. 2) A triangle's vertexes must be end points of sticks. A triangle's vertex couldn't be in the middle of a stick. 3) Zu didn't have to use all sticks. Unfortunately, Zu didn't solve that problem because it was an algorithm problem rather than a mathematical problem. You can't solve that problem without a computer if there are too many sticks. So please bring your computer and go back to Zu's time to help him so that maybe you can change the history.

【Input】There are no more than 10 test cases. For each case: The first line is an integer N(3 <= N<= 12), indicating the number of sticks Zu Chongzhi had got. The second line contains N integers, meaning the length of N sticks. The length of a stick is no more than 100. The input ends with N = 0.

【Output】For each test case, output the maximum total area of triangles Zu could make. Round the result to 2 digits after decimal point. If Zu couldn't make any triangle, print 0.00 .

【题目大意】祖冲之blah,blah. 多组数据,每组第一行表示n个木棍,第二行为木棍的长度。输出用木棍首尾相接构成的三角形的总面积。保留2位小数。

【题解】将木棍进行排序,从小到大,相邻的三根木棍如果可以构成三角形则ans+=s.贪心证明较难,毕竟标算是状态压缩dp.可以考虑当三角形三条边和相等时,总是等边三角形面积最大.所以如果存在一条边可以组成多个三角形,优先考虑与程度接近的边构成三角形。可以通过海伦公式硬算得出此结论.

int n,len[20];

double ans;

double size(int a,int b,int c){

double p=(a+b+c)/2.0;

double S=sqrt ( p*(p-a)*(p-b)*(p-c) );

return S;

}

int main(){

int i,j,k;

while(true)   {

   scanf("%d",&n);ans=0.0;

   if(n==0)break;

   for(i=1;i<=n;i++) scanf("%d",&len[i]);

   sort(len+1,len+1+n);

   for(i=n;i>=3;i--)

       if( len[i-2]+len[i-1]>len[i] ){

          ans+=size(len[i-2],len[i-1],len[i]);

          i-=2;}

   printf("%.2lf\n",ans);

}

}

【K - How Many Maos Does the Guanxi Worth】【HDU - 5137】

"Guanxi" is a very important word in Chinese. It kind of means "relationship" or "contact". Guanxi can be based on friendship, but also can be built on money. So Chinese often say "I don't have one mao (0.1 RMB) guanxi with you." or "The guanxi between them is naked money guanxi." It is said that the Chinese society is a guanxi society, so you can see guanxi plays a very important role in many things. Here is an example. In many cities in China, the government prohibit the middle school entrance examinations in order to relief studying burden of primary school students. Because there is no clear and strict standard of entrance, someone may make their children enter good middle schools through guanxis. Boss Liu wants to send his kid to a middle school by guanxi this year. So he find out his guanxi net. Boss Liu's guanxi net consists of N people including Boss Liu and the schoolmaster. In this net, two persons who has a guanxi between them can help each other. Because Boss Liu is a big money(In Chinese English, A "big money" means one who has a lot of money) and has little friends, his guanxi net is a naked money guanxi net -- it means that if there is a guanxi between A and B and A helps B, A must get paid. Through his guanxi net, Boss Liu may ask A to help him, then A may ask B for help, and then B may ask C for help ...... If the request finally reaches the schoolmaster, Boss Liu's kid will be accepted by the middle school. Of course, all helpers including the schoolmaster are paid by Boss Liu. You hate Boss Liu and you want to undermine Boss Liu's plan. All you can do is to persuade ONE person in Boss Liu's guanxi net to reject any request. This person can be any one, but can't be Boss Liu or the schoolmaster. If you can't make Boss Liu fail, you want Boss Liu to spend as much money as possible. You should figure out that after you have done your best, how much at least must Boss Liu spend to get what he wants. Please note that if you do nothing, Boss Liu will definitely succeed.

【Input】There are several test cases. For each test case: The first line contains two integers N and M. N means that there are N people in Boss Liu's guanxi net. They are numbered from 1 to N. Boss Liu is No. 1 and the schoolmaster is No. N. M means that there are M guanxis in Boss Liu's guanxi net. (3 <=N <= 30, 3 <= M <= 1000) Then M lines follow. Each line contains three integers A, B and C, meaning that there is a guanxi between A and B, and if A asks B or B asks A for help, the helper will be paid C RMB by Boss Liu. The input ends with N = 0 and M = 0. It's guaranteed that Boss Liu's request can reach the schoolmaster if you do not try to undermine his plan.

【Output】For each test case, output the minimum money Boss Liu has to spend after you have done your best. If Boss Liu will fail to send his kid to the middle school, print "Inf" instead.

【题目大意】中国的“关系“一词很丰富复杂,有时候人际之间的”关系“是建立在金钱的基础之上。Liu老板(简称L)想找校长办事,但人脉较少,不过钱多,可以一层层托关系,每一层L都会付钱。然而你讨厌L,阻挠他的贿赂计划。你可以说服L的关系网中的某一个人拒绝L老板的任何请求(当然这个人不是校长或L老板本人),这样L老板将无法完成贿赂,或者是花费了尽可能多的钱来打通关系。输入多组数据,每组数据第一行N,M表示关系网中有N个人,(1~N),L老板是1,校长是n. M条关系(往下M行),记为A B C,表示A和B打通关系L老板要付C元。保证如果不作阻挠,L老板一定能成功贿赂。L老板在阻挠计划执行后会尝试用最小价钱打通关系,输出L老板的最后结果(最大化的最小花费或是Inf表示无法打通)。

【题解】n个点m条边,将某个点(非1,n)删除后1到n最短路最长,或者删掉的点是割点。枚举删除的点,跑最短路记录答案即可。

struct node{

int y,c,next;

}a[maxm*2];int len,first[maxn];

void ins(int x,int y,int c){

len++;a[len].y=y;a[len].c=c;

a[len].next=first[x];first[x]=len;}

int n,ans;

int mymax(int x,int y){return (x>y)?x:y;}

queueq;int d[maxn];bool vis[maxn];

void spfa(int ban){

memset(vis,false,sizeof(vis));

memset(d,-1,sizeof(d));

while (!q.empty()) q.pop();

d[1]=0;q.push(1);vis[1]=true;

while (!q.empty()){

   int x=q.front();q.pop();

   for (int i=first[x];i!=-1;i=a[i].next){

       int y=a[i].y;

       if (y==ban) continue;

       if (d[y]==-1 || d[y]>d[x]+a[i].c){

          d[y]=d[x]+a[i].c;

          if (!vis[y]){

              q.push(y);

              vis[y]=true;}}}

   vis[x]=false;}

if (d[n]==-1) ans=-1;

else ans=mymax(ans,d[n]);}

int main(){

int m,i,x,y,c;

while (1){

   scanf("%d%d",&n,&m);

   if (n==0 && m==0) break;

   len=0;memset(first,-1,sizeof(first));

   for (i=1;i<=m;i++){scanf("%d%d%d",&x,&y,&c);

          ins(x,y,c);ins(y,x,c);}

   ans=0;

   for (i=2;i

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

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

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

推荐阅读更多精彩内容