'commit'
This commit is contained in:
16
C++专题课程/NOIP算法总结/贪心/合并果子/P1090.cpp
Normal file
16
C++专题课程/NOIP算法总结/贪心/合并果子/P1090.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include<bits/stdc++.h>
|
||||
using namespace std;
|
||||
int n,x,ans;
|
||||
priority_queue<int,vector<int>,greater<int> >q;
|
||||
int main(){
|
||||
cin>>n;
|
||||
for(int i=1;i<=n;i++) cin>>x,q.push(x);
|
||||
while(q.size()>=2){
|
||||
int a=q.top(); q.pop();
|
||||
int b=q.top(); q.pop();
|
||||
ans+=a+b;
|
||||
q.push(a+b);
|
||||
}
|
||||
cout<<ans<<endl;
|
||||
return 0;
|
||||
}
|
||||
1
C++专题课程/NOIP算法总结/贪心/合并果子/题目链接.txt
Normal file
1
C++专题课程/NOIP算法总结/贪心/合并果子/题目链接.txt
Normal file
@@ -0,0 +1 @@
|
||||
https://www.luogu.org/problem/P1090
|
||||
63
C++专题课程/NOIP算法总结/贪心/旅行家的预算/P1016.cpp
Normal file
63
C++专题课程/NOIP算法总结/贪心/旅行家的预算/P1016.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include<bits/stdc++.h>
|
||||
using namespace std;
|
||||
double maxx,mo=0,d2,temlen=0,d1,c,p;
|
||||
//temlen:油箱中在到达了下一个加油站时油箱中的剩余油量可以继续走的路程
|
||||
int n;
|
||||
struct add
|
||||
{
|
||||
double co;
|
||||
double dis;
|
||||
}pl[10000];//加油站结构体:dis-距离起点的距离,co:油价
|
||||
int move(int now)//1.now:现在到达的加油站
|
||||
{
|
||||
int can=99999;
|
||||
int f=pl[now].dis;
|
||||
for(int i=now+1;i<=n&&pl[i].dis-f<=maxx;i++)
|
||||
{
|
||||
if(pl[i].co<pl[now].co)//2.
|
||||
{
|
||||
mo+=((pl[i].dis-f-temlen)/d2)*pl[now].co;
|
||||
temlen=0;
|
||||
return i;
|
||||
}
|
||||
if(can==99999||pl[i].co<pl[can].co)can=i;
|
||||
}
|
||||
if(d1-pl[now].dis<=maxx)
|
||||
{
|
||||
mo+=((d1-pl[now].dis-temlen)/d2)*pl[now].co;
|
||||
return 9999;
|
||||
}
|
||||
if(can==99999)//4.
|
||||
{
|
||||
cout<<"No Solution";
|
||||
return -1;
|
||||
}
|
||||
else//3.
|
||||
{
|
||||
mo+=c*pl[now].co;
|
||||
temlen+=(maxx-pl[can].dis+f);
|
||||
return can;
|
||||
}
|
||||
}
|
||||
int cmp(add a,add b)
|
||||
{
|
||||
return a.dis<b.dis;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
cin>>d1>>c>>d2>>p>>n;
|
||||
pl[0].dis=0;
|
||||
pl[0].co=p;
|
||||
for(int i=1;i<=n;i++)cin>>pl[i].dis>>pl[i].co;
|
||||
sort(pl,pl+n,cmp);
|
||||
maxx=c*d2;
|
||||
int k=0,t;
|
||||
do
|
||||
{
|
||||
t=move(k);
|
||||
k=t;
|
||||
if(t==-1)return 0;
|
||||
}while(t!=9999);
|
||||
printf("%.2f",mo);
|
||||
return 0;
|
||||
}
|
||||
1
C++专题课程/NOIP算法总结/贪心/旅行家的预算/试题链接.txt
Normal file
1
C++专题课程/NOIP算法总结/贪心/旅行家的预算/试题链接.txt
Normal file
@@ -0,0 +1 @@
|
||||
https://www.luogu.org/problem/P1016
|
||||
1
C++专题课程/NOIP算法总结/贪心/篝火晚会/P1053.txt
Normal file
1
C++专题课程/NOIP算法总结/贪心/篝火晚会/P1053.txt
Normal file
@@ -0,0 +1 @@
|
||||
https://blog.csdn.net/largecub233/article/details/68923039
|
||||
Reference in New Issue
Block a user