1 Star 0 Fork 1

saigon/Algorithms

forked from charlieshu/Algorithms 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
P1941 [NOIP2014 提高组] 飞扬的小鸟.cpp 1.69 KB
一键复制 编辑 原始数据 按行查看 历史
charlie 提交于 2024-01-09 00:01 . move from github to gitee
#include <iostream>
#include <math.h>
#include <string.h>
#include <algorithm>
#pragma GCC optimize(3,"Ofast","inline")
using namespace std;
const int inf=0x7fffffff;
struct motion{
int up,down;
};
struct pipeline{
int location,ceiling,floor;
};
bool cmp(pipeline a,pipeline b){
return a.location<b.location;
}
int main(){
int n,m,k,ans=inf;
bool can_pass;
scanf("%d%d%d",&n,&m,&k);
motion a[n];
pipeline b[k+1];
int dp1[m+1],dp2[m+1];
memset(dp1,0,sizeof(dp1));
for(int i=0;i<n;i++)
scanf("%d%d",&a[i].up,&a[i].down);
for(int i=0;i<k;i++)
scanf("%d%d%d",&b[i].location,&b[i].floor,&b[i].ceiling);
/// cin>>b[i].location>>b[i].floor>>b[i].ceiling;
sort(b,b+k,cmp);
int index=0;
for(int i=1;i<=n;i++){
can_pass = false;
int have_pipeline=false;
for(int j=1;j<=m;j++){
if(b[index].location == i){
if(j <= b[index].floor || j >= b[index].ceiling){
dp2[j] = inf;
have_pipeline = true;
continue;
}
have_pipeline = true;
}
dp2[j] = j+a[i-1].down>m?inf:dp1[j+a[i-1].down];
if(j == m){
dp2[j] = min(dp2[j],dp1[j]==inf?inf:dp1[j]+1);
for(int k=m-1;k>0;k--)
dp2[j] = min(dp2[j]+0.0,dp1[k]==inf?inf:dp1[k]+ceil((j-k+0.0)/a[i-1].up));
}
else
for(int k=j-a[i-1].up;k>0;k-=a[i-1].up)
dp2[j] = min(dp2[j],dp1[k]!=inf?dp1[k]+(j-k)/a[i-1].up:inf);
// if(dp2[j] < 0)
// cout<<i<<endl<<endl;
if(dp2[j] != inf)
can_pass = true;
}
if(!can_pass){
cout<<0<<endl;
cout<<index;
return 0;
}
if(have_pipeline)
index++;
memcpy(dp1,dp2,sizeof(dp1));
}
cout<<1<<endl;
for(int i=1;i<=m;i++)
ans = min(ans,dp1[i]);
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