河南省第十届省赛 Binary to Prime
题目描述:
To facilitate the analysis of a DNA sequence, a DNA sequence is represented by a binary number. The group of DNA-1 has discovered a great new way . There is a certain correlation between binary number and prime number. Instead of using the ordinary decadic numbers, they use prime base numbers. Numbers in this base are expressed as sequences of zeros and ones similarly to the binary numbers, but the weights of bits in the representation are not powers of two, but the elements of the primes ( 2, 3, 5, 7,... ).
For example 01101 , ie. 2+5+7=14
Herefore, it is necessary to convert the binary number to the sum of prime numbers
输入:
The input consists of several instances, each of them consisting of a single line. Each line of the input contains a 01 string, length of not more than 150. The end of input is not marked in any special way.
输出:
For each test case generate a single line containing a single integer , The sum of the primes.
样例输入:
000010
0011
11001
样例输出:
3
5
20
分析:
给出一个二进制的序列,逆着看这个序列,输出每个‘1’位上对应的素数.
例如: 01101
逆着看的话为1的分别为第一位,加上第一个素数2
第三位,加上第三个素数5
第四位,加上第四个素数7
最终结果为2+5+7=14
代码:
#include <cstdio>
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
using namespace std;
char st[160];
bool vis[2000];
int s[2000];
using namespace std;
void Shusu()///首先把素数表给打印出来
{
int i,j;
for(i=2; i<=3000; i++)
{
for(j=i+i; j<=3000; j+=i)
{
if(!vis[j])
{
vis[j] = true;
}
}
}
int k = 0;
for(i=1; i<=3000; i++)
{
if(vis[i]==false)
{
s[k++] = i;
}
}
}
int main()
{
memset(vis,false,sizeof(vis));
Shusu();
while(scanf(" %s",st)!=EOF)
{
int i;
long long sum = 0;
int len = strlen(st);
for(i=1; i<=len; i++)
{
if(st[len-i]=='1')///然后直接加上每一位对应的素数就行
{
sum += s[i];
}
}
printf("%lld\n",sum);
}
return 0;
}
河南省第十届省赛 Binary to Prime的更多相关文章
- 河南省第十届省赛 Plumbing the depth of lake (模拟)
title: Plumbing the depth of lake 河南省第十届省赛 题目描述: There is a mysterious lake in the north of Tibet. A ...
- 河南省第十届省赛 Intelligent Parking Building
title: Intelligent Parking Building 河南省第十届省赛 tags: [模拟,省赛] 题目描述: There is a new revolution in the pa ...
- 四川第十届省赛 A.Angel Beats bitset
四川第十届省赛 A.Angel Beats bitset 题目链接 题解参考:http://www.cnblogs.com/Aragaki/p/9142250.html 考虑用bitset来维护对于所 ...
- 河南省acm第九届省赛--《表达式求值》--栈和后缀表达式的变形--手速题
表达式求值 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 假设表达式定义为:1. 一个十进制的正整数 X 是一个表达式.2. 如果 X 和 Y 是 表达式,则 X+Y, ...
- 每天一套题打卡|河南省第十届ACM/ICPC
A.谍报分析 题意:请你编程,快速统计出频率高的前十个单词. 思路:字符串输入,map哈希表map<string,int >记录每个单词出现的次数,pair重载优先级 #include&l ...
- 【河南省第十届ACM 省赛 A-谍报分析】
题目描述 “八一三”淞沪抗战爆发后,*几次准备去上海前线视察和指挥作战.但都因为宁沪之间的铁路和公路遭到了敌军的严密封锁,狂轰滥炸,一直未能成行. 特科组织,其主要任务是保卫的安全,了解和掌握敌方的动 ...
- CSU 1511 残缺的棋盘 第十届湖南省赛题
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1511 题目大意:在一个8*8的棋盘中,给你一个起点位置和一个终点位置,同时也给你一个陷阱 ...
- CSU 1507 超大型LED显示屏 第十届湖南省赛题
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1507 解题思路:这是一道模拟题,看了那么多人的代码,我觉得我的代码是最简的,哈哈,其实就 ...
- 福州大学第十届校赛 & fzu 2128最长子串
思路: 对于每个子串,求出 母串中 所有该子串 的 开始和结束位置,保存在 mark数组中,求完所有子串后,对mark数组按 结束位置排序,然后 用后一个的结束位置 减去 前一个的 开始 位置 再 减 ...
随机推荐
- VSCode 前端必备插件
VSCode 前端必备插件 Debugger for Chrome 让 vscode 映射 chrome 的 debug功能,静态页面都可以用 vscode 来打断点调试 { "versio ...
- Python登录小程序
------------------------------------------------- 主要实现功能 1.用户输入用户名,在用户名文件中查找对应的用户,若无对应用户名则打印输入错误 2.用 ...
- windows下git hub的GUI软件配置与使用
转载自:http://www.cnblogs.com/haore147/p/3618930.html 1. 安装两个软件 1 2 1. git的命令行程序--git for windows:htt ...
- BZOJ 1923 SDOI2010 外星千足虫 异或方程组+bitset
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1923 懒得贴题目了......这就是解一个异或方程组的裸题...... YY了一下异或方程 ...
- PHP中的6种加密方式
PHP中的6种加密方式 1. MD5加密 string md5 ( string $str [, bool $raw_output = false ] ) 参数 str -- 原始字符串. raw ...
- 学习bash——环境配置
一.环境配置文件的重要性 Bash在启动时直接读取这些配置文件,以规划好bash的操作环境. 即使注销bash,我们的设置仍然保存. 二.login shell 通过完整的登录流程取得的bash,称为 ...
- await和async再学习
await太不容易理解了,自己常常迷惑,不知道该怎么用. 文章:探索c#之Async.Await剖析 这篇文章,有一个很清晰的描述: 使用Async标记方法Async1为异步方法,用Await标记Ge ...
- Java 中的异常和处理详解(转载)
原文出处: 代码钢琴家 简介 程序运行时,发生的不被期望的事件,它阻止了程序按照程序员的预期正常执行,这就是异常.异常发生时,是任程序自生自灭,立刻退出终止,还是输出错误给用户?或者用C语言风格:用函 ...
- VS2015中常用快捷键的修改推荐
首先,在VS2015中修改快捷键的步骤如下: 工具--选项--环境--键盘. 如图: 然后就是修改快捷键:(以下是个人的使用习惯,仅供参考) 1.编辑.设置选定内容的格式.设置为ctrl+E,Ctrl ...
- Google Play sign sha1 转 Facebook login 需要的 hashkey
:4E:::::3A:1F::A6:0F:F6:A1:C2::E5::::2E | xxd -r -p | openssl base64 输出 M05IhBlQOh9jpg/2ocIx5QE4VS4= ...