poj 2551 Ones
本题的想法很简单,就是模拟手算乘法。不一样的是,需要控制输出的结果:每一位都是由1构成的整数。
代码如下:
#include <iostream>
using namespace std; int a[][] ={{,,,},{,,,},{,,,},{,,,},{,,,},{,,,},{,,,},{,,,},{,,,},{,,,}}; int get(int n)
{
int k = ,mm,t;
if(n% == ) t = ;
if(n% == ) t = ;
if(n% == ) t = ;
if(n% == ) t = ; int nm = n*a[nm%][t]; while(nm!=)
{
mm = nm%;
if(mm == ) { nm = nm/; k ++;}
else nm = nm + n*a[mm][t];
}
return k;
} int main()
{
int n;
while(cin>>n)
cout<<get(n)<<endl;
return ;
}
注意二维数组的构造方式: 使得每一次第20行代码执行之后的所得到的数的末位是1。数组中的第一维是上一次nm对10的余数,第二维与所输入的数的末位对应。
另外注意,数组a是可以改变的,也就是说,如果遇到有其他的要求的时候,数组a可以根据要求来改变。
poj 2551 Ones的更多相关文章
- POJ 2551
#include<iostream> #include<stdio.h> #include<string> using namespace std; //int m ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- POJ 2255. Tree Recovery
Tree Recovery Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11939 Accepted: 7493 De ...
- POJ 2752 Seek the Name, Seek the Fame [kmp]
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17898 Ac ...
随机推荐
- grunt集成自动启动
Grunt可以执行像压缩, 编译, 单元测试, 代码检查以及打包发布的任务. 本文介绍使用Grunt实现nodejs程序自启动功能. 目录: Grunt介绍 Grunt安装 Grunt使用 Grunt ...
- activiti自定义流程之整合(六):获取我的申请任务
流程启动后,流程节点便进入到了任务相关的部分.可以看到我之前的做法是在启动节点就绑定了form表单,启动时就填写相关的数据.实际上在之前我的做法是不对开始节点做任何操作,知道任务节点的时候再填写相关的 ...
- 【巩固】CSS3的3D动画 ——3D旋转(1)
最近学了妙味的css3的动画,2D,3D的都有,先写一个最简单的3d翻转效果,鼠标移入div,正反面翻转效果. 注意点有: 要给正反面外面加个父级: transform-style: preserve ...
- 解决ftp连接出现 无法从控制 Socket 读取。Socket 错误 = #10054。
ftp连接会显示以下错误信息 无法从控制 Socket 读取.Socket 错误 = #10054 或者是这样的信息 Opening data channel for directory list.T ...
- Graph单元
感谢世外苏子恒同学提供 一.调用单元 例:uses graph; 二.初始化 例:initgraph(var graphdriver,graphmode:integer; const path ...
- CentOS 7 yum安装Zabbix
一.Zabbix简介 zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案.zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供灵活的通知机制以让系统 ...
- 【Tree 2】树形结构数据呈现的非递归算法(循环)实现
一.基本概况 上一篇博客介绍到用递归实现树结构数据的查找,那么这篇博客,我就结合自己对于树的理解,然后用一种非递归的方式进行树结构数据的处理.首先,改造数据库表设计,加入度的概念: 首先,layer的 ...
- Web SQL Database实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 【Linux】netdata监控组件
github:https://github.com/firehol/netdata 安装:https://github.com/firehol/netdata/wiki/Installation 内存 ...
- 关于@property()的那些属性及ARC简介
@property()常用的属性有:nonatomic,atomic,assign,retain,strong,weak,copy. 其中atomic和nonatomic用来决定编译器生成的gette ...