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

你可能感兴趣的文章
NIFI大数据进阶_NIFI的模板和组的使用-介绍和实际操作_创建组_嵌套组_模板创建下载_导入---大数据之Nifi工作笔记0022
查看>>
NIFI大数据进阶_NIFI监控功能实际操作_Summary查看系统和处理器运行情况_viewDataProvenance查看_---大数据之Nifi工作笔记0026
查看>>
NIFI大数据进阶_NIFI监控的强大功能介绍_处理器面板_进程组面板_summary监控_data_provenance事件源---大数据之Nifi工作笔记0025
查看>>
NIFI大数据进阶_NIFI集群知识点_认识NIFI集群以及集群的组成部分---大数据之Nifi工作笔记0014
查看>>
NIFI大数据进阶_NIFI集群知识点_集群的断开_重连_退役_卸载_总结---大数据之Nifi工作笔记0018
查看>>
NIFI大数据进阶_使用NIFI表达式语言_来获取自定义属性中的数据_NIFI表达式使用体验---大数据之Nifi工作笔记0024
查看>>
NIFI大数据进阶_内嵌ZK模式集群1_搭建过程说明---大数据之Nifi工作笔记0015
查看>>
NIFI大数据进阶_内嵌ZK模式集群2_实际操作搭建NIFI内嵌模式集群---大数据之Nifi工作笔记0016
查看>>
NIFI大数据进阶_外部ZK模式集群1_实际操作搭建NIFI外部ZK模式集群---大数据之Nifi工作笔记0017
查看>>
NIFI大数据进阶_实时同步MySql的数据到Hive中去_可增量同步_实时监控MySql数据库变化_实际操作_03---大数据之Nifi工作笔记0035
查看>>
NIFI大数据进阶_实时同步MySql的数据到Hive中去_可增量同步_实时监控MySql数据库变化_操作方法说明_01---大数据之Nifi工作笔记0033
查看>>
NIFI大数据进阶_实时同步MySql的数据到Hive中去_可增量同步_实时监控MySql数据库变化_操作方法说明_02---大数据之Nifi工作笔记0034
查看>>
NIFI大数据进阶_离线同步MySql数据到HDFS_01_实际操作---大数据之Nifi工作笔记0029
查看>>
NIFI大数据进阶_离线同步MySql数据到HDFS_02_实际操作_splitjson处理器_puthdfs处理器_querydatabasetable处理器---大数据之Nifi工作笔记0030
查看>>
NIFI大数据进阶_离线同步MySql数据到HDFS_说明操作步骤---大数据之Nifi工作笔记0028
查看>>
NIFI大数据进阶_连接与关系_设置数据流负载均衡_设置背压_设置展现弯曲_介绍以及实际操作---大数据之Nifi工作笔记0027
查看>>
NIFI数据库同步_多表_特定表同时同步_实际操作_MySqlToMysql_可推广到其他数据库_Postgresql_Hbase_SqlServer等----大数据之Nifi工作笔记0053
查看>>
NIFI汉化_替换logo_二次开发_Idea编译NIFI最新源码_详细过程记录_全解析_Maven编译NIFI避坑指南001---大数据之Nifi工作笔记0068
查看>>
NIFI汉化_替换logo_二次开发_Idea编译NIFI最新源码_详细过程记录_全解析_Maven编译NIFI避坑指南002---大数据之Nifi工作笔记0069
查看>>
NIFI集群_内存溢出_CPU占用100%修复_GC overhead limit exceeded_NIFI: out of memory error ---大数据之Nifi工作笔记0017
查看>>