• 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 }
  • 相关阅读:
    uboot的仓库在哪里?
    git如何查看执行过的历史git命令
    for(;;)和while(true)的区别
    CountDownLatch的理解和使用
    countDownLatch
    websocket @ServerEndpoint(value = "/websocket/{ip}")详解
    Java原子性操作之——Atomic包的原理分析
    CAS原理
    java线程池ThreadPoolExecutor的keepAliveTime=0时,表示超过core线程数的线程在空闲时立即结束!!!
    ThreadPoolExecutor 线程池Demo
  • 原文地址:https://www.cnblogs.com/wolfred7464/p/3033011.html
Copyright © 2020-2023  润新知