1010 Radix
题目:
Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer is "yes", if 6 is a decimal number and 110 is a binary number.
Now for any pair of positive integers N1 and N2, your task is to find the radix of one number while that of the other is given.
Input Specification:
Each input file contains one test case. Each case occupies a line which contains 4 positive integers:
N1 N2 tag radix
Here N1 and N2 each has no more than 10 digits. A digit is less than its radix and is chosen from the set {0-9, a-z} where 0-9 represent the decimal numbers 0-9, and a-z represent the decimal numbers 10-35. The last number "radix" is the radix of N1 if "tag" is 1, or of N2 if "tag" is 2.
Output Specification:
For each test case, print in one line the radix of the other number so that the equation N1 = N2 is true. If the equation is impossible, print "Impossible". If the solution is not unique, output the smallest possible radix.
Sample Input 1:
6 110 1 10
Sample Output 1:
2
Sample Input 2:
1 ab 1 2
Sample Output 2:
Impossible
题解:每一行输入都有4个数,分别是N1和N2各不超过10位,一个数字小于其基数,从集合{0-9,A-z}中选择,其中0-9表示十进制数字0-9,A-z表示十进制数字10-35。
如果标记为1,则最后一个数字基数是N1的基数,如果标记为2,则最后的数字基数是N2的基数。
code:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
unordered_map<char, int>charToint; // 0-9 a-z映射;unoedered_map无存储顺序
ll trans(string s, ll radix){
ll result = 0;
for(auto i : s)
result = result * radix + charToint[i];
return result;
}
ll findRadix(string n1, string n2, ll radix){
ll right = trans(n1, radix), left = -1, tag = right;
for(auto i : n2)
left = max(left, (ll)charToint[i] + 1);
while(left < right){
ll mid = left + (right - left) / 2, k = trans(n2, mid);
if(k < 0 || k >= tag)
right = mid;
else if(k < tag)
left = mid + 1;
}
if(trans(n2, left) != tag)
left = -1;
return left;
}
int main(){
ios::sync_with_stdio(false);
string s1, s2;
ll tag, radix;
cin>>s1>>s2>>tag>>radix;
for(int i = 0; i < 36; i++)
charToint.insert({i < 10 ? i+'0' : i-10+'a', i});
radix = tag == 1 ? findRadix(s1, s2, radix) : findRadix(s2, s1, radix);
if(radix == -1) cout<<"Impossible\n";
else cout<<radix<<endl;
return 0;
}
1011 World Cup Betting
题目:
With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams doing battles for the World Cup trophy in South Africa. Similarly, football betting fans were putting their money where their mouths were, by laying all manner of World Cup bets.
Chinese Football Lottery provided a “Triple Winning” game. The rule of winning was simple: first select any three of the games. Then for each selected game, bet on one of the three possible results — namely W for win, T for tie, and L for lose. There was an odd assigned to each result. The winner’s odd would be the product of the three odds times 65%.
For example, 3 games’ odds are given as the following:
W T L
1.1 2.5 1.7
1.2 3.0 1.6
4.1 1.2 1.1
To obtain the maximum profit, one must buy W for the 3rd game, T for the 2nd game, and T for the 1st game. If each bet takes 2 yuans, then the maximum profit would be (4.1*3.0*2.5*65%-1)*2 = 37.98 yuans (accurate up to 2 decimal places).
Input
Each input file contains one test case. Each case contains the betting information of 3 games. Each game occupies a line with three distinct odds corresponding to W, T and L.
Output
For each test case, print in one line the best bet of each game, and the maximum profit accurate up to 2 decimal places. The characters and the number must be separated by one space.
Sample Input
1.1 2.5 1.7
1.2 3.0 1.6
4.1 1.2 1.1
Sample Output
T T W 37.98
题解:给出三场比赛以及每场比赛的W、T、L的赔率。选取每一场比赛中赔率最大的三个数a b c,先输出三行各自选择的是W、T、L中的哪一个,接着根据计算公式 (a * b * c * 0.65 - 1) * 2 得出最大收益。
code:
#include<bits/stdc++.h>
using namespace std;
int main(){
double a,b,c;
double sum = 0.65;
for(int i = 0; i < 3; i++){
double max_res;
cin>>a>>b>>c;
if(a>b && a>c){
cout<<"W"<<" ";
max_res = a;
}
if(b>a && b>c){
cout<<"T"<<" ";
max_res = b;
}
if(c>b && c>a){
cout<<"L"<<" ";
max_res = c;
}
sum *= max_res;
}
printf("%.2lf\n", (sum-1) * 2);
return 0;
}
1012 The Best Rank
题目:
To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Mathematics (Calculus or Linear Algebra), and E - English. At the mean time, we encourage students by emphasizing on their best ranks -- that is, among the four ranks with respect to the three courses and the average grade, we print the best rank for each student.
For example, The grades of C, M, E and A - Average of 4 students are given as the following:
StudentID C M E A
310101 98 85 88 90
310102 70 95 88 84
310103 82 87 94 88
310104 91 91 91 91
Then the best ranks for all the students are No.1 since the 1st one has done the best in C Programming Language, while the 2nd one in Mathematics, the 3rd one in English, and the last one in average.
Input
Each input file contains one test case. Each case starts with a line containing 2 numbers N and M (<=2000), which are the total number of students, and the number of students who would check their ranks, respectively. Then N lines follow, each contains a student ID which is a string of 6 digits, followed by the three integer grades (in the range of [0, 100]) of that student in the order of C, M and E. Then there are M lines, each containing a student ID.
Output
For each of the M students, print in one line the best rank for him/her, and the symbol of the corresponding rank, separated by a space.
The priorities of the ranking methods are ordered as A > C > M > E. Hence if there are two or more ways for a student to obtain the same best rank, output the one with the highest priority.
If a student is not on the grading list, simply output "N/A".
Sample Input
5 6
310101 98 85 88
310102 70 95 88
310103 82 87 94
310104 91 91 91
310105 85 90 90
310101
310102
310103
310104
310105
999999
Sample Output
1 C
1 M
1 E
1 A
3 A
题意理解:
已知n个考生的3门分数,平均分按三门成绩计算。然后分别对这四个分数从高到低排序,每个考生就有4个排名。
查询学生排名:输入某学生id,输出当前id学生的最好的排名和它对应的分数;如果名次相同,按照A>C>M>E的优先级输出;如果当前id不存在,输出N/A。
code:
#include<bits/stdc++.h>
using namespace std;
struct node{
int id, best_score;
int score[4], rank[4];
}student[2005];
int exist[1000000], flag = -1;
bool cmp1(node a, node b){
return a.score[flag] > b.score[flag];
}
int main(){
int N, M, id;
cin>>N>>M;
for(int i = 0; i < N; i++){
cin>>student[i].id>>student[i].score[1]>>student[i].score[2]>>student[i].score[3];
student[i].score[0] = (student[i].score[1] + student[i].score[2] + student[i].score[3]) / 3.0 + 0.5;
}
for(flag = 0; flag <= 3; flag++){
sort(student, student+N, cmp1);
student[0].rank[flag] = 1;
for(int i = 1; i < N; i++){
student[i].rank[flag] = i + 1;
if(student[i].score[flag] == student[i-1].score[flag])
student[i].rank[flag] = student[i-1].rank[flag];
}
}
for(int i = 0; i < N; i++){
exist[student[i].id] = i + 1;
student[i].best_score = 0;
int minN = student[i].rank[0];
for(int j = 1; j <= 3; j++){
if(student[i].rank[j] < minN){
minN = student[i].rank[j];
student[i].best_score = j;
}
}
}
char c[5] = {'A', 'C', 'M', 'E'};
for(int i = 0; i < M; i++){
cin>>id;
int temp = exist[id];
if(temp){
int best_score = student[temp -1].best_score;
cout<<student[temp-1].rank[best_score]<<" "<<c[best_score]<<endl;
}
else{
cout<<"N/A"<<endl;
}
}
return 0;
}