HDU 4486(周长确定三角形的个数统计 对比上次的互质三角形)

             对比:给一根长度为n的铁丝,将它分为若干份,不过需要每一份都相似


Pen Counts

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 237    Accepted Submission(s): 137


Problem Description
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).

 

Input
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).
 

Output
For each data set there is a single line of output. It contains the data set number, K, followed by a single space which is then followed by an integer which is the total number of different three-sided chicken pen configurations that can be made using the entire roll of fence.
 

Sample Input
 
   
5 1 3 2 11 3 12 4 100 5 9999
 

Sample Output
 
   
1 1 2 5 3 4 4 392 5 4165834
 

Source
Greater New York 2012
 


                      题目大意:题意可转换为求周长为n的三角形的个数,其中等腰三角形计一次,否则计算两次。


             解题思路:先求等腰的,这个只需要知道三角形底的范围即可。   求三边不等的找最长边a的范围,然后是b的范围,统计数量即可。


             题目地址:Pen Counts


今天真的是跪在了B题上,取模的题目,却一心只想用大数,关键敲模板对着敲都敲出来错误。。。得多刷几道大数题。而且自己得手敲,每次都是那样复制没有锻炼。。。贵在坚持!


AC代码:

#include
#include
#include
#include
#include
#include
using namespace std;

int main()
{
     int tes,cas,p,a,b,res;
     scanf("%d",&tes);
     while(tes--)
     {
          scanf("%d%d",&cas,&p);
          int res1=0,res2=0;
          if(p&1)   //等腰三角形或等边三角形且边长为奇
          {
               a=p/2;
               if(!(a&1))
                    a--;
               res1+=a/2+1;
          }
            else  //等腰三角形或等边三角形且边长为偶数
            {
                a=p/2-1;
                if(a&1)
                    a--;
                res1+=a/2;
            }

          a=p/2;
          if(!(p&1))
               a--;
          for(;a>=p/3+1;a--) //a>b>c 
          {
               int x=p-a;
               b=x/2+1; 
               if(b


你可能感兴趣的:(思维)