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" => ...
随机推荐
- BZOJ 2329: [HNOI2011]括号修复( splay )
把括号序列后一定是))))((((这种形式的..所以维护一个最大前缀和l, 最大后缀和r就可以了..答案就是(l+1)/2+(r+1)/2...用splay维护,O(NlogN). 其实还是挺好写的, ...
- SignaLR通信技术
新建MVC项目 如果没有Signale需要使用NuGet安装Signalr namespace SignaLrDemo { public class ChatHub : Hub { public vo ...
- 远程连接MySQL 不允许
报错:1130-host ... is not allowed to connect to this MySql server 1. 改表法. 可能是你的帐号不允许从远程登陆,只能在localhost ...
- [LeetCode]题解(python):135-Candy
题目来源: https://leetcode.com/problems/candy/ 题意分析: 有N个孩子站成一条线.每个孩子有个排名.要求1.每个孩子至少一个糖果,2.相邻的孩子,那么较高排名的孩 ...
- Array.Add () and += in PowerShell
$newArray = @() $newArray.Add("Hello") If I create a new array, and using the method Add() ...
- The request failed with HTTP status 401: Unauthorized.
Reporting Service 控件默认由IIS里面的应用程序池标识 里面所定义的用户连接,如果用户没有权限则报以下错误 The request failed with HTTP status 4 ...
- 使用 Windows Media Center 远程控制
http://windows.microsoft.com/en-us/windows/getting-started-windows-media-center#getting-started-wind ...
- 在Spring Boot启动后执行指定代码
在开发时有时候需要在整个应用开始运行时执行一些特定代码,比如初始化环境,准备测试数据等等. 在Spring中可以通过ApplicationListener来实现相关的功能,不过在配合Spring Bo ...
- Filter 知识总结
Filter对web服务器管理的所有web资源:例如Jsp, Servlet, 静态图片文件或静态 html 文件等进行拦截,从而实现一些特殊的功能.例如实现URL级别的权限访问控制.过滤敏感词汇.压 ...
- CALayer3-层的属性
一.隐式动画属性 * 在前面几讲中已经提到.每个UIView内部都默认关联着一个CALayer,我们可用称这个Layer为Root Layer(根层). 全部的非Root Layer.也就是手动创建的 ...