D. Walking Between Houses

题目链接                                                                D. Walking Between Houses

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

There are nn houses in a row. They are numbered from 11 to nn in order from left to right. Initially you are in the house 11 .

You have to perform kk moves to other house. In one move you go from your current house to some other house. You can't stay where you are (i.e., in each move the new house differs from the current house). If you go from the house xx to the house yy , the total distance you walked increases by |x−y||x−y| units of distance, where |a||a| is the absolute value of aa . It is possible to visit the same house multiple times (but you can't visit the same house in sequence).

Your goal is to walk exactly ss units of distance in total.

If it is impossible, print "NO". Otherwise print "YES" and any of the ways to do that. Remember that you should do exactly kk moves.

Input

The first line of the input contains three integers nn , kk , ss (2≤n≤1092≤n≤109 , 1≤k≤2⋅1051≤k≤2⋅105 , 1≤s≤10181≤s≤1018 ) — the number of houses, the number of moves and the total distance you want to walk.

Output

If you cannot perform kk moves with total walking distance equal to ss , print "NO".

Otherwise print "YES" on the first line and then print exactly kk integers hihi (1≤hi≤n1≤hi≤n ) on the second line, where hihi is the house you visit on the ii -th move.

For each jj from 11 to k−1k−1 the following condition should be satisfied: hj≠hj+1hj≠hj+1 . Also h1≠1h1≠1 should be satisfied.

Examples

Input

Copy

10 2 15

Output

Copy

YES
10 4 

Input

Copy

10 9 45

Output

Copy

YES
10 1 10 1 2 1 2 1 6 

Input

Copy

10 9 81

Output

Copy

YES
10 1 10 1 10 1 10 1 10 

Input

Copy

10 9 82

Output

Copy

NO

思路:刚开始队友让我用dfs写,写了一会儿发现不对呀,能直接暴力的呀,结果一交,wa了,TAT

wa代码:没有考虑10 52 449 这种情况

#include<iostream>
#include<cstdio>//
#include<cmath>
using namespace std;
typedef long long int ll;//199979000100000
                         //200000000000000
ll s,y,sum,c,average,yu,n,m;
int main()
{
	while(cin>>n>>m>>c){
		s=(n-1)*m;//2 
		if(s<c||m>c) printf("NO\n");
		else{
			printf("YES\n"); 
			average=c/m;//10 2 15 得到7 
			yu=c-average*(m-1);//15-7==8
			printf("%d",yu+1);
			ll aa=yu+1-average,bb=yu+1;//aa==9-7=2,bb=8+1
			for(ll i=1;i<m;i++){
				if(i&1) cout<<" "<<aa;
				else cout<<" "<<bb;
			}
			printf("\n");
		}
	}
	return 0;	
}

实在是没想出来,参考了大神代码,点击

AC代码:

#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n, k, s;
    cin >> n >> k >> s;
    if(s<k || s>(n-1)*k){
        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << endl;
    int st=1;
    while(k--){//满足 (k-1 <= s-x) && (x <= n-1)
        int rm=min(s-k, n-1);// 
        s-=rm;
        if(st+rm<=n) st+=rm;
        else st-=rm;
        cout << st << " ";

    }
    cout << endl;
}

 

用代码解决这个问题The program committee of the school programming contests, which are often held at the Ural State University, is a big, joyful, and united team. In fact, they are so united that the time spent together at the university is not enough for them, so they often visit each other at their homes. In addition, they are quite athletic and like walking. Once the guardian of the traditions of the sports programming at the Ural State University decided that the members of the program committee spent too much time walking from home to home. They could have spent that time inventing and preparing new problems instead. To prove that, he wanted to calculate the average distance that the members of the program committee walked when they visited each other. The guardian took a map of Yekaterinburg, marked the houses of all the members of the program committee there, and wrote down their coordinates. However, there were so many coordinates that he wasn't able to solve that problem and asked for your help. The city of Yekaterinburg is a rectangle with the sides parallel to the coordinate axes. All the streets stretch from east to west or from north to south through the whole city, from one end to the other. The house of each member of the program committee is located strictly at the intersection of two orthogonal streets. It is known that all the members of the program committee walk only along the streets, because it is more pleasant to walk on sidewalks than on small courtyard paths. Of course, when walking from one house to another, they always choose the shortest way. All the members of the program committee visit each other equally often. Input The first line contains the number n of members of the program committee (2 ≤ n ≤ 105). The i-th of the following n lines contains space-separated coordinates xi, yi of the house of the i-th member of the program committee (1 ≤ xi, yi ≤ 106). All coordinates are integers. Output Output the average distance, rounded down to an integer, that a member of the program committee walks from his house to the house of his colleague.
05-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值