zoukankan      html  css  js  c++  java
  • SDUT ACM 2411 Pixel density 字符串处理 Anti

     

    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大学生程序设计竞赛
     
     
     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<math.h>
     4 char s[10010][1010];
     5 int main()
     6 {
     7     char c;
     8     int t, item, div, n;
     9     double wp, hp, inch, dp;
    10     scanf("%d", &t);
    11     for(item = 1; item <= t; item++)
    12     {
    13         for(n = 0; scanf("%s%c", s[n], &c); n++)
    14         {
    15             if(!strcmp(s[n], "inches"))div = n; //记录“inches”的下标
    16             if(c == '\n')break;
    17         }
    18         sscanf(s[div-1], "%lf", &inch); //屏幕尺寸
    19         sscanf(s[div+1], "%lf*%lf", &hp, &wp); //高度和宽度
    20         for(int i = 2; i <= n; i++)  //类型名大写换成小写
    21         {
    22             for(int j = 0; s[div+i][j]; j++)
    23                 if(s[div+i][j] >= 'A' && s[div+i][j] <= 'Z')
    24                     s[div+i][j] += 32;
    25         }
    26         dp = 10 * sqrt(hp/10*hp/10  + wp/10*wp/10); //避免乘法溢出,缩小了一点
    27         printf("Case %d: The", item);
    28         for(int i = div+2; i <= n; i++)
    29             printf(" %s", s[i]);
    30         printf(" of");
    31         for(int i = 0; i <= div-2; i++)
    32             printf(" %s", s[i]);
    33         printf("'s PPI is %.2lf.\n", inch <= 1e-9 ? 0.0 : dp/inch); //屏幕尺寸为0时输出0.00,当初没看清这个条件WA了几次。。
    34     }
    35     return 0;
    36 }
  • 相关阅读:
    Redis面试总结
    文件上传文件的权限lnmp 环境配置,尤其整个项目复制过来
    linux cat /etc/passwd 说明
    php上传文件与图片到七牛的实例详解
    一起谈.NET技术,参数编码 完全解决方案 狼人:
    一起谈.NET技术,在.NET中使用域对象持续模式 狼人:
    一起谈.NET技术,从.NET中委托写法的演变谈开去(中):Lambda表达式及其优势 狼人:
    一起谈.NET技术,从扩展方法到流畅的程序体验(一) 狼人:
    一起谈.NET技术,构建高性能ASP.NET站点之一 剖析页面的处理过程(前端) 狼人:
    一起谈.NET技术,ASP.NET MVC 2 验证消息本地化策略扩展 狼人:
  • 原文地址:https://www.cnblogs.com/wolfred7464/p/3033011.html
Copyright © 2011-2022 走看看