首页 > ACM题库 > HDU-杭电 > HDU 3654-Draw Regular Polygon[解题报告]HOJ
2014
11-30

HDU 3654-Draw Regular Polygon[解题报告]HOJ

Draw Regular Polygon

问题描述 :

A regular polygon is a polygon whose all angles are equal in measure and all sides have the same length. Great mathematician Carl Friedrich Gauss had drawn a regular heptadecagon with only ruler and compass when he was 19. But today, we will not draw regular polygons that way. You had a circle of unit radius and some rulers, each can only measure certain distance, which equals to 2 sin (k*PI/n) , where n and k are known for each ruler. Thus you can measure an arc of 2k*PI/n on that circle with a ruler of parameters
n and k. Rulers can be used only to measure arcs on that circle, othe uses are forbidden. Each ruler can be used arbitrary many times. Now give you the parameters of r rulers, how many different regular polygons can you draw? Two regular polygons are said to be the same if they had the same number of sides, but may be differ in orientations. And a regular polygon should have at least 3 sides.

输入:

Each test case begins with an integer r(1 <= r <=30) the number of rulers, on the first line. Then r lines followed, each line describes a ruler with two positive integers n(1 <= n <= 104) and k(1 <= k <= 104), indicate that ruler can measure a distance of 2 sin k*PI/n .

输出:

Each test case begins with an integer r(1 <= r <=30) the number of rulers, on the first line. Then r lines followed, each line describes a ruler with two positive integers n(1 <= n <= 104) and k(1 <= k <= 104), indicate that ruler can measure a distance of 2 sin k*PI/n .

样例输入:

2
2 1
3 1
1
4 2
1
5 2

样例输出:

2
3 6
0
1
5
Pr

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define LL __int64
const int N = 1e9;
using namespace std;

int r, d[10005], n[40], pr[10005], qpr[10005], tq;

void Pr()
{
 int i, j;
 memset( pr, 1, sizeof(pr) );
 pr[1] = 0;
 for( i = 2; i <= 10000; i ++ )
 if( pr[i] )
 {
 j = i+i;
 while( j <= 10000 )
 {
 pr[j] = 0;
 j += i;
 }
			qpr[tq++] = i;
 }
}
int Gcd( int a, int b )
{
 if( !b )
 return a;
 else
 return Gcd( b, a%b );
}
void Op()
{
 memset( d, 0, sizeof(d) );
 int t, i, j, tt;
 for( j = 0; j < r; j ++ )
 {
 t = n[j];
 for( i = 0; i < tq && t > 1; i ++ )
 if( !( t % qpr[i] ) )
 {
 tt = 1;
				t/=qpr[i];
 while( !( t%qpr[i] ) )
 {
 tt ++;
 t/=qpr[i];
 }
				d[ qpr[i] ] = d[ qpr[i] ] > tt ? d[ qpr[i] ] : tt;
 }
 }
}

int main()
{
 int i, j, k, ti, qu[10004], top, na, mu[30];
	LL qa[30], t, ans;
 Pr();

 while( ~scanf( "%d", &r ) )
 {
 for( i = 0; i < r; i ++ )
 {
 scanf( "%d%d", n+i, &k );
 k = Gcd( n[i], k );
 n[i] /= k;
 }
 Op();
 ans = 1;
 top = 0;
 for( i = 0; i < tq; i ++ )
 if( d[ qpr[i] ] > 0)
 {
 ans *= d[ qpr[i] ]+1;
 qu[ top++ ] = qpr[i];
 }
		if( top > 0 && qu[0] == 2 )
			na = 2;
 else
			na = 1;
		printf( "%I64d\n", ans-na );
 ans = ans < 16+na ? ans : 16+na;
 	qa[0] = 1;
		mu[0] = 0;
		for( k = 1; k < ans; k ++ )
		{
			t = N*(LL)N;
			for( i = 0; i < k; i ++ )
				if( mu[i] < top && qu[ mu[i] ] * qa[i] < t )
					t = qu[ mu[i] ]*qa[i];
			qa[k] = t;
			mu[k] = -1;
			for( j = 0; j <= k; j ++ )
				if( mu[j] < 0 || ( mu[j] < top && qu[ mu[j] ] * qa[j] == qa[k] ) )
				{
					for( i = mu[j]+1; i < top; i ++ )
					{
						ti = 0;
						t = qa[j];
						while( !( t % qu[i] ) )
						{
							ti ++;
							t /= qu[i];
						}
						if( ti < d[ qu[i] ] )
							break;
					}
					mu[j] = i;
				}
		}
		if( na < ans )
		{
			printf( "%I64d", qa[na] );
			na ++;
			for( j = 1; na < ans && j < 16; na ++, j ++ )
				printf( " %I64d", qa[na] );
			printf( "\n" );
		}			
 }


 //out
 return 0;
}

  1. 这道题目的核心一句话是:取还是不取。
    如果当前取,则index+1作为参数。如果当前不取,则任用index作为参数。

  2. Hello Web Admin, I noticed that your On-Page SEO is is missing a few factors, for one you do not use all three H tags in your post, also I notice that you are not using bold or italics properly in your SEO optimization. On-Page SEO means more now than ever since the new Google update: Panda. No longer are backlinks and simply pinging or sending out a RSS feed the key to getting Google PageRank or Alexa Rankings, You now NEED On-Page SEO. So what is good On-Page SEO?First your keyword must appear in the title.Then it must appear in the URL.You have to optimize your keyword and make sure that it has a nice keyword density of 3-5% in your article with relevant LSI (Latent Semantic Indexing). Then you should spread all H1,H2,H3 tags in your article.Your Keyword should appear in your first paragraph and in the last sentence of the page. You should have relevant usage of Bold and italics of your keyword.There should be one internal link to a page on your blog and you should have one image with an alt tag that has your keyword….wait there's even more Now what if i told you there was a simple WordPress plugin that does all the On-Page SEO, and automatically for you? That's right AUTOMATICALLY, just watch this 4minute video for more information at.

  3. 换句话说,A[k/2-1]不可能大于两数组合并之后的第k小值,所以我们可以将其抛弃。
    应该是,不可能小于合并后的第K小值吧