首页 > ACM题库 > HDU-杭电 > HDU 4486-Pen Counts-计算几何-[解题报告]HOJ
2015
07-17

HDU 4486-Pen Counts-计算几何-[解题报告]HOJ

Pen Counts

问题描述 :

Chicken farmer Xiaoyan is getting three new chickens, Lucy, Charlie and CC. She wants to build a chicken pen so that each chicken has its own, unobstructed view of the countryside. The pen will have three straight sides; this will give each chicken its own side so it can pace back and forth without interfering with the other chickens. Xiaoyan finds a roll of chicken wire (fencing) in the barn that is exactly N feet long. She wants to figure out how many different ways she can make a three sided chicken pen such that each side is an integral number of feet, and she uses the entire roll of fence.
Different rotations of the same pen are the same, however, reflections of a pen may be different (see below).

B-CastingB-Casting

输入:

The first line of input contains a single integer P,(1<= P <=1000), which is the number of data sets that follow. Each data set should be processed identically and independently.

Each data set consists of a single line of input. It contains the data set number, K, and the length of the roll of fence, N, (3 <= N <= 10000).

输出:

The first line of input contains a single integer P,(1<= P <=1000), which is the number of data sets that follow. Each data set should be processed identically and independently.

Each data set consists of a single line of input. It contains the data set number, K, and the length of the roll of fence, N, (3 <= N <= 10000).

样例输入:

5
1 3
2 11
3 12
4 100
5 9999

样例输出:

1 1
2 5
3 4
4 392
5 4165834

要求求出周长为n的不同的三角个数。。

如果三条边互不相等时,则个数再加1。(x,y,z;     x,z,y;)

假设三角形边长为x,y,z,已知z,则有x+y=n-z,x-y<z,令x-y=t,(0<=t<z),求解得 x=(n-z+t)/2,y=(n-z-t)/2,对于y,ymax=(n-z)/2,ymin=(n-z-(z-1))/2.。。。

看别人的代码的出的理解。。还是怪怪的,希望大神能指点下~!!!!

 

#include<iostream>
using namespace std;
#include<iostream>
using namespace std;
int max(int a,int b)
{
	if(a>b)return a;
	return b;
}
int main()
{
	int num,n,t,s,x,j,z,temp;
	cin>>t;
	while(t--)
	{
		cin>>num>>n;
		s=0;
		for(z=1;z<=n/3;z++)
		{
			temp=0;
			x=(n-z)/2;
			j=max(z,n/2-z+1);
			
			if(x+z<=n-z-x||x>n-z-x)continue;
			if(j==z)
			{
				temp=z;
				s--;
			}
			if(temp!=x&&x==n-z-x)s--;
			s+=(x-j+1)*2;
			//cout<<z<<" "<<x<<" "<<j<<" "<<temp<<" "<<s<<endl;


		}
		cout<<num<<" "<<s<<endl;
	}
	return 0;
}

 

版权声明:本文为博主原创文章,未经博主允许不得转载。

参考:http://blog.csdn.net/yylxid/article/details/8601075