167 条题解
-
-1hz4zxueyf LV 8 @ 2016-11-06 22:11:17
这道题标准解法是用动态规划,但是用贪心也是可以的,而且比较容易理解,就是要考虑的情况有点多。我就是因为少加了一所以检查了一个小时。下面是Pascal代码(抱歉加了文件,有点乱):
var
m,s,t,ans1,ans2,a,b:longint;
begin
//assign(input,'escape.in'); reset(input);
//assign(output,'escape.out'); rewrite(output);
readln(m,s,t);//writeln(m,s,t);
while (m>=10) and (ans1+1<=t) do begin
m:=m-10;
ans2:=ans2+60;
ans1:=ans1+1; //writeln(ans1);
if ans2>=s then begin writeln('Yes'); writeln(ans1); close(input); close(output); halt; end;
end;
if ans1=t then begin writeln('No'); writeln(ans2); close(input); close(output); halt; end;
//writeln(ans2);
repeat
if m>=10 then begin m:=m-10; ans1:=ans1+1; ans2:=ans2+60; end;
if ans2>=s then begin writeln('Yes'); writeln(ans1); {write('1 ');} close(input); close(output); halt; end;
if ((t-ans1-1)*4+m<10) and ((t-ans1)*17+ans2<s) then begin
writeln('No'); writeln((t-ans1)*17+ans2); {write('2 '); close(input);} close(output); halt; end;
if ((t-ans1-1)*4+m<10) and ((t-ans1)*17+ans2>=s) then begin
writeln('Yes');
repeat ans1:=ans1+1; ans2:=ans2+17; until ans2>s;
writeln(ans1); {write('3 ');} close(input); close(output); halt; end;
a:=s-ans2; if (10-m) mod 4=0 then b:=m div 4
else b:=(10-m) div 4 +2; //write(b,'(b) ');
if b*17>=a then begin
writeln('Yes');
repeat ans1:=ans1+1; ans2:=ans2+17; until ans2>s;
writeln(ans1); {writeln('6 ');} close(input); close(output); halt; end;
ans1:=ans1+1;
m:=m+4; //write(ans2,' ');
until false;
end. -
-12016-10-28 22:41:27@
下面的程序68那里改成67,66,65,64都对
-
-12016-10-28 22:40:46@
#include <bits/stdc++.h>
using namespace std;int main()
{
int i,j,k,l,m,s,t,e,n=0,x=0;
cin>>m>>s>>t;
for(;n<s&&x<t;) {if(m>=10)
{
n+=60,m-=10,x+=1;
//cout<<"1"<<endl;
}
else if((s-n)>68 && (t-x)>(10-m)/4){
m+=4,x+=1;
//cout<<"3"<<endl;
}
else {
n+=17,x+=1;
//cout<<"2"<<endl;
}}
if(n>s) cout<<"Yes\n"<<x<<endl;
else cout<<"No\n"<<n<<endl;
return 0;
} -
-12016-10-28 22:36:46@
#include <bits/stdc++.h>
using namespace std;int main()
{
int i,j,k,l,m,s,t,e,n=0,x=0;
cin>>m>>s>>t;
for(;n<s&&x<t;) {
if(m>=10) {
n+=60,m-=10,x+=1;
//cout<<"1"<<endl;
}
else if((s-n)>64 && (t-x)>(10-m)/4){
m+=4,x+=1;
//cout<<"3"<<endl;
}
else {
n+=17,x+=1;
//cout<<"2"<<endl;
}
}
if(n>s) cout<<"Yes\n"<<x<<endl;
else cout<<"No\n"<<n<<endl;
return 0;
} -
-12016-09-18 13:45:54@
###****简单DP****
```c++
评测结果
编译成功测试数据 #0: Accepted, time = 0 ms, mem = 4080 KiB, score = 10
测试数据 #1: Accepted, time = 15 ms, mem = 4076 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 4076 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 4080 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 4080 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 4076 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 4076 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 4076 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 4076 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 4080 KiB, score = 10
Accepted, time = 15 ms, mem = 4080 KiB, score = 100
代码
#include <algorithm>
#include <iostream>
using namespace std;
//ifstream cin("escape.in",ios :: in);
//ofstream cout("escape.out",ios :: out);
int m,s,t,MaxDist;
struct DP {
int f,g,m;
/*
dp[t].f:表示在t秒最远距离
dp[t].g:表示在t秒只闪烁的最远距离
dp[t].m:表示在t秒最大魔法
/
}dp[300001];
int main() {
ios :: sync_with_stdio(false);
cin >> m >> s >> t;
dp[0].f = dp[0].g = 0;
dp[0].m = m;
for (int i = 1;i <= t;i++) {
if (dp[i-1].m >= 10) { //可以闪烁
dp[i].m = dp[i-1].m-10;
dp[i].g = dp[i-1].g+60;
} else { //否则休息
dp[i].m = dp[i-1].m+4;
dp[i].g = dp[i-1].g;
}
dp[i].f = max(dp[i-1].f+17/走路*/,dp[i].g/*闪烁*/);
}
if (dp[t].f < s) { //不能逃离
cout << "No\n" << dp[t].f;
return 0;
}
while (dp[t].f >= s) t--; //得到最小时间
cout << "Yes\n" << ++t;
return 0;
}
``` -
-12016-09-05 13:29:54@
#include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<stdio.h> #include<algorithm> using namespace std; int disleft[10]={119,119,51,51,51,51,34,34,34,34}; int timeleft[10]={7,7,3,3,3,3,2,2,2,2}; int usemagic[10]={2,2,1,1,1,1,1,1,1,1}; long long m,s,t,dis=0,time=0; int main() { //freopen("escape.in","r",stdin); //f/reopen("escape.out","w",stdout); cin>>m>>s>>t; while(m>=10) { m=m-10; dis=dis+60;time++; if(time>=t && dis<s){cout<<"No"<<endl;cout<<dis<<endl;return 0;} if(dis>=s && time<=t){cout<<"Yes"<<endl;cout<<time<<endl;return 0;} } while(time<t) { if(s-dis>=disleft[m] && t-time>=timeleft[m]) { int m2=m; dis=dis+usemagic[m2]*60; time=time+timeleft[m2]; m=m+(timeleft[m2]-usemagic[m2])*4-usemagic[m2]*10; if(time>=t && dis<s){cout<<"No"<<endl;cout<<dis<<endl;return 0;} else if(dis>=s && time<=t){cout<<"Yes"<<endl;cout<<time<<endl;return 0;} } else { int tt=timeleft[m]; while(tt>0) { tt=tt-1; dis=dis+17; time=time+1; if(time>=t && dis<s){cout<<"No"<<endl;cout<<dis<<endl;return 0;} else if(dis>=s && time<=t){cout<<"Yes"<<endl;cout<<time<<endl;return 0;} } } } cout<<"No"<<endl;cout<<dis<<endl; fclose(stdin);fclose(stdout); }
-
-12016-08-30 13:05:57@
var m,s,t,i:longint;f:array [0..300000] of longint;
begin
readln(m,s,t);
for i:=1 to t do
if m>=10 then begin f[i]:=f[i-1]+60;m:=m-10;end
else begin m:=m+4;f[i]:=f[i-1];end;
for i:=1 to t do
begin
if f[i]<f[i-1]+17 then f[i]:=f[i-1]+17;
if f[i]>s then begin writeln('Yes');writeln(i);exit;end;
end;
writeln('No');writeln(f[t]);
end.