codeforces 160

来源:互联网 发布:1919是真酒吗 知乎 编辑:程序博客网 时间:2024/05/02 04:53

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.

Example
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

一道输出英文数字的题,水题map过,原来18忘掉,萎了,2A

#include<bits/stdc++.h>using namespace std;int n;map<int,string>M;int main(){    cin>>n;    if(n==0) {puts("zero");return 0;}    M[1]="one";M[2]="two";M[3]="three";M[4]="four";    M[5]="five";M[6]="six";M[7]="seven";M[8]="eight";    M[9]="nine";    M[20]="twenty";M[30]="thirty";M[40]="forty";M[50]="fifty";    M[60]="sixty";M[70]="seventy";M[80]="eighty";M[90]="ninety";    M[10]="ten";M[11]="eleven";M[12]="twelve";M[13]="thirteen";    M[14]="fourteen";M[15]="fifteen";M[16]="sixteen";M[17]="seventeen";    M[18]="eighteen";    M[19]="nineteen";    if(n<20)    {        cout<<M[n];    }    else    {        int k=(n/10)*10;        if(n%10==0)        {            cout<<M[n];        }        else         cout<<M[k]<<"-"<<M[n%10]<<endl;    }}

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.

Example
Input
4
Output
1
Input
7
Output
2
Input
77
Output
6

B题,直接按位搜就可以A了

#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include"new"using namespace std;long long it;long long n;long long ans;void dfs(long long x){    if(x>n) return;    ans++;    dfs(x*10+7);    dfs(x*10+4);    return;}int main(){    cin>>n;    dfs(4);    dfs(7);    cout<<ans;}

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.

Example
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

本题是挺裸的二分查找,不过要注意到以下性质:数列递增
所以我们最后取出来的数列最大数不大于t,且和不大于m*t,然后就可以二分然后判断一下A了。

#include<bits/stdc++.h>using namespace std;#define N 10000001long long S[N];long long l,t,m,a,n,b,ll;long long ans;bool pan(long long xx){    if(((xx-1)*b+a)>t) return 0;    long long dance=((xx-1)*b+a+(ll-1)*b+a)*(xx-ll+1)/2;    long long it=m*t;    if(dance<=it) return 1;else return 0;}int main(){    cin>>a>>b>>n;    while(n--)    {        cin>>l>>t>>m;        ans=-1;        long long r=(l+(t-a)/b+100);        ll=l;        while(l<=r)        {            long long mid=(l+r)>>1;            if(pan(mid))            {                ans=mid;                l=mid+1;            }            else r=mid-1;        }        cout<<ans<<endl;    }}

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.

Example
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).

一道KMP的裸题,其余人的方法是去填,不能填就覆盖,我的方法是保证每次和上一次不冲突,如果可以就把剩下位置的数量统计出来26的快速幂即可。
ne数组的妙用

%:pragma GCC optimize(4)#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<cstdlib>#include<new>#include<map>using namespace std;#define N 2000001int ne[N];char s[2000001];char t[2000001];int n,m;int it[2000001];//int x,pre;int x[2000001];int S[N];long long ans=1;const long long mod=1e9+7;bool can[N];int main(){    scanf("%d%d",&n,&m);    if(n==20)    {//      puts("0");return 0;    }    scanf("%s",t);    int wei=0;    int len=strlen(t);    for(int i=1;i<len;i++)    {        while(t[i]!=t[wei]&&wei)wei=ne[wei-1];        if(t[i]==t[wei])wei++;        ne[i]=wei;    }    int k=len-1;    while(k)    {        if(ne[k-1])        can[ne[k-1]]=1;        k=ne[k-1];    }    if(t[len-1]==t[0])can[0]=1;    for(int i=1;i<=m;i++)    {        scanf("%d",&x[i]);        if(x[i]+len-1>n) {puts("0");return 0;}        if(i==1) continue;        if((x[i]-x[i-1])>=len) continue;        else        {            int k=len-(x[i]-x[i-1]);            if(!can[k-1])            {                puts("0");return 0;            }        }    }    for(int i=1;i<=m;i++)    {        S[x[i]]=len;    }    for(int i=1;i<=n;i++)    {        if(S[i]==0)        {            ans*=26;            ans=ans%mod;        }        S[i+1]=max(S[i]-1,S[i+1]);    }    cout<<ans;//  puts("");cout<<ne[2];}

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 si meters 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.

Example
Input
3
1 3
2 2
3 1
Output
1 2 3
Input
3
1 2
1 1
2 1
Output
1 3

斜率优化我们对于两个保证他们的s递增,(我们要先排除s和r均递增的情况,否则前者一定不忧)然后我们就计算一下中间的比两边大的时候的区间,要是不交那么中间一定不优,这是可以推成斜率优化的,所以就可以斜率优化了,最后把那些重复的都搞出来就行了

#include<cstdio>#include<iostream>#include"algorithm"#include<cstring>#include<map>using namespace std;#define N 500001int n;struct node{    int s,r,no;}xx[N],dance[N],fire[N];bool cmp(node x,node y){    return x.s>y.s||(x.s==y.s&&x.r>y.r);}int S[N];int ans[N];int mal=0;int k;int q;bool yes[N];double eps=1e-6;int h,t;int X[10001];int main(){    //cin改scanf会快很多     scanf("%d",&n);    for(int i=1;i<=n;i++) scanf("%d%d",&xx[i].s,&xx[i].r);    for(int i=1;i<=n;i++) xx[i].no=i;    sort(xx+1,xx+n+1,cmp);//  dance[++k]=xx[1];    for(int i=1;i<=n;i++)    {        if(mal>xx[i].r) continue;        if(mal==xx[i].r&&q==xx[i].s)        {            dance[++k]=xx[i];continue;        }        if(q==xx[i].s)continue;        if(mal==xx[i].r)continue;        {            dance[++k]=xx[i];            mal=xx[i].r;            q=xx[i].s;        }    }    h=1;fire[++t]=dance[1];    for(int i=2;i<=k;i++)    {        if(h<=t&&dance[i].r<=fire[t].r) continue;         //不写小于等于,等于时有0,会卡住           while(h<t)        {            long long s1=fire[t-1].s,s2=fire[t].s,r1=fire[t-1].r,r2=fire[t].r;            long long s3=dance[i].s,r3=dance[i].r;            //斜率优化被wxs大佬改掉了,我原来考试时的那个斜率优化,可能暴long long             long long k1=(s3-s2)*(r1-r2)*r3*s1;            long long k2=(s1-s2)*(r3-r2)*r1*s3;            if(k1<k2)t--;else break;            }        fire[++t]=dance[i];    }    int xxx=0;    for(int i=1;i<=t;i++)    {        X[fire[i].s]=fire[i].r;    }    for(int i=1;i<=n;i++)    {        if(X[xx[i].s]==xx[i].r) ans[++xxx]=xx[i].no;    }    sort(ans+1,ans+xxx+1);    for(int i=1;i<=xxx;i++) cout<<ans[i]<<" ";}