2013山东省第三届ACM省赛 Pixel density
2016-04-30 18:08
246 查看
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 carelessboy 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 decimalplaces. 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.
#include<iostream> #include<stdio.h> #include<string.h> #include<math.h> using namespace std; char str[12345]; char str1[12345]; char str2[12345]; char num1[12345]; char num2[12345]; char num3[12345]; int main(){ int T; int i; int len; int len1,len2; int p1,p2; int p3,p4; int len_num1,len_num2,len_num3; int j; double a,a1,a2,b,b1,b2,c,c1,c2; int p5; double Dp; double ans; int ca=0; int p6,p7; scanf("%d",&T); getchar(); //scanf("%[^\n]",str); //cout<<str<<endl; while(T--){ scanf("%[^\n]",str); getchar(); //printf(""); //printf("%s\n",str); //cout<<str<<endl; len=strlen(str); //cout<<len<<endl; len1=0; len2=0; len_num1=0; len_num2=0; len_num3=0; for(i=0;i<len;++i){ if(str[i]=='i'){ if(str[i+1]=='n'&&str[i+2]=='c'&&str[i+3]=='h'&& str[i+4]=='e'&&str[i+5]=='s'&&str[i+6]==' '){ p1=i; j=i-1; while(str[j]==' '){ --j; } while(str[j]!=' '){ num1[len_num1++]=str[j--]; } while(str[j]==' '){ --j; } p3=j; } } if(str[i]=='*'){ if(i>=1&&'0'<=str[i-1]&&str[i-1]<='9'){ if('0'<=str[i+1]&&str[i+1]<='9'){ p2=i; j=i-1; while(str[j]!=' '){ num2[len_num2++]=str[j--]; } j=i+1; while(str[j]!=' '){ num3[len_num3++]=str[j++]; } while(str[j]==' '){ ++j; } p4=j; } } } } for(i=0;i<=p3;++i){ if(str[i]!=' '){ break; } } str1[len1++]=str[i++]; for(;i<=p3;++i){ if(str[i]==' '&&str1[len1-1]==' '){ continue; } str1[len1++]=str[i]; } str1[len1]='\0'; for(i=p4;i<len;++i){ if(str[i]==' '&&str2[len2-1]==' '){ continue; } if('a'<=str[i]&&str[i]<='z'){ str2[len2++]=str[i]; } else if('A'<=str[i]&&str[i]<='Z'){ str2[len2++]=str[i]+32; } else{ str2[len2++]=str[i]; } } str2[len2]='\0'; for(i=len2-1;i>=0;--i){ if(str2[i]!=' '){ len2=i+1; break; } } str2[i+1]='\0'; /* cout<<str1<<endl; cout<<str2<<endl; cout<<num1<<endl; cout<<num2<<endl; cout<<num3<<endl; */ p5=-1; for(i=0;i<len_num1;++i){ if(num1[i]=='.'){ p5=i; break; } } a=0; a1=0; a2=0; if(p5==-1){ for(i=0;i<len_num1;++i){ a1=a1+(num1[i]-'0')*pow(10,i); } } else{ //a2=0; for(i=0;i<p5;++i){ a2=a2/10+(num1[i]-'0')/10.0; } //a1=0; for(i=p5+1;i<len_num1;++i){ a1=a1+(num1[i]-'0')*pow(10,(i-(p5+1))); } } //cout<<a2<<endl; //cout<<a1<<endl; a=a1+a2; //cout<<"a:"<<a<<endl; if(a==0){ printf("Case %d: The %s of %s's PPI is %.2f.\n",++ca,str2,str1,0.0); continue; } p6=-1; for(i=0;i<len_num2;++i){ if(num2[i]=='.'){ p6=i; break; } } if(p6==-1){ b=0; for(i=0;i<len_num2;++i){ b=b+(num2[i]-'0')*pow(10,i); } } else{ b=0; b1=0; b2=0; //cout<<p6<<"***"<<endl; for(i=0;i<p6;++i){ b2=b2/10+(num2[i]-'0')/10.0; //cout<<"##"<<b2<<endl; } for(i=p6+1;i<len_num2;++i){ b1=b1+(num2[i]-'0')*pow(10,(i-(p6+1))); } /* for(i=p5-1;i>=0;--i){ a2=a2/10+(num1[i]-'0')/10.0; } //a1=0; for(i=p5+1;i<len_num1;++i){ a1=a1+(num1[i]-'0')*pow(10,(i-(p5+1))); } */ b=b1+b2; //cout<<"b:"<<b<<endl; } p7=-1; for(i=0;i<len_num3;++i){ if(num3[i]=='.'){ p7=i; break; } } if(p7==-1){ c=0; for(i=0;i<len_num3;++i){ c=c*10+(num3[i]-'0'); } } else{ c=0; c1=0; c2=0; for(i=0;i<p7;++i){ //c2=c2/10+(num3[i]-'0')/10.0; c1=c1*10+(num3[i]-'0'); //cout<<"##"<<c2<<endl; } for(i=p7+1;i<len_num3;++i){ //c1=c1+(num3[i]-'0')*pow(10,(i-(p7+1))); c2=c2/10+(num3[i]-'0')/10.0; } c=c1+c2; //cout<<"c:"<<c<<endl; } //cout<<b<<endl; //cout<<c<<endl; Dp=sqrt(b*b+c*c); ans=Dp/a; //cout<<ans<<endl; printf("Case %d: The %s of %s's PPI is %.2f.\n",++ca,str2,str1,ans); } /* 33 ip 00300.00600 inches 00500.00600*00700.00800 IPHone 2 iPhone 4S 3.5 inches 960*640 PHONE The new iPad 0009.7 inches 2048*1536 PAD */ return 0; }
相关文章推荐
- Mysql5-7-11 安装教程
- 关于线程池三个静态方法的概述
- 依赖关系(“使用”关系)
- Java并发编程--CountDownLatch配合线程池
- Java循环练习:打印图案-6
- Handler简单用法
- poj 3071 Football (概率DP水题)
- 9.单字段分组和多字段分组
- Android模仿IOS的自定义switch
- HDU 4502 吉哥系列故事——临时工计划(dp)
- 算法学习笔记之鸡兔同笼
- 类成员函数回调
- Codeforces Round #349 (Div. 2)-A. Pouring Rain(数学)
- Leetcode - Excel Sheet Column Title
- Worm
- bootstrap ch2清除浮动+12
- NBUT1461 数字整除(大数处理,减法、除法)
- nyoj_106 背包问题
- 微信公众号第三方开发之四回调url中获取授权方的授权信息以及基本信息
- NSLog的实现