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 .

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 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
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 ≤ 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
D. Tavas and Malekas
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Tavas is a strange creature. Usually "zzz" comes out of people's mouth while sleeping, but string s of length n comes out from Tavas' mouth instead.

Today Tavas fell asleep in Malekas' place. While he was sleeping, Malekas did a little process on s. Malekas has a favorite string p. He determined all positions x1 < x2 < ... < xk where p matches s. More formally, for each xi (1 ≤ i ≤ k) he condition sxisxi + 1... sxi + |p| - 1 = p is fullfilled.

Then Malekas wrote down one of subsequences of x1, x2, ... xk (possibly, he didn't write anything) on a piece of paper. Here a sequence b is a subsequence of sequence a if and only if we can turn a into b by removing some of its elements (maybe no one of them or all).

After Tavas woke up, Malekas told him everything. He couldn't remember string s, but he knew that both p and s only contains lowercase English letters and also he had the subsequence he had written on that piece of paper.

Tavas wonders, what is the number of possible values of s? He asked SaDDas, but he wasn't smart enough to solve this. So, Tavas asked you to calculate this number for him.

Answer can be very large, so Tavas wants you to print the answer modulo 109 + 7.

Input

The first line contains two integers n and m, the length of s and the length of the subsequence Malekas wrote down (1 ≤ n ≤ 106 and 0 ≤ m ≤ n - |p| + 1).

The second line contains string p (1 ≤ |p| ≤ n).

The next line contains m space separated integers y1, y2, ..., ym, Malekas' subsequence (1 ≤ y1 < y2 < ... < ym ≤ n - |p| + 1).

Output

In a single line print the answer modulo 1000 000 007.

Sample test(s)
input
6 2
ioi
1 3
output
26
input
5 2
ioi
1 2
output
0
Note

In the first sample test all strings of form "ioioi?" where the question mark replaces arbitrary English letter satisfy.

Here |x| denotes the length of string x.

Please note that it's possible that there is no such string (answer is 0).

E. Tavas and Pashmaks
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Tavas is a cheerleader in the new sports competition named "Pashmaks".

This competition consists of two part: swimming and then running. People will immediately start running R meters after they finished swimming exactly S meters. A winner is a such person that nobody else finishes running before him/her (there may be more than one winner).

Before the match starts, Tavas knows that there are n competitors registered for the match. Also, he knows that i-th person's swimming speed is simeters per second and his/her running speed is ri meters per second. Unfortunately, he doesn't know the values of R and S, but he knows that they are real numbers greater than 0.

As a cheerleader, Tavas wants to know who to cheer up. So, he wants to know all people that might win. We consider a competitor might win if and only if there are some values of R and S such that with these values, (s)he will be a winner.

Tavas isn't really familiar with programming, so he asked you to help him.

Input

The first line of input contains a single integer n (1 ≤ n ≤ 2 × 105).

The next n lines contain the details of competitors. i-th line contains two integers si and ri (1 ≤ si, ri ≤ 104).

Output

In the first and the only line of output, print a sequence of numbers of possible winners in increasing order.

Sample test(s)
input
3
1 3
2 2
3 1
output
1 2 3 
input
3
1 2
1 1
2 1
output
1 3 

A题:

   题目大意:

      比较逗比的一道题目,输入一个[0,99]的数字,让你把他翻译成为英语。

   解题思路:

      直接模拟搞就好了,因为只有两位数,所以我们先处理数的位数,一口气先打一个[0,19]的表。然后,凡是[20,99]的通过按位取模和分离整数来求就好了

   但是,,,一定要注意下20,30,40,50,这样的情况,,,第一次输出了 twenty-zero。。。。

       代码:

  

# include<cstdio>
# include<iostream>
# include<string>

using namespace std;

string s1[20] = {"zero","one","two","three","four","five","six","seven","eight",
                    "nine","ten","eleven","twelve","thirteen","fourteen","fifteen",
                    "sixteen","seventeen","eighteen","nineteen"};

string s2[20] = {"twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};

int main(void)
{
    int n;
    while ( scanf("%d",&n)!=EOF )
    {
        if ( n>=0&&n<=19 )
        {
            cout<<s1[n]<<endl;
        }
        else
        {
            cout<<s2[n/10-2];
            if ( n%10!=0 )
            {
                cout<<"-";
                cout<<s1[n%10];
            }
            cout<<endl;
        }
    }


    return 0;
}

 

 

 

B题:

  题目大意:

    这题好像是SDOI某年的原题,,,就是说lucky是一个这样的数字,这个数字中,只能包含4和7,对他们从小到大进行排序,输出他是第几个.

  解题思路:

     我们把[4,10^9]以内的具有这种特征的数字都搞出来,怎么搞呢?其实就用queue搞就可以了,我们每次插入一个按照从小到大的顺序插入两个数字, 插入的数字都放到vector中,然后再定义一个迭代器,开始从头到尾找一遍就OK了。。

    代码:

 1 # include<cstdio>
 2 # include<iostream>
 3 # include<queue>
 4 # include<set>
 5 
 6 using namespace std;
 7 
 8 # define limit 1e9
 9 
10 typedef long long LL;
11 vector<LL>v;
12 
13 void init()
14 {
15     queue<LL>q;
16     q.push(4);
17     q.push(7);
18     while ( !q.empty() )
19     {
20         int cur = q.front();
21         q.pop();
22         if ( cur > limit )
23             return;
24         v.push_back(cur);
25         LL nxt1 = cur*10+4;
26         LL nxt2 = cur*10+7;
27         q.push(nxt1);
28         q.push(nxt2);
29     }
30 }
31 
32 int main(void)
33 {
34     LL n;
35     init();
36     while ( cin>>n )
37     {
38         LL cnt = 0;
39         vector<LL>::iterator it;
40         for ( it=v.begin();it!=v.end();it++ )
41         {
42             cnt++;
43             if ( *it == n )
44             {
45                 break;
46             }
47         }
48         cout<<cnt<<endl;
49 
50     }
51 
52 
53     return 0;
54 }

 

 

 

C题:

  题目大意:

    题目的意思是说,给你个等差数列的首项和公差和n个询问,再给你三个数字,分别为,l,t,m,让你找出[l,r]区间中,每次都最多减去m,进行t次。找到这个最大的r,使得他们的高度差为-1.(也就是说t*m-sum[l,r] == - 1)。有的话,输出这个最大的r,否则输出”-1“.

  解题思路:

  直接维护前缀和好了,然后二分出来那个最大的r,,,吃饭去了,回来再写。

  代码:

 

posted @ 2015-04-15 17:28  BYYB_0506  阅读(285)  评论(0编辑  收藏  举报