Codeforces Round #299 (Div. 2) -- (A,B,C)
来源:互联网 发布:2015年老龄化数据 编辑:程序博客网 时间:2024/05/21 11:26
题目传送: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 0x7fffffffusing 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 0x7fffffffusing 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 longusing 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;}
- Codeforces Round #299 (Div. 2) -- (A,B,C)
- Codeforces Round #299 (Div. 2)A B C
- Codeforces Round #299 (Div. 2)【A,B,C】
- Codeforces Round #285 (Div. 2) (A、B、C、D)
- Codeforces Round #301 (Div. 2) -- (A,B,C,D)
- Codeforces Round #302 (Div. 2) -- (A,B,C)
- Codeforces Round #313 (Div. 2) (A、B、C、D)
- Codeforces Round #364 (Div. 2)(A,B,C,D)
- Codeforces Round #376 (Div. 2) (A.B.C)
- 【Codeforces Round #383 (Div. 2)】 (A,B,C)
- 【Codeforces Round #384 (Div.2)】(A,B,C)
- 【Codeforces Round #402 (Div. 2) 】(A,B,C,D )
- Codeforces Round #441 (Div. 2)A + B + C
- Codeforces Beta Round #95 (Div. 2) A B C E
- 【CodeForce】Codeforces Round #140 (Div. 2) A B C
- 【CodeForce】Codeforces Round #142 (Div. 2) A B C
- Codeforces Round #160 (Div. 2)——A,B,C
- Codeforces Round #177 (Div. 2)——A,B,C
- BP神经网络Python实现
- 省选模版复习——LCT
- 第五周项目5——友元类
- 第六周上机项目2我的数组类
- 第6周项目1.1深复制
- Codeforces Round #299 (Div. 2) -- (A,B,C)
- 图像操作的形态学处理MATLAB
- 第六周项目1 深复制体验
- android中的线程(二上)
- 第六周阅读程序2:构造函数与析构函数
- 省选模版复习——FFT
- 第六周 课后实践:阅读程序
- 第六周 程序阅读-深复制、友元、类模板(3)
- 2-6-2 我的数组类