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
题目链接: http://codeforces.com/contest/535/problem/A
代码清单:
#include<iostream>
using namespace std;
string str[100]={"zero","one","two","three","four","five","six","seven","eight","nine","ten",
                    "eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty"};
void init(){
    str[30]="thirty"; str[40]="forty"; str[50]="fifty"; str[60]="sixty";
    str[70]="seventy"; str[80]="eighty"; str[90]="ninety";
}

int n;

int main(){
    cin>>n;
    init();
    if(n<=20) cout<<str[n]<<endl;
    else{
        int m=n-n%10;
        n%=10;
        cout<<str[m];
        if(n) cout<<"-"<<str[n];
        cout<<endl;
    }
    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 n. Lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 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
分析:优先队列。
题目链接: http://codeforces.com/contest/535/problem/B
代码清单:
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int ans;
ll n;
int bfs(){
    priority_queue<ll,vector<ll>,greater<ll> >q;
    while(q.size()) q.pop();
    q.push(4);q.push(7);
    while(q.size()){
        ll x=q.top();q.pop(); //cout<<x<<endl;
        if(x>n) return ans;
        ans++;
        q.push(x*10+4);
        q.push(x*10+7);
    }
}

int main(){
    cin>>n;
    cout<<bfs()<<endl;
    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 l, t 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 A, B and n (1 ≤ A, B ≤ 106, 1 ≤ 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 4
1 5 3
3 3 10
7 10 2
6 4 8
Output
4
-1
8
-1
Input
1 5 2
1 5 10
2 7 4
Output
1
2

题意:给你一个等差数列。每一次选m个不同的数使得都减一,问你最多能承受t次的右端点是多少(尽可能靠右)。
分析:这个题目看了半天没看懂,感觉好久没做英文题的样子。没看懂于是去搜了题解(蒟蒻表示无能为力)。
            二分求解。满足 max(Sl, Sl+1, Sl+2, ……, Sr) <= t  &&  (Sl)+(Sl+1)+(Sl+2)+……+(Sr) <= m*t 。
题目链接: http://codeforces.com/contest/535/problem/C
代码清单:
ps:一个二分查找我也写了n久 orz…给跪了
#include<map>
#include<cmath>
#include<ctime>
#include<cctype>
#include<queue>
#include<stack>
#include<string>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;

ll a,b,n;
ll l,t,m;
ll zuo,you,mid;
ll getNum(ll pose){
    return a+(pose-1)*b;
}

ll getSum(ll left,ll right){
    return (getNum(left)+getNum(right))*(right-left+1)/2;
}

void binary_Search(){
    ll sum=m*t;
    if(getNum(l)>t) printf("-1\n");
    else{
        zuo=l; you=((t-a)/b+1)+1;
        while(you-zuo>1){
            mid=(zuo+you)/2;
            else zuo=mid;
        }
        printf("%I64d\n",zuo);
    }
}

int main(){
    scanf("%I64d%I64d%I64d",&a,&b,&n);
    while(n--){
        scanf("%I64d%I64d%I64d",&l,&t,&m);
        binary_Search();
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值