[Codeforces]1015D Walking Between Houses

題目URL:http://codeforces.com/contest/1015/problem/D
這題有個小技巧,就是將總數均分k份,不足的一些各加1。
記得特判(n-1)*k是否小於s


#include<bits/stdc++.h>
using namespace std;
#define int  long long
signed main()
{
     int a,b,c,num,mo,tot=1;
     cin >> a >> b >> c;
     if((a-1)*b<c || b>c) return cout << "NO" ,0;
     else
     {
          cout << "YES" << endl;
          num=c/b; mo=c%b;
          for(int i=0;i<b;i++)
          {
               if(mo==0)
               {
                    if(tot+num > a)
                    {
                         tot-=num;
                         cout << tot << " ";
                    }
                    else
                    {
                         tot+=num;
                         cout << tot << " ";     
                    }
               }
               else
               {
                    if(tot+num+1 > a)
                    {
                         tot-=num+1;
                         cout << tot << " ";
                    }
                    else
                    {
                         tot+=num+1;
                         cout << tot << " ";     
                    }
                    mo--;
               }
           }
          cout << endl;
     }
     return 0;
}

留言

這個網誌中的熱門文章

[ZJ] b229: TOI 2009 第一題:路徑問題

交大資工(APCS組)(面試&心得)

滿是挫傷的ION CAMP