zoukankan      html  css  js  c++  java
  • Problem C HDU 5224

    Description

      There is a piece of paper in front of Tom, its length and width are integer. Tom knows the area of this paper, he wants to know the minimum perimeter of this paper.
     

      Input

    In the first line, there is an integer T indicates the number of test cases. In the next T lines, there is only one integer n in every line, indicates the area of paper.
    Tleq 10,nleq {10}^{9}
     

      Output

    For each case, output a integer, indicates the answer.
     

    Sample Input

    3 2 7 12
     

    Sample Output

    6 16 14
     
     
      题目大意:给出一张纸的面积,要求输出这张纸的最少周长。
     
      思路:纸的面积等于长乘以宽,即一个数等于它的两个质因子数之积,当有多个质因子时,
    每两个质因子数之积等于该数的分为一组,分别以这两个质因子作为长宽算出其周长再比较大小,最后输出最小的那个值。
    由于时间为1s,给出的n的最大值为1e9,直接写1-n一定会超时,所以先将其开平方就减为1e4-1e5了,这样就不会超时了。
     
     
     
    #include <iostream>
    #include <cstdio>
    #include <cmath>
    #include <algorithm>
    using namespace std;
    int main()
    {
    	int t,s;
    	double m;
    	scanf("%d",&t);
    	while(t--)
    	{
    		int x,y,c;
    		int mini=1e9;
    		scanf("%d",&s);
    		m=(double)sqrt(s);
    		for(x=1;x<=m;x++)
    		{
    			if(s%x==0)
    			{
    				y=s/x;
    				c=(x+y)*2;
    				mini=min(c,mini);
    			}
    		}
    		printf("%d
    ",mini);
    		
    	}
    }
     
     
     
     
  • 相关阅读:
    Maximum Profit Aizu
    Maximum Profit Aizu
    Codeforces Round #552 (Div. 3) —— B. Make Them Equal
    Codeforces Round #552 (Div. 3) —— B. Make Them Equal
    每周一题 —— 3n+1问题
    每周一题 —— 3n+1问题
    Georgia and Bob POJ
    Georgia and Bob POJ
    LeetCode 292. Nim Game
    OpenCV:初试牛刀-带滚动条的视频播放-2
  • 原文地址:https://www.cnblogs.com/xl1164191281/p/4696723.html
Copyright © 2011-2022 走看看