URAL 1068 Sum

用最笨但是最省心的写法……

 1 import java.util.Scanner;
 2
 3 public class P1068
 4 {
 5     public static void main(String args[])
 6     {
 7         try (Scanner cin = new Scanner(System.in))
 8         {
 9             while (cin.hasNext())
10             {
11                 int n = cin.nextInt();
12                 int result = 0;
13                 if (n < 1)
14                     for (int i = n; i <= 1; i++)
15                         result += i;
16                 else
17                     for (int i = 1; i <= n; i++)
18                         result += i;
19                 System.out.println(result);
20             }
21         }
22     }
23 }
时间: 2024-08-09 06:34:27

URAL 1068 Sum的相关文章

可以使用C#语言的在线ACM题库

俄罗斯乌拉尔大学在线题库 是一个可以使用C#语言的在线ACM题库,有兴趣的朋友可以去试试. Problem 1000. A+B Problem 是入门,就是简单地求整数 A 和 B 的和就行了,答案如下: 1 using System; 2 3 // http://acm.timus.ru/problem.aspx?space=1&num=1000 4 class Acm1000 5 { 6   static void Main() 7   { 8     string[] ss = Conso

[数学] 方差和标准差

均值: \[ \mu = \frac{1}{m}\sum^m_{i=0}{x_i} \] 方差的定义: \[ \sigma^2=\frac{1}{m}\sum (x_i-\mu)^2 \] 标准差: \[ std = \sqrt{\sigma^2} \] 第一组 身高cm \(|x-\mu|\) \((x-\mu)^2\) 第二组 身高cm \(|x-\mu|\) \((x-\mu)^2\) A1 188 10 100 A2 166 12 144 B1 169 9 81 B2 175 3 9 C

Ural 1146 Maximum Sum(DP)

题目地址:Ural 1146 这题是求最大子矩阵和.方法是将二维转化一维. 首先用n*n的方法来确定矩阵的列.需要先进行预处理,只对每行来说,转化成一维的前缀和,这样对列的确定只需要前后两个指针来确定,只需要用前缀和相减即可得到.前后两个指针用n*n的枚举. 确定好了哪几列,那么再确定行的时候就转化成了一维的最大连续子序列的和.再来一次O(n)的枚举就可以. 这样,总复杂就变成了O(n^3),对于n为100来说,已经足够了. 代码如下: #include <iostream> #include

URAL 1146 Maximum Sum(最大子矩阵的和 DP)

Maximum Sum 大意:给你一个n*n的矩阵,求最大的子矩阵的和是多少. 思路:最开始我想的是预处理矩阵,遍历子矩阵的端点,发现复杂度是O(n^4),就不知道该怎么办了.问了一下,是压缩矩阵,转换成最大字段和的问题. 压缩行或者列都是可以的. 1 int n, m, x, y, T, t; 2 int Map[1010][1010]; 3 4 int main() 5 { 6 while(~scanf("%d", &n)) 7 { 8 memset(Map, 0, siz

最大子矩阵和 URAL 1146 Maximum Sum

题目传送门 1 /* 2 最大子矩阵和:把二维降到一维,即把列压缩:然后看是否满足最大连续子序列: 3 好像之前做过,没印象了,看来做过的题目要经常看看:) 4 */ 5 #include <cstdio> 6 #include <iostream> 7 #include <cstring> 8 #include <algorithm> 9 using namespace std; 10 11 const int MAXN = 1e2 + 10; 12 co

URAL 1146. Maximum Sum(求最大子矩阵和)

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1146 1146. Maximum Sum Time limit: 0.5 second Memory limit: 64 MB Given a 2-dimensional array of positive and negative integers, find the sub-rectangle with the largest sum. The sum of a rectangle is

ural 1146. Maximum Sum

1146. Maximum Sum Time limit: 0.5 secondMemory limit: 64 MB Given a 2-dimensional array of positive and negative integers, find the sub-rectangle with the largest sum. The sum of a rectangle is the sum of all the elements in that rectangle. In this p

ural 1146 Maximum Sum 最大连续和

1146. Maximum Sum Time limit: 0.5 second Memory limit: 64 MB Given a 2-dimensional array of positive and negative integers, find the sub-rectangle with the largest sum. The sum of a rectangle is the sum of all the elements in that rectangle. In this

URAL 1021 Sacrament of the Sum

题好长,,,,题意就是能否在两块里各找一个数和为10000.............先想到将两个数组排序,,,大加小.......但是超时了.......应该就想到二分,,,,也不知道二分能不能过就是试试呗,,,,反正代码也很短...... 过了...... #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <queue>