CF 192 DIV.2
总结一下这场比赛,就是我太SB了。说多了都是泪。
A,大水题。
B,根据题意,可以肯定有一个城市是可以与所有城市相连的,直接找到该点然后输出该点与其他所有点相连即可。
int x[111111] , y[111111] ,num ;
bool vis[111111] ;
int aa[111111] ,nn = 0 ;
void antry(){
num = 0 ;
int n , m ;
cin >> n >> m ;
mem(vis,0) ; for (int i = 0 ;i < m ;i ++ ){
int a , b ;
cin >> a >> b ;
vis[a] = 1 ;
vis[b] = 1 ;
}
int pos ;
for (int i = 1 ;i <= n ;i ++ ){
if(!vis[i]){
pos = i ;
break ;
}
}
cout << n - 1 << endl;
for (int i = 1 ;i <= n ;i ++ ){
if(i == pos)continue ;
cout << pos <<" " << i << endl;
}
}
int main() {
antry() ;
return 0 ;
}
C,先说-1的情况,当点[x , y ]行x 与列y 都是E的时候,那么就是-1。
然后只要判断 每一行 ,是否没满 ,或者每一列是否没满 。
如果每一行都没满 ,那么每一行都输出一个点,如果每一列都没满,那么每一列都找一个点输出。
char Map[1111][1111] ;
int hang[1111] ;
int lie[1111] ;
int main() { int n ;
cin >> n ;
for (int i = 1 ; i <= n ;i ++ ){
for (int j = 1 ;j <= n ;j ++ ){
cin >> Map[i][j] ;
if(Map[i][j] == 'E'){
hang[i] ++ ;
lie[j] ++ ;
}
}
}
int flag = 0 ;
for (int i = 1 ;i <= n ;i ++ ){
for (int j = 1 ;j <= n ;j ++ ){
if(hang[i] == n && lie[j] == n){
flag = 1 ;
}
}
}
if(flag)cout << -1 << endl;
else {
int num1 = 0 ;
int num2 = 0 ;
for (int i = 1 ;i <= n ;i ++ ){
if(hang[i] != n)num1 ++ ;
if(lie[i] != n)num2 ++ ;
}
if(num1 == n){
for (int i = 1 ;i <= n ;i ++ )
{
bool ff = 0 ;
for (int j = 1 ;j <= n ;j ++ ){
if(Map[i][j] == '.'){
cout << i << " " << j << endl;
ff = 1 ;
}
if(ff)break ;
}
}
}
else if(num2 == n){
for (int i = 1 ;i <= n ;i ++ ){
int ff = 0 ;
for (int j = 1 ;j <= n ;j ++ ){
if(Map[j][i] == '.'){
cout << j << " " <<i << endl;
ff = 1 ; }
if(ff)break ;
}
}
}
}
return 0;
}
D,大水题,直接从E开始BFS,找出所有点的距离,然后判断是否比S 到E的时间小,加起来即可。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <map>
#include <iomanip>
#define PI acos(-1.0)
#define Max 2505
#define inf 1<<28
#define LL(x) ( x << 1 )
#define RR(x) ( x << 1 | 1 )
#define REP(i,s,t) for( int i = ( s ) ; i <= ( t ) ; ++ i )
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
#define mp(a,b) make_pair(a,b)
#define PII pair<int,int>
using namespace std; inline void RD(int &ret) {
char c;
do {
c = getchar();
} while(c < '0' || c > '9') ;
ret = c - '0';
while((c=getchar()) >= '0' && c <= '9')
ret = ret * 10 + ( c - '0' );
} char Map[1111][1111] ;
PII st[11111111] ;
int sx ,sy ;
int ex ,ey ;
int vis[1005][1005] ;
int n , m ;
int num[1005][1005] ;
queue<PII > qe ;
int mx[4] = {0 , 0 ,-1, 1} ;
int my[4] = {1, -1, 0 ,0 } ;
int inmap(int x ,int y){
if(x >= 1 && x <= n && y >= 1 && y <= m)return 1 ;
return 0 ;
}
int dbfs(){
PII s , e ;
mem(vis,0) ;
mem(num , 0) ;
e.first = ex ;
e.second = ey ;
while(!qe.empty())qe.pop() ;
qe.push(e) ;
num[ex][ey] = 0 ;
vis[ex][ey] = 1 ;
while(!qe.empty()){
PII tmp = qe.front() ;
qe.pop() ;
for (int i = 0 ;i < 4 ;i ++ ){
int tx = tmp.first + mx[i] ;
int ty = tmp.second + my[i] ;
if(inmap(tx, ty) && Map[tx][ty] != 'T'){
if(!vis[tx][ty]){
vis[tx][ty] = 1 ;
num[tx][ty] = num[tmp.first][tmp.second] + 1 ;
qe.push(mp(tx,ty)) ;
} }
}
}
return inf ;
}
void antry(){ cin >> n >> m ;
int num1 = 0 ;
for (int i = 1 ;i <= n ; i ++ ){
for (int j = 1 ;j <= m ; j ++ ){
cin >> Map[i][j] ;
if(Map[i][j] >= '1' && Map[i][j] <= '9'){
st[num1].first = i ;
st[num1].second = j ;
num1 ++ ;
}
else if(Map[i][j] == 'S'){
sx = i ;
sy = j ;
}
else if(Map[i][j] == 'E'){
ex = i ;
ey = j ;
}
}
}
dbfs() ;
int ans = 0 ;
int s1 = num[sx][sy] ;
for (int i = 0 ;i < num1 ; i ++ ){
int s2 = num[st[i].first][st[i].second] ;
if(s2 <= s1 && s2 != 0){
ans += Map[st[i].first][st[i].second] - '0' ;
}
}
cout << ans << endl;
}
int main() {
antry() ;
return 0 ;
}
E,在搞。
CF 192 DIV.2的更多相关文章
- CF #376 (Div. 2) C. dfs
1.CF #376 (Div. 2) C. Socks dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...
- CF #375 (Div. 2) D. bfs
1.CF #375 (Div. 2) D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多 ...
- CF #374 (Div. 2) D. 贪心,优先队列或set
1.CF #374 (Div. 2) D. Maxim and Array 2.总结:按绝对值最小贪心下去即可 3.题意:对n个数进行+x或-x的k次操作,要使操作之后的n个数乘积最小. (1)优 ...
- CF #374 (Div. 2) C. Journey dp
1.CF #374 (Div. 2) C. Journey 2.总结:好题,这一道题,WA,MLE,TLE,RE,各种姿势都来了一遍.. 3.题意:有向无环图,找出第1个点到第n个点的一条路径 ...
- CF #371 (Div. 2) C、map标记
1.CF #371 (Div. 2) C. Sonya and Queries map应用,也可用trie 2.总结:一开始直接用数组遍历,果断T了一发 题意:t个数,奇变1,偶变0,然后与问的 ...
- CF #365 (Div. 2) D - Mishka and Interesting sum 离线树状数组
题目链接:CF #365 (Div. 2) D - Mishka and Interesting sum 题意:给出n个数和m个询问,(1 ≤ n, m ≤ 1 000 000) ,问在每个区间里所有 ...
- CF #365 (Div. 2) D - Mishka and Interesting sum 离线树状数组(转)
转载自:http://www.cnblogs.com/icode-girl/p/5744409.html 题目链接:CF #365 (Div. 2) D - Mishka and Interestin ...
- Codeforces Round #192 (Div. 2) (330B) B.Road Construction
题意: 要在N个城市之间修建道路,使得任意两个城市都可以到达,而且不超过两条路,还有,有些城市之间是不能修建道路的. 思路: 要将N个城市全部相连,刚开始以为是最小生成树的问题,其实就是一道简单的题目 ...
- Codeforces Round #192 (Div. 2) (330A) A. Cakeminator
题意: 如果某一行没有草莓,就可以吃掉这一行,某一列没有也可以吃点这一列,求最多会被吃掉多少块蛋糕. //cf 192 div2 #include <stdio.h> #include & ...
随机推荐
- 逗比学树莓派之GPIO
wiringPi适合那些具有C语言基础,在接触树莓派之前已经接触过单片机或者嵌入式开发的人群.wiringPi的API函数和arduino很相似,这也使得它广受欢迎.作者给出了大量的说明 ...
- POJ 3390 Print Words in Lines(DP)
Print Words in Lines Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1624 Accepted: 864 D ...
- PO Box简介
使用Erlang写程序的时候,经常会碰到一种情况:因为Erlang进程的mailbox是没有大小限制的,所以它会一直接受消息,直到Erlang节点内存溢出.在大多数情况下,我们可以通过限制消息生产者的 ...
- 怎样在Upstart机制下的系统中加入upstart事件型的任务
/********************************************************************* * Author : Samson * Date ...
- Ubuntu中改变文件的默认打开方式
其实最简单的方法是右键,在属性中修改,不过这样做没啥意义. ubuntu中与文件的打开方式相关的配置文件有四个: /etc/gnome/defaults.list 这是全局配置文件 /usr/shar ...
- Linux Shell脚本入门--Uniq命令
uniq uniq命令可以去除排序过的文件中的重复行,因此uniq经常和sort合用.也就是说,为了使uniq起作用,所有的重复行必须是相邻的. uniq语法 [root@www ~]# uniq [ ...
- 基于C# 语言的两个html解析器
基于C# 语言的两个html解析器 1)Html Agility Pack http://nsoup.codeplex.com/ 代码段示例: HtmlDocument doc = new HtmlD ...
- WebIM(4)----Comet的特殊之处
WebIM系列文章 在一步一步打造WebIM(1)一文中已经使用Comet实现了一个简单的WebIM,那么,Comet究竟和一般的打开网页有何区别,本文将通过编写一个简单的HTTP服务器来说明两者的区 ...
- jQuery插件的编写相关技术 设计总结和最佳实践
原文:http://www.itzhai.com/jquery-plug-in-the-preparation-of-related-technical-design-summary-and-best ...
- 深入理解javascript new的机制
我们在使用对象的时候,除了一些浏览器内置的单体对象可以直接使用外,都会new一个出来使用. 1.最简单的莫过于如下获取一个Object对象实例 var obj = new Object(); 说明:此 ...