• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Codeforce Round #228 Div2 D

 

Sponsored by
In English По-русски
HaibaraAi | Logout
 
 
 
 
 
  • Home
  • Contests
  • Gym
  • Problemset
  • Groups
  • Rating
  • Help
  • Rockethon

 
 
Codeforces Round #229 (Div. 2)
Finished
Practice
Add to favourites
 
 
→ Practice
 
You are registered for practice. You can solve problems unofficially. Results can be found in the contest status and in the bottom of standings.
 
 
→ Submit?
 
Language:
Choose file:
Be careful: there is 50 points penalty for submission which fails the pretests or resubmission (except failure on the first test, denial of judgement or similar verdicts). "Passed pretests" submission verdict doesn't guarantee that the solution is absolutely correct and it will pass system tests.
 
 
→ Last submissions
 
SubmissionTimeVerdict
5978428 02/14/2014 05:38PM Accepted
5975258 02/14/2014 05:18AM Wrong answer on test 8
5975254 02/14/2014 05:16AM Wrong answer on test 3
5975240 02/14/2014 05:12AM Wrong answer on test 3
 
 
→ Problem tags
 
 
 
 
 
constructive algorithms
 
 
 
 
dfs and similar
 
 
 
 
implementation
No tag edit access
 
 
→ Contest materials
 
  • Announcement
     
  • Tutorial
     
  •  
     
     
  • Problems
  • Submit
  • My submissions
  • Status
  • Hacks
  • Room
  • Standings
  • Custom test
D. Inna and Sweet Matrix
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Inna loves sweets very much. That's why she decided to play a game called "Sweet Matrix".

Inna sees an n × m matrix and k candies. We'll index the matrix rows from 1 to n and the matrix columns from 1 to m. We'll represent the cell in the i-th row and j-th column as (i, j). Two cells (i, j) and (p, q) of the matrix are adjacent if |i - p| + |j - q| = 1. A path is a sequence of the matrix cells where each pair of neighbouring cells in the sequence is adjacent. We'll call the number of cells in the sequence the path's length.

Each cell of the matrix can have at most one candy. Initiallly, all the cells are empty. Inna is trying to place each of the k candies in the matrix one by one. For each candy Inna chooses cell (i, j) that will contains the candy, and also chooses the path that starts in cell (1, 1) and ends in cell (i, j) and doesn't contain any candies. After that Inna moves the candy along the path from cell (1, 1) to cell (i, j), where the candy stays forever. If at some moment Inna can't choose a path for the candy, she loses. If Inna can place all the candies in the matrix in the described manner, then her penalty equals the sum of lengths of all the paths she has used.

Help Inna to minimize the penalty in the game.

Input

The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 50, 1 ≤ k ≤ n·m).

Output

In the first line print an integer — Inna's minimum penalty in the game.

In the next k lines print the description of the path for each candy. The description of the path of the candy that is placed i-th should follow on the i-th line. The description of a path is a sequence of cells. Each cell must be written in the format (i, j), where i is the number of the row and j is the number of the column. You are allowed to print extra whitespaces in the line. If there are multiple optimal solutions, print any of them.

Please follow the output format strictly! If your program passes the first pretest, then the output format is correct.

Sample test(s)
Input
4 4 4
Output
8 (1,1) (2,1) (2,2) (1,1) (1,2) (1,1) (2,1) (1,1)
Note

Note to the sample. Initially the matrix is empty. Then Inna follows her first path, the path penalty equals the number of cells in it — 3. Note that now no path can go through cell (2, 2), as it now contains a candy. The next two candies go to cells (1, 2) and (2, 1). Inna simply leaves the last candy at cell (1, 1), the path contains only this cell. The total penalty is: 3 + 2 + 2 + 1 = 8.

Note that Inna couldn't use cell (1, 1) to place, for instance, the third candy as in this case she couldn't have made the path for the fourth candy.


Codeforces (c) Copyright 2010-2014 Mike Mirzayanov
The only programming contests Web 2.0 platform
Server time: 02/14/2014 05:41PM (c4).
 
 
 
 1 #pragma comment(linker,"/STACK:102400000,102400000")
 2 #include <cstdio>
 3 #include <vector>
 4 #include <cmath>
 5 #include <stack>
 6 #include <queue>
 7 #include <cstring>
 8 #include <iostream>
 9 #include <algorithm>
10 using namespace std;
11 #define INF 0x7fffffff
12 #define maxn 200005
13 typedef pair<int, int> pii;
14 int n, m, t, b, y, k, x, s, ans;
15 int a[maxn];
16 pii p[maxn];
17 int main(){
18     cin >> n >> m >> k;
19     for (s = 2; x < k; s++)
20     for (int i = max(1, s - m); x<k&&i <= min(s-1,n); i++){
21         p[x++] = pii(i, s-i);
22         y += s-1;
23     }
24     cout << y << endl;
25     for (int i = k-1; i >= 0; i--){
26         for (int j = 1; j <= p[i].first;j++)
27         cout << '(' << j << ',' << '1' << ')' << ' ';
28         for (int j = 2; j <= p[i].second;j++)
29         cout << '(' << p[i].first << ',' << j << ')' << ' ';
30         cout << endl;
31     }
32     return 0;
33 }
View Code
posted @ 2014-02-14 21:42  HaibaraAi  阅读(123)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3