Codeforces Round #257 (Div. 2,

Source: Internet
Author: User

Codeforces Round #257 (Div. 2,
Problem AA. Jzzhu and Childrentime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

There areNChildren in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1N.I-Th child wants to get at leastAICandies.

Jzzhu asks children to line up. Initially,I-Th child stands atI-Th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm:

  1. GiveMCandies to the first child of the line.
  2. If this child still haven' t got enough candies, then the child goes to the end of the line, else the child go home.
  3. Repeat the first two steps while the line is not empty.

Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order?

Input

The first line contains two integersN, Bytes,M(1 digit ≤ DigitNLimit ≤ limit 100; 1 limit ≤ limitMLimit ≤0000100). The second line containsNIntegersA1, bytes,A2, middle..., middle ,...,AN(1 digit ≤ DigitAILimit ≤ limit 100 ).

Output

Output a single integer, representing the number of the last child.

Sample test (s) input
5 21 3 1 4 2
Output
4
Input
6 41 1 2 2 3 3
Output
6

Portal: Click to open the link

Idea of disintegration: simple question simulation. Use the queue to simulate this process.

Code:

#include <cstdio>#include <queue>using namespace std;typedef pair<int, int> P;queue<P> q;int main(){#ifndef ONLINE_JUDGEfreopen("257Ain.txt", "r", stdin);#endifint n, m, ans = 0;scanf("%d%d", &n, &m);for(int i = 0; i < n; i++){int x;scanf("%d", &x);q.push(P(x, i + 1));}while(!q.empty()){P p = q.front(); q.pop();if(p.first > m){p.first -= m;q.push(p);}ans = p.second;}printf("%d\n", ans);return 0;}


Problem B

B. Jzzhu and Sequencestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Jzzhu has sorted Ted a kind of sequences, they meet the following property:

You are givenXAndY, Please calculateFNModulo 1000000007 (109 rows + rows 7 ).

Input

The first line contains two integersXAndY(|X|, Bytes |Y| Limit ≤ limit 109). The second line contains a single integerN(1 digit ≤ DigitNLimit ≤ limit 2 · 109 ).

Output

Output a single integer representingFNModulo 1000000007 (109 rows + rows 7 ).

Sample test (s) input
2 33
Output
1
Input
0 -12
Output
1000000006

Portal: Click to open the link

Idea of disintegration: Derivation of simple mathematical formulas,

F (n) = f (n-1) + f (n + 1), f (n + 1) = f (n) + f (n + 2 );

The two formula is added as follows: f (n-1) + f (n + 2) = 0,

Push from the above formula: f (n + 2) + f (n + 5) = 0;

From the above two formula: f (n-1) = f (n + 5), so the period of f (n) is 6;

We only need to find the first six items of f. ps: note that f (n) may be negative, and mod should be added to the negative number for negative modulo, convert a negative number to a positive number and then perform the modulo operation.

Code:

#include <cstdio>const int mod = 1000000007;int main(){#ifndef ONLINE_JUDGE//freopen("257Bin.txt", "r", stdin);#endifint n, a [7];scanf("%d%d%d", &a[0], &a[1], &n);for(int i = 2; i < 7; i++)a[i] = a[i - 1] - a[i - 2];int t = a[(n - 1)% 6];printf("%d\n",  t >= 0 ? t % mod : (t + 2 * mod) % mod);return 0;}

Problem C

C. Jzzhu and Chocolatetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Jzzhu has a big rectangular chocolate bar that consistsNLimit × limitMUnit squares. He wants to cut this bar exactlyKTimes. Each cut must meet the following requirements:

  • Each cut shoshould be straight (horizontal or vertical );
  • Each cut shoshould go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut );
  • Each cut shoshould go inside the whole chocolate bar, and all cuts must be distinct.

The picture below shows a possible way to cut a 5 rows × six 6 chocolate for 5 times.

Imagine Jzzhu have madeKCuts and the big chocolate is splitted into several pieces. consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. what is the maximum possible area of smallest piece he can get with exactlyKCuts? The area of a chocolate piece is the number of unit squares in it.

Input

A single line contains three integersN, Bytes,M, Bytes,K(1 digit ≤ DigitN, Bytes,MLimit ≤ limit 109; 1 ≤ bytesKLimit ≤ limit 2 · 109 ).

Output

Output a single integer representing the answer. If it is impossible to cut the big chocolateKTimes, print-1.

Sample test (s) input
3 4 1
Output
6
Input
6 4 2
Output
8
Input
2 3 4
Output
-1
Portal: Click to open the link

Disintegration ideas:

N rows m column, in the horizontal direction to cut n-1 knife, vertical direction to cut at most m-knife, if k> n + m-2, is not cut; we can find the largest number of knives mx that can be switched in the horizontal or vertical direction. If k> mx, we can switch the mx knife in this direction now, the rest is to cut a (mn + 1) chocolate into a (k-mx) knife; the other is to either cut k knives along the horizontal direction, either it is to cut the k-knife along the vertical direction, and take the greater of the two.

Code:

#include <cstdio>#include <iostream>#include <algorithm>using namespace std;int main(){int n, m, k;long long ans = -1;cin >> n >> m >> k;if(k > n + m -2)ans = -1;else{int mx = max(n - 1, m - 1);int mn = min(n - 1, m - 1);if(k > mx)ans = (mn + 1) / (k - mx + 1);elseans = max(1ll * n / (k + 1) * m, 1ll * m / (k + 1) * n);}cout << ans << endl;return 0;}





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: info-contact@alibabacloud.com 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.