1294 - Positive Negative Sign(规律)
Time Limit: 2 second(s) | Memory Limit: 32 MB |
Given two integers: n and m and n is divisible by 2m, you have to write down the first n natural numbers in the following form. At first take first m integers and make their sign negative, then take next m integers and make their sign positive, the next m integers should have negative signs and continue this procedure until all the n integers have been assigned a sign. For example, let n be 12 and m be 3. Then we have
-1 -2 -3 +4 +5 +6 -7 -8 -9 +10 +11 +12
If n = 4 and m = 1, then we have
-1 +2 -3 +4
Now your task is to find the summation of the numbers considering their signs.
Input
Input starts with an integer T (≤ 10000), denoting the number of test cases.
Each case starts with a line containing two integers: n and m (2 ≤ n ≤ 109, 1 ≤ m). And you can assume that n is divisible by 2*m.
Output
For each case, print the case number and the summation.
Sample Input |
Output for Sample Input |
2 12 3 4 1 |
Case 1: 18 Case 2: 2 |
题解:这个规律比较好推,直接每隔m一正一负,依次相减就是m了,因为整除2*m,就直接是m*n/2;因为没有加case,wa了一次,还是太不细心了啊;
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define mem(x,y) memset(x,y,sizeof(x))
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
int main(){
int T,flot=;
LL n,m;
scanf("%d",&T);
while(T--){
scanf("%lld%lld",&n,&m);
printf("Case %d: %lld\n",++flot,m*(n/));
}
return ;
}
1294 - Positive Negative Sign(规律)的更多相关文章
- light oj 1294 - Positive Negative Sign
1294 - Positive Negative Sign PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: ...
- LightOJ - 1294 - Positive Negative Sign(规律)
链接: https://vjudge.net/problem/LightOJ-1294 题意: Given two integers: n and m and n is divisible by 2m ...
- lightoj--1294--Positive Negative Sign(水题,规律)
Positive Negative Sign Time Limit: 2000MS Memory Limit: 32768KB 64bit IO Format: %lld & %llu ...
- 阳/阴性预测值Positive/negative Predictive Value(推荐AA)
sklearn实战-乳腺癌细胞数据挖掘(博主亲自录制视频教程) https://study.163.com/course/introduction.htm?courseId=1005269003&am ...
- 智课雅思短语---二、exert positive/ negative effects on…
智课雅思短语---二.exert positive/ negative effects on… 一.总结 一句话总结:对…产生有利/不利的影响 1.the advantages far outweig ...
- 零宽断言 -- Lookahead/Lookahead Positive/Negative
http://www.vaikan.com/regular-expression-to-match-string-not-containing-a-word/ 经常我们会遇到想找出不包含某个字符串的文 ...
- Amazon评论数据的预处理代码(Positive & Negative)
Amazon评论数据的预处理代码,用于情感分析,代码改自 https://github.com/PaddlePaddle/Paddle/tree/develop/demo/quick_start/da ...
- [LeetCode] Valid Number 验证数字
Validate if a given string is numeric. Some examples:"0" => true" 0.1 " => ...
- [leetcode]65. Valid Number 有效数值
Validate if a given string can be interpreted as a decimal number. Some examples:"0" => ...
随机推荐
- XML 文档解析操作
sing System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security; ...
- C++中 指针 与 引用 的区别
四点区别:可否为空,可否修改,使用时是否需要判断,使用场景 非空区别. 引用必须指向某个对象,而指针可以指向空. 可修改区别. 引用总是与初始化时的那个对象绑定,不可变更:指针可以重新赋值,指向另外一 ...
- Laravel5 学习与使用(一)
2015-07-04 (1) 安装Laravel框架 ① 安装前的准备工作 使用Apache24 + PHP 5.6 + MySQL 开发环境完成PHP网站开发,所以Laravel的安装是建立在以上 ...
- django1.4.5无法安装MySQLdb1.2.3
解决办法是: yum install python-devel mysql-devel zlib-devel openssl-devel 然后再build.install
- FASTCGI程序,做个备份,以后用
11FastCGI 用来作为 Web 服务器的设计方案,有着很多优点.要搭建这样一个服务,有一个最简单的办法来搭建,可以使用 Apache 以及 mod_fcgid 模块来实现. 鉴于网上有关 Fas ...
- 从51跳新唐cortex学习3——细说新唐两种定时器
的定时器我们已经是相当熟悉啦.但是,对于第一次接触新唐,第一次接触cortex的定时器一样,都是加1计数,但是功能和容量变大了),包括4个32位定时器(里面放24位的数据),还有分频功能.TMER0到 ...
- python defaultdict 类型
在Python里面有一个模块collections,解释是数据类型容器模块.这里面有一个collections.defaultdict()经常被用到.主要说说这个东西. 综述: 这里的defaultd ...
- php 实现简单的登录
//登录页面: V层前端模板: Administrator@QCEE61NZ66FEX2D /cygdrive/c/wamp/www/thinkphp/Home/Tpl/Login $ ls inde ...
- 基于Visual C++2013拆解世界五百强面试题--题16-进制分析
清写出下列代码的输出内容 #include <stdio.h> int main() { int a = -1, b = -12, c = -123, d = -1234; printf( ...
- 基于Visual C++2013拆解世界五百强面试题--题14-循环删除
有一个数组a[1000]存放0-1000,要求每隔二个数删除一个数,到末尾时循环到开头继续进行,求最后一个被删掉数的原始下标. 看到题目可以用循环链表保存这些数,然后循环删除,大大减少了一些复杂的边界 ...