题解:P11296 [NOISG2018 Prelim] Snail
Fish_and_Chips_ · · 题解
这道题与小学奥数仅差了一个条件:当蜗牛的高度小于
而这道小学奥数的解法十分简单:记录每天所有阶段结束后的总爬升高度
所以我们考虑如何将原题转化为这道小学奥数。
考虑直接模拟前两天的情况。若模拟过程中蜗牛爬出了井则直接输出。若
证明:有人托梦给我。
当
之后就可以用小学奥数法过掉此题啦。
code:
#include<bits/stdc++.h>
std::string Set_Nsolution = "-1";
#define int __int128
#define NO_SOLUTION {cout << Set_Nsolution;return 0;}
namespace IO{
inline bool isnum(char ch){return ch>='0'&&ch<='9';}
inline int read()
{
int x=0,f=1;char ch=getchar();
while (!isnum(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isnum(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
inline void out(int x,char ch){
if(x<0){putchar('-');x=-x;}
if(x>9)out(x/10,'/');
putchar(x%10+'0');
if(ch=='l')putchar('\n');
if(ch=='s')putchar(' ');
}
}
using namespace std;
using namespace IO;
const int N = 1e4 + 10, inf = 1145141919810;
int h = read(), n = read(), p[N], sum, mx = -inf, d;
signed main()
{
Set_Nsolution = "-1 -1";
for (int i = 1; i <= n; ++i)
sum += (p[i] = read());
int tmp = 0;
for (int i = 1; i <= n; ++i) {
tmp += p[i];
mx = max(mx, tmp);
}
tmp = 0;
for (int i = 1; i <= n; ++i) {
tmp += p[i];
tmp = max(tmp, (int)0);
if (tmp >= h) {
out(0, 's');
out(i - 1, 'l');
return 0;
}
}
for (int i = 1; i <= n; ++i) {
tmp += p[i];
tmp = max(tmp, (int)0);
if (tmp >= h) {
out(1, 's');
out(i - 1, 'l');
return 0;
}
}
if (sum <= 0) NO_SOLUTION;
d = (h - mx - tmp) / sum + ((h - mx - tmp) % sum != 0) + 2;
int dth = h - tmp - (d - 2) * sum;
tmp = 0;
for (int i = 1; i <= n; ++i) {
tmp += p[i];
if (tmp >= dth) {
out(d, 's');
out(i - 1, 'l');
return 0;
}
}
return 0;
}
// ypa!