codeforces #392 div2 C.Unfair Poll

题目

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 ≤ 1e18, 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.

分析

题意本身是老师点名的顺序是从第一排点到最后一排在逆序点到第一排,每排都是从第一个点到最后一个,让你求点名最多的点了多少次,点名最少的点了多少次,和一个指定的位置点了多少次。
  比赛的时候一边过了,赛后重测跪了,后来发现果然有更稳妥的写法,我原来写的是直接去算最大值,最小值,某个位置的值,需要考虑的细节太多,确实容易跪。后来直接开一个二维数组记录每个人被点到的次数,然后先初始化为0,再去考虑整次的加上循环次数,最后一次的时候手动加,这样就不会在时间上爆掉,也比较稳妥。

ac代码

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;

const int inf = 1e9 + 7;
const int inff = 1e8 + 7;
int main(){
    int n; 
    cin >> n;
    int maxx = inf; int minn = 0;
    int num, d;
    bool text = 1;
    for(int i = 0; i < n; i++){
        cin >> num >> d;
        if(d == 1){
            if(minn < 1900) minn = 1900;
            else{
                if(maxx < 1900)
                    text = 0;
            }
        }
        if(d == 2){
            if(maxx >= 1900) maxx = 1899;
            else {
                if(minn >= 1900)
                    text = 0;
            }
        }
        minn += num;
        maxx += num;
    }
    //cout << maxx << " " << minn << endl;
    if(maxx < minn) text = 0;
    if(text == 0) cout << "Impossible" << endl;
    else if(maxx > inff) cout << "Infinity" << endl;
    else cout << maxx << endl;
    return 0;
}

你可能感兴趣的:(codeforces #392 div2 C.Unfair Poll)