版权声明:转载时 别忘了注明出处 https://blog.csdn.net/ZCY19990813/article/details/83510862
比赛地址:http://acm.sdibt.edu.cn/vjudge/contest/view.action?cid=2111#overview
A
题意:给出4个数,两个一个组合,求最小的差距。
思路:直接排序,中间两个一组,两边一组,这样差最小。
注意:一定是正数。
INPut
4 7 10 20
0 0 1 1000
1 2 3 4
OUtput
7
999
0
#include <iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std;
int main()
{
long long int a[5];
while(~scanf("%lld",&a[0]))
{
for(int i=1; i<=3; i++)
scanf("%lld",&a[i]);
sort(a,a+4);
long long int ans=abs(a[3]+a[0]-a[1]-a[2]);
printf("%lld\n",ans);
}
}
D
题意:将延伸出去的最大边连起来,求最大面积。
思路:分成n个三角形,根据面积公式求加和。S=1/2sin(A)bc,其中A是角度(弧度制),要想面积最大,首先角度要平均,所以角度已知,A=360/n,主要是求所有bc和的最大值。
注意:错误主要是精度不准确
Sample Input
6
10 60 70 70 80 80
3
100 100 100
7
16 37 50 35 12 39 24
Sample Output
10002.593
12990.381
2772.765
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <deque>
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
#define pi acos(-1)
const int AA=4e5+7;
map<string,ll> M;
map<string,string> N;
double a[100101];
deque<double> q;
bool cmp(double s,double ss)
{
return s<ss;
}
int main()
{
ll n,i;
while(cin>>n)
{
double ans=0,aa;
double sum=0;
for(i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
for(i=0;i<n;i++)
{
if(i%2==0)
q.push_front(a[i]);
else
q.push_back(a[i]);
}
double x=q.front();
double y=q.back();
while(1)
{
if(q.empty())
break;
double t=q.front();
//printf("%.3lf\n",t);
q.pop_front();
if(q.empty())
break;
double tt=q.front();
sum+=sin(2.0*pi/n)*t*tt/2.0;
}
sum+=sin(2.0*pi/n)*x*y/2.0;
printf("%.3lf\n",sum);
}
return 0;
}
H
题意:给出n是酒店的个数 k是住这些次酒店可以免费住一次酒店,求最小花费
思路:应用优先队列(从大到小),从后往前遍历,先放进去要是满足i%(k+1)==0就让最前面的出优先队列,将最后剩余的优先队列中的元素相加即可。
Sample Input
6 2
10 3 12 15 12 18
6 1
10 3 12 15 12 18
5 5
1 2 3 4 5
Sample Output
37
25
15
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <deque>
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
#define pi acos(-1)
const int AA=4e5+7;
map<string,ll> M;
map<string,string> N;
ll a[100010];
priority_queue<int,vector<int>,greater<int> > p;
priority_queue<int> q;
int main()
{
ll n,i,k,ans=0;
while(cin>>n>>k)
{
ans=0;
for(i=1; i<=n; i++)
cin>>a[i];
for(i=n; i>=1; i--)
{
q.push(a[i]);
if(i%(k+1)==0)
q.pop();
}
while(q.size()>0)
{
ans+=q.top();
q.pop();
}
cout<<ans<<endl;
}
return 0;
}