A - Tavas and Nafas iran的作者肯定在卖萌
#include <bits/stdc++.h>
using namespace std;
string t[20] = {"zero","one","two","three","four","five","six","seven","eight","nine","ten",
"eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
string b[10] = {"twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};
int main()
{
int x;
cin >> x;
if(x < 20)
cout << t[x] << endl;
else
{
cout << b[ x / 10 - 2 ];
if( x % 10 )
cout << "-" << t[x % 10] << endl;;
}
return 0;
}
B - Tavas and SaDDas 把47分别对应01串,然后当成二进制算就行了
char a[20];
int f( int x )
{
int c = 1;
while( x-- )
c *= 2;
return c;
}
int main()
{
while( ~scanf("%s", a) )
{
int len = strlen(a);
int ans = 1, tmp = 0;
for( int i = len-1; i >= 0; --i )
{
if( a[i] == '4' )
ans += 0 * f(tmp);
else
ans += 1 * f(tmp);
tmp++;
}
if( len > 1 )
{
for( int i = 1; i < len; ++i )
ans += f(i);
printf("%d\n", ans);
}
else
printf("%d\n", ans);
}
return 0;
}
C - Tavas and Karafs 给出一个等差数列,然后给出l, t, m,表示每次从下标l开始,一次最多能使m个数-1,问t次后能使被减的数都为0的最远的位置r。
首先可以得到两个关系,假设等差数列第i项为ai,那么1. 最远的那项ar <= t 2. sum( al, al+1, ....ar ) <= m*t.然后根据这个上限不断二分查询就行了
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
#define ls rt << 1
#define rs rt << 1 | 1
#define pi acos(-1.0)
#define eps 1e-8
typedef long long ll;
const int inf = 0x3f3f3f3f;
ll A, B, l, t, m, n;
ll cal( ll x )
{
return A + (x-1) * B;
}
ll sum( ll left, ll right )
{
ll L = A + (left-1) * B;
ll R = A + (right-1) * B;
return ( L+R ) * ( right-left+1 ) / 2;
}
int main()
{
while( cin >> A >> B >> n )
{
while( n-- )
{
cin >> l >> t >> m;
ll L = l, R = 1000010, mid;
while( L <= R )
{
mid = ( L + R ) >> 1;
if( cal(mid) <= t && sum(l, mid) <= m*t )
L = mid + 1;
else
R = mid - 1;
}
if( R <= l-1 )
puts("-1");
else
cout << R << endl;
}
}
return 0;
}
输入顺序不要弄错- -找了好久eggpain