zoukankan      html  css  js  c++  java
  • hdu4486 Pen Counts(水题)

    Pen Counts

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

    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
     

    这个题我写了大部分,线性时间内求得三角形的数目没问题,却在判断三角形中等腰三角形的数目时出了问题,无奈之下百度一下解题报告,看完后恍然大悟,对于每一个确定的a,它的等腰三角形数目最多为两个,对于等边三角形则要注意不要多减1次


    #include<stdio.h>
    int main()
    {
    	int t,n,i,m,ans,temp1,temp2,a,b,c,temp;
    	scanf("%d",&t);
    	while(t--)
    	{
    		scanf("%d%d",&n,&m);
    		temp1=m/3;
    		ans=0;
    		for(a=1;a<=temp1;a++)
    		{
    			temp2=(m-a)/2;//b上限
    			temp=0;
    			b=(m/2-a+1)>a?(m/2-a+1):a;//b下限
    			if(a==b)
    			{
    				ans--;
    				temp=a;
    			}
    			if(temp!=temp2&&temp2==m-a-temp2)//判断b==c,并防止一个等腰三角形三角形减去两次
    				ans--;
    			ans+=2*(temp2-b+1);//不管等腰三角形先都加2,在上面判断减一
    		}
    		printf("%d %d
    ",n,ans);
    	}
    	return 0;
    }


  • 相关阅读:
    mvc性能优化
    wordpress分享到微信无缩略图的问题
    wordpress插件汉化包,和使用教程
    wordpress重力表单实时提醒功能教程(亲测可用)
    无法建立目录wp-content/uploads/xxxx/xx。有没有上级目录的写权限?解决办法
    font-face自定义字体使用方法
    图片在父元素里面水平垂直居中
    wordpress改不了固定连接的解决办法
    wordpress更换域名
    iframe添加点击事件
  • 原文地址:https://www.cnblogs.com/pangblog/p/3253577.html
Copyright © 2011-2022 走看看