2014
02-24

# Ballot evaluation

Before the 2009 elections at the European Parliament, Bill and Ted have asked their friends to make guesses about the outcome of the ballot. Now, the results have been published, so Bill and Ted want to check who was right. But checking the results of their many friends would take a very long time, and they need the evaluation to be done by a computer. Since they are not so good at programming, they ask you for help.

The data provided by Bill and Ted has the following format: The first line consists of the number p of parties followed by the number g of guesses (with 1 ≤ p ≤ 50 and 1 ≤ g ≤ 10000). Then follow p lines, each line consisting of a unique party name of length ≤ 20 (only containing letters a-z, A-Z and digits 0-9) and the achieved vote percentage of this party with one digit after the decimal point. After the parties follow g lines, each consisting of a guess. A guess has the form P1 + P2 + … + Pk COMP n, where P1 to Pk are party names, COMP is one of the comparison operators <, >, <=, >= or = and n is an integer between 0 and 100, inclusively. Each party name occurs at most once in each guess.

The data provided by Bill and Ted has the following format: The first line consists of the number p of parties followed by the number g of guesses (with 1 ≤ p ≤ 50 and 1 ≤ g ≤ 10000). Then follow p lines, each line consisting of a unique party name of length ≤ 20 (only containing letters a-z, A-Z and digits 0-9) and the achieved vote percentage of this party with one digit after the decimal point. After the parties follow g lines, each consisting of a guess. A guess has the form P1 + P2 + … + Pk COMP n, where P1 to Pk are party names, COMP is one of the comparison operators <, >, <=, >= or = and n is an integer between 0 and 100, inclusively. Each party name occurs at most once in each guess.

6 5
CDU 30.7
SPD 20.8
Gruene 12.1
FDP 11.0
CSU 7.2
FDP > 11
CDU + SPD < 50
SPD + CSU >= 28
FDP + SPD + CDU <= 42
CDU + FDP + SPD + DIELINKE = 70

Guess #1 was incorrect.
Guess #2 was incorrect.
Guess #3 was correct.
Guess #4 was incorrect.
Guess #5 was correct.

HintBe careful with the comparison of floating point values, because some values in the input (like 0.1) do not have an exact representation
as a floating point number.  

Problem – 2986

之前在华工赛见过的一道简单的模拟，用map轻松干掉。为了精确，要全程用整型比较。轻松1y~

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>

using namespace std;

map<string, int> val;

int con(char *str) {
int a, b;
sscanf(str, "%d.%d", &a, &b);
return a * 10 + b;
}

bool check(int a, int b, char *p) {
if (!strcmp(p, "=")) return a == b;
if (!strcmp(p, "<=")) return a <= b;
if (!strcmp(p, ">=")) return a >= b;
if (!strcmp(p, "<")) return a < b;
if (!strcmp(p, ">")) return a > b;
return false;
}

int main() {
int n, m;
char buf[2][100];
while (cin >> n >> m) {
for (int i = 0; i < n; i++) {
for (int i = 0; i < 2; i++) cin >> buf[i];
val[buf[0]] = con(buf[1]);
}
for (int cas = 1; cas <= m; cas++) {
int sum = 0;
while (true) {
cin >> buf[0];
sum += val[buf[0]];
cin >> buf[0];
if (buf[0][0] != '+') break;
}
int x;
cin >> x;
cout << "Guess #" << cas << " was " << (check(sum, x * 10, buf[0]) ? "correct." : "incorrect.") << endl;
}
}
return 0;
}

——written by Lyon

1. for(int i=1; i<=m; i++){
for(int j=1; j<=n; j++){
dp = dp [j-1] + 1;
if(s1.charAt(i-1) == s3.charAt(i+j-1))
dp = dp[i-1] + 1;
if(s2.charAt(j-1) == s3.charAt(i+j-1))
dp = Math.max(dp [j - 1] + 1, dp );
}
}
这里的代码似乎有点问题？ dp(i)(j) = dp(i)(j-1) + 1;这个例子System.out.println(ils.isInterleave("aa","dbbca", "aadbbcb"));返回的应该是false