CodeForces Round 192 Div2
1 second
256 megabytes
standard input
standard output
You are given a rectangular cake, represented as an r × c grid. Each cell either has an evil strawberry, or is empty. For example, a 3 × 4 cake may look as follows:
The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains at least one cake cell that has not been eaten before, and eats all the cake cells there. He may decide to eat any number of times.
Please output the maximum number of cake cells that the cakeminator can eat.
The first line contains two integers r and c (2 ≤ r, c ≤ 10), denoting the number of rows and the number of columns of the cake. The next r lines each contains c characters — the j-th character of the i-th line denotes the content of the cell at row i and column j, and is either one of these:
- '.' character denotes a cake cell with no evil strawberry;
- 'S' character denotes a cake cell with an evil strawberry.
Output the maximum number of cake cells that the cakeminator can eat.
3 4 S... .... ..S.
8
For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats).
#include<stdio.h>
#include<string.h>
int r,c;
char ch[15][15];
bool g[15][15];
bool judger(int x)
{
int i;
for (i=0;i<c;i++)
if (ch[x][i]=='S') return false;
return true;
}
bool judgec(int x)
{
int i;
for (i=0;i<r;i++)
if (ch[i][x]=='S') return false;
return true;
}
int main()
{
while (scanf("%d%d",&r,&c)!=EOF)
{
int i,j;
for (i=0;i<r;i++) scanf("%s",ch[i]);
memset(g,0,sizeof(g));
for (i=0;i<r;i++)
if (judger(i))
for (j=0;j<c;j++) g[i][j]=true;
for (i=0;i<c;i++)
if (judgec(i))
for (j=0;j<r;j++) g[j][i]=true;
int ans=0;
for (i=0;i<r;i++)
for (j=0;j<c;j++)
if (g[i][j]) ans++;
printf("%d\n",ans);
}
return 0;
}
2 seconds
256 megabytes
standard input
standard output
A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two roads. You are also given m pairs of cities — roads cannot be constructed between these pairs of cities.
Your task is to construct the minimum number of roads that still satisfy the above conditions. The constraints will guarantee that this is always possible.
The first line consists of two integers n and m .
Then m lines follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that it is not possible to construct a road connecting cities ai and bi. Consider the cities are numbered from 1 to n.
It is guaranteed that every pair of cities will appear at most once in the input.
You should print an integer s: the minimum number of roads that should be constructed, in the first line. Then s lines should follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that a road should be constructed between cities ai and bi.
If there are several solutions, you may print any of them.
This is one possible solution of the example:
These are examples of wrong solutions:
The above solution is wrong because it doesn't use the minimum number of edges (4 vs 3). In addition, it also tries to construct a road between cities 1 and 3, while the input specifies that it is not allowed to construct a road between the pair.
The above solution is wrong because you need to traverse at least 3 roads to go from city 1 to city 3, whereas in your country it must be possible to go from any city to another by traversing at most 2 roads.
Finally, the above solution is wrong because it must be possible to go from any city to another, whereas it is not possible in this country to go from city 1 to 3, 2 to 3, and 4 to 3.
At first I was scared by the description,because I didn't know how to handle it.But after a few minutes,I noticed that m<(n/2).That mean for each case ,there would exist a point which can draw a street with any other citise.So, the minimum of the roads must be n-1.Then just find a city above,and link it with all the other cities.
#include<stdio.h>
#include<string.h>
bool s[1024];
int main()
{
int N,M,u,v,i;
while (scanf("%d%d",&N,&M)!=EOF)
{
memset(s,true,sizeof(s));
for (i=1;i<=M;i++)
{
int u,v;
scanf("%d%d",&u,&v);
s[u]=false;
s[v]=false;
}
printf("%d\n",N-1);
for (i=1;i<=N;i++)
if (s[i])
{
u=i;
break;
}
for (i=1;i<=N;i++)
if (i!=u) printf("%d %d\n",u,i);
}
return 0;
}
CodeForces Round 192 Div2的更多相关文章
- Codeforces Round #539 div2
Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...
- 【前行】◇第3站◇ Codeforces Round #512 Div2
[第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...
- Codeforces Round#320 Div2 解题报告
Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...
- Codeforces Round #564(div2)
Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...
- Codeforces Round #361 div2
ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...
- Codeforces Round #192 (Div. 2) (330A) A. Cakeminator
题意: 如果某一行没有草莓,就可以吃掉这一行,某一列没有也可以吃点这一列,求最多会被吃掉多少块蛋糕. //cf 192 div2 #include <stdio.h> #include & ...
- Codeforces Round #626 Div2 D,E
比赛链接: Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) D.Present 题意: 给定大 ...
- Codeforces Round #192 (Div. 1) C. Graph Reconstruction 随机化
C. Graph Reconstruction Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/3 ...
- Codeforces Round #192 (Div. 1) B. Biridian Forest 暴力bfs
B. Biridian Forest Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/pr ...
随机推荐
- 虚拟机里面安装Openfiler 2.99
简介 Openfiler 由rPath Linux驱动,它是一个基于浏览器的免费网络存储管理实用程序,可以在单一框架中提供基于文件的网络连接存储 (NAS) 和基于块的存储区域网 (SAN).Open ...
- 使用 nginx + thin 的配置启动 rails server
http://www.iwangzheng.com 在大师的指导下配置了新的服务器的nginx,通过top命令查看了服务器是8个cpu的,所以起了8个端口,把它们都映射到一个总的端口3600上,需要在 ...
- sql注入攻击的预防函数
/* 待更新 */ addslashes htmlspecialchars mysql_escape_string($string) mysql_real_escape_string($strin ...
- DCMTK354之VC++ 2008 MFC应用程序配置完整过程
花了一个礼拜,终于在VC++2008 MFC 应用程序中完成了首个基于DCMTK354的首个程序ECHOSCUWIN32,现将过程记录下来,便于日后查阅,同时也提供给那些有幸看到此博文而对他们又有帮助 ...
- redhat 6 / centos 6 搭建Django环境
1)首先 安装的时候 到 选择安装那些包的时候 把 编译环境和开发的包 那块全部打上勾 2)系统虽然自带Python安装包,但是版本比较低.所以推荐自行进行tar包编译安装比较新的 https:// ...
- 【SpringMVC】SpringMVC系列10之视图与视图解析器
10.视图与视图解析器 10.1.概述 请求处理方法执行完成后,最终返回一个 ModelAndView处理方法,Spring MVC 也会在内部将它们装配成一个ModelAndView 对象, ...
- java回顾巩固
看视频复习java有一段时间了.虽然现在做的东西是net的,但是一直没忘记复习java. 更多的大概在这里. java变量的命名规则: (A)组成规则: 1:英文大小写字母 2:数字 3:$和_ (2 ...
- Java面向对象的多态
Java中多态的概念是面向对象中除封装和继承外非常重要的知识点,也是Java面向对象三大特性最后一个特性 多态其实就是指对象存在的多种形态,多态分为引用多态和方法多态 引用多态的含义就是:父类的引用可 ...
- Java for LeetCode 048 Rotate Image
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- 11.python之线程,协程,进程,
一,进程与线程 1.什么是线程 线程是操作系统能够进行运算调度的最小单位.它被包含在进程之中,是进程中的实际运作单位.一条线程指的是进程中一个单一顺序的控制流,一个进程中可以并发多个线程,每条线程并行 ...