poj 1426
来源:互联网 发布:linux文件系统管理 编辑:程序博客网 时间:2024/05/29 09:49
题意:求解一个数n的倍数且这个数只有0与1两个数字组成。
思路:开始的时候想着做搜索题,上网搜了一下,说这个是,但是最后做的时候感觉跟搜索关系不是很大,直接进行计算就行。可悲的是用C++直接TLE了,后来看了一下discuss,第一个的做法跟我差不多,他的竟然过了。然后我改改少了一个判断,但是还是TLE。果断的换了语言提交试试,G++竟然神奇的过了,虽然时间也很多,四百多。(网上说有优化的方法,把模余相同的不在进行进队,这样会节省时间,但是没有试。)
#include<iostream>#include<queue>using namespace std;void bfs(int n){ queue<long long> q; while(!q.empty()) q.pop(); long long t; q.push(1); while(!q.empty()) { t=q.front(); if(t%n==0) { cout<<t<<endl; break; } t=t*10; q.pop(); q.push(t); q.push(t+1); }}int main(){ int m; while(cin>>m) { if(m==0)break; bfs(m); } return 0;}
- poj 1426
- poj 1426
- POJ 1426
- POJ 1426
- poj 1426
- poj 1426
- poj 1426
- POJ 1426
- poj-1426
- poj 1426
- poj 1426
- 1426POJ
- poj 1426
- poj 1426
- poj--1426
- POJ 1426
- POJ 1426
- poj 1426
- Spring基础之二:xml配置注入
- Three20
- 非常感人的分手对白:伤感日志
- FastCGI: A High-Performance Web Server Interface 中文翻译版本
- Flash Builder 4.6.1的安装与破解
- poj 1426
- 基于ARM核的芯片选择
- printf 输出彩色字体
- vsftpd 530 login incrrect 虚拟用户配置无法登陆问题处理
- 2010-09-21 12:11 jstl fmt:parseDate
- 图像金字塔
- javax.el.PropertyNotFoundExceptionProperty 'Tid' not found on type com.msz.sims.domain.Teacher
- 伤感女生空间日志-难舍难分的淡淡情愁
- 邻接表模版c+