题目描述:

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的更多相关文章

  1. 河南省第十届省赛 Plumbing the depth of lake (模拟)

    title: Plumbing the depth of lake 河南省第十届省赛 题目描述: There is a mysterious lake in the north of Tibet. A ...

  2. 河南省第十届省赛 Intelligent Parking Building

    title: Intelligent Parking Building 河南省第十届省赛 tags: [模拟,省赛] 题目描述: There is a new revolution in the pa ...

  3. 四川第十届省赛 A.Angel Beats bitset

    四川第十届省赛 A.Angel Beats bitset 题目链接 题解参考:http://www.cnblogs.com/Aragaki/p/9142250.html 考虑用bitset来维护对于所 ...

  4. 河南省acm第九届省赛--《表达式求值》--栈和后缀表达式的变形--手速题

    表达式求值 时间限制:1000 ms | 内存限制:65535 KB 难度:3   描述 假设表达式定义为:1. 一个十进制的正整数 X 是一个表达式.2. 如果 X 和 Y 是 表达式,则 X+Y, ...

  5. 每天一套题打卡|河南省第十届ACM/ICPC

    A.谍报分析 题意:请你编程,快速统计出频率高的前十个单词. 思路:字符串输入,map哈希表map<string,int >记录每个单词出现的次数,pair重载优先级 #include&l ...

  6. 【河南省第十届ACM 省赛 A-谍报分析】

    题目描述 “八一三”淞沪抗战爆发后,*几次准备去上海前线视察和指挥作战.但都因为宁沪之间的铁路和公路遭到了敌军的严密封锁,狂轰滥炸,一直未能成行. 特科组织,其主要任务是保卫的安全,了解和掌握敌方的动 ...

  7. CSU 1511 残缺的棋盘 第十届湖南省赛题

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1511 题目大意:在一个8*8的棋盘中,给你一个起点位置和一个终点位置,同时也给你一个陷阱 ...

  8. CSU 1507 超大型LED显示屏 第十届湖南省赛题

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1507 解题思路:这是一道模拟题,看了那么多人的代码,我觉得我的代码是最简的,哈哈,其实就 ...

  9. 福州大学第十届校赛 & fzu 2128最长子串

    思路: 对于每个子串,求出 母串中 所有该子串 的 开始和结束位置,保存在 mark数组中,求完所有子串后,对mark数组按 结束位置排序,然后 用后一个的结束位置 减去 前一个的 开始 位置 再 减 ...

随机推荐

  1. DO NOT BELIEVE HIS LIES 游戏随笔

    这游戏是我大学的一个基友推荐的,好吧,感觉被他坑了··· 解谜游戏~慢慢来玩玩··· 恩,就是下面红色圈圈画起来的这个家伙. #1 第一关 好吧,界面上也没啥可聊的,上面写了一行字,THE FIRST ...

  2. Android Google Maps 开始

    由于工作需要,最近对Android的各大地图进行了试用. 其中有Google地图,百度地图,高德地图,还有开源的OSM. 在使用Google地图的时候,官网流程写的非常清楚,但是其中也遇到一些问题.这 ...

  3. (转) Unreal Engine 4 Custom Shaders Tutorial

    说明: 1.这里的Custom Shaders 为且仅为 Custom Node的使用和USF的包含.并非全局Shader和Material Shader. 2.原文来源:https://www.ra ...

  4. react错误总结

    react-native 错误总结 The development server returned response error code: 500 in react-native https://b ...

  5. 第5讲——cin处理字符输入

    本来这一讲应该是while.for.if之类的,但是,我们可是学过C的男人,再浪费时间搞这个??? 还不如学点C++中的新知识. cin对象支持3种不同模式的单字符输入,其用户接口各不相同. 下面我们 ...

  6. 【iOS开发】UIViewController的基本概念与生命周期

    http://www.cnblogs.com/wayne23/p/3868535.html UIViewController是iOS顶层视图的载体及控制器,用户与程序界面的交互都是由UIViewCon ...

  7. JAVA课程设计——植物大战僵尸(团队)

    1.团队名称.团队成员介绍 团名:嗷嗷嗷嗷嗷 吴军霖(组长) 写得一手好代码也改得一手好bug 代码整洁好看源于强迫症 大概没有什么不会的东西叭 真正的王者段位 欧阳震霆(组员) 同样擅长写代码 在青 ...

  8. 使用HTML5的JavaScript选择器操作页面中的元素

    <!doctype html><html lang="en"> <head>     <meta charset="UTF-8& ...

  9. MySQL 服务器安装及命令使用

    本文来自实验楼相关部分的文档和实验操作过程. 一.MySQL简介 MySQL是一种关系数据库管理系统,关系数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,提高了速度并提高了灵活性.My ...

  10. bzoj 1878

    莫队乱搞的第一题,(感觉这个算法初学的时候就能想到啊) 总之就是离线,然后扫一遍然后回答,用数组记录状态 但还是有一个地方不太明白 为什么要除siz?这样为什么会优化复杂度呢?? bool cmp(c ...