【POJ - 3347 】Kadj Squares (计算几何,思维 或 扫描线)

题干:

In this problem, you are given a sequence S1, S2, ..., Sn of squares of different sizes. The sides of the squares are integer numbers. We locate the squares on the positive x-y quarter of the plane, such that their sides make 45 degrees with x and y axes, and one of their vertices are on y=0 line. Let bi be the x coordinates of the bottom vertex of Si. First, put S1 such that its left vertex lies on x=0. Then, put S1, (i > 1) at minimum bi such that

  • bi > bi-1 and
  • the interior of Si does not have intersection with the interior of S1...Si-1.

 

 

The goal is to find which squares are visible, either entirely or partially, when viewed from above. In the example above, the squares S1, S2, and S4 have this property. More formally, Si is visible from above if it contains a point p, such that no square other than Siintersect the vertical half-line drawn from p upwards.

Input

The input consists of multiple test cases. The first line of each test case is n (1 ≤ n ≤ 50), the number of squares. The second line contains n integers between 1 to 30, where the ith number is the length of the sides of Si. The input is terminated by a line containing a zero number.

Output

For each test case, output a single line containing the index of the visible squares in the input sequence, in ascending order, separated by blank characters.

Sample Input

4
3 5 1 4
3
2 1 2
0

Sample Output

1 2 4
1 3

解题报告:

     扫描线忘了啊,不然就试试扫描线了。

AC代码:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 200 + 5;
struct Node {ll l,r;ll s;//边长 
} node[MAX],nnnn[MAX];
ll Abs(ll x) {if(x < 0) x=-x;return x;
}
int main()
{int n;while(~scanf("%d",&n) && n) {for(int i = 1; i<=n; i++) {scanf("%lld",&node[i].s);node[i].l = 0;//先初始化一波for(int j = 1; j<i; j++) {node[i].l = max(node[i].l,node[j].r - (ll)Abs(node[j].s-node[i].s));} node[i].r = node[i].l + 2*node[i].s;}for(int i = 1; i<=n; i++) {
//			nnnn[i] = node[i];//这个必须有、、、、 for(int j = 1; j<i; j++) {if(node[i].l  < node[j].r && node[i].s < node[j].s) {node[i].l = node[j].r;//即左边只能看到  这里  这么远// }}for(int j = i+1; j<=n; j++) {if(node[i].r > node[j].l && node[i].s < node[j].s) {node[i].r = node[j].l;}}}int flag = 1;for(int i = 1; i<=n; i++) {if(node[i].l < node[i].r) {if(flag) {flag=0;printf("%d",i);}else printf(" %d",i);		}}puts("");}return 0 ;}

想问为什么这样就wa????两者就那一个地方有区别(node或者nnnn)

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 200 + 5;
struct Node {ll l,r;ll s;//边长 
} node[MAX],nnnn[MAX];
ll Abs(ll x) {if(x < 0) x=-x;return x;
}
int main()
{int n;while(~scanf("%d",&n) && n) {for(int i = 1; i<=n; i++) {scanf("%lld",&node[i].s);node[i].l = 0;//先初始化一波for(int j = 1; j<i; j++) {node[i].l = max(node[i].l,node[j].r - (ll)Abs(node[j].s-node[i].s));} node[i].r = node[i].l + 2*node[i].s;}for(int i = 1; i<=n; i++) {nnnn[i] = node[i];//这个必须有、、、、 for(int j = 1; j<i; j++) {if(node[i].l  < node[j].r && node[i].s < node[j].s) {nnnn[i].l = node[j].r;//即左边只能看到  这里  这么远// }}for(int j = i+1; j<=n; j++) {if(node[i].r > node[j].l && node[i].s < node[j].s) {nnnn[i].r = node[j].l;}}}int flag = 1;for(int i = 1; i<=n; i++) {if(nnnn[i].l < nnnn[i].r) {if(flag) {flag=0;printf("%d",i);}else printf(" %d",i);		}}puts("");}return 0 ;}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441343.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

按钮开关java代码,Android自定义实现开关按钮代码

我们在应用中经常看到一些选择开关状态的配置文件&#xff0c;做项目的时候用的是android的Switch控件&#xff0c;但是感觉好丑的样子子个人认为还是自定义的比较好&#xff0c;先上个效果图&#xff1a;实现过程&#xff1a;1.准备开关不同状态的两张图片放入drawable中。2.x…

*【CodeForces - 202C 】Clear Symmetry (思维,找规律,特判)

题干&#xff1a; Consider some square matrix A with side n consisting of zeros and ones. There are nrows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. Well denote the element of the matrix wh…

*【CodeForces - 768B】Code For 1 (分治策略,模拟二分思想,模拟线段树思想)

题干&#xff1a; Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the decease…

matlab 自适应噪声对消,基于Matlab的RLS自适应语音噪声对消系统的设计与实现

基于Matlab 的R LS 自适应语音噪声对消系统的设计与实现①肖 哲(湖南工业大学科技学院, 湖南株洲 412008)摘 要:自适应信号处理的理论和技术经过40多年的发展和完善,已逐渐成为人们常用的语音去噪技术.而Matlab 的出现又为其提供了更为方便快捷的方法来对语音信号进行消噪处…

贪心算法 -- 最小延迟调度

转自&#xff1a;https://blog.csdn.net/bqw18744018044/article/details/80285414 总结&#xff1a; 首先&#xff0c;证明贪心的时候交换论证是万能的&#xff01;其次&#xff0c;这一点如果要满足&#xff0c;也就是&#xff0c;如果你要用交换论证法&#xff0c;那么首先…

apache2+支持php7,Ubuntu14.04下配置PHP7.0+Apache2+Mysql5.7

Apache步骤一&#xff1a;安装apacheronyaoubuntu:~$ sudo apt install apache2安装好后&#xff0c;在浏览器上输入localhost(服务器端&#xff0c;请输入你的IP地址)&#xff0c;回车就会看到&#xff1a;PHP7.0步骤二&#xff1a;Ubuntu14.04下的默认源是PHP5.0&#xff0c;…

【CodeForces - 1051D】Bicolorings (dp,类似状压dp)

题干&#xff1a; You are given a grid, consisting of 22 rows and nn columns. Each cell of this grid should be colored either black or white. Two cells are considered neighbours if they have a common border and share the same color. Two cells AA and BB be…

【 HDU - 1796】How many integers can you find (容斥原理,二进制枚举或者dfs)

题干&#xff1a; Now you get a number N, and a M-integers set, you should find out how many integers which are small than N, that they can divided exactly by any integers in the set. For example, N12, and M-integer set is {2,3}, so there is another set {2,…

【CodeForces - 1027B 】Numbers on the Chessboard (没有营养的找规律题,无聊题)

题干&#xff1a; You are given a chessboard of size nnnn. It is filled with numbers from 11 to n2n2 in the following way: the first ⌈n22⌉⌈n22⌉ numbers from 11 to ⌈n22⌉⌈n22⌉ are written in the cells with even sum of coordinates from left to right f…

【CodeForces - 1060C】Maximum Subrectangle (思维,预处理前缀和,dp,枚举长度)

题干&#xff1a; You are given two arrays aa and bb of positive integers, with length nn and mmrespectively. Let cc be an nmnm matrix, where ci,jai⋅bjci,jai⋅bj. You need to find a subrectangle of the matrix cc such that the sum of its elements is at m…

【Codeforces 631C 】Report(单调栈,思维模拟)

题干&#xff1a; Each month Blake gets the report containing main economic indicators of the company "Blake Technologies". There are n commodities produced by the company. For each of them there is exactly one integer in the final report, that d…

【CodeForces - 215A】Bicycle Chain (水题)

题干&#xff1a; Vasyas bicycle chain drive consists of two parts: n stars are attached to the pedal axle, m stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation. We know that the i-th sta…

ubuntu 在线安装php,ubuntu在线安装LNMP

一直以来个人安装lamp环境都是源码编译的&#xff0c;这个过程呢其实也要去经历的&#xff0c;但是毕竟占用时间久&#xff0c;有些时候在做一些测试环境的时候&#xff0c;可以在线安装比较快源码编译nginx可看往期&#xff1a;Nginx的安装对于lnmp的在线安装&#xff0c;如下…

【CodeForces - 215B 】Olympic Medal (数学,公式推导)

题干&#xff1a; The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of r1 cm, inner radius of r2 cm, (0 < r2 < r1)made of metal with density p1 g/cm3. The second part is an i…

【CodeForces - 215C 】Crosses (思维,图形题)

题干&#xff1a; There is a board with a grid consisting of n rows and m columns, the rows are numbered from 1 from top to bottom and the columns are numbered from 1 from left to right. In this grid we will denote the cell that lies on row number i and co…

Scaffold php,GitHub - yiiplus/scaffold: scaffold是一个基于Yii2高级项目模版工程化实现的应用程序...

Yii 2 Scaffold Project Kit易加-脚手架(scaffold)是一个基于Yii2高级项目模版工程化实现的应用程序&#xff0c;它将更加高效、规范和工程化的满足项目开发的需求。DIRECTORY STRUCTUREcommonconfig/ contains shared configurationsmail/ contains view files for e-mailsmod…

oracle修改某个数据类型,Oracle 修改某个字段的数据类型三种方式

1.将该列设置为null,再修改其类型(这样会丢失数据)2.最简单的方法&#xff1a;假设你的表名为 tab_targetcreate table test as select * from tab_target whre 12;alter table test modify (col_name number(5));insert into test select * from tab_target;drop table tab_t…

【EOJ Monthly 2018.10 - B】 莫干山奇遇 (思维构造,数学,数组,贪心)(总结)

题干&#xff1a; Time limit per test: 2.0 seconds Memory limit: 512 megabytes 出题人当然是希望出的题目有关 oxx&#xff0c;于是想方设法给题目配上一些有关 oxx 的背景故事&#xff0c;使得它看起来不那么无趣。但有的时候却无法引入合适的小姐姐&#xff0c;使得 o…

有奶瓶的linux系统,用U盘启动BEINI(奶瓶)系统

用U盘启动&#xff1a;奶瓶(beini)这个系统&#xff0c;是一款基于Tiny Core Linux 搭建的无线网络安全测试系统&#xff0c;当然由于它是用来安全测试的系统&#xff0c;因此在安全方面自然有着强大的功能。而且&#xff0c;这个系统非常简便易学&#xff0c;因此现在已经逐渐…

【CodeForces - 227A】Where do I Turn? (计算几何,叉积判断直线拐向)

题干&#xff1a; Trouble came from the overseas lands: a three-headed dragon Gorynych arrived. The dragon settled at point C and began to terrorize the residents of the surrounding villages. A brave hero decided to put an end to the dragon. He moved from…