//模拟题,理解题意比较辛苦 //说的是在一个电路中,找到满足条件的电阻,使得LED能够发光且不超过LED管的额定电压 //用MAP对电阻值和名称进行关联 //排个序,找到大于等于最优解的值就行了 #include<iostream> #include<algorithm> #include<map> #include<vector> #include<string> using namespace std; int main() { //freopen("in.txt","r",stdin); int V,V_led,I_led,n,R,flag; double R_led,optimum; string R_name; bool ok; while(cin >> V >> V_led >> I_led >> n) { ok = 0; map<int,string> M; vector<int> v; R_led = V_led/(double)I_led*1000; while(n--) { cin >> R_name >> R; v.push_back(R); M[R] = R_name; } sort(v.begin(),v.end()); optimum = V*R_led/V_led - R_led; for(int i = 0;i < v.size();++i) { if(optimum <= (double)v[i]) { ok = 1; flag = v[i]; break; } } if(V <= V_led && V > 0) printf("---/n");//注意只要提供的USB电源小于LED所需电源且USB电源大于0的话就无需添加额外电阻了 else if(!ok || V <= 0) printf("IMPOSSIBLE/n"); else printf("%.2f %s/n", optimum,M[flag].data()); } return 0; }