//以下为原blog搬迁过来的内容
【题目大意】:给出矩形的变长,确保矩形从左往右摆放,问摆放完毕后从上往下看可以看见多少个矩形。
【解题思路】:将矩形的边长映射到x轴上,变成一个线段的覆盖的问题。可惜,做了n个小时还是wa。最后参考了别人的想法乘了个根号2,把所有数据都整数化,就a了。应该是wa在精度上,研究中......
【代码】:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <queue> #include <cmath> #include <string> #include <cctype> #include <map> #include <iomanip> using namespace std; #define eps 1e-8 #define pi acos(-1.0) #define inf 1<<30 #define pb push_back #define lc(x) (x << 1) #define rc(x) (x << 1 | 1) #define lowbit(x) (x & (-x)) #define ll long long #define tmp sqrt(2) int ABS(double k) { if (k>0) return k; else return -k; } struct Point { double le,ri,len; Point() {} Point(double a,double b,double c); { le=a,ri=b,len=c; } }point[56]; int main() { int n; while(~scanf("%d",&n)) { if (n==0) break; for (int i=1; i<=n; i++) { scanf("%lf",&point[i].len); point[i].le=0; for (int j=1; j<i; j++) { point[i].le=max(point[i].le,point[j].ri-ABS(point[i].len-point[j].len)); } point[i].ri=point[i].le+point[i].len*2; } for (int i=2; i<=n; i++) { for (int j=1; j<i; j++) { if(point[j].le<point[j].ri) { if(point[i].le<point[j].ri && point[i].len<point[j].len) { point[i].le=point[j].ri; } if(point[i].le<point[j].ri && point[i].len>point[j].len) { point[j].ri=point[i].le; } } } } for (int i=1; i<=n; i++) { if(point[i].le<point[i].ri) { printf("%d ",i); } } printf("\n"); } return 0; }