AIM Tech Round 5 (rated, Div. 1 + Div. 2) A暴力 B构造思维C排序,暴力 D贪心

版权声明:本文为博主原创文章,未经博主允许也可以转载。 https://blog.csdn.net/FrankAx/article/details/82319610

A

Code:

#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int AX = 115+6;
char s[AX][AX];
int main(){
    int n , m; 
    scanf("%d%d",&n,&m);
    for( int i = 0 ; i < n ; i++ ){
        scanf("%s",s[i]);
    }
    int sx , sy , ex = -1 , ey = -1 ;
    for( int i = 0 ; i < n ; i++ ){
        sx = -1 ;
        for( int j = 0 ; j < m ; j++ ){
            if( s[i][j] == 'B' ){
                for( int k = i ; k < n ; k ++ ){
                    if( s[k][j] == 'B' ) ex = max( ex , k );
                    else break;
                }
                for( int k = j ; k < m ; k++ ){
                    if( s[i][k] == 'B' ) ey = max( ey , k );
                    else break;
                }   
                sx = i ;
                sy = j ;
                break;
            }
            if( sx == i ) break;
        }
        if( ~sx ) break;
    }
    printf("%d %d\n",(ex+sx)/2+1,(ey+sy)/2+1);
    return 0 ; 
}

B

#include <bits/stdc++.h>
#define LL long long
using namespace std;

int main(){
    int n ,m ; 
    scanf("%d%d",&n,&m);
    for( int i = 1 ; i <= 2000 ; i ++ ){
        cout << 5 ;
    }cout << 4 << endl;
    for( int i = 1 ; i <= 2000 ; i++ ){
        cout << 4 ;
    }cout << 6 << endl;
    return 0 ; 
}

C
思路:最后围成的矩形是max(x1,y1),min(x2,y2),暴力枚举不参与的那个矩形。
Code:

#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int AX = 132674 + 666 ;
int b[AX];
int c[AX];
int d[AX];
int e[AX];
struct Node{
    int x1 , x2 ;
    int y1 , y2 ;
}a[AX];
int main(){
    int n ; 
    scanf("%d",&n);
    for( int i = 0 ; i < n ; i++ ){
        scanf("%d%d%d%d",&b[i],&c[i],&d[i],&e[i]);
        a[i].x1 = b[i];
        a[i].y1 = c[i];
        a[i].x2 = d[i];
        a[i].y2 = e[i];
    }
    sort( b , b + n ) ;
    sort( c , c + n ) ;
    sort( d , d + n ) ;
    sort( e , e + n ) ;
    for( int i = 0 ; i < n ; i++ ){
        int lim_x1 = b[n-1];
        int lim_y1 = c[n-1];
        int lim_x2 = d[0];
        int lim_y2 = e[0];
        if( a[i].x1 == lim_x1 ) lim_x1 = b[n-2];
        if( a[i].y1 == lim_y1 ) lim_y1 = c[n-2];
        if( a[i].x2 == lim_x2 ) lim_x2 = d[1];
        if( a[i].y2 == lim_y2 ) lim_y2 = e[1];
        if( lim_x1 <= lim_x2 && lim_y1 <= lim_y2 ){
            return 0*printf("%d %d\n",lim_x1,lim_y1);
        } 
    }
}

D
题意:给出BUY (从大到小)和 SELL (从小到大),且BUY里面的数都小于SELL里的, 给出两种操作add:添加一个数进去,不知道添到哪里,
Accept:将一个数x删除掉,并且这个数必须是再SELL顶端或者BUY顶端。如果矛盾输出0,否则输出可能的组合情况。
思路:记录Buy顶端 l 和SELL顶端 r ,add操作就将x加入set里,如果x介于l,r之间,那么x加到哪里都可以。
accept操作时,如果x不介于l,r之间输出0,因为每次只能取出顶端的值,
如果不等于l也不等于r,说明又有2种方案。删除x并更新l,r

Code:

#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int MOD = 1e9 + 7 ;
int main(){
    ios_base::sync_with_stdio(false); cin.tie(0) ; cout.tie(0);
    int n ; 
    int x ; 
    char op[10];    
    cin >> n ; 
    set<int> s ;
    int res = 1 ;
    int ans = 1 ;
    int l = -1e9 , r = 1e9 ;  
    s.insert(-1e9);
    s.insert(1e9);
    while( n -- ){
        cin >> op >> x ; 
        if( op[1] == 'D' ){
            s.insert(x);
            if( l < x && x < r ) ans ++ ; 
        }else{ 
            if( x < l || x > r ){
                cout << 0 << endl;
                return 0 ; 
            }
            if( l != x && r != x ){
                res = res * 2 % MOD ;
            }
            ans = 1 ; 
            s.erase(x);
            set<int>::iterator it = s.upper_bound(x) ;  
            r = (*it);
            l = *(--it);
        }
    }
    cout << ( 1LL * res * ans ) % MOD << endl;
    return 0 ; 
}

猜你喜欢

转载自blog.csdn.net/FrankAx/article/details/82319610