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 ...
 
随机推荐
- [Effective JavaScript 笔记] 第10条:避免使用with
			
with特性,提供的任何“便利”都更让其变得不可靠和低效率. with语句的用法,可以很方便地避免对对象的重复引用.上面的代码整理成下面的形式 function status(info){ var w ...
 - unity3d 加密资源并缓存加载
			
原地址:http://www.cnblogs.com/88999660/archive/2013/04/10/3011912.html 首先要鄙视下unity3d的文档编写人员极度不负责任,到发帖为止 ...
 - iPhone socket 编程之BSD Socket篇
			
iPhone socket 编程之BSD Socket篇 收藏在进行iPhone网络通讯程序的开发中,不可避免的要利用Socket套接字.iPhone提供了Socket网络编程的接口CFSocket, ...
 - ios 百度地图api 入门
			
百度地图api 官方教程: http://developer.baidu.com/map/index.php?title=iossdk 这个非常好, 很适合新手 CLLocationCoordinat ...
 - Java数据库ResultSet转json实现
			
现在有很多json相关的Java工具,如json-lib.gson等,它们可以直接把JavaBean转换成json格式. 在开发中,可能会从数据库中获取数据,希望直接转成json数组,中间不通过bea ...
 - HDU1068 最大独立点集
			
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
 - 双参数Bellman-ford带队列优化类似于背包问题的递推
			
为方便起见,将Bellman-ford队列优化称为SPFA,= = 抓住 ZMF (ZMF.pas/c/cpp) 题目描述 话说这又是一个伸手不见五指的夜晚,为了机房的电子竞技事业永远孜孜不倦的 ZM ...
 - tar: Removing leading `/’ from member names
			
tar: Removing leading `/’ from member names+2 分类:Web服务器 标签:tar 3,910人浏览 这并不是一个错误,而是一个警告,原因很简单,就是你在 ...
 - 【云计算】开源的Docker Registry WebUI
			
kwk/docker-registry-frontend Code Issues 9 Pull requests 6 Wiki ...
 - SQL union和union all的区别
			
Union因为要进行重复值扫描,所以效率低.如果合并没有刻意要删除重复行,那么就使用Union All 两个要联合的SQL语句 字段个数必须一样,而且字段类型要“相容”(一致): 如果我们需要将两个 ...