zoukankan      html  css  js  c++  java
  • Codeforces 525C Ilya and Sticks

    题意:给你n条线段,问你这些线段可以组成的矩形和最大是多少。每条线段可以-1,。

    解题思路:贪心.

    解题代码:

      1 // File Name: d.cpp
      2 // Author: darkdream
      3 // Created Time: 2015年03月27日 星期五 16时05分31秒
      4 
      5 #include<vector>
      6 #include<list>
      7 #include<map>
      8 #include<set>
      9 #include<deque>
     10 #include<stack>
     11 #include<bitset>
     12 #include<algorithm>
     13 #include<functional>
     14 #include<numeric>
     15 #include<utility>
     16 #include<cstdio>
     17 #include<cmath>
     18 #include<cstdlib>
     19 #include<ctime>
     20 #include<queue>
     21 #define LL long long
     22 
     23 using namespace std;
     24 int n ,m ;
     25 char mp[2005][2005];
     26 bool vis[2005][2005];
     27 struct  node{
     28     int x, y;
     29     node(){}
     30     node(int _x, int _y)
     31     {
     32         x = _x; 
     33         y = _y ;
     34     }
     35 }tmp;
     36 int lx, ly ,rx,ry;
     37 int xadd[] = {0,0,1,-1};
     38 int yadd[] = {1,-1,0,0};
     39 queue<node>qu;
     40 void bfs(int x,int y)
     41 {
     42       qu.push(node(x,y));
     43       int tx,ty;
     44       while(!qu.empty())
     45       {
     46          tmp = qu.front();
     47          qu.pop();
     48          if(mp[tmp.x][tmp.y] != '.')
     49              continue;
     50          if(mp[tmp.x-1][tmp.y] == '.' && mp[tmp.x][tmp.y+1] =='.' && mp[tmp.x-1][tmp.y+1] == '*')
     51          {
     52            tx = tmp.x -1;
     53            ty = tmp.y +1; 
     54            mp[tx][ty] = '.';
     55            qu.push(node(tx,ty));
     56            for(int i = 0 ;i <= 3 ;i ++)
     57                qu.push(node(tx+xadd[i],ty+yadd[i]))    ;   
     58          }
     59          if(mp[tmp.x-1][tmp.y] == '.' && mp[tmp.x][tmp.y-1] =='.' && mp[tmp.x-1][tmp.y-1] == '*')
     60          {
     61            tx = tmp.x -1;
     62            ty = tmp.y -1; 
     63            mp[tx][ty] = '.';
     64            qu.push(node(tx,ty));
     65            for(int i = 0 ;i <= 3 ;i ++)
     66                qu.push(node(tx+xadd[i],ty+yadd[i]))    ;   
     67          }
     68          if(mp[tmp.x+1][tmp.y] == '.' && mp[tmp.x][tmp.y+1] =='.' && mp[tmp.x+1][tmp.y+1] == '*')
     69          {
     70            tx = tmp.x +1;
     71            ty = tmp.y +1; 
     72            mp[tx][ty] = '.';
     73            qu.push(node(tx,ty));
     74            for(int i = 0 ;i <= 3 ;i ++)
     75                qu.push(node(tx+xadd[i],ty+yadd[i]))    ;   
     76          }
     77          if(mp[tmp.x+1][tmp.y] == '.' && mp[tmp.x][tmp.y-1] =='.' && mp[tmp.x+1][tmp.y-1] == '*')
     78          {
     79            tx = tmp.x +1;
     80            ty = tmp.y -1; 
     81            mp[tx][ty] = '.';
     82            qu.push(node(tx,ty));
     83            for(int i = 0 ;i <= 3 ;i ++)
     84                qu.push(node(tx+xadd[i],ty+yadd[i]))    ;   
     85          }
     86       }
     87 }
     88 int main(){
     89     scanf("%d %d",&n,&m);
     90     for(int i = 1;i <= n;i ++)
     91     {
     92         scanf("%s",&mp[i][1]);        
     93     }
     94     for(int i = 1 ;i <= n;i ++)
     95     {
     96         for(int j = 1;j <= m;j ++)
     97         {
     98             if( mp[i][j] == '.')
     99             {
    100                 bfs(i,j);
    101             }
    102         }
    103     }
    104     for(int i = 1;i <= n;i ++)
    105         puts(&mp[i][1]);
    106     return 0;
    107 }
    View Code
    没有梦想,何谈远方
  • 相关阅读:
    vue项目进行时,script标签中,methods事件中函数使用的async/await
    css阴影——box-shadow
    vue报错——Module not found: Error: Can't resolve 'less-loader sass' in ...
    vue组件如何引入外部.js/.css/.scss文件
    获得汉字的拼音或者拼音简写
    model转XML
    sql server 添加表注释、字段注释
    (转)SQL Server 监控统计阻塞脚本信息
    系统首页右下角弹框
    DropDownListExtend控件
  • 原文地址:https://www.cnblogs.com/zyue/p/4372805.html
Copyright © 2011-2022 走看看