UVa 201 Squares】的更多相关文章

题意: 给出这样一个图,求一共有多少个大小不同或位置不同的正方形. 分析: 这种题一看就有思路,最开始的想法就是枚举正方形的位置,需要二重循环,枚举边长一重循环,判断是否为正方形又需要一重循环,复杂度为O(n4),对于n≤9来说,这个复杂度可以接受. 可以像预处理前缀和那样,用O(1)的时间判断是否为正方形,这样总的复杂度就优化到O(n3). 这个方法转自这里 We can think that vertical or horizontal lines are edges between two…
题意 给你n*n的图,让你数正方形 题解:暴力for每个点,对于每个点从它出发顺时针走一个正方形.走完就ans[i]++; 坑:多输了一行******,然后在那里手摸样例,无限debug orz #define _CRT_SECURE_NO_WARNINGS #include<cmath> #include<iostream> #include<stdio.h> #include<algorithm> #include<cstring> #inc…
题目 题目     分析 记录一下再预处理一下.     代码 #include <bits/stdc++.h> int main() { int t=0,s,n; while(scanf("%d",&s)==1) { if(t!=0) printf("\n**********************************\n\n"); int ans[11],H[21][21],V[21][21]; memset(V,0,sizeof(V))…
A children's board game consists of a square array of dots that contains lines connecting some of the pairs of adjacent dots. One part of the game requires that the players count the number of squares of certain sizes that are formed by these lines.…
旋转卡壳求凸包直径. 参考:http://www.cppblog.com/staryjy/archive/2010/09/25/101412.html #include <cstdio> #include <cmath> #include <algorithm> using namespace std; << ; struct Point { int x, y; Point( , ):x(x), y(y) { } }; typedef Point Vecto…
旋转卡壳算法: 直接在这个上面粘的模板 主要用途:用于求凸包的直径.宽度,两个不相交凸包间的最大距离和最小距离··· 这题就是求凸包的直径 #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> #include <vector> #define eps 1e-9 using namespace std; ); int dcmp(double x) {…
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17267 [思路] 凸包+旋转卡壳 求出凸包,用旋转卡壳算出凸包的直径即可. [代码] #include<cstdio> #include<vector> #include<iostream> #include<algorithm> using namespace std; struct Pt { int x,y; Pt(,):…
题意: 如图,有n个正方形和一个角(均在第一象限中),使这些正方形与这个角构成封闭的阴影区域,求阴影区域面积的最大值. 分析: 直观上来看,当这n个正方形的对角线在一条直线上时,封闭区域的面积最大.(虽然我不太会证明,=_=||) 设所有正方形边长之和为L,OA.OB两直线方程分别为:y = k1x  y = k2x,设A(x1, k1x1), B(x2, k2x2),可列出方程: ,解得,相应的就得到AB两点坐标,用叉积算出△OAB的面积再减去这些正方形面积的一半就是答案. #include…
题意: 总共有6个2*2的正方形,判断是否能够成所给的形状. 思路: 一个正方形总共有9种摆放方式,对于整个地图来说摆放方式总共有2的9次方种摆放方式.然后将地图用9*5的数组表示,正方形的位置用其8个边的下标和4个中空的下标表示. 代码: #include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;int bian[9][8]={…
题意:有n个正方形和一个角(均在第一象限中),使这些正方形与这个角构成封闭的阴影区域,求阴影区域面积的最大值. 析:很容易知道只有所有的正方形的对角形在一条直线时,是最大的,然后根据数学关系,就容易得到答案. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #incl…