博客
关于我
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/

你可能感兴趣的文章
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
查看>>
NIFI从MySql中增量同步数据_通过Mysql的binlog功能_实时同步mysql数据_配置数据路由_生成插入Sql语句_实际操作02---大数据之Nifi工作笔记0041
查看>>
NIFI从MySql中离线读取数据再导入到MySql中_03_来吧用NIFI实现_数据分页获取功能---大数据之Nifi工作笔记0038
查看>>
NIFI从MySql中离线读取数据再导入到MySql中_不带分页处理_01_QueryDatabaseTable获取数据_原0036---大数据之Nifi工作笔记0064
查看>>
NIFI从MySql中离线读取数据再导入到MySql中_无分页功能_02_转换数据_分割数据_提取JSON数据_替换拼接SQL_添加分页---大数据之Nifi工作笔记0037
查看>>
NIFI从Oracle11G同步数据到Mysql_亲测可用_解决数据重复_数据跟源表不一致的问题---大数据之Nifi工作笔记0065
查看>>
NIFI从PostGresql中离线读取数据再导入到MySql中_带有数据分页获取功能_不带分页不能用_NIFI资料太少了---大数据之Nifi工作笔记0039
查看>>
nifi使用过程-常见问题-以及入门总结---大数据之Nifi工作笔记0012
查看>>
NIFI分页获取Mysql数据_导入到Hbase中_并可通过phoenix客户端查询_含金量很高的一篇_搞了好久_实际操作05---大数据之Nifi工作笔记0045
查看>>
NIFI分页获取Postgresql数据到Hbase中_实际操作---大数据之Nifi工作笔记0049
查看>>
NIFI同步MySql数据_到SqlServer_错误_驱动程序无法通过使用安全套接字层(SSL)加密与SQL Server_Navicat连接SqlServer---大数据之Nifi工作笔记0047
查看>>
NIFI同步MySql数据源数据_到原始库hbase_同时对数据进行实时分析处理_同步到清洗库_实际操作06---大数据之Nifi工作笔记0046
查看>>
Nifi同步过程中报错create_time字段找不到_实际目标表和源表中没有这个字段---大数据之Nifi工作笔记0066
查看>>
【Flink】Flink 1.9 版本 web UI 突然没有日志
查看>>
NIFI大数据进阶_FlowFile拓扑_对FlowFile内容和属性的修改删除添加_介绍和描述_以及实际操作---大数据之Nifi工作笔记0023
查看>>
NIFI大数据进阶_FlowFile生成器_GenerateFlowFile处理器_ReplaceText处理器_处理器介绍_处理过程说明---大数据之Nifi工作笔记0019
查看>>