Codeforces Round #299 (Div. 2) -- (A,B,C)

来源:互联网 发布:2015年老龄化数据 编辑:程序博客网 时间:2024/05/21 11:26

题目传送:Codeforces Round #299 (Div. 2)



A. Tavas and Nafas
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

The first and only line of input contains an integer s (0 ≤ s ≤ 99), Tavas's score.

Output

In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces.

Sample test(s)
input
6
output
six
input
99
output
ninety-nine
input
20
output
twenty
Note

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;}





B. Tavas and SaDDas
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."

The problem is:

You are given a lucky number nLucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 477444 are lucky and 517467 are not.

If we sort all lucky numbers in increasing order, what's the 1-based index of n?

Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back.

Input

The first and only line of input contains a lucky number n (1 ≤ n ≤ 109).

Output

Print the index of n among all lucky numbers.

Sample test(s)
input
4
output
1
input
7
output
2
input
77
output
6



思路:题意是去求该数以内的幸运数个数,对应二进制求即可


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;}




C. Tavas and Karafs
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Karafs is some kind of vegetable in shape of an 1 × h rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs.

Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the i-th Karafs is si = A + (i - 1) × B.

For a given m, let's define an m-bite operation as decreasing the height of at most m distinct not eaten Karafses by 1. Karafs is considered as eaten when its height becomes zero.

Now SaDDas asks you n queries. In each query he gives you numbers lt and m and you should find the largest number r such that l ≤ r and sequence sl, sl + 1, ..., sr can be eaten by performing m-bite no more than t times or print -1 if there is no such number r.

Input

The first line of input contains three integers AB and n (1 ≤ A, B ≤ 1061 ≤ n ≤ 105).

Next n lines contain information about queries. i-th line contains integers l, t, m (1 ≤ l, t, m ≤ 106) for i-th query.

Output

For each query, print its answer in a single line.

Sample test(s)
input
2 1 41 5 33 3 107 10 26 4 8
output
4-18-1
input
1 5 21 5 102 7 4
output
12



思路:英语真的是硬伤啊,先是看半天没看懂题,后来问了下学长,才理解题意,于是乎没时间调出来了,就是二分找符合条件的最右


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;}







0 0
原创粉丝点击