首页 > ACM题库 > HDU-杭电 > HDU 2812-74LS00-模拟-[解题报告]HOJ
2014
02-17

HDU 2812-74LS00-模拟-[解题报告]HOJ

74LS00

问题描述 :

It’s known to us that 74LS00 is a useful digital logic chip for use in a variety of projects. Give you the voltage in all the pins. Your task is quite simple, just estimate whether the chip could work normally or not.
  Here are some essential hints about the pins:

Note: If you chose Pins (1, 2) for input, only Pins (3) would indicate logic.

Here follow the definition of “logic”
If voltage Vi, |Vi-5|<=0.5 then we call it a “High Logic”
If voltage Vi is no larger than 0.8V, and Vi>=0 then we call it a “Low Logic”

“H”: High Logical
“L”: Low Logical
That is to say, if the voltage in Pin 1 is 5.0V and the voltage in Pin 2 is 5.0V, so the Pin 3 indicates Low Logic.
The voltage in Pin 14 must be exactly 5.0V so that the chip could work normally; the voltage in Pin 7 must be always Low Logic.

输入:

The input consists of several test cases.
In the first line there is an integer n (2<=n<=10), indicating the number of descriptions.
The next n lines contain the descriptions of the different Pins
All the descriptions are given in the following format
Pin_ID Voltage
We guarantee that the Voltage is always in the range. (0<=Voltage<=0.8 or 4.5<=Voltage<=5.5)
We guarantee that Pin 14 and Pin 7 will always be given in every case.

输出:

The input consists of several test cases.
In the first line there is an integer n (2<=n<=10), indicating the number of descriptions.
The next n lines contain the descriptions of the different Pins
All the descriptions are given in the following format
Pin_ID Voltage
We guarantee that the Voltage is always in the range. (0<=Voltage<=0.8 or 4.5<=Voltage<=5.5)
We guarantee that Pin 14 and Pin 7 will always be given in every case.

样例输入:

2
14 5.00000000
7 0.1
2
14 5.1
7 0.8
4
14 5.0000
7 0.7
1 0.3766
2 5.1344
6
14 5.00000000000
7 0
1 5.1
2 5.1
4 5.1
5 5.1

样例输出:

Yes
No
Yes
3 H
Yes
3 L
6 L

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2812

题目大意:

给你一个芯片的各个引脚的信息,求如果芯片能正常工作时,各个输出引脚能输出的高低电平的情况。

解题思路:

水题一道,但是考察点在于精度的控制。这点也是自己比较薄弱的地方,尤其是2个double数据,不能通过简单的“=”来判断,应该是通过相减小于一个特别小(1e-16)的数来判断。总之,以后也要多练习这样的模拟题。争取水题早点A。节省时间。

代码如下:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
double pin[15];

bool judge()
{
    if(fabs(pin[14] - 5)  < 1e-16 && (pin[7] >= 0 && pin[7] <= 0.8))
        return true;
    else
        return false;
}

bool gaodi(double a)
{
    int temp;
    if(a >= 0.0 && a <= 0.8)
        return 0; //low
    else
            return 1; //high
}

char cal(double a, double b)
{
    if(gaodi(a) && gaodi(b))
        return 'L';
    else
        return 'H';
}

int main()
{
    int n;
    int a;
    double dianya;
    while(scanf("%d", &n) != EOF)
    {
        for(int i = 1; i <= 14; ++i)
            pin[i] = -1.0;
        for(int i = 0; i < n; ++i)
        {
            scanf("%d%lf", &a, &dianya);
            pin[a] = dianya;
        }
        if(!judge())
        {
            printf("No\n");
            continue;
        }
        else
        {
            printf("Yes\n");
            if(pin[1] != -1 && pin[2] != -1)
            {
                printf("3 %c\n", cal(pin[1], pin[2]));
            }
            if(pin[4] != -1 && pin[5] != -1)
            {
                printf("6 %c\n", cal(pin[4], pin[5]));
            }
            if(pin[9] != -1 && pin[10] != -1)
            {
                printf("8 %c\n", cal(pin[9], pin[10]));
            }
            if(pin[12] != -1 && pin[13] != -1)
            {
                printf("11 %c\n", cal(pin[12], pin[13]));
            }
        }
    }
    return 0;
}

解题参考:http://blog.csdn.net/niushuai666/article/details/7184446


  1. 不要再看见陈赫 太让人失望了 让一直挺他的粉丝情何以堪 。一封认错书真的是让粉丝彻底看透他了,没时间维系家庭却有时间去做小三,许婧太无辜了

  2. 不要再看见陈赫 太让人失望了 让一直挺他的粉丝情何以堪 。一封认错书真的是让粉丝彻底看透他了,没时间维系家庭却有时间去做小三,许婧太无辜了

  3. 不要再看见陈赫 太让人失望了 让一直挺他的粉丝情何以堪 。一封认错书真的是让粉丝彻底看透他了,没时间维系家庭却有时间去做小三,许婧太无辜了

  4. 不要再看见陈赫 太让人失望了 让一直挺他的粉丝情何以堪 。一封认错书真的是让粉丝彻底看透他了,没时间维系家庭却有时间去做小三,许婧太无辜了

  5. 不要再看见陈赫 太让人失望了 让一直挺他的粉丝情何以堪 。一封认错书真的是让粉丝彻底看透他了,没时间维系家庭却有时间去做小三,许婧太无辜了

  6. 不要再看见陈赫 太让人失望了 让一直挺他的粉丝情何以堪 。一封认错书真的是让粉丝彻底看透他了,没时间维系家庭却有时间去做小三,许婧太无辜了

  7. 不要再看见陈赫 太让人失望了 让一直挺他的粉丝情何以堪 。一封认错书真的是让粉丝彻底看透他了,没时间维系家庭却有时间去做小三,许婧太无辜了

  8. 不要再看见陈赫 太让人失望了 让一直挺他的粉丝情何以堪 。一封认错书真的是让粉丝彻底看透他了,没时间维系家庭却有时间去做小三,许婧太无辜了

  9. 不要再看见陈赫 太让人失望了 让一直挺他的粉丝情何以堪 。一封认错书真的是让粉丝彻底看透他了,没时间维系家庭却有时间去做小三,许婧太无辜了

  10. 老实说,这种方法就是穷举,复杂度是2^n,之所以能够AC是应为题目的测试数据有问题,要么数据量很小,要么能够得到k == t,否则即使n = 30,也要很久才能得出结果,本人亲测

  11. 第一句可以忽略不计了吧。从第二句开始分析,说明这个花色下的所有牌都会在其它里面出现,那么还剩下♠️和♦️。第三句,可以排除2和7,因为在两种花色里有。现在是第四句,因为♠️还剩下多个,只有是♦️B才能知道答案。

  12. #include <stdio.h>
    int main(void)
    {
    int arr[] = {10,20,30,40,50,60};
    int *p=arr;
    printf("%d,%d,",*p++,*++p);
    printf("%d,%d,%d",*p,*p++,*++p);
    return 0;
    }

    为什么是 20,20,50,40,50. 我觉得的应该是 20,20,40,40,50 . 谁能解释下?