Shrinking Polygons hust 14048

Shrinking Polygons
Time Limit: Unknown
 
Memory Limit: Unknown
 
64bit IO Format: %lld & %llu
[Submit]   [Go Back]   [Status]  
Description
 
 
A polygon is said to be inscribed in a circle when all its vertices lie on that circle. In this problem you will be given a polygon inscribed in a circle, and you must determine the minimum number of vertices that should be removed to transform the given polygon into a regular polygon, i.e., a polygon that is equiangular (all angles are congruent) and equilateral (all edges have the same length).
When you remove a vertex v from a polygon you first remove the vertex and the edges connecting it to its adjacent vertices w1 and w2, and then create a new edge connecting w1 and w2. Figure (a) below illustrates a polygon inscribed in a circle, with ten vertices, and figure (b) shows a pentagon (regular polygon with five edges) formed by removing five vertices from the polygon in (a).
 
In this problem, we consider that any polygon must have at least three edges.
 

Input

The input contains several test cases. The first line of a test case contains one integer
N indicating the number of vertices of the inscribed polygon (3 ≤
N ≤ 10
4). The second line contains
N integers
X
i separated by single spaces (1 ≤
X
i ≤ 10
3, for 0 ≤
i ≤
N -1). Each
X
i represents the length of the arc defined in the inscribing circle, clockwise, by vertex
i and vertex (
i+1) mod
N. Remember that an
arc is a segment of the circumference of a circle; do not mistake it for a
chord, which is a line segment whose endpoints both lie on a circle.
The end of input is indicated by a line containing only one zero.
 

Output


For each test case in the input, your program must print a single line, containing the minimum number of vertices that must be removed from the given polygon to form a regular polygon. If it is not possible to form a regular polygon, the line must contain only the value -1.
Sample input
3
1000 1000 1000
6
1 2 3 1 2 3
3
1 1 2
10
10 40 20 30 30 10 10 50 24 26
0

Output for the sample input
0
2
-1
5

ACM ICPC::South American Regional 2008
Source
South America 2008-2009
n개의 숫자를 제시하고 최소 몇 번을 합치면 한 무더기의value와 같을 수 있습니다.
큰 소의 방법은hash처리sum[i], 시작점px를 일일이 열거하여 매번 한 무더기의 것과 dd를 탐지한다.sum[end]+t*dd가 모두hash가 도착할 수 있다면 이 해는 ok이다.
#include #include #include #include #include using namespace std; const int P = 999997; int n,m; int a[20005]; int hash[1100005]; int Max(int x,int y) { return x>y?x:y; } void insert_hash(int x) { int k = x % P; while (hash[k] >= 0) k++; hash[k] = x; } bool is_in(int x) { int k = x % P; while (hash[k] >= 0 && hash[k] != x) k++; if (hash[k] == x) return true; else return false; } int main() { int i,j,k,s,t,ans,dd,px; int x,y; while (cin >>n) { if (n == 0) break; memset(hash,-1,sizeof(hash)); memset(a,0,sizeof(a)); for (i=1;i<=n;i++) { cin >>a[i]; a[i] += a[i-1]; insert_hash(a[i]);//printf("%d ",a[i]); } m = n*2; ans = 0; for (i=n+1;i<=m;i++){ a[i] = a[n] + a[i-n]; insert_hash(a[i]);//printf("%d ",a[i]); } for (px=1;px<=n;px++) { bool bo = false; for (i=px;i ans) {ans = a[n]/dd;} } if (ans < 3) cout <<"-1"<이렇게 하면 시간이 좀 걸린다. 더 절약된 해법은sum[i]%dd를 수조 B[]에 존재하게 하고 B[i]에서 가장 많이 나타나는 원소(sort를 한 번에 하는 것)를 찾아서 횟수를 maxn으로 기록하는 것이다.if(maxn== 구분된 그룹 수), ok, 이렇게 그룹 수를 N에서 3까지 열거하면 됩니다.

좋은 웹페이지 즐겨찾기