Sum Up


Time Limit: 2 Seconds      Memory Limit: 65536 KB

Vivid has stored a piece of private information, which consisted of a serial of integers in a secret number format. All the stored numbers are in the range [-63, 63]. So every number contains exactly 7 bits - the leftmost bit is the sign bit (0 for positive and 1 for negative), and all other bits represent the absolute value of the number (e.g. 000000 stands for 0, 000001 stands for 1 and 111111 stands for 63). With the sign bit, 1000000 and 0000000 are considered to be equal, both of them stand for 0.

All the numbers have been pushed into 16-bits integers, that is, one 16-bits integer is enough to hold 2 numbers plus 2 bits of another number.

In this problem, you are given a serial of 16-bits integers, and you need to output the sum of these 7-bits integers.

Input:

There are multiple test cases. Each test case begins with an integer N (the number of 16-bits numbers, 0 <= N <= 7000, N is always a multiple of 7). Then N 16-bits numbers follow, all of which are in the range [0, 65535]. A case with N = -1 denotes the end of input, which should not be proceeded.

Output:

For each test case, output an integer indicating the sum of these 7bits-integers in a single line.

Sample Input:

7
1 0 0 0 0 0 0
7
65535 65535 65535 65535 65535 65535 65535
-1

Sample Output:

32
-1008
题解:就是给你一些16位的数,这些数字按照二进制一字排开,现在让变成7位,每7位读取一个数,让求这些数字的和;
代码:
 #include<stdio.h>
const int MAXN=;
int m[MAXN],b[MAXN*];
int main(){
int N;
while(scanf("%d",&N),N!=-){
for(int i=;i<N;i++)scanf("%d",m+i);
int sum=;
int top=;
for(int i=N-;i>=;i--){
int t=;
while(t<){
b[top]=m[i]&;
top++;m[i]>>=;t++;
}
}
int a=;
for(int i=;i<top;i++){
if(i%){
a+=b[i]<<(i%-);
}
else{
if(b[i])sum-=a;
else sum+=a;
a=;
}
}
printf("%d\n",sum);
}
return ;
}

zoj2729 Sum Up(模拟)的更多相关文章

  1. PAT甲题题解-1081. Rational Sum (20)-模拟分数计算

    模拟计算一些分数的和,结果以带分数的形式输出注意一些细节即可 #include <iostream> #include <cstdio> #include <algori ...

  2. HDU 5776 sum (模拟)

    sum 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5776 Description Given a sequence, you're asked ...

  3. 2017ACM暑期多校联合训练 - Team 3 1003 HDU 6058 Kanade's sum (模拟)

    题目链接 Problem Description Give you an array A[1..n]of length n. Let f(l,r,k) be the k-th largest elem ...

  4. hdu 6058 Kanade's sum(模拟链表)

    Kanade's sum Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  5. CF280D-k-Maximum Subsequence Sum【模拟费用流,线段树】

    正题 题目链接:https://www.luogu.com.cn/problem/CF280D 题目大意 一个长度为\(n\)的序列,\(m\)次操作 修改一个数 询问一个区间中选出\(k\)段不交子 ...

  6. iOS开发之再探多线程编程:Grand Central Dispatch详解

    Swift3.0相关代码已在github上更新.之前关于iOS开发多线程的内容发布过一篇博客,其中介绍了NSThread.操作队列以及GCD,介绍的不够深入.今天就以GCD为主题来全面的总结一下GCD ...

  7. 破解 crackme(“不可逆“函数)

    系统 : Windows xp 程序 : crackme 程序下载地址 :http://pan.baidu.com/s/1i41oh9r 要求 : 注册机编写 使用工具 : IDA Pro & ...

  8. java异步任务处理

    1.场景 最近做项目的时候遇到了一个小问题:从前台提交到服务端A,A调用服务端B处理超时,原因是前端一次请求往db插1万数据,插完之后会去清理缓存.发送消息. 服务端的有三个操作 a.插DB b.清理 ...

  9. HUD-1999-不可摸数

    参考博客https://www.cnblogs.com/dongsheng/archive/2012/08/18/2645594.html Problem Description s(n)是正整数n的 ...

随机推荐

  1. 获得当前设备可用的内存 和 获取当前任务所占用的内存 (单位:MB)(转)

    获取当前任务所占的内存: #include <sys/sysctl.h> #include <mach/mach.h> // 任务占用内存 double usedMemory( ...

  2. Session和Cookie的关系

    Session和Cookie关系 两者构建了web的回话数据 Cookie作为客户端的回话,Session为服务器端的 共同点: 都是1对1的,(一个客户一个独立的回话) 都以键值对的方式存储数据 都 ...

  3. 推荐大家使用的CSS书写规范、顺序(转载)

    转自:http://www.admin10000.com/document/2979.html 写了这么久的CSS,但大部分前端er都没有按照良好的CSS书写规范来写CSS代码,这样会影响代码的阅读体 ...

  4. 好的组件,无须太复杂 – KISSY Slide 组件简介

    KISSY Slide 组件首页:http://gallery.kissyui.com/slide/1.1/guide/index.html V1.1 New Featurs Slide是一个幻灯切换 ...

  5. 博士论文》》》 Journal,magazine,transaction,proceeding

    Journal期刊:刊登关于某特殊主题的文章的期刊 magazine杂志:综合性内容的期刊 transactions(学会等的)议事录,会报,会刊 proceedings记录, 会议录; 年[学]报; ...

  6. WPS Office手机版调用接口代码指导帖之一(Android)

    经常会有一些喜欢开发鼓捣的童鞋问我们,WPS Office手机版是否提供调用接口,希望在android中使用一个调用命令,直接调用WPS手机版来打开指定的DOC文件,而不用弹出一个程序可选列表(如果用 ...

  7. snort简介以及在Ubuntu下的安装

    一.简介 Snort是一套开放源代码的网络入侵预防软件与网络入侵检测软件.Snort使用了以侦测签章(signature-based)与通信协议的侦测方法.Snort是一个免费的IDS(入侵监测系统) ...

  8. Velocity引擎导致jvm内存外内存泄露

    我公司一兄弟,在controller层,每次调用controller的时候都创建了velocity引擎,而且没有去关闭,最终导致的现象就是jvm的内存信息正常,但是jvm之外的内存发生了泄露,导致是用 ...

  9. .NET程序员生活开始

    不知不觉,开始踏入程序员生活了!加油吧.有关Session的好文章: 最近这两天被一个Web Farm环境下的Session处理问题虐得很痛苦,网上到处找解决方案,在无意中翻看到这篇文章,感觉很不错, ...

  10. C语言-进制

    本文目录 • 一.十进制 • 二.二进制 • 三.八进制 • 四.十六进制 • 五.进制总结 • 六.变量与进制 • 七.printf的简单使用上一讲简单介绍了常量和变量,这讲补充一点计算机的基础知识 ...