题目描述:

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. Linux-Shell脚本编程-学习-6-Shell编程-使用结构化命令-文件比较-case编程

    这一片主要说test文件的比较,文件比较在日常使用的频率比较高,这里重点把每个部分都试着说说看 1. 检车目录 -d -d测试会检查指定的文件名是否在系统上以目录的形式存在,当我们要写文件到某个目录之 ...

  2. CSS : @media 示例

    .example { padding: 20px; color: white; } /* Extra small devices (phones, 600px and down) */ @media ...

  3. react实现换肤功能

    一.目标   提供几种主题色给用户选择,然后根据用户的选择改变应用的主题色: 二.实现原理   1.准备不同主题色的样式文件:   2.将用户的选择记录在本地缓存中:   3.每次进入应用时,读取缓存 ...

  4. Daily Scrum02 11.30

    纵然编译大作业压顶,大家还是顶住压力,保证了软工项目的持续进行. Member Today's Task Tomorrow's Task 李孟 Task856 熟悉单元测试方法熟悉单元测试方法 Tas ...

  5. nopcommerce商城系统--开发者常遇问题清单

    原址:http://www.nopcommerce.com/docs/74/frequently-asked-development-questions.aspx 以下是开发者常见问题的清单.也介绍了 ...

  6. input设置为readonly后js设置intput的值后台仍然可以接收到

    今天发现一个奇怪现象,一个input属性readonly的值被设置为readonly,然后有前台js给input设置了新值. 虽然前台看不到效果,但是提交到后台后,仍然可以接收到新值,感觉很奇怪. 我 ...

  7. const在c/c++中的区别

    #include <iostream> using namespace std; int main() { ; ; }; ; i < sizeof array / sizeof *a ...

  8. 怎么获取textarea中选中文字

    textarea设置select="saveSelectionText()" //保存选中内容 saveSelectionText: function () { var focus ...

  9. [剑指Offer] 14.链表中倒数第k个结点

    [思路]利用两个相隔为k-1个结点的指针进行遍历,当后一个指针移到末尾时,前一个指针就是要求的结点. /* struct ListNode { int val; struct ListNode *ne ...

  10. Div+Css制作圆

    Div+Css制作四分之一圆主要是使用Css3.0中的border-radius这个圆角隐藏属性.利用这一属性,我们可以画圆,画半圆,四分之三圆,四分之一圆等.以后我会更新…… 如何使用border- ...