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
代码清单:
#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;
}
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.
The first and only line of input contains a lucky number n (1 ≤ n ≤ 109).
Print the index of n among all lucky numbers.
4
1
7
2
77
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;
}
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.
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.
For each query, print its answer in a single line.
2 1 4 1 5 3 3 3 10 7 10 2 6 4 8
4 -1 8 -1
1 5 2 1 5 10 2 7 4
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;
}