Unfair Poll CodeForces - 758C

On the Literature lesson Sergei noticed an awful injustice, it seems that some students are asked more often than others.

Seating in the class looks like a rectangle, where n rows with m pupils in each.

The teacher asks pupils in the following order: at first, she asks all pupils from the first row in the order of their seating, then she continues to ask pupils from the next row. If the teacher asked the last row, then the direction of the poll changes, it means that she asks the previous row. The order of asking the rows looks as follows: the 1-st row, the 2-nd row, ..., the n - 1-st row, the n-th row, the n - 1-st row, ..., the 2-nd row, the 1-st row, the 2-nd row, ...

The order of asking of pupils on the same row is always the same: the 1-st pupil, the 2-nd pupil, ..., the m-th pupil.

During the lesson the teacher managed to ask exactly k questions from pupils in order described above. Sergei seats on the x-th row, on the y-th place in the row. Sergei decided to prove to the teacher that pupils are asked irregularly, help him count three values:

  1. the maximum number of questions a particular pupil is asked,
  2. the minimum number of questions a particular pupil is asked,
  3. how many times the teacher asked Sergei.

If there is only one row in the class, then the teacher always asks children from this row.

Input

The first and the only line contains five integers n, m, k, x and y (1 ≤ n, m ≤ 100, 1 ≤ k ≤ 1018, 1 ≤ x ≤ n, 1 ≤ y ≤ m).

Output

Print three integers:

  1. the maximum number of questions a particular pupil is asked,
  2. the minimum number of questions a particular pupil is asked,
  3. how many times the teacher asked Sergei.
Example
Input
1 3 8 1 1
Output
3 2 3
Input
4 2 9 4 2
Output
2 1 1
Input
5 5 25 4 3
Output
1 1 1
Input
100 100 1000000000000000000 100 100
Output
101010101010101 50505050505051 50505050505051
Note

The order of asking pupils in the first test:

  1. the pupil from the first row who seats at the first table, it means it is Sergei;
  2. the pupil from the first row who seats at the second table;
  3. the pupil from the first row who seats at the third table;
  4. the pupil from the first row who seats at the first table, it means it is Sergei;
  5. the pupil from the first row who seats at the second table;
  6. the pupil from the first row who seats at the third table;
  7. the pupil from the first row who seats at the first table, it means it is Sergei;
  8. the pupil from the first row who seats at the second table;

The order of asking pupils in the second test:

  1. the pupil from the first row who seats at the first table;
  2. the pupil from the first row who seats at the second table;
  3. the pupil from the second row who seats at the first table;
  4. the pupil from the second row who seats at the second table;
  5. the pupil from the third row who seats at the first table;
  6. the pupil from the third row who seats at the second table;
  7. the pupil from the fourth row who seats at the first table;
  8. the pupil from the fourth row who seats at the second table, it means it is Sergei;
  9. the pupil from the third row who seats at the first table;

细节题,感觉自己就是改练这种题,我一般这种题,直接废掉,由于情况是在是太多。

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll INF=1e18;
/*
这道题WA了一万遍,简直吐血了,要不是看着测试数据,感觉指定就废了
但是还是想把自己的思路实现,发现真的很麻烦,想着能够一步到位可是
需要考虑的情况实在是太多,就是这个细节的问题,我不愿意写长代码
因为我怕忘了,自己的脑子,一看代码量十分大的话,就很痛苦,
逻辑直接就乱了,这个代码大改三遍,小改了无数遍
还是思路得到,不能一想就是了,我们要把极端想进来,自己构造测试数据,
自己心里有底了,我们再去提交代码,不要自己心里都没有底,就去提交,
白白的WA,很是痛苦啊
还有就是看见有人用二维数组模拟,感觉那个应该会更简单
*/

ll num[110];

int main()
{
   ll n,m,x,y;
   ll k;
   scanf("%I64d %I64d %I64d %I64d %I64d",&n,&m,&k,&x,&y);
   ll ans_max=0,ans_min=INF;
   ll ans_peo;
   if(n==1)
   {
       ll ans_time=k/m;
       ll ans_rest=k%m;
       ans_max=ans_min=ans_peo=ans_time;
       if(ans_rest)
       {
           if(y<=ans_rest)
              ans_peo=ans_time+1;
           ans_max++;
       }
   }
   else if(k<m)
   {
       if(k==0)
        ans_max=ans_min=ans_peo=0;
       else
       {
           ans_max=1;ans_min=ans_peo=0;
           if(y<=k&&x==1)
            ans_peo=1;
       }

   }
   else
   {
       ll one_time=(n-1)*m;
       ll ans_time=(k-m)/one_time;
       ll ans_rest=(k-m)%one_time;
       for(int i=2;i<=n-1;i++)
       {
           num[i]=ans_time;
       }
       if(ans_time&1)
       {
            num[1]= num[n]=(ans_time+1)/2;
            ans_max=max(ans_max,num[n]);
            ans_min=min(ans_min,num[n]);
            int i;
            int flag=0;
            for(i=n-1;i>=1;)
            {
                if(ans_rest>=m)
                {
                    ans_rest-=m;
                    num[i]++;
                }
                else if(ans_rest==0)
                {
                    ans_max=max(ans_max,num[i]);
                    ans_min=min(ans_min,num[i]);
                    break;
                }
                else if(ans_rest>0)
                {
                   num[i]++;
                   if(x==i&&y<=ans_rest)
                   {
                       ans_peo=num[i];
                       flag=1;
                   }
                   else if(x==i&&y>ans_rest)
                   {
                         ans_peo=num[i]-1;
                         flag=1;
                   }
                   ans_max=max(ans_max,num[i]);
                   ans_min=min(ans_min,num[i]-1);
                   i++;
                   break;
                }
                ans_max=max(ans_max,num[i]);
                ans_min=min(ans_min,num[i]);
                i--;
            }
            for(int j=i-1;j>=1;j--)
            {
                ans_max=max(ans_max,num[i]);
                ans_min=min(ans_min,num[i]);
            }
            if(!flag)
                ans_peo=num[x];
       }
       else
       {
           num[n]=num[1]=ans_time/2;
           num[1]++;
           //printf("num:%I64d\n",num[1]);
           ans_max=max(ans_max,num[1]);
           ans_min=min(ans_min,num[n]);
           int i;
           int flag=0;
           for(i=2;i<=n;)
           {
               if(ans_rest>=m)
               {
                   ans_rest-=m;
                   num[i]++;
               }
               else if(ans_rest==0)
               {
                   ans_max=max(ans_max,num[i]);
                   ans_min=min(ans_min,num[i]);
                   break;
               }
               else if(ans_rest>0)
               {
                   num[i]++;
                   if(x==i&&y<=ans_rest)
                   {
                        ans_peo=num[i];
                        flag=1;
                   }
                   else if(x==i&&y>ans_rest)
                   {
                         ans_peo=num[i]-1;
                         flag=1;
                   }
                   ans_max=max(ans_max,num[i]);
                   ans_min=min(ans_min,num[i]-1);
                   break;
               }
               ans_max=max(ans_max,num[i]);
               ans_min=min(ans_min,num[i]);
               i++;
           }
           for(int j=i+1;j<=n;j++)
           {
               ans_max=max(ans_max,num[i]);
               ans_min=min(ans_min,num[i]);
           }
           if(!flag)
            ans_peo=num[x];
       }
   }
   printf("%I64d %I64d %I64d\n",ans_max,ans_min,ans_peo);
   return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值