题目传送:Codeforces Round #299 (Div. 2)
Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas.
His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words.
He ate coffee mix without water again, so right now he's really messed up and can't think.
Your task is to help him by telling him what to type.
The first and only line of input contains an integer s (0 ≤ s ≤ 99), Tavas's score.
In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces.
6
six
99
ninety-nine
20
twenty
You can find all you need to know about English numerals in http://en.wikipedia.org/wiki/English_numerals .
就是由数字转换为100以内的英语
AC代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#define LL long long
#define INF 0x7fffffff
using namespace std;
void fun(int s) {
if(s == 0) printf("zero\n");
else if(s == 1) printf("one\n");
else if(s == 2) printf("two\n");
else if(s == 3) printf("three\n");
else if(s == 4) printf("four\n");
else if(s == 5) printf("five\n");
else if(s == 6) printf("six\n");
else if(s == 7) printf("seven\n");
else if(s == 8) printf("eight\n");
else if(s == 9) printf("nine\n");
else if(s == 10) printf("ten\n");
else if(s == 11) printf("eleven\n");
else if(s == 12) printf("twelve\n");
else if(s == 13) printf("thirteen\n");
else if(s == 14) printf("fourteen\n");
else if(s == 15) printf("fifteen\n");
else if(s == 16) printf("sixteen\n");
else if(s == 17) printf("seventeen\n");
else if(s == 18) printf("eighteen\n");
else if(s == 19) printf("nineteen\n");
else if(s == 20) printf("twenty\n");
}
void fun1(int s) {
if(s == 2) printf("twenty");
else if(s == 3) printf("thirty");
else if(s == 4) printf("forty");
else if(s == 5) printf("fifty");
else if(s == 6) printf("sixty");
else if(s == 7) printf("seventy");
else if(s == 8) printf("eighty");
else if(s == 9) printf("ninety");
}
int main() {
int s;
scanf("%d", &s);
if(s <= 20) {
fun(s);
}
else {
fun1(s / 10);
if(s % 10 != 0) {
printf("-");
fun(s % 10);
}
else if(s % 10 == 0){
printf("\n");
}
}
return 0;
}
思路:题意是去求该数以内的幸运数个数,对应二进制求即可
AC代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#define LL long long
#define INF 0x7fffffff
using namespace std;
int fun(int x) {
int cnt = 0;
while(x) {
cnt ++;
x /= 10;
}
return cnt;
}
int main() {
int n;
scanf("%d", &n);
int len = fun(n);
int tmp = 1;
int ans = 0;
int t = n;
while(t) {
if(t % 10 == 4) {
ans += (tmp * 1);
}
else {
ans += (tmp * 2);
}
t /= 10;
tmp *= 2;
}
printf("%d\n", ans);
return 0;
}
思路:英语真的是硬伤啊,先是看半天没看懂题,后来问了下学长,才理解题意,于是乎没时间调出来了,就是二分找符合条件的最右
AC代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
using namespace std;
LL A, B, n;
LL fun(LL l, LL r) { //算出l到r区间的食物数目
return (A + (l - 1) * B + A + (r - 1) * B) * (r - l + 1) / 2;
}
int main() {
cin >> A >> B >> n;
LL l, t, m;
for(int i = 0; i < n; i++) {
scanf("%I64d %I64d %I64d", &l, &t, &m);
LL maxR = (t - A) / B + 1; //先计算出所能达到的最右,由公式反推
LL tot = t * m; //算出总和
if(maxR < l) {
printf("-1\n");
}
else {
LL le = l;
LL ri = maxR;
LL mid = ri;
LL ans = ri;
while(le <= ri) { //二分
mid = (le + ri) / 2;
if(fun(l, mid) <= tot) {
le = mid + 1;
ans = mid;
}
else {
ri = mid - 1;
}
}
printf("%I64d\n", ans);
}
}
return 0;
}