【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;}