http://blog.csdn.net/queuelovestack/article/details/53055418php
下午重現了一下大連賽區的比賽,感受有點神奇,重現時竟然改了現場賽的數據範圍,本來過的人數比較多的題結果重現過的變少了,而本來現場賽全場過的人最少的題重現作出的人反而多了一堆,不過仍是不影響最水的6題,然而殘酷的現實是6題纔有機會拿銅...(╥╯^╰╥)java
連接→2016ACM/ICPC亞洲區大連站-重現賽node
Accept: 0 Submit: 0
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
ios
Nowadays, at least one wrestling match is held every year in our country. There are a lot of people in the game is "good player」, the rest is "bad player」. Now, Xiao Ming is referee of the wrestling match and he has a list of the matches in his hand. At the same time, he knows some people are good players,some are bad players. He believes that every game is a battle between the good and the bad player. Now he wants to know whether all the people can be divided into "good player" and "bad player". git
Input contains multiple sets of data.For each set of data,there are four numbers in the first line:N (1 ≤ N≤ 1000)、M(1 ≤M ≤ 10000)、X,Y(X+Y≤N ),in order to show the number of players(numbered 1toN ),the number of matches,the number of known "good players" and the number of known "bad players".In the next M lines,Each line has two numbersa, b(a≠b) ,said there is a game between a and b .The next line has X different numbers.Each number is known as a "good player" number.The last line contains Y different numbers.Each number represents a known "bad player" number.Data guarantees there will not be a player number is a good player and also a bad player.app
If all the people can be divided into "good players" and "bad players」, output "YES", otherwise output "NO".ide
解題思路:svg
【題意】優化
這個題目意思,感受仍是存疑的( ̄へ ̄),我只能以本人過了此題的想法來解釋ui
N個選手,M場摔跤比賽,已知N個選手中有X個選手是"good player",Y個選手是"bad player"
問是否能夠將N個選手劃分紅"good player"和"bad player"兩個陣營,使得每場摔跤比賽的兩位選手一定是一位來自"good player",一位來自"bad player"
【類型】
搜索(bfs or dfs)
【分析】
有挺多人要求解釋樣例的,由於不太明白爲啥不告訴2是哪個陣營就沒法劃分陣營了?明明(1,5)和(3,4)也不知道是哪一陣營
可是,咱們能夠這樣理解一下,即使我不知道(1,5)是屬於"good player"陣營仍是屬於"bad player"陣營,他們只能屬於一種陣營
而2是沒有告訴你和其餘選手的關係,那麼2能夠同屬於兩個陣營,顯然這與題目要求" there will not be a player number is a good player and also a bad player"不符
好了,接下來說作法,首先考慮已經告訴你是哪一個陣營的選手A,那麼和A選手比賽的選手B一定對立陣營的,若選手B和選手A是同一陣營,那顯然是沒法繼續劃分的,bfs or dfs一下,將已知陣營的選手肯定
而後開始處理未知陣營但有比賽的選手,咱們徹底能夠假設其中一方爲"good player",那麼另外一方就是"bad player",接着仍是bfs or dfs判斷
處理完以後,再遍歷一遍每一個選手,看是否還有未知陣營的選手存在便可
重現的時候被本身蠢哭了,(ಥ _ ಥ),由於每輸入一個已知陣營的選手,我都會去搜索判一次,而後遇到衝突就break了,致使題目尚未徹底輸入就被我結束了,因而WA了好幾發,心疼本身
【時間複雜度&&優化】
O(n)
Accept: 0 Submit: 0
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Given two positive integers a and b,find suitable X and Y to meet the conditions:
X+Y=a
Least Common Multiple (X, Y) =b
Input includes multiple sets of test data.Each test data occupies one line,including two positive integers a(1≤a≤2*10^4),b(1≤b≤10^9),and their meanings are shown in the description.Contains most of the 12W test cases.
For each set of input data,output a line of two integers,representing X, Y.If you cannot find such X and Y,output one line of "No Solution"(without quotation).
解題思路:
【題意】
給你兩個整數a和b
求X和Y,知足X+Y=a,且LCM(X,Y)=b [LCM(X,Y)表示X和Y的最小公倍數]
若不存在,輸出"No Solution"
不然輸出X最小的解
【類型】
數學推導題
【分析】
現場賽的時候,咋看一眼感受是水題啊,a的範圍才10^4,那我枚舉一下X和Y,而後判斷它們的最小公倍數是否是b不就完事了?
但看作的人並很少,又仔細看了下題,發現題目組數有點多,12萬,好吧,放棄暴力枚舉
首先,學過最小公倍數的咱們知道,兩數之積等於兩數的最大公約數乘最小公倍數,用式子表示以下
X*Y=LCM(X,Y)*GCD(X,Y)
因而,咱們不妨假設GCD(X,Y)=k,那麼咱們能夠知道
假設X≥Y,則
這個方程組仍是好解的
無解的狀況有以下三種(知足任意一種都是無解):
【時間複雜度&&優化】
O(1)
題目連接→HDU 5974 A Simple Math Problem
Accept: 0 Submit: 0
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
In a highly developed alien society, the habitats are almost infinite dimensional space.
In the history of this planet,there is an old puzzle.
You have a line segment with x units’ length representing one dimension.The line segment can be split into a number of small line segments: a1,a2, … (x= a1+a2+…) assigned to different dimensions. And then, the multidimensional space has been established. Now there are two requirements for this space:
1.Two different small line segments cannot be equal ( ai≠aj when i≠j).
2.Make this multidimensional space size s as large as possible (s= a1∗a2*...).Note that it allows to keep one dimension.That's to say, the number of ai can be only one.
Now can you solve this question and find the maximum size of the space?(For the final number is too large,your answer will be modulo 10^9+7)
The first line is an integer T,meaning the number of test cases.
Then T lines follow. Each line contains one integer x.
1≤T≤10^6, 1≤x≤10^9
Maximum s you can get modulo 10^9+7. Note that we wants to be greatest product before modulo 10^9+7.
解題思路:
【題意】
給定一個天然數x,讓你給出一種拆分方式x=a1+a2+...(ai≠aj),使得每一個小部分的乘積s=a1*a2*...最大
【類型】
貪心構造
【分析】
此題關鍵在於得出如何能使乘積s最大
按照以往經驗,必然是取一段連續天然數可以使得乘積最大,而這段連續天然數可從2開始(爲啥不從1開始?從1開始還不如將這個1給這段連續天然數的最後一個數),因而咱們能夠獲得形如2+3+4+...+k(k=2,3,...)的式子,而x是10^9內的任意整數,咱們不可能剛好可以湊成連續天然數之和,可能會多出△x
而這個△x的值,我能夠保證它的範圍爲0≤△x≤k,相信大於等於0仍是好理解的,爲何會小於等於k呢?由於當它大於k時,原式不是能夠增長一項?即2+3+4+...+k+(k+1)
那麼多出來的△x怎麼處理呢?顯然是從後往前均攤給連續天然數中的(k-1)個數,爲啥從後往前?由於若咱們從前日後,老是會使連續天然數重複,很差處理
因而,在咱們分配完△x以後,咱們大體會獲得下述兩種式子:
①2*3*...*(i-1)*(i+1)*...*k*(k+1)
②3*4*...*i*(i+1)*...*k*(k+2)
顯然,咱們要計算此結果,能夠藉助階乘,而階乘中缺失的項,咱們除掉就能夠了,那麼便會涉及除法取模,顯然須要用到乘法逆元
作法講解完畢,如下是爲何連續段乘積最大的大概證實:
【時間複雜度&&優化】
O(logn)
題目連接→HDU 5976 Detachment
Accept: 0 Submit: 0
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
A box contains black balls and a single red ball. Alice and Bob draw balls from this box without replacement, alternating after each draws until the red ball is drawn. The game is won by the player who happens to draw the single red ball. Bob is a gentleman and offers Alice the choice of whether she wants to start or not. Alice has a hunch that she might be better off if she starts; after all, she might succeed in the first draw. On the other hand, if her first draw yields a black ball, then Bob’s chances to draw the red ball in his first draw are increased, because then one black ball is already removed from the box. How should Alice decide in order to maximize her probability of winning? Help Alice with decision.
Multiple test cases (number of test cases≤50), process till end of input.
For each case, a positive integer k (1≤k≤10^5) is given on a single line.
For each case, output:
1, if the player who starts drawing has an advantage
2, if the player who starts drawing has a disadvantage
0, if Alice's and Bob's chances are equal, no matter who starts drawing
on a single line.
解題思路:
【題意】
箱子裏有1個紅球和k個黑球
Alice和Bob輪流不放回地從箱子裏隨機取出一個球
當某人取到紅球時得到勝利,遊戲結束
問先手是否獲勝概率更大,概率更大,輸出"1";概率更小,輸出"2";概率相等,輸出"0"
【類型】
機率水題
【分析】
此題關鍵仍是要多嘗試,手動計算一下
當k=1時,一個紅球和一個黑球,先手獲勝的機率P爲
當k=2時,一個紅球和兩個黑球,先手獲勝的機率P爲
當k=3時,一個紅球和三個黑球,先手獲勝的機率P爲
故,當k時,先手獲勝的機率P爲
那我只需判斷二者大小關係便可
【時間複雜度&&優化】
O(1)
題目連接→HDU 5978 To begin or not to begin
Accept: 0 Submit: 0
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
We have a special convex that all points have the same distance to origin point.
As you know we can get N segments after linking the origin point and the points on the convex. We can also get N angles between each pair of the neighbor segments.
Now give you the data about the angle, please calculate the area of the convex
There are multiple test cases.
The first line contains two integer N and D indicating the number of the points and their distance to origin. (3 <= N <= 10, 1 <= D <= 10)
The next lines contain N integers indicating the angles. The sum of the N numbers is always 360.
For each test case output one float numbers indicating the area of the convex. The printed values should have 3 digits after the decimal point.
解題思路:
【題意】
二維座標中有N個點,它們到原點的距離均爲D
將這N個點分別與原點相連,如今告訴你任意相鄰兩條線段的夾角爲θi,求這N個點構成的凸包面積(N邊形面積)
【類型】
三角形面積水題
【分析】
題目大概樣子以下
由圖可知,n邊形的面積能夠拆分紅n個三角形面積之和
而已知每一個三角形的兩邊及兩邊夾角,咱們能夠經過三角形面積公式算出每一個三角形的面積,相加之和即是最終的n邊形面積
因爲math.h頭文件中封裝的sin運算是以弧度制來計算的,而題目所給的是角度制,故咱們還需多一步角度轉弧度
【時間複雜度&&優化】
O(1)
題目連接→HDU 5979 Convex
Accept: 0 Submit: 0
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
As is known to all,the ASCII of character 'a' is 97. Now,find out how many character 'a' in a group of given numbers. Please note that the numbers here are given by 32 bits’ integers in the computer.That means,1digit represents 4 characters(one character is represented by 8 bits’ binary digits).
The input contains a set of test data.The first number is one positive integer N (1≤N≤100),and then N positive integersai (1≤ ai≤2^32 - 1) follow
Output one line,including an integer representing the number of 'a' in the group of given numbers.
解題思路:
【題意】
給你n個32位整數,每一個整數能夠表示成4個字符(由於一個字符在計算機中佔8位),問n個整數共包含多少個字符'a'
【類型】
簽到題
【分析】
因爲一個字符佔二進制8位,因此每一個整數至關於轉化爲2^8=256進制數
那麼將32位整數循環對256取模,看是否是97(字符'a')便可
其中須要注意的一點是,2^32-1已經超過了int型的範圍,故須定義成 __int64 或 long long
int型的最大值爲2^31-1
【時間複雜度&&優化】
O(1)