Codeforces Round #369 (Div. 2) A B 暴力 模拟
2 seconds
256 megabytes
standard input
standard output
ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has nrows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris are good friends. They insist to get a pair of neighbouring empty seats. Two seats are considered neighbouring if they are in the same row and in the same pair. Given the configuration of the bus, can you help ZS and Chris determine where they should sit?
The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of rows of seats in the bus.
Then, n lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and the last two of them denote the second pair of seats in the row.
Each character, except the walkway, equals to 'O' or to 'X'. 'O' denotes an empty seat, 'X' denotes an occupied seat. See the sample cases for more details.
If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next n lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by exactly two charaters (they should be equal to 'O' in the input and to '+' in the output).
If there is no pair of seats for Chris and ZS, print "NO" (without quotes) in a single line.
If there are multiple solutions, you may print any of them.
- 6
OO|OX
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX
- YES
++|OX
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX
- 4
XO|OX
XO|XX
OX|OX
XX|OX
- NO
- 5
XX|XX
XX|XX
XO|OX
XO|OO
OX|XO
- YES
XX|XX
XX|XX
XO|OX
XO|++
OX|XO
Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX
题意:n排座位 每排两对座位 X代表已经被占了 现在两个人找座位 座位必须是某一对
若能找到输出YES 并用+标注找到的座位 否则输出NO
题解:模拟暴力
- /******************************
- code by drizzle
- blog: www.cnblogs.com/hsd-/
- ^ ^ ^ ^
- O O
- ******************************/
- #include<bits/stdc++.h>
- #include<iostream>
- #include<cstring>
- #include<cstdio>
- #include<map>
- #include<algorithm>
- #include<queue>
- #define ll __int64
- using namespace std;
- int n;
- char a[][];
- int main()
- {
- scanf("%d",&n);
- int flag=;
- for(int i=; i<=n; i++)
- {
- getchar();
- for(int j=; j<=; j++)
- {
- scanf("%c",&a[i][j]);
- if(flag)
- {
- if(j==)
- {
- if(a[i][]=='O'&&a[i][]=='O')
- {
- a[i][]='+';
- a[i][]='+';
- flag=;
- }
- }
- }
- if(flag)
- {
- if(j==)
- {
- if(a[i][]=='O'&&a[i][]=='O')
- {
- a[i][]='+';
- a[i][]='+';
- flag=;
- }
- }
- }
- }
- }
- if(flag==)
- {
- printf("YES\n");
- for(int i=; i<=n; i++)
- {
- for(int j=; j<=; j++)
- printf("%c",a[i][j]);
- printf("\n");
- }
- }
- else
- printf("NO\n");
- return ;
- }
2 seconds
256 megabytes
standard input
standard output
ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n × n magic grid on the entrance which is filled with integers. Chris noticed that exactly one of the cells in the grid is empty, and to enter Udayland, they need to fill a positive integer into the empty cell.
Chris tried filling in random numbers but it didn't work. ZS the Coder realizes that they need to fill in a positive integer such that the numbers in the grid form a magic square. This means that he has to fill in a positive integer so that the sum of the numbers in each row of the grid (), each column of the grid (
), and the two long diagonals of the grid (the main diagonal —
and the secondary diagonal —
) are equal.
Chris doesn't know what number to fill in. Can you help Chris find the correct positive integer to fill in or determine that it is impossible?
The first line of the input contains a single integer n (1 ≤ n ≤ 500) — the number of rows and columns of the magic grid.
n lines follow, each of them contains n integers. The j-th number in the i-th of them denotes ai, j (1 ≤ ai, j ≤ 109 or ai, j = 0), the number in the i-th row and j-th column of the magic grid. If the corresponding cell is empty, ai, j will be equal to 0. Otherwise, ai, j is positive.
It is guaranteed that there is exactly one pair of integers i, j (1 ≤ i, j ≤ n) such that ai, j = 0.
Output a single integer, the positive integer x (1 ≤ x ≤ 1018) that should be filled in the empty cell so that the whole grid becomes a magic square. If such positive integer x does not exist, output - 1 instead.
If there are multiple solutions, you may print any of them.
- 3
4 0 2
3 5 7
8 1 6
- 9
- 4
1 1 1 1
1 1 0 1
1 1 1 1
1 1 1 1
- 1
- 4
1 1 1 1
1 1 0 1
1 1 2 1
1 1 1 1
- -1
In the first sample case, we can fill in 9 into the empty cell to make the resulting grid a magic square. Indeed,
The sum of numbers in each row is:
4 + 9 + 2 = 3 + 5 + 7 = 8 + 1 + 6 = 15.
The sum of numbers in each column is:
4 + 3 + 8 = 9 + 5 + 1 = 2 + 7 + 6 = 15.
The sum of numbers in the two diagonals is:
4 + 5 + 6 = 2 + 5 + 8 = 15.
In the third sample case, it is impossible to fill a number in the empty square such that the resulting grid is a magic square.
题意:一个n*n的矩阵 在0的位置上(只有一个零)填写一个正整数使得这个矩阵中每一行每一列以及两个对角线的和都相等
输出这个数 不存在则输出-1
题解:暴力 对于这个矩阵求出每一行每一列以及两个对角线的和 判断这个和的值有多少种
对于只有两种的 因为只能填写正整数 按要求比较大小输出值差值 特判 n=1
- /******************************
- code by drizzle
- blog: www.cnblogs.com/hsd-/
- ^ ^ ^ ^
- O O
- ******************************/
- #include<bits/stdc++.h>
- #include<iostream>
- #include<cstring>
- #include<cstdio>
- #include<map>
- #include<algorithm>
- #include<queue>
- #define ll __int64
- using namespace std;
- int n;
- ll a[][];
- ll r[],l[];
- ll s,d;
- ll ans[];
- ll xx,yy;
- map<ll,int> mp;
- int main()
- {
- scanf("%d",&n);
- s=;
- d=;
- mp.clear();
- memset(r,,sizeof(r));
- memset(l,,sizeof(l));
- for(int i=;i<=n;i++)
- {
- for(int j=;j<=n;j++)
- {
- scanf("%I64d",&a[i][j]);
- if(a[i][j]==)
- {
- xx=i;
- yy=j;
- }
- r[i]+=a[i][j];
- l[j]+=a[i][j];
- if(i==j)
- s+=a[i][j];
- if((i+j)==(n+))
- d+=a[i][j];
- }
- }if(n==)
- {
- printf("1\n");
- return ;
- }
- int jishu=;
- for(int i=;i<=n;i++)
- {
- if(mp[r[i]]==)
- ans[jishu++]=r[i];
- mp[r[i]]++;
- }
- for(int i=;i<=n;i++)
- {
- if(mp[l[i]]==)
- ans[jishu++]=l[i];
- mp[l[i]]++;
- }
- if(mp[s]==)
- ans[jishu++]=s;
- mp[s]++;
- if(mp[d]==)
- ans[jishu++]=d;
- mp[d]++;
- int s1=;
- if(xx==yy)
- s1++;
- if((xx+yy)==(n+))
- s1++;
- if(jishu!=)
- printf("-1\n");
- else{
- if(mp[ans[]]==s1&&ans[]<ans[])
- {
- printf("%I64d\n",ans[]-ans[]);
- return ;
- }
- if(mp[ans[]]==s1&&ans[]<ans[])
- {
- printf("%I64d\n",ans[]-ans[]);
- return ;
- }
- printf("-1\n");
- }
- return ;
- }
Codeforces Round #369 (Div. 2) A B 暴力 模拟的更多相关文章
- Codeforces Round #368 (Div. 2) B. Bakery (模拟)
Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...
- Codeforces Round #284 (Div. 2)A B C 模拟 数学
A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #285 (Div. 2) A B C 模拟 stl 拓扑排序
A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- Codeforces Round #369 (Div. 2) B. Chris and Magic Square (暴力)
Chris and Magic Square 题目链接: http://codeforces.com/contest/711/problem/B Description ZS the Coder an ...
- Codeforces Round #369 (Div. 2) C 基本dp+暴力
C. Coloring Trees time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Round #307 (Div. 2) B. ZgukistringZ 暴力
B. ZgukistringZ Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/probl ...
- Codeforces Round #328 (Div. 2) A. PawnChess 暴力
A. PawnChess Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/problem/ ...
- Codeforces Round #404 (Div. 2)(A.水,暴力,B,排序,贪心)
A. Anton and Polyhedrons time limit per test:2 seconds memory limit per test:256 megabytes input:sta ...
- Codeforces Round #369 (Div. 2) E. ZS and The Birthday Paradox 数学
E. ZS and The Birthday Paradox 题目连接: http://www.codeforces.com/contest/711/problem/E Description ZS ...
随机推荐
- POJ 2739 Sum of Consecutive Prime Numbers 难度:0
题目链接:http://poj.org/problem?id=2739 #include <cstdio> #include <cstring> using namespace ...
- 在Win7下安装IIS
由于工作上的需要,有朋友在问在windows7系统下如何来配置IIS,大部分用户平时都很少接触到这个功能,所以对于安装配置十分陌生也是在所难免的,下面就让小编与你分享下windows7系统下IIS详细 ...
- SPOJ SUBLEX 求第k小子串
题目大意: 对于一个给定字符串,找到其所有不同的子串中排第k小的子串 先构建后缀自动机,然后我们可以将整个后缀自动机看做是一个DAG图,那么我们先进行拓扑排序得到 *b[N] 对于每个节点记录一个sc ...
- UITableViewCell Property “icon” cannot be found in forward class object “DJWeiBo”
UITableViewCell 自定义表格 实体属性不显示错误 Property “icon” cannot be found in forward class object “DJWeiBo”引入实 ...
- 【转】linux下如何查看某个软件 是否安装?安装路径在哪
以redhat\centos 中php-mysql为例1:如果包是通过yum或者rpm方式安装[root@localhost yum.repos.d]# rpm -qa //找出系统所有的包,找到对应 ...
- mybatis分页插件PageHelper的使用(转)
Mybatis 的分页插件PageHelper-4.1.1的使用 Mybatis 的分页插件 PageHelper 项目地址:http://git.oschina.net/free/Mybatis_P ...
- 网络安全之PHP安全编程建议
要提供互联网服务,当你在开发代码的时候必须时刻保持安全意识.可能大部分 PHP 脚本都对安全问题都不在意,这很大程度上是因为有大量的 无经验程序员 在使用这门语言.但是,没有理由让你因为对你的代码的不 ...
- Tengine安装配置
为了加快网站的大流量访问速度,公司要求把Nginx更换为Tengine,下面记录下整个安装配置过程: #安装必要依赖 yum install -y pcre pcre-devel zlib zlib- ...
- 一看就会之—利用IIS服务发布网站(实践篇)上
转自:http://blog.csdn.net/zwk626542417/article/details/9796259 概述 IIS全称为互联网信息服务,是由微软公司提供的基于运行Microsoft ...
- (转)HTML5 本地存储
原文:http://www.cnblogs.com/rainman/archive/2011/06/22/2086069.html HTML5 本地存储 1.sessionStorage 2.loca ...