Codeforces Round #299 (Div. 2)【A,B,C】

codeforces 535A-水题;

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

char s2[15][20]={"eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
char s1[15][20]={"ten","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};
char s3[15][20]={"one","two","three","four","five","six","seven","eight","nine"};

int main()
{

	int n;
	scanf("%d",&n);
	if(n==0)
	{
		puts("zero");
		return 0;
	}
	if(n>=10)
	{
		if(n%10==0)
			printf("%s",s1[n/10-1]);
		else if((n/10)==1)
			printf("%s",s2[n%10-1]);
		else
			printf("%s-%s",s1[n/10-1],s3[n%10-1]);
	}
	else
		printf("%s",s3[n%10-1]);

	
	return 0;	
}

codeforces 535B
最多才2^9个数,直接预处理,然后找一遍。

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

LL p[1000000];

LL Pow(int k)
{
	LL ans=1;
	for(int i=1;i<=k;i++)
		ans=ans*10LL;
	return ans;
}
int num;
void init()
{

	LL k;
	p[0]=4LL;
	p[1]=7LL;
	num=2;
	bool flag=false;
	for(int i=1;i<=9;i++)
	{
		int t=0;
		k=Pow(i);
		for(int j=0;j<num;j++)
		{
			if(p[j]*10<k) continue;
			p[num+t]=k*4LL+p[j];
			if(p[num+t]>1000000000)
			{
				num=num+t;
				flag=true;
				break;
			}
			t++;
			p[num+t]=k*7LL+p[j];
			if(p[num+t]>1000000000)
			{
				num+=t;
				flag=true;
				break;
			}
			t++;
		}
		if(flag) break;
		num=num+t;
	}
}

int main()
{
	init();
	LL n;
	scanf("%lld",&n);
	sort(p,p+num);
	for(int i=0;i<num;i++)
	{
		if(p[i]==n)
		{
			printf("%d
",i+1);
			return 0;	
		}
	}
	return 0;
}
codeforces 535C:题意:
给等差数列:首项A,公差B,n个询问
每个询问 给l,t,m
以l为左端点,每次可以最多选择m个数,使这些数 -1   
t次操作后,求最长序列使所有数为0,输出这个最长序列的右端序号
思路:
二分对吧。
那么就去找二分的满足条件对吧。
首先数列里面最大的数肯定<=t,对勾
数列里面所有的数相加和<=t*m 对勾
然后二分 11111100000型 对勾
#include <cstdio>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long LL;
int n;
LL a,b,t,m;

LL sum[1000100];
void init()
{
	sum[0]=0;
	sum[1]=a;
	for(LL i=2;i<=1000000;i=i+1LL)
		sum[i]=sum[i-1]+a+(i-1LL)*b;
}

int main()
{
	LL tmp;
	scanf("%I64d%I64d%I64d",&a,&b,&n);
	init();
	while(n--)
	{
		scanf("%I64d%I64d%I64d",&tmp,&t,&m);
		LL left=tmp,right=1000000;
		while(left<right)
		{
			LL mid=left+(right-left+1LL)/2LL;
			if((a+(mid-1LL)*b)<=t&&(sum[mid]-sum[tmp-1])<=t*m)
				left=mid;
			else
				right=mid-1LL;
		}
		if((a+(left-1LL)*b)<=t&&(sum[left]-sum[tmp-1])<=t*m)
			printf("%I64d
",left);
		else
			puts("-1");
	}
	return 0;
} 
/*
2 1 4
1 5 3
3 3 10
7 10 2
6 4 8
*/




原文地址:https://www.cnblogs.com/keyboarder-zsq/p/6777390.html