QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#95428#5133. Imperfect Imperial Units_b_WA 0ms3596kbC++141.3kb2023-04-09 17:25:432023-04-09 17:25:48

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-09 17:25:48]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3596kb
  • [2023-04-09 17:25:43]
  • 提交

answer

#include<iostream>
#include<map>
#include<utility>
#include<vector>
#include<iomanip>
using namespace std;
#define ld long double
map<pair<string,string>, ld>convert;
map<pair<string, string>, int>book;
vector<string>tol;

int n, q;

int main() {
	cin >> n >> q;
	ld tmp1, tmp2; string s1, s2; string trash;
	for (int i = 0; i < n; i++) {
		cin >> tmp1 >> s1 >> trash >> tmp2 >> s2;
		convert[{s1, s2}] = tmp2 / tmp1; convert[{s2, s1}] = tmp1 / tmp2;
		book[{s1, s2}] = 1; book[{s2, s1}] = 1;
		for (auto& s : tol) {
			if (s != s1 && s != s2) {
				if (book[{s, s1}]) {
					book[{s, s2}] = 1; book[{s2, s}] = 1;
					convert[{s, s2}] = convert[{s, s1}] * convert[{s1, s2}];
					convert[{s2, s}] = convert[{s2, s1}] * convert[{s1, s}];
				}
				else if (book[{s, s2}]) {
					book[{s, s1}] = 1; book[{s1, s1}] = 1;
					convert[{s, s1}] = convert[{s, s2}] * convert[{s2, s1}];
					convert[{s1, s}] = convert[{s1, s2}] * convert[{s2, s}];
				}
			}
		}
		tol.push_back(s1); tol.push_back(s2);
	}
	ld target;
	for (int i = 0; i < q; i++) {
		cin >> target >> s1 >> trash >> s2;
		ld ans = target * convert[{s1, s2}];
		if (book[{s1,s2}]==0) {
			cout << "impossible" << endl;
		}
		else {
			cout << setprecision(18) << ans << endl;
		}
	}
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3596kb

input:

4 3
1 foot = 12 inch
1 yard = 3 foot
1 meter = 100 centimeter
1 centimeter = 10 millimeter
750 millimeter to meter
42 yard to inch
10 meter to foot

output:

0.75
impossible
impossible

result:

wrong answer