10.22 Examination reflection

Contest2208 - 2019 Nian 10 Yue joint training school multi-layer test B 13

T1 friendly D title

http://www.accoders.com/problem.php?cid=2208&pid=0

 

We first saw this question, the product of the largest and certainly the first thought is positive, then, consider what can certainly be positive, it must be an even number multiplied by a negative number and any integer multiplied, we consider how to make the largest answer , negative answers * -1-1 become smaller, so that we can let all the greedy numbers are negative, then look n is not even, if not even, put them inside the smallest negative number (absolute value of the maximum that out into a positive number) concrete proof as follows

 

Maximum value of the current sequence is a, the minimum value is b, the product is now negative ans

1. Remove the answer becomes a time ans / a * (- a-1); Simplification obtained ans-ans / abs (a); b away when Similarly ans-ans / abs (b), since the b is greater than the absolute value of the absolute value of a, so that when the answer to take maximum advantages, permit Bi

 

#include <bits/stdc++.h>
#define ll long long
#define res register 
#define MAXN 100050
#define int ll 
using namespace std;
int n,maxn,a[MAXN];
ll read()
{
    int s=0,w=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=(s<<1)+(s<<3)+ch-48;ch=getchar();}
    return s*w;
}
signed main()
{
    n=read();
    for(res int i=1;i<=n;i++) a[i]=read(),a[i]=a[i]>=0?-a[i]-1:a[i],maxn=max(maxn,abs(a[i]));
    if(n&1) for(res int i=1;i<=n;i++) if(a[i]==-maxn) {a[i]=-a[i]-1;break;}
    for(res int i=1;i<=n;i++) cout<<a[i]<<" ";
    return 0;
}
View Code

 

T2 friendly E title

http://www.accoders.com/problem.php?cid=2208&pid=1

Preprocessing the prefix 0 and 1 and, since each interval remaining after removal of a number gets shorter, so to take large (i.e. the prosequence is 1) then take a small, set interval lr 1 the number of occurrences is the number of c1,0 appear to c2, the answer is (2 ^ c1-1) * 2 ^ c2, pre-out power to 2.

 

#include <bits/stdc++.h>
#define ll long long
#define res register 
#define MAXN 100500
#define int ll 
#define mo 1000000007
using namespace std;
int n,m,l,r,sum[MAXN],kc[MAXN];
char a[MAXN];
bool vis[MAXN];
ll read()
{
    int s=0,w=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=(s<<1)+(s<<3)+ch-48;ch=getchar();}
    return s*w;
}
signed main()
{
    n=read(),m=read();kc[1]=1;
    for(res int i=2;i<=100005;i++) kc[i]=((kc[i-1]<<1))%mo;
    cin>>a+1;
    for(res int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i]-'0';
    while(m--){
        l=read(),r=read();
        int summ=sum[r]-sum[l-1];
        int length=r-l+1;
        int zero=length-summ;
        int one=length-zero;
        int q1=(kc[one+1]-1)*(kc[zero+1])%mo;
        printf("%lld\n",q1);
    }
    return 0;
}
View Code

 

T3. F-friendly title

http://www.accoders.com/problem.php?cid=2208&pid=2

#include <bits/stdc++.h>
#define ll long long
#define res register 
#define MAXN 1000500
#define mo 1000000007
#define int ll 
using namespace std;
int head[MAXN],n,m,x,y,z,ans[3],dp[MAXN][3],siz[MAXN];
bool vis[MAXN];
struct Node{
    int to,nxt,dis,sum[3],exist[3];
}g[MAXN];
inline void dfs(int u){
    vis[u]=1;int to=g[u].to,dis=g[u].dis;
    for(res int i=head[to];i;i=g[i].nxt){
        if(i==(u^1)) continue;
        if(!vis[i]) dfs(i);
        for(res int j=0;j<=2;j++){
            if(!g[i].exist[j]) continue;
            g[u].exist[(dis+j)%3]+=g[i].exist[j];
            g[u].sum[(dis+j)%3]=(g[u].sum[(dis+j)%3]+dis*g[i].exist[j]+g[i].sum[j])%mo;
        }    
    }
}
inline void add(int u,int v,int dis){
    static int top=1;
    g[++top].to=v;g[top].nxt=head[u];g[top].sum[dis%3]=dis;
    g[top].exist[dis%3]=1;g[top].dis=dis;head[u]=top;
}
ll read()
{
    int s=0,w=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=(s<<1)+(s<<3)+ch-48;ch=getchar();}
    return s*w;
}
signed main()
{
    n=read();
    for(res int i=1;i<n;i++){
        x=read()+1,y=read()+1,z=read();
        add(x,y,z),add(y,x,z);
    }
    for(res int i=2;i<n*2;i++) {
        if(!vis[i]) dfs(i);
        for(res int j=0;j<=2;j++) ans[j]=(ans[j]+g[i].sum[j])%mo;
    }
    for(res int i=0;i<=2;i++) cout<<ans[i]<<" ";
    return 0;
}
View Code

For 50% of the data, the length of v is a multiple of 3, which means we only statistical data map 1 on it for each node processes a f array representing the child nodes all point to the current point the sum of the path, for each child node of the current node, a recursive process at total path length and the previous node added in the answer, again traversing the tree while statistics can answer.

For 100% of the data, it maintains three array, between arrays at the same time statistical process to determine what the answer to which an array of go

Guess you like

Origin www.cnblogs.com/Lbmttw/p/11842641.html