Codeforces 758c:unfair Poll (thinking + Simulation)

Source: Internet
Author: User


Test instructions: There are n rows of m in the classroom, and the teacher calls from the first row to the next point, until the point to the first row of M row, from the first row of the second column starting point, when the name of the nth column, then click the name of the N-1 column. And so on, from the column: 1,2,3,4,......,n,n-1,n-2,......,1, 2, .... In this order roll-call. The teacher in the Class A total of K, ask the class can point to the same number of students how many times, at least can point the same number of classmates, point the location for (x, y) students how many times name.

Idea: It's a bit metrorrhagia to meet this problem. Convinced that it is a formula can be made out of the topic, and then wrote a page of grass paper, even the sample is not enough, at a loss. After the game want to look at other people's formula, the results have been seen through the calculation + simulation. Since the use of computer, in accordance with the time complexity of the case with simulation help calculation, as if there is no problem ah. (Why am I directly convinced that I'm going to push the formula, and it doesn't seem like the first time I've made such a mistake?)

First of all to pay attention to the column order, as if a lot of people did not read the topic (even if I understand the egg), assuming that N is 4, then the order is 1,2,3,4,3,2,1,2,3, .... So, a period from the column is (n+n-2), because when n = 1, this is equal to 0, so the case of n = 1 is a special sentence. If n = 1, then each time is a point this row, the most people are forget k/m times, the remainder with k% m from the first row to simulate plus, until the remainder becomes 0. If n > 1, then the number of the 1th and nth columns per periodic point is only once, and the number of points 2~n-1 is two times, then the number of cycles that can be ordered = k/m/(n+n-2), then the remainder is simulated with K (M * (n+n-2)). Since the initial start is from the first column, it starts from the first column.

1#include <cstdio>2#include <algorithm>3#include <iostream>4#include <cstring>5#include <string>6#include <cmath>7#include <queue>8#include <vector>9#include <map>Ten#include <Set> One#include <stack> A using namespacestd; - #defineINF 0x3f3f3f3f - #defineN 100010 thetypedefLong LongLL; -LL mp[ the][ the]; -  - intMain () { +     intx, y, N, M; - LL K; +CIN >> n >> m >> k >> x >>y; ALL mi =-1, MA =-1; at     if(n = =1) { -LL Yu = k%m; -LL cnt = k/m; -          for(inti =1; I <= m; i++) mp[1][i] + =CNT; -          for(inti =1; I <= m; i++) -             if(Yu) mp[1][i]++, yu--; in}Else { -LL num = (n + N-2) *m; toLL cnt = k/num;//Number of Cycles +LL Yu = k%num; -          for(inti =1; I <= N; i++) the              for(intj =1; J <= M; J + +) *                 if(i = =1|| i = = N) mp[i][j] + =CNT; $                 ElseMP[I][J] + = CNT *2;Panax Notoginseng          for(inti =1; I <= N; i++) -              for(intj =1; J <= M; J + +) the                 if(Yu) mp[i][j]++, yu--; +          for(inti = n-1; I >=1; i--) A              for(intj =1; J <= M; J + +) the                 if(Yu) mp[i][j]++, yu--; +     } -      for(inti =1; I <= N; i++) { $          for(intj =1; J <= M; J + +) { $             if(Ma < mp[i][j]) Ma =Mp[i][j]; -             if(Mi = =-1|| Mi > mp[i][j]) mi =Mp[i][j]; -         } the     } -printf"%i64d%i64d%i64d\n", MA, MI, mp[x][y]);Wuyi     return 0; the}

Codeforces 758c:unfair Poll (thinking + Simulation)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.