• hdu 4941 Magical Forest


    被虐了一下午。。离散化,开一个rr[mnx], cc[mnx],初始化为rr[i] = i, cc[i],然后换的时候就换这两个数组就好了。。

    然后就是不断的lower_bound

     1 #include<iostream>
     2 #include<cstring>
     3 #include<algorithm>
     4 #include<cstdio>
     5 #include<string>
     6 #include<queue>
     7 #include<cmath>
     8 #include<vector>
     9 
    10 using namespace std;
    11 
    12 #define mnx 104000
    13 #define ll long long
    14 #define inf 0x3f3f3f3f
    15 #define lson l, m, rt << 1
    16 #define rson m+1, r, rt << 1 | 1
    17 
    18 int cx[mnx], cy[mnx], rr[mnx], cc[mnx], sx, sy;
    19 struct point{
    20     int x, y, c;
    21     point( int x = 0, int y = 0, int c = 0 ) : x(x), y(y), c(c) {}
    22     bool operator < ( const point & b ) const{
    23         if( x != b.x ) return x < b.x;
    24         if( y != b.y ) return y < b.y;
    25         return c < b.c;
    26     }
    27 }p[mnx];
    28 void init( int n ){
    29     for( int i = 0; i <= n; i++ ){
    30         rr[i] = i, cc[i] = i;
    31     } 
    32 }
    33 int main(){
    34     int cas, cnt = 1;
    35     scanf( "%d", &cas );
    36     while( cas-- ){
    37         int n, m, k, x, y, c;
    38         scanf( "%d %d %d", &n, &m, &k );
    39         for( int i = 0; i < k; i++ ){
    40             scanf( "%d %d %d", &x, &y, &c );
    41             p[i].x = x, p[i].y = y, p[i].c = c;
    42             cx[i] = x, cy[i] = y;
    43         }
    44         sort( p, p + k );
    45         sort( cx, cx + k );
    46         sx = unique( cx, cx + k ) - cx;
    47         sort( cy, cy + k );
    48         sy = unique( cy, cy + k ) - cy;
    49         init( k );
    50         int q;
    51         scanf( "%d", &q );
    52         printf( "Case #%d:
    ", cnt++ );
    53         while( q-- ){
    54             scanf( "%d %d %d", &c, &x, &y );
    55             if( c == 1 ){
    56                 int a = lower_bound( cx, cx + sx, x ) - cx;
    57                 int b = lower_bound( cx, cx + sx, y ) - cx;
    58                 if( cx[a] != x ) continue;
    59                 swap( rr[a], rr[b] );
    60             }
    61             if( c == 2 ){
    62                 int a = lower_bound( cy, cy + sy, x ) - cy;
    63                 int b = lower_bound( cy, cy + sy, y ) - cy;
    64                 if( cy[a] != x ) continue;
    65                 swap( cc[a], cc[b] );
    66             }
    67             if( c == 3 ){
    68                 int a = lower_bound( cx, cx + sx, x ) - cx;
    69                 int b = lower_bound( cy, cy + sy, y ) - cy;
    70                 if( x != cx[a] || y != cy[b] ){
    71                     puts( "0" );
    72                 }
    73                 a = rr[a], b = cc[b];
    74                 a = cx[a], b = cy[b];
    75                 int ans = lower_bound( p, p + k, point( a, b, 0 ) ) - p;
    76                 if( p[ans].x == a && p[ans].y == b ){
    77                     printf( "%d
    ", p[ans].c );
    78                 }
    79                 else puts( "0" );
    80             }
    81         }
    82     }
    83     return 0;
    84 }
    View Code
  • 相关阅读:
    C# get folder's Md5 generated by file's and filename's md5. get dictionary md5
    C# DataTable to List<T> based on reflection.
    C# MySql Transaction Async
    C# read file to bytes,File.ReadAllFiles,File.Open(),BinaryReader
    C# get md5,renamed file and can not change file's md5
    C# copy source directory files with original folder to the destination path
    C# transfer local file to remote server based on File.Copy
    C# copy folder and files from source path to target path
    vue slot
    vue 全局配置键盘事件
  • 原文地址:https://www.cnblogs.com/LJ-blog/p/3908523.html
Copyright © 2020-2023  润新知