Codeforces Round #547 (Div. 3)

https://codeforces.com/contest/1141/problem/B

#include 
using namespace std;
const int maxn = 2e5 + 5;
int a[maxn],b[maxn];
int main()
{
    int n;
    while ( cin >> n )
    {
        for(int i=0;i>a[i];


        int ans=0;
        int maxs=0;
        for(int i=0;i<2*n;i++)
        {
            if(a[i%n]==1)
            {
                ans++;
            }
            else
            {

                ans=0;
            }
            maxs=max(ans,maxs);
        }
        cout<

https://codeforces.com/contest/1141/problem/C

#include 
using namespace std;
const int maxn = 2e5 + 5;
int a[maxn];
int main()
{
    int n;
    while ( cin >> n )
    {
        int x, ans = 0,y=0,z=0;
        for ( int i = 2; i <= n; i++ )
        {
            cin >> a[i];
            ans+=a[i];
            if(ans<1)
            {
                z+=(1-ans);
                ans=1;
            }
        }
        cout<

https://codeforces.com/contest/1141/problem/D

#include 
using namespace std;
int n;
map >a,b;
stack< pair > tag;
int main() {

    while ( cin >> n ) {
        string s1, s2;
        cin >> s1 >> s2;
        for ( int i = 0; s1[i]; i++ ) {
            a[s1[i]].push ( i + 1 );
        }
        for ( int i = 0; s2[i]; i++ )
        {
            if(s2[i]=='?')
            {
              b['?'].push(i+1);
              continue ;
            }
            else if ( a[s2[i]].size() ) {
                tag.push ( make_pair ( a[s2[i]].top(), i + 1  ) );
                a[s2[i]].pop();
            } else if ( a['?'].size() ) {
                tag.push ( make_pair ( a['?'].top(), i + 1  ) );
                a['?'].pop();
            }
        }
        for(int i=0;s1[i];i++)
        {
          if(a[s1[i]].size() &&b['?'].size())
          {
            tag.push ( make_pair ( a[s1[i]].top(), b['?'].top()  ) );
            a[s1[i]].pop();
            b['?'].pop();
          }
        }
        cout << tag.size() << endl;
        while ( !tag.empty() ) {
            cout << tag.top().first << ' ' << tag.top().second << endl;
            tag.pop();
        }
    }
}

https://codeforces.com/contest/1141/problem/E

数学公式推理:
if(tag[n]==0) tag[n]=-1;
timee=(max((long long )0,h-tag[i])/tag[n]+( (h-tag[i])%tag[n]>0 &&tag[n]>0) )*n+i;
遍历一遍寻找一个最小时间


#include 
using namespace std;
const long long maxn = 2e5+5;
long long a[maxn], tag[maxn];
int main()
{
    long long h,n;
    while(cin>>h>>n)
    {
        long long q=0,times=1e18;
        for(long long i=1;i<=n;i++)
        {
            cin>>a[i];
            a[i]=-a[i];
            tag[i]+=tag[i-1]+a[i];
        }
        if(tag[n]==0) tag[n]=-1;
        for(int i=1;i<=n;i++)
        {
           long long  timee=(max((long long )0,h-tag[i])/tag[n]+( (h-tag[i])%tag[n]>0 &&tag[n]>0) )*n+i;
           if(timee>0) times=min(times,timee);
        }
        if(times<1e18)cout<

https://codeforces.com/contest/1141/problem/F2

题解 贪心看每个和的右边,取一个最小的,然后和下次的这个和对比,如果下次的这个和的左边存在大于上次右边的,
则这个和的记录++

#include 
using namespace std;
std::map tag_r;
std::map >  > dp;
int sum[10005];
int main() {
    int n;
    while(cin >> n) {
        int x, mx = 0, vs;
        for(int i = 1; i <= n; i++) {
            cin >> x;
            sum[i] = sum[i - 1] + x;
            for(int j = 1; j <= i; j++) {
                int ans = sum[i] - sum[j - 1];
                if(j > tag_r[ans]) {
                    tag_r[ans] = i;
                    dp[ans].push_back( make_pair(j, i) );
                    if(dp[ans].size() > mx) {
                        mx = dp[ans].size();
                        vs = ans;
                    }
                }
            }
        }
        cout << mx << endl;
        for(int i = 0; i < mx; i++) {
            cout << dp[vs][i].first << ' ' << dp[vs][i].second << endl;
        }
    }
}

https://codeforces.com/contest/1141/problem/G

题解:
轻松的找到。最少使用多少种颜色。
就是 找到第m+1 小的点。
然后 对每个边循环染色。
这样 小于等于m+1 的边的点,绝对不会重复

#include 
using namespace std;
const int maxn = 2e5+5;
int n,m;
#define mp make_pair
vector< pair  > grp[maxn];
struct node
{
    int x;
    int nums=0;
} d[maxn] ;
bool cmp(node &a,node &b)
{
    return a.nums>b.nums;
}
int tag[maxn] ;
int maxr;
void dfs(int node ,int dad,int r)
{
    int le=0;
    for(int i=0;i>n>>m)
    {
        int x,y;
        for(int i=1;i>x>>y;
            d[x].nums++;
            d[y].nums++;
            grp[x].push_back( mp (y,i ));
            grp[y].push_back( mp (x,i) );
        }
        sort(d+1,d+1+n,cmp) ;
        maxr=d[m+1].nums;
        dfs(1,0,0);
        cout<

你可能感兴趣的:(Codeforces Round #547 (Div. 3))