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)