[sicily online]1097. LED Modding

來源:互聯網
上載者:User
/*普通計算題,只要注意,給的電壓小於額定電壓也是工作的,但是小於等於0除外ConstraintsTime Limit: 1 secs, Memory Limit: 32 MBDescriptionPC Modding has become the latest trendy hobby sweeping the nation. Since you don't have too much money to spare, and since modding is supposed to be a Do-It-Yourself sort of activity, you've decided to apply some simple modifications to your own PC.One quick modification you figured wouldn't cost too much is to add some Light Emitting Diodes (LEDs) to your case. Thus, you bought yourself some LEDs, and, once they arrived to your house, you started looking for power. In order to draw power from one of the standard connectors on your motherboard you would need a connector. Alas, you forgot to order any of those. You're left with your back-up plan: take the power from the USB adapter available on your motherboard using a USB cable, and plug in your bright blue LEDs. You have the USB cable ready to go, but you realize that you still have a problem to solve: the USB port on the motherboard does not always provide power at the same voltage required by the LEDs. Looking around, you find a convenient box of resistors that might just do the trick.Fortunately, you remember Ohm's Law:Voltage (in volts) = Current (in amperes) * Resistance (in ohms)and realize you can use resistance to lower the voltage provided by the USB adapter to that expected by the LEDs. You even remember that if you can't reduce the voltage to exactly what they expect, you can still get a nice glow if you reduce it to below the expected voltage. Of course, if you provide too much voltage, you'll get a very short bright display,  but you don't want to destroy your LEDs, so this is not acceptable.Likewise, if the voltage provided is 0 or lower, there will be no power to the LED, so this case is also unacceptable.InputThe input file for this problem includes a series of 1 or more test cases.Each test case begins with a line formatted as follows:<USB> <LED_V> <LED_mA> <N>Where:<USB> is a positive integer value indicating how many volts the USB adapter on the motherboard produces;<LED_V> is a positive integer value indicating how many volts the LEDs expect to receive;<LED_mA> is a positive integer value, in milliampere (each milliampere is a thousandth of an ampere) indicating the current at which the LEDs operate;<N> is a non-negative integer number indicating how many types of resistors are available in the test case.This line is followed by <N> lines each describing a type of resistor available. All types of resistors available in a given test case are different from each other. This means that their names and resistance values are all different. These lines are formatted as follows:<Resistor_Name> <Resistance>Where <Resistor_Name> is a sequence of at most 40 alphabetic characters, and<Resistance> is a positive integer, giving the resistance of that type of resistors,measured in ohms.The end of input will be indicated by end of file.OutputFor each test case in the input file you should produce a single line in the output file formatted as follows:<Optimum_Res> <Resistor_Name>Where <Optimum_Res> is the optimum resistance in ohms that should be added to the circuit to make the LEDs receive the power they expect, and <Resistor_Name> is the name of the resistor, out of those available in the test case, that should be used. In displaying the optimal resistance, use 2 decimal digits, rounding any additional digits.When no resistor available provides the optimal resistance for the test case, you should select the resistor that is the closest to the optimum resistance and still makes the circuit work (providing to the LEDs less current than they expect).If the circuit cannot be made to work with the given parts, instead of a line formatted as described above, your output file should include a line with only the "IMPOSSIBLE" string in it.If the USB port provides acceptable voltage without addition to resistance to the LED, the output line should only include the "---" string.Sample Input5 3 20 2Red 90Orange 1105 3 20 2ThisOne 110TheOtherOne 1005 3 20 1TooLittle 905 5 20 1Sample 10Sample Output100.00 Orange100.00 TheOtherOneIMPOSSIBLE---*/#include<iostream>  #include <iomanip>  #include<stdio.h>  #include<cmath>  #include<iomanip>  #include<list>  #include <map>  #include <vector>  #include <string>  #include <algorithm>  #include <sstream>  #include <stack>  #include<queue>  #include<string.h>  #include<set>  using namespace std;  typedef struct RESISTENT{string name;double value;}Resistent;int main()  {  int privideVol;while(cin>>privideVol){int needVol;int current;int n;cin>>needVol>>current>>n;vector<Resistent> data(n);for(int i=0;i<n;i++)cin>>data[i].name>>data[i].value;if(privideVol<=0)cout<<"IMPOSSIBLE"<<endl;else if(privideVol<=needVol)cout<<"---"<<endl;else {int cha=privideVol-needVol;double needRes=cha/(double)current;needRes=needRes*1000.0;double min=999999999.0;int index=-1;for(int i=0;i<data.size();i++){if(data[i].value<min&&data[i].value>=needRes){index=i;min=data[i].value;if((min-needRes)<1e-6)break;}}if(index==-1)cout<<"IMPOSSIBLE"<<endl;else cout<<setiosflags(ios::fixed)<<setprecision(2)<<needRes<<" "<<data[index].name<<endl;}}}                                 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.