1 Star 0 Fork 1

saigon/Algorithms

forked from charlieshu/Algorithms 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
P2678 [NOIP2015 提高组] 跳石头.cpp 1.40 KB
一键复制 编辑 原始数据 按行查看 历史
charlie 提交于 2024-01-09 00:01 . move from github to gitee
#include <iostream>
#include <queue>
#include <string.h>
using namespace std;
struct step{
int next_right,next_left,length;
bool operator < (const step x)const{
return length>x.length;
}
};
int main(){
int l,n,m;
priority_queue<step> q;
cin>>l>>n>>m;
int a[n],len[n+1];
bool vis[n];
cin>>a[0];
vis[0] = true;
len[0] = a[0]-0;
step b;
b.left = 0;
b.right = 1;
b.length = a[0]-0;
q.push(b)
for(int i=1;i<n;i++){
cin>>a[i];
vis[i] = true;
len[i] = a[i]-a[i-1];
b.left = i;
b.right = i+1;
b.length = len[i];
q.push(b);
}
len[n] = l-a[n-1]+1;
b.left = n;
b.right = n+1;
b.length = len[n];
q.push(b);
for(int i=0;i<m;i++){
step now;
now = q.top();
q.pop();
if(vis[now.left-1] == false || vis[now.right-1] == false){
i--;
continue;
}
if(len[now.left-1] <= len[now.right]){
vis[now.left-1] = false;
len[now.left-1] += len[now.left];
b.left = now.left-1;
b.right = now.right;
b.length = len[now.left-1]
q.push(b);
}
else{
vis[now.n] = false;
len[now.n+1] += len[now.n];
}
}
for(int i=0;i<n;i++)
cout<<vis[i]<<" ";
cout<<endl;
int ans=0x7fffffff;
for(int i=0;i<n-1;i++){
if(vis[i] == false || vis[i+1] == false)
continue;
cout<<i<<" "<<len[i+1]<<endl;
ans = min(ans,len[i+1]);
}
if(vis[0] == true)
ans = min(ans,len[0]);
cout<<ans;
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/saigonshu/algorithm.git
git@gitee.com:saigonshu/algorithm.git
saigonshu
algorithm
Algorithms
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385