【CF1015D】Walking Between Houses(构造,贪心)

题意:从1开始走,最多走到n,走k步,总长度为n,不能停留在原地,不能走出1-n,问是否有一组方案,若有则输出

n<=1e9,k<=2e5,s<=1e18

思路:无解的情况分为两种:总长度太大,步数太多

每次贪心从1走到n或从n走到1,但要注意给剩下的步数留出空间

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<string>
 4 #include<cmath>
 5 #include<iostream>
 6 #include<algorithm>
 7 #include<map>
 8 #include<set>
 9 #include<queue>
10 #include<vector>
11 using namespace std;
12 typedef long long ll;
13 typedef unsigned int uint;
14 typedef unsigned long long ull;
15 typedef pair<int,int> PII;
16 typedef vector<int> VI;
17 #define fi first
18 #define se second 
19 #define MP make_pair
20 #define N  100010
21 #define M  200
22 #define MOD 998244353
23 #define eps 1e-8 
24 #define pi acos(-1)
25 
26 
27 
28 int main()
29 {
30     //freopen("D.in","r",stdin);
31     //freopen("D.out","w",stdout);
32     ll n,k,s;
33     scanf("%lld%lld%lld",&n,&k,&s);
34     ll now=1;
35     if(k>s||k*(n-1)<s)
36     {
37         printf("NO\n");
38         return 0;
39     }
40     printf("YES\n");
41     while(k)
42     {
43         ll t=min(n-1,s-(k-1));
44         if(now-t>0) now-=t;
45          else now+=t;
46         printf("%lld ",now);
47         s-=t;
48         k--;
49     }
50      return 0;
51 }

 

posted on 2018-10-25 21:07  myx12345  阅读(182)  评论(0编辑  收藏  举报

导航