lightoj--1294--Positive Negative Sign(水题,规律)
| Time Limit: 2000MS | Memory Limit: 32768KB | 64bit IO Format: %lld & %llu |
Description
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
2
12 3
4 1
Sample Output
Case 1: 18
Case 2: 2
Source
#include<stdio.h>
#include<string.h>
long long m,n;
int main()
{
int t;
scanf("%d",&t);
int Case=1;
while(t--)
{
long long sum=0;
scanf("%lld%lld",&n,&m);
printf("Case %d: ",Case++);
sum=m*n/2;//就这麽一个简单的规律,超时好多次
printf("%lld\n",sum);
}
return 0;
}
lightoj--1294--Positive Negative Sign(水题,规律)的更多相关文章
- LightOJ - 1294 - Positive Negative Sign(规律)
链接: https://vjudge.net/problem/LightOJ-1294 题意: Given two integers: n and m and n is divisible by 2m ...
- 1294 - Positive Negative Sign(规律)
1294 - Positive Negative Sign PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: ...
- light oj 1294 - Positive Negative Sign
1294 - Positive Negative Sign PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: ...
- LightOJ 1338 && 1387 - Setu && LightOJ 1433 && CodeForces 246B(水题)
B - B Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit Status P ...
- LightOJ 1245 Harmonic Number (II) 水题
分析:一段区间的整数除法得到的结果肯定是相等的,然后找就行了,每次是循环一段区间,暴力 #include <cstdio> #include <iostream> #inclu ...
- LightOJ 1259 Goldbach`s Conjecture 水题
不想说了 #include <cstdio> #include <iostream> #include <ctime> #include <vector> ...
- LightOJ 1166 Old Sorting 置换群 或 贪心 水题
LINK 题意:给出1~n数字的排列,求变为递增有序的最小交换次数 思路:水题.数据给的很小怎么搞都可以.由于坐标和数字都是1~n,所以我使用置换群求循环节个数和长度的方法. /** @Date : ...
- lightoj 1010 (水题,找规律)
lightoj 1010 Knights in Chessboard 链接:http://lightoj.com/volume_showproblem.php?problem=1010 题意:国际象棋 ...
- LightOJ 1065 - Number Sequence 矩阵快速幂水题
http://www.lightoj.com/volume_showproblem.php?problem=1065 题意:给出递推式f(0) = a, f(1) = b, f(n) = f(n - ...
随机推荐
- ComboxBox控件、checklistbox控件和listbox控件的组合开发
第一步:先创建一个WinForm窗体应用程序,按照下图所示的进行布局. 第二步:为ComboxBox控件.checklistbox控件和listbox控件和button控件设置属性 第三步:在代码中的 ...
- 判断输入的值是否为Double
using System; using System.Collections.Generic; using System.Text; namespace TDRFactory { public cla ...
- 关于各浏览器下Hack的写法
下面是我收集有关于各浏览器下Hack的写法: 1.Firefox @-moz-document url-prefix() { .selector { property: value; } } 上面是仅 ...
- JavaScript实现延时提示框
<html> <head> <meta charset="utf-8"> <title>无标题文档</title> &l ...
- linux下使用Android studio启动模拟器时提示 waiting for target device to come online 的问题
方法来自:http://stackoverflow.com/questions/42612468/how-can-i-get-more-information-about-waiting-for-ta ...
- epoll的实现与深入思考
提契 纸上得来终觉浅,绝知此事要躬行. 正文 前段时间写了一篇epoll的学习文章,但没有自己的心得总觉得比较肤浅,花了一些时间补充一个epoll的实例,并浅析一下过程中遇到的问题. 上epoll_s ...
- C# dataGridView1 添加数据 和清空数据
#region MyRegion DataGridViewTextBoxColumn col = new DataGridViewTextBoxColumn(); DataGridViewTextBo ...
- Kattis - Different Distances
Input The input file contains up to 10001000 test cases, each of which contains five real numbers, x ...
- SciSharpCube:容器中的SciSharp,.NET机器学习开箱即用
SciSharp Cube 在Docker容器中快速体验SciSharp机器学习工具的最新功能. 项目地址:https://github.com/SciSharp/SciSharpCube 从Dock ...
- JS 写<ul><li>
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...