zoukankan      html  css  js  c++  java
  • Pixel density sdut2411 ACM算法设计

    Pixel density

    Time Limit: 1000MS Memory limit: 65536K

    题目描述

    Pixels per inch (PPI) or pixel density is a measurement of the resolution of devices in various contexts; typically computer displays, image scanners, and digital camera image sensors. Note, the unit is not square inches. Good quality photographs usually require 300 pixels per inch when printed. When the PPI is more than 300(phone), we call it retina screen. Sunnypiggy like the retina screen very much.

     

    But you know it is expensive for Sunnypiggy and Sunnypiggy’s own smart phone isn’t like that.
    I tell you how to calculate the PPI. First we must know how big the mobile phone’s screen is. Then we get the resolution (Hp*Wp) about it. After that we calculate the diagonal resolution in pixels (Dp) and divided by diagonal size in inches. Now you get the answer.
    Maybe you knew it, but Sunnypiggy’s math is very bad and he wants you to help him to calculate the pixel density of all the electronic products he dreamed.
     

    输入

    First you will get an integer T which means the number of test cases, and then Sunnypiggy will tell you the name and type of the electronic products. And you know, Sunnypiggy is a careless boy and some data aren’t standard, just like 04.00 inches or 0800*0480.

    输出

    Output the answers to Sunnypiggy just like the sample output. Maybe it is not a phone. Sunnypiggy like such a form, although it seems no use. The result should be rounded to 2 decimal places. When it has no screen (0.0 inches) that we define the answer is 0.00(PPI).

    示例输入

    2
    iPhone 4S  3.5 inches 960*640 PHONE
    The new iPad  0009.7 inches 2048*1536 PAD
    

    示例输出

    Case 1: The phone of iPhone 4S's PPI is 329.65.
    Case 2: The pad of The new iPad's PPI is 263.92.
    

    提示

    Dp= sqrt(Wp*Wp+Hp*Hp )
    Wp is width resolution in pixels, Hp is height resolution in pixels.

    来源

    2012年"浪潮杯"山东省第三届ACM大学生程序设计竞赛
     
    做题一定要慎之又慎,充分理解题意啊 ...
     
    #include <iostream>
    #include <cmath>
    #include <string>
    //#include <fstream>
    #include <iomanip>
    #include <vector>
    #include <stdio.h>
    using namespace std;
    
    int main()
    {
    	//fstream cin("in.txt");
    	int rowCount = 0;
    	cin>>rowCount;	
    	cin.ignore(1024,'\n');
    	int cases = 1;
    	vector<string> vs;
    	while (rowCount --)
    	{
    		//字符串解析
    		string str;
    		vs.clear();		
    		int inchesIndex,wphpIndex,typeIndex,nameBorder;
    		for(int i = 0;cin >> str;i++)
    		{
    			vs.push_back(str);
    			if("inches" == str)
    			{
    				nameBorder = i - 2;
    				inchesIndex = i - 1;
    				wphpIndex = i + 1;
    				typeIndex = wphpIndex + 1;
    				continue;
    			}
    			char c;
    			cin.get(c);
    			if('\n' == c) break;
    		}
    		//转换成double
    		double inches = 0.0,wp = 0.0,hp = 0.0;
    		int flag = 0;
    		double p = 10;
    		for(int i = 0;i != vs[inchesIndex].size();i++)
    		{
    			if(vs[inchesIndex][i] == '.')
    			{
    				flag = 1;
    				p = 0.1;
    				continue;
    			}
    			if(flag == 0)//整数部分
    			{
    				inches *= p;
    				inches += vs[inchesIndex][i] - '0';
    			}
    			else if(flag == 1)
    			{
    				inches += (vs[inchesIndex][i] - '0') * p;
    				p *= 0.1;
    			}
    		}
    		flag = 0; p = 10;
    		for(int i = 0; i != vs[wphpIndex].size();i++)
    		{
    			if('.' == vs[wphpIndex][i])
    			{
    				flag = 1;
    				p = 0.1;
    				continue;
    			}
    			if('*' == vs[wphpIndex][i])
    			{
    				flag = 0;
    				p = 10;
    				hp = wp;
    				wp = 0.0;
    				continue;
    			}
    			if(1 == flag)
    			{
    				wp += (vs[wphpIndex][i] - '0') * p;
    				p *= 0.1;
    			}
    			if(0 == flag)
    			{
    				wp *= p;
    				wp += vs[wphpIndex][i] - '0';
    			}
    		}
    		double dp = sqrt(wp*wp + hp*hp);
    
    		cout<<"Case "<<cases++<<": The ";
    		//吧type转换成小写
    		for(int i = typeIndex;i != vs.size();i ++)
    		{
    			for(int j = 0;j != vs[i].size();j ++)
    			{
    				if(vs[i][j] >= 65 && vs[i][j] <= 90)
    					printf("%c",vs[i][j] + 32);
    				else printf("%c",vs[i][j]);
    			}
    			cout<<" ";
    		}
    		cout<<"of";
    		for(int i = 0;i <= nameBorder;i ++)
    		{
    			cout<<" "<<vs[i];
    		}
    		if(inches <= 1e-9)
    			cout<<"'s PPI is "<<0.00<<'.'<<endl;
    		else
    			cout<<"'s PPI is "<<setprecision(2)<<std::fixed<<dp/inches<<'.'<<endl;
    	}
    }
    
    本博客所有博文,若无专门说明皆为原创,转载请注明作者和出处!
  • 相关阅读:
    CF 118E Bertown roads 桥
    hdu 3917 Road constructions 最大权闭合子图
    hdu 4714 Tree2cycle 树形经典问题
    POJ 2516 Minimum Cost 最小费用流
    POJ 3921 Destroying the bus stations 沿着最短路迭代加深搜索
    POJ 3422 Kaka's Matrix Travels K取方格数
    BZOJ 3083: 遥远的国度 dfs序,树链剖分,倍增
    hdu 4010 Query on The Trees LCT
    poj 2455 Secret Milking Machine 二分+最大流 sap
    定制标记---简单标记处理器
  • 原文地址:https://www.cnblogs.com/ifinver/p/3017267.html
Copyright © 2011-2022 走看看