跳到正文

题解

题解:P15007 [UOI 2019 II Stage] 草坪

佩露薇利约 11 分钟
原文
文章信息与版本

文章信息

收录
2026年1月25日
更新
2026年1月25日
篇幅
约 11 分钟
题目
P15007

版本

  1. v1当前

题目传送门

思路

一般情况

不考虑草重新生长对特殊场景的影响,先计算最少需要多少次修剪才能覆盖整个草坪。

用长度为 mm 的连续区间覆盖长度为 nn 的区间,最少区间数为 ⌈nm⌉\left \lceil \frac{n}{m} \right \rceil。

二般情况,为什么 WA 只得76pts

当 nn 满足 m<n<2×mm<n<2\times m 时,单次修剪只能覆盖 mm 米的区域,剩余 n−mn-m 米的区域无法与第一次修剪的区域重叠(因为第一次修剪的区域需要 11 小时后才会长草,而第二次操作必须在第一次操作之后立即进行(追求最短时间),此时第一次修剪的区域还未长草,无法再次选择)。

所以,这种情况下用之前的方法会 WA\textcolor{red}{WA},必须额外加 11 次操作,才能覆盖剩余的区域。

代码

C++
#include<bits/stdc++.h>
#define lcm(x,y) x/__gcd(x,y)*y
#define lb(x) (x&-x)
#define str to_string
#define endl '\n'
#define endr '\r'
#define emp_ '\0'
using namespace std;
// #define int long long
using ll=long long;
namespace Fast{
    namespace Fread{const int SZ=1<<20;char buf[SZ],*S,*TT;inline char getchar(){if(S==TT){TT=(S=buf)+fread(buf,1,SZ,stdin);if(S==TT)return endl;}return *S++;}}
    namespace Fwrite{const int SZ=1<<20;char buf[SZ],*S=buf,*TT=buf+SZ;inline void flush(){fwrite(buf,1,S-buf,stdout);S=buf;}inline void putchar(char c){*S++=c;if(S==TT)flush();}struct NTR{~NTR(){flush();}} ztr;}
    using namespace Fread;
    using namespace Fwrite;
    #define getchar Fread::getchar
    #define putchar Fwrite::putchar
    namespace FastIO{
        struct R{
            template<typename T>
            R&operator>>(T&from){from=0;short f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9')from=(from<<3)+(from<<1)+(c^48),c=getchar();from*=f;return*this;}
            R&operator>>(double&from){from=0;double t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')from=from*10+(c^48),c=getchar();if(c=='.')c=getchar();else{from*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;from=(from+t)*f;return*this;}
            R&operator>>(long double&from){from=0;long double t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')from=from*10+(c^48),c=getchar();if(c=='.')c=getchar();else{from*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;from=(from+t)*f;return*this;}
            R&operator>>(__float128&from){from=0;__float128 t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')from=from*10+(c^48),c=getchar();if(c=='.')c=getchar();else{from*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;from=(from+t)*f;return*this;}
            R&operator>>(char&c){c=getchar();while(c==' '||c==endl||c==endr)c=getchar();return*this;}
            R&operator>>(char*str){int len=0;char c=getchar();while(c==' '||c==endl||c==endr)c=getchar();while(c!=' '&&c!=endl&&c!=endr)str[len++]=c,c=getchar();str[len]=emp_;return*this;}
            R(){}
        }cin;
        struct W{
            const int S=6;
            typedef int M;
            template<typename T>
            W&operator<<(T from){if(from==0){putchar('0');return*this;}if(from<0)putchar('-'),from=-from;static short sta[40];short top=0;while(from>0)sta[++top]=from%10,from/=10;while(top>0)putchar(sta[top]+'0'),top--;return*this;}
            W&operator<<(double from){if(from<0)putchar('-'),from=-from;M _=from;from-=(double)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<S;i++)from*=10;_=from;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<S-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}
            W&operator<<(long double from){if(from<0)putchar('-'),from=-from;M _=from;from-=(long double)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<S;i++)from*=10;_=from;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<S-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}
            W&operator<<(__float128 from){if(from<0)putchar('-'),from=-from;M _=from;from-=(__float128)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<S;i++)from*=10;_=from;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<S-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}
            W&operator<<(char c){putchar(c);return*this;}
            W&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}
            W&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}
            W(){}
        }cout;
    }
    int max(register const int e,register const int b){register const int from(e),to(b);return(from>to?from:to);}
    int min(register const int e,register const int b){register const int from(e),to(b);return(from>to?to:from);}
}
using namespace Fast;
#define cin FastIO::cin
#define cout FastIO::cout
const double EPS=1e-6,PAI=acos(-1.0);
const int MAX=5e5+5,mod=1e9+7,MOD=998244353;
int n,m;
void solve(){
    cin>>n>>m;
    int ans=ceil(1.0*n/m); // 向上取整
    if(n<m+m&&n!=m)cout<<ans+1<<endl; // 二般情况
    else cout<<ans<<endl; // 一般情况
}
signed main(){
    int t=1;
//  cin>>t;
    while(t--)solve();
    return 0;
}
原文