河南省第十届省赛 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数组按 结束位置排序,然后 用后一个的结束位置 减去 前一个的 开始 位置 再 减 ...
随机推荐
- CSS里一个奇怪的属性
事情是这样的,在一个手机界面的制作中,我发现按钮点击后总会出现一个边框,于是开始搜索解决方案.搜到的解决方案是这样的. a:focus,input:focus{ -webkit-tap-highlig ...
- m个苹果放在n个盘子中有多少种结果
题目 m个苹果放在n个盘子中有多少种结果,前置条件: 允许存在空盘 重复的摆放结果忽略不计 根据题意,也就是有3种情况,的确完全重复的摆放方式是没多大意义的 思路 这题可以用枚举的描述方式进行尾递归求 ...
- Spring实战第九章学习笔记————保护Web应用
保护Web应用 在这一章我们将使用切面技术来探索保护应用程序的方式.不过我们不必自己开发这些切面----我们将使用Spring Security,一种基于Spring AOP和Servlet规范的Fi ...
- 学习bash——管道命令
摘要:管道命令概述.常见管道命令的使用(cut/grep.sort/wc/uniq.tee.tr/col/join/paste/expand.xargs.减号-) 一.概述 命令执行完会在屏幕上打印相 ...
- [Java] 为什么要定义接口
摘自:https://www.douban.com/note/61810488/ 通俗的讲,就是为了降低耦合度. 一个很搞笑的例子: 看看下面的程序: 一个学校里边,有两种人:学生.老师.他们都要吃饭 ...
- Hibernate基本演示
保存一个对象到数据库中 目录结构 hibernate.cfg.xml <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hi ...
- 用Web Service实现客户端图片上传到网站
由于项目需要,通过本地客户端,把图片上传到网站.通过webservice. 这是客户端代码: private void btnimg_Click(object sender, EventArgs e) ...
- Lyft Level 5 Challenge 2018 - Final Round Div. 1没翻车记
夜晚使人着迷.没有猝死非常感动. A:显然对于水平线段,只有横坐标的左端点为1的时候才可能对答案产生影响:对于竖直直线,如果要删一定是删去一段前缀.枚举竖直直线删到哪一条,记一下需要删几条水平线段就可 ...
- [洛谷P3693]琪露诺的冰雪小屋
题目大意:琪露诺的冰雪小屋,我做的第一道大模拟题. 题解:模拟... 卡点:无数小错误,要是没有写一点调一点,那大概是永远调不出来了... C++ Code: #include <cstdio& ...
- 【CF Round 434 B. Which floor?】
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...