xml地图|网站地图|网站标签 [设为首页] [加入收藏]

正规赌博平台

当前位置:网上十大正规赌博平台 > 正规赌博平台 > 网上十大正规赌博平台统计字符串中每个字符出

网上十大正规赌博平台统计字符串中每个字符出

来源:http://www.nb-machinery.com 作者:网上十大正规赌博平台 时间:2019-08-28 22:10

hdu1254 推箱子(bfs bfs)

iostream 2#include string 3using namespace std; 4 5int main(){ 6 string str; 7 int ascii[256]={}; 8 cout"请输入一个字符串:"; 9 getline(cin,str); 10 for(int i=0;...

#include "file_info.h"

推箱子

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6386 Accepted Submission(s): 1825

Problem Description 推箱子是一个很经典的游戏.今天我们来玩一个简单版本.在一个M*N的房间里有一个箱子和一个搬运工,搬运工的工作就是把箱子推到指定的位置,注意,搬运工只能推箱子而不能拉箱子,因此如果箱子被推到一个角上(如图2)那么箱子就不能再被移动了,如果箱子被推到一面墙上,那么箱子只能沿着墙移动.

现在给定房间的结构,箱子的位置,搬运工的位置和箱子要被推去的位置,请你计算出搬运工至少要推动箱子多少格.

网上十大正规赌博平台 1

Input 输入数据的第一行是一个整数T(1<=T<=20),代表测试数据的数量.然后是T组测试数据,每组测试数据的第一行是两个正整数M,N(2<=M,N<=7),代表房间的大小,然后是一个M行N列的矩阵,代表房间的布局,其中0代表空的地板,1代表墙,2代表箱子的起始位置,3代表箱子要被推去的位置,4代表搬运工的起始位置.

Output 对于每组测试数据,输出搬运工最少需要推动箱子多少格才能帮箱子推到指定位置,如果不能推到指定位置则输出-1.

Sample Input

1
5 5
0 3 0 0 0
1 0 1 4 0
0 0 1 0 0
1 0 2 0 0
0 0 0 0 0

Sample Output

4

Author Ignatius.L & weigang Lee
分析:bfs嵌套bfs,一个搜人的轨迹,一个搜箱子的轨迹。

#include 
#include 
#include 
#include 
#include 
#include
#include 
#include 
#include 
#include 
using namespace std;
const double eps = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
#define ll long long
#define CL(a,b) memset(a,b,sizeof(a))

int n,m;
int mat[11][11],dir[4][2]= {{0,1},{0,-1},{1,0},{-1,0}};
bool vis[11][11][4],vm[11][11];
int man_x,man_y,box_x,box_y,en_x,en_y;

struct A
{
    int x,y;
};
struct node
{
    int step;
    struct A box,man;
};
bool bb(int b_x, int b_y, int m_x, int m_y, int k)//搜人是否能到达要推的位置
{
    CL(vm, false);
    queue qq;
    node ss,tt;
    ss.man.x=m_x;
    ss.man.y=m_y;
    vm[ss.man.x][ss.man.y]=true;
    vm[b_x][b_y]=true;//当前箱子的位置标记不可访问
    qq.push(ss);
    while(!qq.empty())
    {
        ss=qq.front();
        qq.pop();

        if(ss.man.x dir[k][0]==b_x&&ss.man.y dir[k][1]==b_y) return true;
        for(int i=0; i<4; i  )
        {
            tt.man.x=ss.man.x dir[i][0];
            tt.man.y=ss.man.y dir[i][1];
            if(mat[tt.man.x][tt.man.y]!=0) continue;
            if(!vm[tt.man.x][tt.man.y])
            {
                vm[tt.man.x][tt.man.y]=true;
                qq.push(tt);
            }
        }
    }
    return false;
}
void bfs()//搜箱子的轨迹
{
    queue q;
    node now,next;
    now.box.x=box_x;
    now.box.y=box_y;
    now.man.x=man_x;
    now.man.y=man_y;
    now.step=0;
    q.push(now);
    while(!q.empty())
    {
        now=q.front();
        q.pop();
        if(now.box.x==en_x&&now.box.y==en_y)
        {
            cout<<>T;
    while(T--)
    {
        CL(mat, -1);//地图初始化,边界全为-1
        cin>>n>>m;
        for(int i=1; i<=n; i  )
        {
            for(int j=1; j<=m; j  )
            {
                cin>>mat[i][j];
                if(mat[i][j]==2)//人、箱子和终点的位置存储好,再把地图中相应位置变为可走,即0
                {
                    box_x=i;
                    box_y=j;
                    mat[i][j]=0;
                }
                if(mat[i][j]==3)
                {
                    en_x=i;
                    en_y=j;
                    mat[i][j]=0;
                }
                if(mat[i][j]==4)
                {
                    man_x=i;
                    man_y=j;
                    mat[i][j]=0;
                }
            }
        }
        CL(vis, false);
        bfs();
    }
    return 0;
}
<

 

推箱子(bfs bfs) 推箱子 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6386 Accepted Submission(s): 1825 Pro...

1#include <iostream>
 2#include <string>
 3using namespace std;
 4
 5int main(){
 6    string str;
 7    int ascii[256]={};
 8    cout<<"请输入一个字符串:";
 9    getline(cin,str);
10    for(int i=0; i<str.size(); i )
11        ascii[(int)str[i]] ;
12    for(int i=0; i<256; i )
13        if(ascii[i]!=0)
14            cout<<(char)i<<"出现:"<<ascii[i]<<endl;
15}

  memcpy(buffer, &file_info, file_info_size);
  memcpy(buffer file_info_size, filename, filename_size);

#include <iostream>
#include <cstdio>
#include <cstring>
#include <boost/shared_ptr.hpp>
#include "file_info.h"

  #if USE_ASIO_ALONE
    #include <asio.hpp>
  #else
    #include <boost/asio.hpp>
    namespace asio {
      using namespace boost::asio;
      using boost::system::error_code;
    }
  #endif
 
  struct File_info {
    typedef unsigned long long Size_type;
    Size_type filesize;
    size_t filename_size;
    File_info() : filesize(0), filename_size(0) {}
  };
 
#endif

class Session : public boost::enable_shared_from_this<Session> {
public:
  typedef asio::ip::tcp TCP;
  typedef asio::error_code Error;
  typedef boost::shared_ptr<Session> Pointer;
  typedef File_info::Size_type Size_type;
 
  static void print_asio_error(const Error& error) { std::cerr << error.message() << " ";}
 
  static Pointer create(asio::io_service& io) { return Pointer(new Session(io));}
 
  TCP::socket& socket() { return socket_; }
 
  ~Session()
  {
    if (fp_) fclose(fp_);
    clock_ = clock() - clock_;
    Size_type bytes_writen = total_bytes_writen_;
    if (clock_ == 0) clock_ = 1;
    double speed = bytes_writen * (CLOCKS_PER_SEC / 1024.0 / 1024.0) / clock_ ;
    std::cout << "cost time: " << clock_ / (double) CLOCKS_PER_SEC << " s  "
       << "bytes_writen: " << bytes_writen << " bytes "
       << "speed: " <<  speed << " MB/s ";
  }
 
  void start()
  {
    clock_ = clock();
    std::cout << "client: " << socket_.remote_endpoint().address() << " ";
    socket_.async_receive(
      asio::buffer(reinterpret_cast<char*>(&file_info_), sizeof(file_info_)),
      boost::bind(&Session::handle_header, shared_from_this(), asio::placeholders::error));
  }
 
private:
  Session(asio::io_service& io) : socket_(io), fp_(NULL), total_bytes_writen_(0) { }
 
  void handle_header(const Error& error)
  {
    if (error) return print_asio_error(error);
    size_t filename_size = file_info_.filename_size;
    if (filename_size > k_buffer_size) {
      std::cerr << "Path name is too long! ";
      return;
    }
    //得用async_read, 不能用async_read_some,防止路径名超长时,一次接收不完
    asio::async_read(socket_, asio::buffer(buffer_, file_info_.filename_size),
      boost::bind(&Session::handle_file, shared_from_this(), asio::placeholders::error));
  }
 
  void handle_file(const Error& error)
  {
    if (error) return print_asio_error(error);
    const char *basename = buffer_ file_info_.filename_size - 1;
    while (basename >= buffer_ && (*basename != && *basename != /)) --basename;
    basename;
   
    std::cout << "Open file: " << basename << " (" << buffer_ << ") ";
   
    fp_ = fopen(basename, "wb");
    if (fp_ == NULL) {
      std::cerr << "Failed to open file to write ";
      return;
    }
    receive_file_content();
  }
 
  void receive_file_content()
  {
    socket_.async_receive(asio::buffer(buffer_, k_buffer_size),
      boost::bind(&Session::handle_write, shared_from_this(), asio::placeholders::error,
        asio::placeholders::bytes_transferred));
  }
 
  void handle_write(const Error& error, size_t bytes_transferred)
  {
    if (error) {
      if (error != asio::error::eof) return print_asio_error(error);
      Size_type filesize = file_info_.filesize;
      if (total_bytes_writen_ != filesize)
          std::cerr <<  "Filesize not matched! " << total_bytes_writen_
            << "/" << filesize << " ";
      return;    
    } 
    total_bytes_writen_ = fwrite(buffer_, 1, bytes_transferred, fp_);
    receive_file_content();
  }
 
  clock_t clock_;
  TCP::socket socket_;
  FILE *fp_;
  File_info file_info_;
  Size_type total_bytes_writen_;
  static const unsigned k_buffer_size = 1024 * 32;
  char buffer_[k_buffer_size];
};

void sender(asio::io_service& io, const char* ip_address, unsigned port, const char* filename)
{
  typedef asio::ip::tcp TCP;
 
  FILE *fp = fopen(filename, "rb");
  if (fp == NULL) {
    std::cerr << "cannot open file ";
    return;
  }
 
  //使用智能指针,防止程序出现异常时,fclose未被调用。
  boost::shared_ptr<FILE> file_ptr(fp, fclose);
 
  clock_t cost_time = clock();
 
  const size_t k_buffer_size = 32 * 1024;
  char buffer[k_buffer_size];
  File_info file_info;
 
  int filename_size  = strlen(filename) 1;
  size_t file_info_size = sizeof(file_info);
  size_t total_size = file_info_size filename_size;
  if (total_size > k_buffer_size) {
    std::cerr << "File name is too long";
    return;
  }
  file_info.filename_size = filename_size;
 
  fseek(fp, 0, SEEK_END);
  file_info.filesize = ftell(fp);
  rewind(fp);

private:
  void start_accept()
  {
    Session::Pointer session = Session::create(acceptor_.get_io_service());
    acceptor_.async_accept(session->socket(),
      boost::bind(&Tcp_server::handle_accept, this, session, asio::placeholders::error));
  }
 
  void handle_accept(Session::Pointer session, const Error& error)
  {
    if (error) return print_asio_error(error);
    session->start();
    start_accept();
  }
 
  TCP::acceptor acceptor_;
};

int main()
{
  std::cout << "Auto receive files and save then in current directory. ";
  asio::io_service io;
  Tcp_server receiver(io, 1345); 
  io.run();
}

本文由网上十大正规赌博平台发布于正规赌博平台,转载请注明出处:网上十大正规赌博平台统计字符串中每个字符出

关键词: www.4355mg.c