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 ...
随机推荐
- JSP基本面试的试题
JSP基本面试的试题 1.jsp有哪些内置对象作用分别是什么 答:JSP共有以下9种基本内置组件(可与ASP的6种内部组件相对应): request 用户端请求,此请求会包含来自GET/PO ...
- JS 自定义正则表达式
1. 正则表达式规则 1.1 普通字符 字母.数字.汉字.下划线.以及后边章节中没有特殊定义的标点符号,都是"普通字符".表达式中的普通字符,在匹配一个字符串的时候,匹配与之相同的 ...
- linux防止sshd被爆破(安装denyhosts)
这是一篇收集在日志里的文档,当初查看服务器sshd日志发现很多不明IP尝试登陆,因此想用什么办法阻止这样的事情发生.网上找了下用denyhosts可以解决这样的问题,因而也就将其收集在日志里了.由于时 ...
- poj1185
状态压缩dp #include <cstdio> #include <cstring> #include <cstdlib> #include <iostre ...
- Android 和iOS中 View的滚动
在最近的程序中用到了Android中的View的滚动,记录一下,待总结.
- Sql Server 深入的探讨锁机制
一: 当select遇到性能低下的update会怎么样? 1. 还是使用原始的person表,插入6条数据,由于是4000字节,所以两条数据就是一个数据页,如下图: 1 DROP TABLE dbo. ...
- Oracle的锁表与解锁
Oracle的锁表与解锁 SELECT /*+ rule */ s.username, decode(l.type,'TM','TABLE LOCK', 'TX','ROW LOCK', NULL) ...
- c++ template函数的声明和实现需要在同一个文件中
新建一个class C;生成2个文件C.h和C.cpp,在C.h中声明一个函数 template<class T> T stringTo(char* str); 直接用VAssistX的R ...
- 记录远程桌面登录者的IP和MAC
WINDOWS 2003 远程桌面不能记录登陆IP真是件头痛的事,本方法可以记录登陆者IP,具体的操作步骤如下: 1.建立一个存放日志的目录,如C盘下建立一个RDP的目录“C:/RDP”. 2.然后在 ...
- Session的使用(登录例案+其它页面访问)
本程序功能是使用Session将用户输入的用户名保存在Session中(登录成功情况下,登录失败不会有Session值),其它页面想访问时会先判断是否有之前存的Session值. 登录Login.ht ...