poj-3253-Fence Repair
来源:互联网 发布:东方财富行情软件 编辑:程序博客网 时间:2024/05/17 01:00
#include<stdio.h>
#include<stdlib.h>
#define M 20010
int a[M];
int cmp(const void*a,const void *b)
{
return *(int *)a-*(int *)b;
}
int main()
{
int n,i,j,t;
long long sum;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)
scanf("%d",&a[i]);
qsort(a,n,sizeof(a[0]),cmp);
sum=0;
for(i=1;i<n;i++)
{
a[i]+=a[i-1];
sum+=a[i];
for(j=i;j<n-1;j++)
{
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
printf("%lld\n",sum);
}
return 0;
}
#include<stdlib.h>
#define M 20010
int a[M];
int cmp(const void*a,const void *b)
{
return *(int *)a-*(int *)b;
}
int main()
{
int n,i,j,t;
long long sum;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)
scanf("%d",&a[i]);
qsort(a,n,sizeof(a[0]),cmp);
sum=0;
for(i=1;i<n;i++)
{
a[i]+=a[i-1];
sum+=a[i];
for(j=i;j<n-1;j++)
{
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
printf("%lld\n",sum);
}
return 0;
}
- POJ 3253 Fence Repair
- poj 3253 Fence Repair
- POJ 3253 Fence Repair
- POJ 3253 Fence Repair
- POJ 3253 Fence Repair
- POJ 3253 Fence Repair
- poj 3253 Fence Repair
- POJ 3253Fence Repair
- POJ--3253 -- Fence Repair
- poj-3253-Fence Repair
- POJ 3253 Fence Repair
- POJ 3253 Fence Repair
- poj 3253 Fence Repair
- poj 3253 Fence Repair
- POJ - 3253 Fence Repair
- POJ 3253 Fence Repair
- poj 3253 Fence Repair
- poj 3253---Fence Repair
- A2-不当的认证和会话管理
- 金额数据格式化
- android log 调试
- Linux命令大全
- 对中级 Linux 用户非常有用的 20 个命令
- poj-3253-Fence Repair
- SMP与AMP-UMA与NUMA概念
- 认识smack中的基本对象 - Roster对象
- import paramiko时一个AttributeError错误的解决
- poj2211 约瑟夫问题变形 递归法
- JSP与Servlet之间设置Cookie可能导致Cookie无法读取的解决办法
- python2.7中print()的使用
- Android ProgressBar使用简单例子
- android学习:对话框(Dialog)