zoukankan      html  css  js  c++  java
  • Codeforces758C

    C. Unfair Poll

    time limit per test:1 second
    memory limit per test:256 megabytes
    input:standard input
    output:standard output

    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 nmkx 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.

    Examples

    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;

    数学题, 做法很丑。

     1 //2017.01.20
     2 #include <iostream>
     3 #include <cstdio>
     4 #include <cstring>
     5 
     6 using namespace std;
     7 
     8 int main()
     9 {
    10     int n, m, x, y;
    11     long long k;
    12     long long maximum, minimum, cnt;
    13     while(cin>>n>>m>>k>>x>>y)
    14     {
    15         if(n==1){
    16             if(k%m==0)maximum = minimum = k/m;
    17             else{
    18                 maximum = k/m+1;
    19                 minimum = maximum-1;
    20             }
    21         }else{
    22             long long row = k/m;
    23             if(row*m != k)row++;
    24             if(n==2)maximum = (row+1)/n;
    25             else maximum = (row-2)/(n-1)+1;
    26             minimum = (row+n-2)/(2*n-2);
    27             if(minimum*(2*n-2) == (row+n-2) && row*m != k)
    28                   minimum--;
    29         }
    30         int pos = (x-1)*m+y;
    31         if(n==1)
    32         {
    33             if(pos <= k%m)cnt = maximum;
    34             else cnt = minimum;
    35         }else
    36         {
    37             long long cyc = k/(m*(2*n-2));
    38             cnt = (x==1||x==n) ? cyc : 2*cyc;
    39             long long other = k-cyc*(m*(2*n-2));
    40             if(other < pos)cnt+=0;
    41             else if(((n-1-x)*m+y)>(other-m*n)||(x==1||x==n))cnt+=1;
    42             else cnt+=2;
    43         }
    44 
    45         cout<<maximum<<" "<<minimum<<" "<<cnt<<endl;
    46         
    47     }
    48     
    49 
    50     return 0;
    51 }
  • 相关阅读:
    反向迭代
    c++知识点
    LeetCode-Count Bits
    LeetCode-Perfect Rectangle
    LeetCode-Perfect Squares
    LeetCode-Lexicographical Numbers
    LeetCode-Find Median from Data Stream
    LeetCode-Maximal Square
    LeetCode-Number of Digit One
    LeetCode-Combination Sum IV
  • 原文地址:https://www.cnblogs.com/Penn000/p/6322983.html
Copyright © 2011-2022 走看看