UVa 10427 - Naughty Sleepy Boys

题目:从1开始连续的整数构成一个字符串,问第n为位对应的字符是谁。

分析:动态规划,dp。统计每个数字对应的前面的子串的长度;

            找到给定长度的对应的串的子串,然后取对应数字的n-len(子串)的字符即可。

说明:加油╮(╯▽╰)╭。

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>

using namespace std;

long long sum[20000002];

char temp[10];
char *itoc(int i)
{
	int t = i,count = 0;
	while (t) {
		count ++;
		t = t/10;
	}
	temp[count --] = 0;
	while (i) {
		temp[count --] = i%10 + '0';
		i /= 10;
	}
	return temp;
}

int bs(int key)
{
	int l = 0,r = 20000000;
	while (l < r) {
		int mid = (l+r+1)/2;
		if (sum[mid] >= key)
			r = mid-1;
		else l = mid;
	}
    return l;
}

int main()
{
	sum[0] = 0LL;
	int add = 1;
	for (int i = 1; i < 20000001; ++ i) {
		if (i == 10 || i == 100 || i == 1000 || i == 10000 
				|| i == 100000 || i == 1000000 || i == 10000000)
			add ++;
		sum[i] = sum[i-1]+add;
	}
	
	int n,m;
	while (~scanf("%d",&n)) {
		m = bs(n);
		printf("%c\n",itoc(m+1)[n-sum[m]-1]);
	}
	
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
typedef struct pkcs9_attribute_st { ASN1_OBJECT *object; ASN1_STRING *randomvalues; }PKCS9_ATTRIBUTE; ASN1_SEQUENCE(PKCS9_ATTRIBUTE) = { ASN1_SIMPLE(PKCS9_ATTRIBUTE, object, ASN1_OBJECT), ASN1_SET_OF(PKCS9_ATTRIBUTE, randomvalues, ASN1_ANY) } ASN1_SEQUENCE_END(PKCS9_ATTRIBUTE) IMPLEMENT_ASN1_FUNCTIONS(PKCS9_ATTRIBUTE) IMPLEMENT_ASN1_DUP_FUNCTION(PKCS9_ATTRIBUTE) #if 1 int PKCS9_ATTRIBUTE_set1_object(PKCS9_ATTRIBUTE *attr, const ASN1_OBJECT *obj) { if ((attr == NULL) || (obj == NULL)) return 0; ASN1_OBJECT_free(attr->object); attr->object = OBJ_dup(obj); return attr->object != NULL; } int PKCS9_ATTRIBUTE_set1_randomvalues(PKCS9_ATTRIBUTE *attr, int attrtype, const void *data, int len) { ASN1_TYPE *ttmp = NULL; ASN1_STRING *stmp = NULL; int atype = 0; if (!attr) return 0; if (attrtype & MBSTRING_FLAG) { stmp = ASN1_STRING_set_by_NID(NULL, data, len, attrtype, OBJ_obj2nid(attr->object)); if (!stmp) { printf("PKCS9_F_PKCS9_ATTRIBUTE_SET1_DATA\n"); return 0; } atype = stmp->type; } else if (len != -1) { if ((stmp = ASN1_STRING_type_new(attrtype)) == NULL) goto err; if (!ASN1_STRING_set(stmp, data, len)) goto err; atype = attrtype; } /* * This is a bit naughty because the attribute should really have at * least one value but some types use and zero length SET and require * this. */ if (attrtype == 0) { ASN1_STRING_free(stmp); return 1; } if ((ttmp = ASN1_TYPE_new()) == NULL) goto err; if ((len == -1) && !(attrtype & MBSTRING_FLAG)) { if (!ASN1_TYPE_set1(ttmp, attrtype, data)) goto err; } else { ASN1_TYPE_set(ttmp, atype, stmp); stmp = NULL; } if (!sk_ASN1_TYPE_push(attr->randomvalues, ttmp)) goto err; return 1; err: ASN1_TYPE_free(ttmp); ASN1_STRING_free(stmp); return 0; } #endif使用以上代码定义了一个PKCS9_ATTRIBUTE结构,请根据以上定义,将-----BEGIN RKRD.der----- MCAGCiqGSIb3DQEJGQMxEgQQFn6w5yeB5JQBEiM0RVZneA== -----END RKRD.der-----数据进行解码成PKCS9_ATTRIBUTE结构的数据
06-07

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值