本文共 6056 字,大约阅读时间需要 20 分钟。
Problem Statement
Takahashi will participate in a programming contest, which lasts for TT minutes and presents NN problems.
With his extrasensory perception, he already knows that it will take AiAi minutes to solve the ii-th problem. He will choose zero or more problems to solve from the NN problems so that it takes him no longer than TT minutes in total to solve them. Find the longest possible time it takes him to solve his choice of problems.Constraints
Input
Input is given from Standard Input in the following format:
NN TTA1A1 …… ANAN
Output
Print the answer as an integer.
Sample Input 1
5 172 3 5 7 11
Sample Output 1
17
If he chooses the 11-st, 22-nd, 33-rd, and 44-th problems, it takes him 2+3+5+7=172+3+5+7=17 minutes in total to solve them, which is the longest possible time not exceeding T=17T=17 minutes.
Sample Input 2
6 1001 2 7 5 8 10
Sample Output 2
33
It is optimal to solve all the problems.
Sample Input 3
6 100101 102 103 104 105 106
Sample Output 3
0
He cannot solve any of the problems.
Sample Input 4
7 2735996816706927 91566569 89131517 71069699 75200339 98298649 92857057
Sample Output 4
273555143
If he chooses the 22-nd, 33-rd, and 77-th problems, it takes him 273555143273555143 minutes in total to solve them.
学到东西了这题是折半搜索+二分。看数据范围,如果硬搜,2^40肯定会死翘翘。但是我们知道2^20没事,所以就先2^20用于前半部分的数据,然后再用2^20用于最后一半的数据,然后排序后进行一个二分的选择就对了。
但是要注意!!!我也不知道怎么回事,如果小数据也折半的话就错了,但是小数据我正常搜索,大数据才折半就对了。以后折半搜索的题目的话, 大数据才折半!!!
代码:
#include#include #include #include #include #include #include #include #include #include #include #include #include
You are given a 4x4 grid. You play a game — there is a sequence of tiles, each of them is either 2x1 or 1x2. Your task is to consequently place all tiles from the given sequence in the grid. When tile is placed, each cell which is located in fully occupied row or column is deleted (cells are deleted at the same time independently). You can place tile in the grid at any position, the only condition is that tiles (and tile parts) should not overlap. Your goal is to proceed all given figures and avoid crossing at any time.
Input
The only line contains a string ss consisting of zeroes and ones (1≤|s|≤10001≤|s|≤1000). Zero describes vertical tile, one describes horizontal tile.
Output
Output |s||s| lines — for each tile you should output two positive integers r,cr,c, not exceeding 44, representing numbers of smallest row and column intersecting with it.
If there exist multiple solutions, print any of them.
Example
Input
010
Output
1 11 21 4
Note
Following image illustrates the example after placing all three tiles:
Then the first row is deleted:
今天的签到题,可是我没有签到。我硬做,直接模拟,总是卡在一个点上。
但是想想这道题,打竖放的我一直放最左边,只要一有两个我就抵消,那我不就一直占用了一个4*1的格子而已吗?
同理,打横的一直放右边两列,那我不就是只占用了2*4的格子吗?这两个互不干扰。
所以,直接,这么放就行了。
虽然想不到卡模拟的数据点,但是,是真的有可能会被卡掉。
代码:
#include#include using namespace std;int zero,one;int main(){ string st; cin>>st; for(int i=0;i
You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct.
You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines?
Input
The first line contains one integer n (1 ≤ n ≤ 105) — the number of points you are given.
Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≤ 109)— coordinates of i-th point. All n points are distinct.
Output
If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO.
Examples
Input
50 00 11 11 -12 2
Output
YES
Input
50 01 02 11 12 3
Output
NO
Note
In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points.
思维+计算几何
害,大一上学期解析几何卷面分有何用?遇到几何题目不也还是做不出来?
很明显,随便取三个点,必定会有其中两个点在同一条直线上。先把这一条直线的点全部找出来,然后判断剩下的点是否都在同一条直线即可。
也就是取第1,第2,第3三条线,两两check一次就可以了。
代码:
#include#include #include #include #include #include #include #include #include #include #include #include #include
转载地址:http://zdzg.baihongyu.com/