博客
关于我
SCAU2021春季个人排位赛第六场 (部分题解)
阅读量:369 次
发布时间:2019-03-04

本文共 6056 字,大约阅读时间需要 20 分钟。

A题

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

 

  • All values in input are integers.
  • 1≤N≤401≤N≤40
  • 1≤T≤1091≤T≤109
  • 1≤Ai≤1091≤Ai≤109

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
#include
using namespace std;int n,di1,di2,di;long long t,ans;long long a[50];long long sum1[100000006],s,sum2[100000006],sum[10000006];void ready(){ ios::sync_with_stdio(false),cin.tie(0); cin>>n>>t; for(int i=1;i<=n;i++) { cin>>a[i]; s+=a[i]; }}void work(){ for(int i=1;i<=n/2;i++) { sum1[++di1]=a[i]; for(int j=di1-1;j>=1;j--) if(a[i]+sum1[j]<=t) sum1[++di1]=a[i]+sum1[j]; } sort(sum1+1,sum1+di1+1); for(int i=n/2+1;i<=n;i++) { sum2[++di2]=a[i]; for(int j=di2-1;j>=1;j--) if(a[i]+sum2[j]<=t) sum2[++di2]=a[i]+sum2[j]; } for(int i=1;i<=di2;i++) { int l=0,r=di1,mid=(l+r)/2; while(l<=r) { mid=(l+r)/2; if(sum2[i]+sum1[mid]<=t) l=mid+1; else r=mid-1; } if(sum1[(l+r)/2]+sum2[i]<=t) ans=max(ans,sum1[(l+r)/2]+sum2[i]); } cout<
=1;j--) if(a[i]+sum[j]<=t) sum[++di]=a[i]+sum[j]; } sort(sum+1,sum+di+1); for(int i=di;i>=0;i--) if(sum[i]<=t) { cout<
20) work(); else work1(); return 0;}

 

 

 

D题

 

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

 

 

E题

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
#include
using namespace std;int n;struct E{ long long xi,yi;}a[100005];void ready(){ ios::sync_with_stdio(false),cin.tie(0); cin>>n; for(int i=1;i<=n;i++) cin>>a[i].xi>>a[i].yi;}bool f[100005];bool check_(int fir,int sec){ memset(f,false,sizeof(f)); f[fir]=true;f[sec]=true; for(int i=1;i<=n;i++) if(!f[i] && (a[fir].xi-a[sec].xi) * (a[fir].yi-a[i].yi) == (a[fir].xi-a[i].xi) * (a[fir].yi-a[sec].yi) ) f[i]=true; long long x1,x2,y1,y2,k=0; for(int i=1;i<=n;i++) if(!f[i]) { k++; if(k==3) break; f[i]=true; if(k==1) { x1=a[i].xi; y1=a[i].yi; } else { x2=a[i].xi; y2=a[i].yi; } } if(k<3) return true; for(int i=1;i<=n;i++) if(!f[i] && (y1-y2) * (x1-a[i].xi) != (x1-x2) * (y1-a[i].yi)) return false; return true;}void work(){ if(n<=3 || check_(1,2) || check_(1,3) || check_(2,3)) cout<<"YES"; else cout<<"NO";}int main(){ ready(); work(); return 0;}

 

 

转载地址:http://zdzg.baihongyu.com/

你可能感兴趣的文章
NHibernate示例
查看>>
nid修改oracle11gR2数据库名
查看>>
NIFI1.21.0/NIFI1.22.0/NIFI1.24.0/NIFI1.26.0_2024-06-11最新版本安装_采用HTTP方式_搭建集群_实际操作---大数据之Nifi工作笔记0050
查看>>
NIFI1.21.0_java.net.SocketException:_Too many open files 打开的文件太多_实际操作---大数据之Nifi工作笔记0051
查看>>
NIFI1.21.0_Mysql到Mysql增量CDC同步中_日期类型_以及null数据同步处理补充---大数据之Nifi工作笔记0057
查看>>
NIFI1.21.0_Mysql到Mysql增量CDC同步中_补充_插入时如果目标表中已存在该数据则自动改为更新数据_Postgresql_Hbase也适用---大数据之Nifi工作笔记0058
查看>>
NIFI1.21.0_Mysql到Mysql增量CDC同步中_补充_更新时如果目标表中不存在记录就改为插入数据_Postgresql_Hbase也适用---大数据之Nifi工作笔记0059
查看>>
NIFI1.21.0_NIFI和hadoop蹦了_200G集群磁盘又满了_Jps看不到进程了_Unable to write in /tmp. Aborting----大数据之Nifi工作笔记0052
查看>>
NIFI1.21.0_Postgresql和Mysql同时指定库_指定多表_全量同步到Mysql数据库以及Hbase数据库中---大数据之Nifi工作笔记0060
查看>>
NIFI1.21.0最新版本安装_连接phoenix_单机版_Https登录_什么都没改换了最新版本的NIFI可以连接了_气人_实现插入数据到Hbase_实际操作---大数据之Nifi工作笔记0050
查看>>
NIFI1.21.0最新版本安装_配置使用HTTP登录_默认是用HTTPS登录的_Https登录需要输入用户名密码_HTTP不需要---大数据之Nifi工作笔记0051
查看>>
NIFI1.21.0通过Postgresql11的CDC逻辑复制槽实现_指定表多表增量同步_增删改数据分发及删除数据实时同步_通过分页解决变更记录过大问题_02----大数据之Nifi工作笔记0054
查看>>
NIFI1.21.0通过Postgresql11的CDC逻辑复制槽实现_指定表多表增量同步_增加修改实时同步_使用JsonPath及自定义Python脚本_03---大数据之Nifi工作笔记0055
查看>>
NIFI1.21.0通过Postgresql11的CDC逻辑复制槽实现_指定表多表增量同步_插入修改删除增量数据实时同步_通过分页解决变更记录过大问题_01----大数据之Nifi工作笔记0053
查看>>
NIFI1.21.0通过Postgresql11的CDC逻辑复制槽实现_指定表或全表增量同步_实现指定整库同步_或指定数据表同步配置_04---大数据之Nifi工作笔记0056
查看>>
NIFI1.23.2_最新版_性能优化通用_技巧积累_使用NIFI表达式过滤表_随时更新---大数据之Nifi工作笔记0063
查看>>
NIFI从MySql中增量同步数据_通过Mysql的binlog功能_实时同步mysql数据_根据binlog实现update数据实时同步_实际操作05---大数据之Nifi工作笔记0044
查看>>
NIFI从MySql中增量同步数据_通过Mysql的binlog功能_实时同步mysql数据_根据binlog实现数据实时delete同步_实际操作04---大数据之Nifi工作笔记0043
查看>>
NIFI从MySql中增量同步数据_通过Mysql的binlog功能_实时同步mysql数据_配置binlog_使用处理器抓取binlog数据_实际操作01---大数据之Nifi工作笔记0040
查看>>
NIFI从MySql中增量同步数据_通过Mysql的binlog功能_实时同步mysql数据_配置数据路由_实现数据插入数据到目标数据库_实际操作03---大数据之Nifi工作笔记0042
查看>>