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" => ...
随机推荐
- hdu 5104 Primes Problem(prime 将三重循环化两重)
//宁用大量的二维不用量小的三维 #include <iostream> #include<cstdio> #include<cstring> using name ...
- JavaScript基础(简介、语法)
一.JavaScript简介 1.JavaScript是个什么东西? 它是个脚本语言,需要有宿主文件,它的宿主文件是HTML文件. 2.它与Java什么关系? 没有什么直接的联系,Java是Sun公司 ...
- mysql修改用户名和密码
修改用户名 mysql> use mysql; 选择数据库Database changedmysql> update user set user="dns" wher ...
- Nmon的安装及使用
1.安装软件 1) 用root用户登录系统,建立目录:#mkdir /nmon 2) 通过FTP将下载的nmon工具上传至服务器 192.168.40.212目录/nmon下. 3) 修改tar包权 ...
- MYSQL异常和错误机制
BEGIN ; ; ; START TRANSACTION; call put_playerbehavior(i_playerid,i_gameid,i_channelid,i_acttime,@a) ...
- poj 2074 Line of Sight 计算几何
/** 大意:给定一个建筑--水平放置,给定n个障碍物, 给定一条街道,从街道上能看到整个建筑的最长的连续的区域 思路: 分别确定每一个障碍物所确立的盲区,即----建筑物的终点与障碍物的起点的连线, ...
- ASP.Net MVC3 - The easier to run Unit Tests by moq #Reprinted#
From: http://www.cnblogs.com/techborther/archive/2012/01/10/2317998.html 前几天调查完了unity.现在给我的任务是让我调查Mo ...
- (Problem 74)Digit factorial chains
The number 145 is well known for the property that the sum of the factorial of its digits is equal t ...
- 进一步探索:Windows Azure 网站中解锁的配置选项
编辑人员注释: 本文章由 Windows Azure 网站团队的项目经理 Erez Benari 撰写. 在 Windows Azure 网站 (WAWS) 中管理网站时,许多选项可使用 Azu ...
- LayoutInflater作用是将layout的xml布局文件实例化为View类对象。
获取LayoutInflater的方法有如下三种: LayoutInflater inflater=(LayoutInflater)context.getSystemService(Context.L ...