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

你可能感兴趣的文章
Nginx反向代理
查看>>
nginx反向代理、文件批量改名及统计ip访问量等精髓总结
查看>>
Nginx反向代理与正向代理配置
查看>>
Nginx反向代理及负载均衡实现过程部署
查看>>
Nginx反向代理和负载均衡部署指南
查看>>
Nginx反向代理是什么意思?如何配置Nginx反向代理?
查看>>
nginx反向代理解决跨域问题
查看>>
nginx反向代理解决跨域问题,使本地调试更方便
查看>>
nginx反向代理转发、正则、重写、负摘均衡配置案例
查看>>
Nginx反向代理配置
查看>>
Nginx启动SSL功能,并进行功能优化,你看这个就足够了
查看>>
nginx启动脚本
查看>>
Nginx和Tomcat的区别
查看>>
Nginx在Windows上和Linux上(Docker启动)分别配置基本身份认证示例
查看>>
Nginx在Windows下载安装启动与配置前后端请求代理
查看>>
Nginx在开发中常用的基础命令
查看>>
Nginx基础知识点与使用场景梳理
查看>>
Nginx多域名,多证书,多服务配置,实用版
查看>>
nginx如何实现图片防盗链
查看>>
Nginx学习总结(10)——Nginx前后端分离将多个请求转发到多个Tomcat,负载均衡反向代理
查看>>