P1383Theft-Black Pearl accepted Tags: monster thief kidd VS oibh[display tag]<textarea id="code" class="textbox" style=""></textarea>Background
Blame theft Kidd VS Oibh
Second words
Describe
This time the strange thief Kidd again against Oibh, the goal is black star! Kidd has broken through several layers of blockade, arrived
The OIBH headquarters to store Black star's room entrance. Oibh people are not daogaoyizhang, they're on the door.
Set a password. There are only two positive integer n,m on the password issue. Kidd has learned how to generate passwords. Is
I want you to help him figure out the password.
The build method is this:
Set an array of A[1..N] (n, which is the N in the above), is incremented by 1. n the number of N. Array S is
A sub-array (that is, the set S is a subset of set a). and the number of any two numbers in the array s is not by M integer
Except. The maximum number of s in the number is the password!
Format input Format
One line of two integers n,m
Output format
There is only one count Max, which is the password.
Example 1 sample input 1[copy]
50 7
Sample output 1[Copy]
23
Limit
1S per point
Tips
1<=n,m<=10000
Very simple Oh ~ ~
Source
From Maiev-The song of the Shadow;
Thank Kaito&aoko for providing test data
Elements of this topic:
Take 1....N to M for redundancy
Got 0.....m-1.
Obviously if 0 appeared, 0 can only appear once,
You can then find that the order in which the results are obtained from the remainder is as follows: 0. 5..m-1,0...5...m-1
So the number that appears before M/2 is definitely more than the number behind, and then because x + y = = M is not true
So all we have to do is take the number in the M/2 range.
#!/usr/bin/env python3#-*-coding:utf-8-*-import mathn, M = Map (Int,raw_input (). Split ()) L = []f = [0] * mfor i in range (1,n + 1): f[i% m] + = 1CNT = 0for i in range (1, M/2 + 1): cnt + f[i]if f[0]: cnt + = 1if m% 2 = = 0: if F[M/2]: cnt-= F[M/2]-1print CNT
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
vijos-p1383 Theft-Black Pearl (python + code optimization)