USACO第二章

castle:染色,对访问过的房间做标记,bfs函数中对没有墙的那一面继续搜索。

ordered fractions:列出所有分数,但只输出和前一个不一样的分数。

sorting a three valued sequence:先交换1部分里的2和2部分里的1,1部分里的3和3部分里的1,再换那种要换两次才到位的。

healthy holsteins:想要检查任意个数是否满足要求的深搜。

preface number:把各个页数的特殊情况列出来。

/* Use the slash-star style comments or the system won't see your
identification information */
/*
ID: dddming1
TASK: preface
LANG: C++
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include<math.h>
#include<sstream>
#include <cstdio>
using namespace std;

int N;
char zimu[7] = { 'I','V','X','L','C','D','M' };
int countN[8] = { 0 };

void checkpage(int page);

void checkpage(int page)
{
	if (page >= 1000) {
		countN[7] = countN[7] + page / 1000;
		checkpage(page - (page / 1000) * 1000);//检查小于1000的那一部分
	}
	if (page >= 100 && page<1000)//四种情况
	{
		if (page >= 900)
		{
			countN[7]++;
			countN[5]++;
			checkpage(page - 900);
		}
		else if (page >= 500) {
			countN[6]++;
			countN[5] += ((page - 500) / 100);
			checkpage(page - (page / 100) * 100);
		}
		else if (page >= 400) {
			countN[5]++;
			countN[6]++;
			checkpage(page - (page / 100) * 100);
		}
		else if (page >= 100) {
			countN[5] += (page / 100);
			checkpage(page - (page / 100) * 100);
		}
	}
	if (page >= 10 && page < 100)
	{
		if (page >= 90)
		{
			countN[3]++;
			countN[5]++;
			checkpage(page - 90);
		}
		else if (page >= 50) {
			countN[4]++;
			countN[3] += (page - 50) / 10;
			checkpage(page - (page / 10) * 10);
		}
		else if (page >= 40) {
			countN[3]++;
			countN[4]++;
			checkpage(page - (page / 10) * 10);
		}
		else if (page >= 10) {
			countN[3] += (page / 10);
			checkpage(page - (page / 10) * 10);
		}
	}
	if (page >= 1 && page < 10)
	{
		if (page == 9)
		{
			countN[3]++;
			countN[1]++;
			return;
		}
		if (page >= 5 && page<9) {
			countN[2]++;
			countN[1] += (page - 5);
			return;
		}
		if (page == 4) {
			countN[1]++;
			countN[2]++;
			return;
		}
		if (page >= 2 && page<4) {
			countN[1] += page;
			return;
		}
		if (page == 1) {
			countN[1]++;
			return;
		}
	}
}



int main()
{
	freopen("preface.in", "r", stdin);
	freopen("preface.out", "w", stdout);
	cin >> N;
	for (int j = 1;j <= N;j++) {
		checkpage(j);
	}
	for (int i = 1;i <= 7;++i)
	{
		if (countN[i] != 0) {
			cout << zimu[i - 1] << " " << countN[i] << endl;
		}
	}
	return 0;
}

subset sums:用深搜超时,用dp很快解决的问题,关键在于递推式。

runaround numbers:字符串和整数形式的转换,sprintf与sprintf_s的运用。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值