数制转换有两种题型,一般一题,分值1.5分。

题型一R进制转十进制

解法就是:按权展开,但要注意各个位的权,最低位(最右边)的权是0次方,权值为1。

纯整数的情况:

(11010110)= 1×27 + 1×26 + 0×25 + 1×24 + 0×23 + 1×22 + 1×21 + 0×2 =  (214)10

(2365)8 = 2×83 + 3×82 + 6×81 + 5×8=  (1269)10

(4BF)16 = 4×162 + B×161 + F×16=  (1215)10

整数带小数的情况:

(110.011)= 1×22 + 1×21 + 0×20 + 0×2-1 + 1×2-2 + 1×2-3 =  (6.375)10

(5.76)8 = 5×80 + 7×8-1 + 6×8-2 =  (5.96875)10

(D.1C)16 = D×160 + 1×16-1 + C×16-2  = (13.109375)10

题型二十进制转R进制

注意:十进制的小数转R进制未必可以转完。


 每日练习

一、任意进制转十进制

1、(1101101)2      = (           )

2、(7754)8       = (           )

3、(F1B9AC)16   = (           )

4、(1011.11101)2   = (           )

5、(75.1076)8     = (           )

6、(59D.10AC)16  = (           )

二、十进制转任意进制

1、(173)10     = (          )2

2、(173.125)10 = (          )2

3、(173)10     = (          )8

4、(173.625)10 = (          )8

5、(173)10     = (          )16

6、(173.375)10 = (          )16


 往年真题

1. 与16进制数 A1.2等值的10进制数是(  )

A.101.2      B.111.4        C.161.125     D.177.25

2. 2E+03表示(  )

A.2.03      B.5        C.8     D.2000

3. 在字长为16位的系统环境下,一个16位带符号整数的二进制补码为1111111111101101。其对应的十进制整数应该是(   )

A.19          B.-19          C.18        D.-18

4. 十进制小数125.125对应的八进制数是(   )

A.100.1       B.175.175     C.175.1     D.100.175

5. 与十进制数28.5625相等的四进制数是(  )

A.123.21       B.131.22        C.130.22      D.130.21     E.130.20

6.  (2008)10+  (5B)16 的结果是(   )。

A.(833)16          B.(2099)10       C.(4063)8      D.(100001100011)2

7. 与十进制数28.5625相等的四进制数是(  )。

A. 123.21       B. 131.22        C. 130.22       D. 130.21

8.  (2008)10+ (5B)16的结果是(   )。

A. (833)16       B. (2089)10       C. (4163)8       D. (100001100011)2

9. 算式 (1000)10-(100)16-(10)8的结果是(   )。

A. (890)10     B. (986)8       C. (1011100000)2       D. (2E0)16        E. (736)10

10. 与十进制数17.5625相对应的8进制数是(   )

A. 21.5625     B. 21.44     C. 21.73      D. 21.731      E. 前4个答案都不对

11.  (2070)16+(34)8的结果是(   ).

A. (8332)10      B. (208C)16     C. (100000000110)2     D. (20214)8

题解:统一为二进制运算,然后再转其他进制

12. 与十进制数1770对应的八进制数是(  )。

A.3350           B.3351             C.3352             D.3540

13.  (2070)16 + (34)8 的结果是(   )。

A.(8332)10   B.(208A)16   C.(100000000110)2     D.(20212)8

14. 与十进制数1770.625对应的八进制数是(  )。

A. 3352.5       B. 3350.5      C. 3352.1161

D. 3350.1151    E. 前4个答案都不对

15. (2010)16 + (32)8的结果是(  )。

A. (8234)10    B. (202A)16     C. (100000000110)2  D. (2042)16


真题参考答案:

1A 2BC 3B 4A 5A 6B 7AC

8AD 9D 10C 11E 12AC 13A 14A

文件读入读出

假设题目名为“add”,那么文件夹名为“add”,c++程序名为“add.cpp”,读入文件名为“add.in”,输出文件名为“add.out”。四个的拼写均不可有误,包括大小写差异。千万不要调试后就忘记修改文件读入读出了。

#include<cstdio>

int main(){

freopen("add.in","r",stdin);//read

freopen("add.out","w",stdout);//write

}


数论算法

1、线性筛

#include<iostream>

#include<cstdio>

#include<cstdlib>

#include<cstring>

using namespace std;

const int maxn=200005;

int prime[maxn];

bool not_prime[maxn];

int main()

{

int n,cnt=0;

scanf("%d",&n);

memset(not_prime,0,sizeof(not_prime));

not_prime[1]=true;

for(inti=2;i<=n;i++)

{

if(!not_prime[i])

prime[++cnt]=i;

for(intj=1;j<=cnt;j++)

{

if(prime[j]*i>n)    break;

not_prime[prime[j]*i]=true;

if(i%prime[j]==0) break;

}

}

for(inti=1;i<=cnt;i++)

printf("%d ",prime[i]);

return 0;

}

2、埃氏筛

#include<iostream>

#include<cstdio>

#include<cstdlib>

#include<cstring>

using namespace std;

inline int read()

{

char c;

c=getchar();

for(;c>'9'||c<'0';c=getchar());

int sum=0;

for(;c<='9'&&c>='0';c=getchar())sum=sum*10+c-48;

return sum;

}

int n,m;

bool f[10010000];

int main()

{

n=read(),m=read();

memset(f,true,sizeof(f));

f[0]=f[1]=false;

for(inti=2;i<=n;i++)

if(f[i])

for(intj=2;i*j<=n;f[i*j]=false,j++);

for(inti=1;i<=m;i++)

{

int x;

x=read();

if(f[x])printf("Yes\n");

elseprintf("No\n");

}

return 0;

}

3、拓展欧几里得算法

#include<iostream>

#include<cstdio>

#include<cstdlib>

#include<algorithm>

using namespace std;

int x,y;

int exgcd(int a,int b)

{

if(!b)

{

x=1;

y=0;

return a;

}

else

{

int t;

intd=exgcd(b,a%b);

t=x;

x=y;

y=t-a/b*x;

return d;

}

}

int main()

{

int a,b;

scanf("%d%d",&a,&b);

exgcd(a,b);

// cout<<__gcd(a,b)<<endl;

cout<<x<<" "<<y<<endl;

return 0;

}

4、GCD&LCM(求最小公倍数与最大公约数) 暂时代码是转载的

#include<iostream>

#include<cstdio>

#include<cstdlib>

using namespace std;

int gcd(int a,int b)

{

if(!b) returna;

else returngcd(b,a%b);

}

int lcm(int a,int b)

{

returna/gcd(a,b)*b;

}

int main()

{

int a,b;

scanf("%d%d",&a,&b);

cout<<gcd(a,b)<<" "<<lcm(a,b)<<endl;

return 0;

}

5、分解质因数

#include<iostream>

#include<cstdio>

#include<cstdlib>

using namespace std;

int main()

{

long long n;

scanf("%lld",&n);

for(long longi=2;i<=n;i++)

{

while(n!=i)

{

if(n%i==0)

{

printf("%lld*",i);

n=n/i;

}

elsebreak;

}

}

printf("%lld",n);

return 0;

}

6、大数翻倍法

#include<iostream>

#include<cstdio>

#include<cstdlib>

using namespace std;

int a[233],mo[233];

int gcd(int a,int b)

{

if(!b) returna;

else returngcd(b,a%b);

}

int lcm(int a,int b)

{

returna/gcd(a,b)*b;

}

int main()

{

int n;

scanf("%d",&n);

for(inti=1;i<=n;i++)

scanf("%d%d",&a[i],&mo[i]);

intans=0,nowmo=1;

for(inti=1;i<=n;i++)

{

intother=a[i],othermo=mo[i];

if(othermo>nowmo)

{

swap(ans,other);

swap(nowmo,othermo);

}

while(ans%othermo!=other)

ans+=nowmo;

nowmo=lcm(nowmo,othermo);

}

printf("%d",ans);

}

7、快速幂

#include<bits/stdc++.h>

using namespace std;

const int MOD = 1007;

int xx(int a,int n,int MOD)

{

int ret=1;

int tmp=a%MOD;

while(n)

{

if(n&1)

ret=ret*tmp%MOD;

tmp=tmp*tmp%MOD;

n>>=1;

}

return ret;

}

int main()

{

int m,n;

while(scanf("%d%d",&m,&n)==2)

{

printf("%d\n",xx(m,n,MOD));

}

}

8、位运算

功能

示例

位运算

去掉最后一位

(101101->10110)

x >> 1

在最后加一个0

(101101->1011010)

x  << 1

在最后加一个1

(101101->1011011)

x << 1+1

把最后一位变成1

(101100->101101)

x  | 1

把最后一位变成0

(101101->101100)

x | 1-1

最后一位取反

(101101->101100)

x  ^ 1

把右数第k位变成1

(101001->101101,k=3)

x | (1 << (k-1))

把右数第k位变成0

(101101->101001,k=3)

x  & !(1 << (k-1))

右数第k位取反

(101001->101101,k=3)

x ^ (1 << (k-1))

取末三位

(1101101->101)

x  & 7

取末k位

(1101101->1101,k=5)

x & (1<< k -1)

取右数第k位

(1101101->1,k=4)

x  >> (k-1) & 1

把末k位变成1

(101001->101111,k=4)

x | (1 << k-1)

末k位取反

(101001->100110,k=4)

x  ^ (1 << k-1)

把右边连续的1变成0

(100101111->100100000)

x & (x+1)

把右起第一个0变成1

(100101111->100111111)

x  | (x+1)

把右边连续的0变成1

(11011000->11011111)

x | (x-1)

取右边连续的1

(100101111->1111)

(x  ^ (x+1)) >> 1

去掉右起第一个1的左边

(100101000->1000)

x & (x ^ (x-1))

NOIP考前复习-数制转换,数论模板与文件读写的更多相关文章

  1. CSP考前复习

    前言 因为loceaner太菜了,他什么东西都不会 所以他打算学一个东西就记录一下 不过因为他很菜,所以他不会写原理-- 而且,他希望在2019CSP之前不会断更 就酱紫,就是写给他自己的--因为他太 ...

  2. Noip前的大抱佛脚----数论

    目录 数论 知识点 Exgcd 逆元 gcd 欧拉函数\(\varphi(x)\) CRT&EXCRT BSGS&EXBSGS FFT/NTT/MTT/FWT 组合公式 斯特林数 卡塔 ...

  3. NOIP考前划水

    NOIP考前划水 君指先跃动の光は.私の一生不変の信仰に.唯私の超電磁砲永世生き! 要开始背配置了? 3行不谢. (setq c-default-style "awk") (glo ...

  4. 考前复习(codevs 2837)

    2837 考前复习  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描述 Description Aiden马上要考试了,可他 ...

  5. java使用链栈实现数制转换

    java实现链栈在前面有所介绍:http://www.cnblogs.com/lixiaolun/p/4644141.html 将前面java实现链栈的代码稍作修改: package linkedst ...

  6. C语言程序设计100例之(24):数制转换

    例24   数制转换 题目描述 请你编一程序实现两种不同进制之间的数据转换. 输入格式 共三行,第一行是一个正整数,表示需要转换的数的进制n(2≤n≤16),第二行是一个n进制数,若n>10则用 ...

  7. vmx转换ofv模板,导入esxi

    使用VMware Workstation安装目录下\OVFTool文件的ovftool.exe工具: 转换示例: 首先进入OVFTool根目录.然后执行 ovftool.exe "D:\ce ...

  8. Network基础(二):数制转换

    一.数制转换 目标: 1)请将下列数字转换为十进制数: (110010011111)2 .(10110101110)2 2)请将下列十进制数转换为二进制: 156.2608.1043 方案: 使用按权 ...

  9. 纪中10日T1 2300. 【noip普及组第一题】模板题

    2300. [noip普及组第一题]模板题 (File IO): input:template.in output:template.out 时间限制: 1000 ms  空间限制: 262144 K ...

随机推荐

  1. web测试小结

    今年5月份开始接触web测试,经过大半年的测试及学习,简单总结下 测试过程: 1.需求理解 2.测试策略.方案.用例编写及评审 3.测试环境搭建 4.测试执行 5.bug提单.问题跟踪 6.回归测试 ...

  2. [Algorithm] How to find all the subsets of an n-element set T?

    There are two direction for us to solve this problem. (1) Recursion Recursive step: T[0] conbines wi ...

  3. fullPage的使用

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...

  4. 大家一起做训练 第一场 G CD

    题目来源:UVA 624 题目的意思就是:我现在需要从 t 张CD中拿出一部分来,尽可能的凑出接近 N 这么久的音乐,但是不能超过 N. CD不超过20张,每张长度不超过 N ,不能重复选. 一个很简 ...

  5. CTF-练习平台-Misc之 MISC图穷匕见

    十七.MISC图穷匕见 用txt打开,发现文件尾有东西,截取出来 用notepad++的插件 HEX转ASCII 得到35019个坐标 根据图片的详细信息的提示 应该是要把这些坐标转换为图形 这里使用 ...

  6. Hadoop之HDFS

    摘要:HDFS是Hadoop的核心模块之一,围绕HDFS是什么.HDFS的设计思想和HDFS的体系结构三方面来介绍. 关键词:Hadoop  HDFS   分布式存储系统 HDFS是Hadoop的核心 ...

  7. 几本不错的graphql 电子书

    当前专门讲graphql 的数据不是很多,但是越来越多的graphql 项目的出现以及graphql 自身的 便捷,老外已经有人去写graphql 的设计以及基本使用了. ebooks 地址 http ...

  8. xsl -fo 了解

    XSL-FO是用于格式化XML数据的语言,全称为Extensible Stylesheet Language Formatting Objects(格式化对象的可扩展样式表语言),是W3C参考标准,现 ...

  9. Tensorflow & Python3 做神经网络(视频教程)

    Tensorflow 简介 1.1 科普: 人工神经网络 VS 生物神经网络 1.2 什么是神经网络 (Neural Network) 1.3 神经网络 梯度下降 1.4 科普: 神经网络的黑盒不黑 ...

  10. 五、概念数据模型(CDM生成LDM,PDM和OOM)

      概念数据模型 概念数据模型(Conceptual Data Model,CDM):表达的是数据整体逻辑结构,该结构独立于任何软件和数据存储结构,即它只是系统分析人员,应用程序设计人员,维护人员和用 ...