2016 GDUT Individual Contest2_A题_codeforces 416B(暴力)
2016-01-21 20:41
495 查看
B. Art Union
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of n painters
who decided to organize their work as follows.
Each painter uses only the color that was assigned to him. The colors are distinct for all painters. Let's assume that the first painter uses color 1, the second one uses color 2, and so on. Each picture will contain all these n colors.
Adding the j-th color to the i-th picture
takes the j-th painter tij units
of time.
Order is important everywhere, so the painters' work is ordered by the following rules:
Each picture is first painted by the first painter, then by the second one, and so on. That is, after the j-th
painter finishes working on the picture, it must go to the (j + 1)-th painter (if j < n);
each painter works on the pictures in some order: first, he paints the first picture, then he paints the second picture and so on;
each painter can simultaneously work on at most one picture. However, the painters don't need any time to have a rest;
as soon as the j-th painter finishes his part of working
on the picture, the picture immediately becomes available to the next painter.
Given that the painters start working at time 0, find for each picture the time when it is ready for sale.
Input
The first line of the input contains integers m, n (1 ≤ m ≤ 50000, 1 ≤ n ≤ 5),
where m is the number of pictures and n is
the number of painters. Then follow the descriptions of the pictures, one per line. Each line contains n integers ti1, ti2, ..., tin (1 ≤ tij ≤ 1000),
where tijis the time the j-th
painter needs to work on the i-th picture.
Output
Print the sequence of m integers r1, r2, ..., rm,
where ri is the moment when
the n-th painter stopped working on the i-th
picture.
Sample test(s)
input
output
input
output
题意:有m幅画和n个画家,每个画家完成一幅画需要一定的时间,每个画家画的顺序从0-n-1,一幅画首先被画家0画完了,才能传到1号画家,然后才能到2号画家。
思路:更新一个n*m 的二维数组
1.当i==0且j==0时,不用更新。
2.当i==0 或者 j == 0,但i和j不同时为0是,a[i][j] = a[i][j-1], a[i][j] = a[i-1][j]
3.当i和j都不等于0时 a[i][j] += max(a[i-1][j], a[i][j-1]); 因为当一个画家要画一幅画时,因为要等他画完前一幅画,以及等他的前一个画家把画传给他,所以要取这两个时间的较大者,a[i][j] = max(a[i-1][j], a[i][j-1]).然后输出数组每一行的最后一个数即可。
代码:
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of n painters
who decided to organize their work as follows.
Each painter uses only the color that was assigned to him. The colors are distinct for all painters. Let's assume that the first painter uses color 1, the second one uses color 2, and so on. Each picture will contain all these n colors.
Adding the j-th color to the i-th picture
takes the j-th painter tij units
of time.
Order is important everywhere, so the painters' work is ordered by the following rules:
Each picture is first painted by the first painter, then by the second one, and so on. That is, after the j-th
painter finishes working on the picture, it must go to the (j + 1)-th painter (if j < n);
each painter works on the pictures in some order: first, he paints the first picture, then he paints the second picture and so on;
each painter can simultaneously work on at most one picture. However, the painters don't need any time to have a rest;
as soon as the j-th painter finishes his part of working
on the picture, the picture immediately becomes available to the next painter.
Given that the painters start working at time 0, find for each picture the time when it is ready for sale.
Input
The first line of the input contains integers m, n (1 ≤ m ≤ 50000, 1 ≤ n ≤ 5),
where m is the number of pictures and n is
the number of painters. Then follow the descriptions of the pictures, one per line. Each line contains n integers ti1, ti2, ..., tin (1 ≤ tij ≤ 1000),
where tijis the time the j-th
painter needs to work on the i-th picture.
Output
Print the sequence of m integers r1, r2, ..., rm,
where ri is the moment when
the n-th painter stopped working on the i-th
picture.
Sample test(s)
input
5 1 1 2 3 4 5
output
1 3 6 10 15
input
4 2 2 5 3 1 5 3 10 1
output
7 8 13 21
题意:有m幅画和n个画家,每个画家完成一幅画需要一定的时间,每个画家画的顺序从0-n-1,一幅画首先被画家0画完了,才能传到1号画家,然后才能到2号画家。
思路:更新一个n*m 的二维数组
1.当i==0且j==0时,不用更新。
2.当i==0 或者 j == 0,但i和j不同时为0是,a[i][j] = a[i][j-1], a[i][j] = a[i-1][j]
3.当i和j都不等于0时 a[i][j] += max(a[i-1][j], a[i][j-1]); 因为当一个画家要画一幅画时,因为要等他画完前一幅画,以及等他的前一个画家把画传给他,所以要取这两个时间的较大者,a[i][j] = max(a[i-1][j], a[i][j-1]).然后输出数组每一行的最后一个数即可。
代码:
<span style="font-size:14px;">#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <cmath> #include <map> #include <set> using namespace std; const int INF = 0x7fffffff; int a[50050][5]; int main() { int m, n; cin >> m >> n; for(int i = 0; i < m; ++i) { for(int j = 0; j < n; ++j) { cin >> a[i][j]; } } for(int i = 0; i < m; ++i) { for(int j = 0; j < n; ++j) { if(i == 0 && j == 0) { continue; } else if(i == 0 && j != 0) { a[i][j] += a[i][j-1]; } else if((i != 0 && j == 0)) { a[i][j] += a[i-1][j]; } else { a[i][j] += max(a[i-1][j], a[i][j-1]); } } } for(int i = 0; i < m; ++i) cout << a[i][n-1] << " "; cout << endl; return 0; } </span>
相关文章推荐
- destoon 部署到服务器如何修改密码使网站能正常访问登录
- [简历] 一些找工作中对简历的写法的看法 20160121
- 自然语言处理中的Attention Model:是什么及为什么
- 网络编程(TCP-客户端并发登录)
- Java NIO使用及原理分析 (四)
- 【vj】给定一些先后约束,求原序列(拓扑排序)
- 例题6-4 UVa11988 静态链表
- Java图片上传压缩处理
- android开发之二维码
- MCPeerID
- 二叉树的镜像
- Android ANR问题分析
- android 制作简单的画板
- 一篇关于机器学习的温和指南
- Java快速入门【11~20待续】
- ajax请求在ie8下缓存问题
- 解析字符串为泛型的方法
- ARM -A9 基础学习()
- python[四]:python爬虫入门
- golang内存分配