zoukankan      html  css  js  c++  java
  • 画画

    题源


    input

    3
    2
    2 2
    2 2
    2
    1 1
    1 1
    3
    2 2 1
    1 2 2

    output

    2
    0
    1

    把转向前后的路径分成两条,看成两个人向右下方走。

    不同的方案只要交换某一段他们的路径就好了

    记交点数为cnt

    答案为 2 ^( cnt - 1)


    暴力 O( n ) 模拟路径记录交点即可

    注意 long long 与重点判断

     1 #include<stdio.h>
     2 #include<algorithm>
     3 #define For(i,a,b) for(register int i=(a);i<=(b);i++)
     4 using namespace std;
     5 const int maxn=1e5+10,mod=1e9+7;
     6 int T,n,ax,ay,bx,by,x[maxn],y[maxn],cnt;
     7 bool flag;
     8 inline int rd(){
     9     int s=0,f=1;char l=getchar();
    10     while(l<'0'||l>'9'){
    11         if(l=='-') f=-1;
    12         l=getchar();
    13     }
    14     while('0'<=l&&l<='9'){
    15         s=10*s+l-'0',l=getchar();
    16     }
    17     return s*f;
    18 }
    19 inline void init(){
    20     flag=0,ax=ay=bx=by=1,cnt=0;
    21 }
    22 inline long long fpow(long long bas,long long pow){
    23     if(!pow) return 1;
    24     long long ans=1;
    25     while(pow){
    26         if(pow&1) ans=ans*bas%mod;
    27         bas=bas*bas%mod,pow>>=1;
    28     }
    29     return ans;
    30 }
    31 signed main(){scanf("%d",&T);while(T--){
    32     init();
    33     n=rd();
    34     For(i,1,n){
    35         x[i]=rd();
    36     }
    37     For(i,1,n){
    38         y[i]=rd();
    39     }
    40     x[1]--,y[1]--;
    41     For(i,1,2*n-2){
    42         (x[ax]>0&&ay<n)?ay++:ax++;
    43         (y[by]>0&&bx<n)?bx++:by++;
    44         y[ay]--,x[bx]--;
    45         if(ax!=bx||ay!=by){
    46             x[ax]--,y[by]--,flag=1;
    47         }else if(flag){
    48             cnt++,flag=0;
    49         }
    50     }
    51     bool cao=0;
    52     For(i,1,n){
    53         if(x[i]!=0||y[i]!=0){
    54             puts("0");cao=1;break;
    55         }
    56     }
    57     if(cao) continue;
    58     printf("%lld
    ",fpow(1LL*2,1LL*cnt));
    59 }}
  • 相关阅读:
    双色球随机一注
    if else的简写
    select
    预解析
    json
    数组方法
    arguments
    国密SM4算法
    AES算法
    Feistel算法结构与DES加密算法
  • 原文地址:https://www.cnblogs.com/monyhzc/p/12184374.html
Copyright © 2011-2022 走看看