Unfair Poll CodeForces

来源:互联网 发布:牛贝 微信淘宝客 编辑:程序博客网 时间:2024/06/05 20:10

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 withm 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: the1-st row, the 2-nd row,..., the n - 1-st row, then-th row, the n - 1-st row,..., the 2-nd row, the1-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 thex-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;}



原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 初中二年级贪玩游戏说不听怎么办 孩子上课经常和别的同学说话怎么办 小孩五年级了上课坐不住怎么办 孩子老是纠结小事抓不住重点怎么办 没文化不懂教不了孩孑怎么办 孩孑学习不好老师不让上课怎么办 5个月婴儿睡得少怎么办 教育案例——幼儿爱打小报告怎么办 上班的时候同事老是爱插话怎么办 孕晚期右侧卧睡觉宝宝好动怎么办 乐扣玻璃碗盖子长霉怎么办 乐扣保鲜盒密封圈有异味怎么办 8个月的宝宝不吃饭怎么办 宝宝十一个月了不爱吃饭怎么办 一岁八个月宝宝不爱吃饭怎么办 14个月的宝宝不爱吃饭怎么办 宝宝一岁多又黑又瘦又小该怎么办? 15个月宝宝偏瘦该怎么办 早期肺癌手术后身体瘦该怎么办 4个月婴儿的眼里有触摸糊怎么办 七个月宝宝断奶不喝奶粉怎么办 2个月的宝宝抓头怎么办 4岁宝宝吃东西一点都不认真怎么办 猫吐了白色黏液或泡沫怎么办 六个月的宝宝拉肚子老不好怎么办 小狗狗呕吐后拉肚子带血怎么办 八个月宝宝拉肚子拉出点血怎么办 在饿了么点外卖吃出虫子怎么办 1岁半宝宝拉肚子拉水怎么办 五个多月宝宝拉鼻涕便怎么办 一岁宝宝拉鼻涕样大便怎么办 宝宝拉粘液大便鼻涕状的怎么办 十个月宝宝拉鼻涕一样大便怎么办 7个月宝宝咳嗽反反复复发热怎么办 婴儿3个月突然不吃奶瓶怎么办? 2个月婴儿突然不肯用奶瓶怎么办 喝母乳的宝宝不喝奶瓶怎么办 三个月宝宝不喝奶瓶母乳不够怎么办 七个多月的宝宝不吃辅食怎么办 婴儿光认奶粉不认母乳怎么办 宝宝11个月断奶不吃奶瓶怎么办