AIM Tech Round 5 (rated, Div. 1 + Div. 2)

AIM Tech Round 5 (rated, Div. 1 + Div. 2)

题目链接:https://codeforces.com/contest/1028

 

A题题解

  • 题意:找到B的中心点。 
  • 题解:找到左上角,算下长度,套公式就行。
  • AC代码
/*
author:Agnel_Cynthia
theme
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

# define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
//ll a[200000+ 10] , c[200000 + 10];
//ll vis[200000 + 10];//记录是否走过 
char mp[200][200];
int main(){
    IOS;
    int n , m ;
    cin >> n >> m;
    for(int i = 0 ; i < n;i ++){
        cin >> mp[i];
    }
    int x , y;
    bool flag = 1;
    int cnt = 0; 
    for(int i = 0 ; i < n ; i++){
        for(int j = 0 ; j < m ; j++){
            if(mp[i][j] == 'B' && flag){
                if(mp[i + 1][j] != 'B') 
                {
                    cout << i+1 << " " << j+1 << endl;
                    return 0;
                }
                flag = 0;
                x = i;y = j;    
            }
              if(i == x && mp[i][j] =='B') cnt ++; 
             // cout << x << endl;
        }
    }
    //0 2
//    cout << x << y << endl; 
    if(cnt % 2 == 0)
    cout << x+1 + cnt / 2 - 1 << " " << y+1 + cnt / 2 - 1<< endl;
    else 
    cout << x+1 + cnt / 2 << " " << y+1 + cnt / 2 << endl;
    return 0;  
}
View Code
  • 题解2:问题的大意是找到黑色区域的中心点。这题直接找到黑色区域左上角和右下角的坐标即可。
  • 这种写起来更快
/*
author:Agnel_Cynthia
theme
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 120;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    char c;
    int flag = 0;
    int sx,sy,ex,ey;
    for(int i = 0;i < n;i++){
        for(int j = 0;j < m;j++){
            cin>>c;
            if(c == 'B' && !flag){
                flag = 1;
                sx= ex = i+1;
                sy = ey = j+1;
            }else if(c == 'B' && flag){
                ex = i+1;
                ey = j+1;
            }
        }
    }
    cout<<(sx+ex)/2<<" "<<(sy+ey)/2<<endl; 
    return 0;
}
View Code

 

B题题解

  • 题意:
  • 本题是一个构造题,问题的大意是给出两个数n,m;输出两个数a,b,使得a的各位上数字之和>=n,b的各位数字之和>=n,但是a+b的各位数上数字之和<=m. 本题有个技巧就是a和b分别为一个大整数,但是a+b首位为1,其余为0即可。
  • 题解:
  •  让a+b的和为100000000...0这样的形式就好了
  • 这样s(a+b)=1<=m就肯定成立了(m>=1)
  • 然后至于s(a)>=n和s(b)>=n
  • 随便写个a=1111111...112然后b=8888888...888这样就好

AC代码

/*
author:Agnel_Cynthia
theme
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

# define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
//ll a[200000+ 10] , c[200000 + 10];
//ll vis[200000 + 10];//记录是否走过 
char mp[200][200];
int main(){
    IOS;
    int n , m;
    cin >> n >> m;
    for(int i = 1 ; i < n; i++)
    cout << 1;
    cout << 2;
    cout << endl;
    for(int i = 1; i <= n ; i++)
    cout << 8 ;
    cout << endl;
    return 0;
}
View Code

 

/*
author:Agnel_Cynthia
theme
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

# define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
//ll a[200000+ 10] , c[200000 + 10];
//ll vis[200000 + 10];//记录是否走过 
char mp[200][200];

typedef pair<int, int> P;
const int N = 1005;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i = 0;i < 1000;i++){
        cout<<5;
    }
    cout<<" ";
    for(int i = 0;i < 999;i++){
        cout<<4;
    }
    cout<<5<<endl;
    return 0;
}
View Code

 

n,m=map(int,input().split())
print('5'*n+'\n'+'4'*(n-1)+'5')
Python

 

C题题解

 

  • 题意:给你n个矩阵的左下角坐标和右上角坐标。让你求出n-1个矩形中都包含有的那个点的坐标。
  • 这道题跟之前的一道很像。
  • https://www.cnblogs.com/Agnel-Cynthia/p/10604967.html#_label0_2
  • 上边的是去掉了这个是否满足。而这个是假设就是这个是否满足。
  • 去掉当前的矩形,判断剩下的左下角的所有左端点要小于右上角的所有右端点,同理判断纵坐标即可。

AC代码

/*
author:Agnel_Cynthia
theme
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//fgets getline
# define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
//ll a[200000+ 10] , c[200000 + 10];
//ll vis[200000 + 10];//记录是否走过 
int mp[155555][4];
multiset<int>s[4];
int main(){
    IOS;
    int n;
    cin >> n;
    for(int i = 0 ; i < n ; i++){
        for(int j = 0 ;j < 4 ; j++){
        //    int x;
            cin >> mp[i][j];
            s[j].insert( mp[i][j]);
        }
    }
    for(int i = 0 ; i < n; i ++){
    for(int j = 0 ; j< 4 ; j++){
        s[j].erase(s[j].find(mp[i][j]));
    }
        if(*s[0].rbegin() <= *s[2].begin()&& *s[1].rbegin() <= *s[3].begin()){
            cout << *s[0].rbegin() << " "  << *s[1].rbegin() << endl;
            break;
        }
            for(int j = 0 ; j< 4 ; j++){
        s[j].insert(mp[i][j]);
    }
    }
    return 0;
}
View Code

 

/*
author:Agnel_Cynthia
theme:
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 132680;
const int INF = 1e9+7;
//第二维表示坐标点x1,y1,x2,y2; 
int a[N][5],b[N][5],c[N][5];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin>>n;
    for(int i = 0;i < n;i++){
        for(int j = 0;j < 4;j++){
            cin>>a[i][j];
        }
    }
    b[0][0] = b[0][1] = c[n][0] = c[n][1] = -INF;
    b[0][2] = b[0][3] = c[n][2] = c[n][3] = INF;
    //前缀交 
    for(int i = 0;i < n;i++){
        //左下交点 
        b[i+1][0] = max(b[i][0],a[i][0]);
        b[i+1][1] = max(b[i][1],a[i][1]);
        //右上交点 
        b[i+1][2] = min(b[i][2],a[i][2]);
        b[i+1][3] = min(b[i][3],a[i][3]);
    }
    //后缀交 
    for(int i = n-1;i >=0;i--){
        c[i][0] = max(c[i+1][0],a[i][0]);
        c[i][1] = max(c[i+1][1],a[i][1]);
        c[i][2] = min(c[i+1][2],a[i][2]);
        c[i][3] = min(c[i+1][3],a[i][3]);
    }
    for(int i = 0;i < n;i++){
        int x1,y1,x2,y2;
        x1 = max(b[i][0],c[i+1][0]);
        y1 = max(b[i][1],c[i+1][1]);
        x2 = min(b[i][2],c[i+1][2]);
        y2 = min(b[i][3],c[i+1][3]);
        if(x1 <= x2 && y1<=y2){
            cout<<x1<<" "<<y1<<endl;
            return 0;
        }
    }
    return 0;
}
View Code

 

 

D题题解

  • 模拟。
  • 考虑每次交易必须选择buy的最大值和sell的最小值
  • 维护一个有序集合SS,每次ACCEPT操作都会确定剩下的buy集合和sell集合
  • 也就是说,sell的是有序集合的右侧,buy是有序集合的左侧。
  • 我们一直维护sell的最小值AA和buy的最大值BB。
  • 对于ACCEPT操作,如果新的元素是在AA和BB之间,是合法的
  • 如果既不是AA,也不是BB,那么说明这两个sell和buy可以随意选,将答案乘2
  • 再重新确定AA和BB的值。
  • 对于ADD操作,我们将其插入有序集合,如果该数小于BB,大于AA。
  • 那么这个数目前可以随意的选择(如果重新确定了AA和BB就不行了)
  • 最后就是累计的答案乘上可以随意选择的数+1,就是枚举从哪里分开,左边是buy,右边是sell
  • AC代码
  • /*
    author:Agnel_Cynthia
    theme:模拟
    */
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    //fgets getline
    # define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
    set<int> s;
    ll mod = 1e9 + 7;
    int main(){
        IOS;
     ll n;
    
     ll ans = 1;
     ll sum = 1;
     cin >> n;
     s.insert(1e9);
     s.insert(-1e9);
     while(n--){
         char mp[100];
         ll x;
         cin >> mp;
         cin >> x;
         if(char[1] == 'D'){
             ans++; 
             s.insert(x);
         }
         else{
             if(ml > x || mf < x)
             {
                 cout << "0" << endl;
                 return 0;
             }
             if(ml <= x && mf >= x){
                 sum = sum * 2 % mod;
             }
             s.erase(s.find(x));
             set<int> :: iterator it = S.lower_bound(x);
                mf = *it;
               ml = *(-- it);
    
         }
         cout << sum * ans % mod << endl;
         return 0; 
     }
        return 0;
    }
    View Code

     

posted @ 2019-03-28 01:03  Agnel_Cynthia  阅读(216)  评论(0编辑  收藏  举报
Live2D