Preliminaries for Benelux Algorithm Programming Contest 2019(2020.03.14)

题目地址:https://www.jisuanke.com/contest/7190?view=challenges

A. Architecture

题意:给定每行最大数和每列最大数,问矩阵是否存在。

思路:求出行列的最大值,如果相同则可能,否则不可能;

AC代码:

#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<list>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
const int maxn = 1e2+10;
int main()
{
    int a[maxn];
    int b[maxn];
    int n,m;
    cin>>n>>m; 
    
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<m;i++)
    {
        cin>>b[i];
    }
    sort(a,a+n);
    sort(b,b+m);
    if(a[n-1]==b[m-1]) cout<<"possible"<<endl;
    else cout<<"impossible"<<endl;
    return 0;
}
View Code

 

B. Bracket Sequence

题意:给定一个字符串,有括号和数字,最外层数字之间用+,向里用*,依次交替,求出最后的结果

注意要手动写栈,否则空间不够

思路:将数字依次存储进栈,遇到 “)” 弹出相应数字相加再压进栈,直到最后。

   用vector 将数字分层 存储,再按照规律+*规律求和

   注意! 算完一层后记得将该层清除,算乘积时  初始值要为1;

AC代码:

#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<list>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
const int maxn = 1e2+10;
const ll mod = 1e9+7;

vector<ll> brr[300010],crr;
int main()
{
    int n;
    cin>>n;
    int p=0;
    while(n--)
    {
        string s;
        cin>>s;
        if(s[0]=='(') p++;
        else if(s[0]==')')
        {
            
            ll b = 0;
            if(p%2==0)
            {
                for(int i=0;i<brr[p].size();i++)
                {
                    b+=brr[p][i];
                    b%=mod;
                }
                
            }
            else
            {
                b=1;
                for(int i=0;i<brr[p].size();i++)
                {
                    b*=brr[p][i];
                    b%=mod;
                }
            }
            brr[p].clear();
            p--;
            brr[p].push_back(b);
            
        }
        else
        {
            ll t = 0;
            for(int i=0;i<s.length();i++)
            {
                t*=10;
                t+=s[i]-'0';
            }
            t%=mod;
            brr[p].push_back(t);
        }
    }
    ll ans = 0;
    for(int i=0;i<brr[0].size();i++)
    {
        ans+=brr[0][i];
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
    
        
    
}
View Code

 

F. Floor Plan

题意:给定n 求m,k 满足 n = m^2-k^2

思路:n = m^2-k^2   = (m-k)(m+k)   设i = m-k ,n = i*(i+2k);遍历找i,求k 看是否存在

AC代码:

#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<list>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
const int maxn = 1e2+10;
int main()
{
    ll n;
    cin>>n;
    ll i;
    for(i=1;i*i<=n;i++)
    {
        if(n%i==0)
        {
            ll j = n/i;
            if((j-i)%2==0)
            {
                ll k = (j-i)/2;
                cout<<i+k<<" "<<k<<endl;
                return 0;
            }
        }
    }
     cout<<"impossible"<<endl;
    return 0;
}
View Code

 

 G. Greetings!

题意:复制字符中的‘e’

AC代码:

#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<list>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
const int maxn = 1e2+10;
int main()
{
    string s;
    cin>>s;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]!='e') cout<<s[i];
        else cout<<"ee";
    }
    cout<<endl;
    return 0;
}
View Code

 

I. Inquiry I

题意:给定一个数组 且满足式子,求最大值。

 

 

 思路:求后缀和,前缀平方和,遍历找最大值

AC代码:

#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<list>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
const int maxn = 1e2+10;
int main()
{
    int n, a[1000005];
    ll l[1000005], r[1000005];
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n; i++) l[i] = l[i - 1] + a[i] * a[i];
    for (int i = n; i >= 1; i--) r[i] = r[i + 1] + a[i];
    ll ans = 0;
    for (int i = 1; i < n; i++) ans = max(ans, l[i] * r[i + 1]);
    printf("%lld\n", ans);
 
    return 0;
}
View Code

 

 

posted @ 2020-03-18 16:01  精神小伙儿  阅读(283)  评论(0编辑  收藏  举报