zoukankan      html  css  js  c++  java
  • Chocolate&&木块拼接&&Cards&& Wet Shark and Bishops

    B. Chocolate
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Bob loves everything sweet. His favorite chocolate bar consists of pieces, each piece may contain a nut. Bob wants to break the bar of chocolate into multiple pieces so that each part would contain exactly one nut and any break line goes between two adjacent pieces.

    You are asked to calculate the number of ways he can do it. Two ways to break chocolate are considered distinct if one of them contains a break between some two adjacent pieces and the other one doesn't.

    Please note, that if Bob doesn't make any breaks, all the bar will form one piece and it still has to have exactly one nut.

    Input

    The first line of the input contains integer n (1 ≤ n ≤ 100) — the number of pieces in the chocolate bar.

    The second line contains n integers ai (0 ≤ ai ≤ 1), where 0 represents a piece without the nut and 1 stands for a piece with the nut.

    Output

    Print the number of ways to break the chocolate into multiple parts so that each part would contain exactly one nut.

    Examples
    input
    3 0 1 0
    output
    1
    input
    5 1 0 1 0 1
    output
    4
    题解:插孔
    代码:
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    const int INF=0x3f3f3f3f;
    #define mem(x,y) memset(x,y,sizeof(x))
    #define SI(x) scanf("%d",&x)
    #define PI(x) printf("%d",x)
    #define P_ printf(" ")
    int a[110];
    int main(){
        int N;
        while(~scanf("%d",&N)){
            int t1=N,t2=N;
            long long ans=1;
            for(int i=0;i<N;i++){
                scanf("%d",&a[i]);
            }
            for(int i=0;i<N;i++){
                if(a[i]){
                    t1=i;break;
                }
            }
            for(int i=N-1;i>=0;i--){
                if(a[i]){
                    t2=i;break;
                }
            }
            if(t1==N){
                ans=1;
                printf("%d
    ",0);continue;
            }
            int temp=1;
            for(int i=t1+1;i<=t2;i++){
                if(!a[i])temp++;
                else ans*=temp,temp=1;
            }
            printf("%lld
    ",ans);
        }
        return 0;
    }
    • [1655] 木块拼接

    • 时间限制: 1000 ms 内存限制: 65535 K
    • 问题描述
    • 好奇的skyv95想要做一个正方形的木块,现在有三种颜色的矩形木块,颜色分别为"A","B","C"。他现在很想把三个木块拼接成一个大正方形,现在求助于你们,问分别给你们三种颜色矩形的两个边长,判断是否能组成一个正方形。
    • 输入
    • 依次输入颜色为A的矩形的两边长度,颜色为B的矩形的两边长度,颜色为C的矩形的两边长度。
    • 输出
    • 可以输出"YES",否则输出"NO"。
    • 样例输入
    • 4 4 2 6 4 2
    • 样例输出
    • YES
    • 提示
    • 例子的图像可以是这样
      6
      BBBBBB
      BBBBBB
      AAAACC
      AAAACC
      AAAACC
      AAAACC
    • 题解:
    • #include<iostream>
      #include<cstdio>
      #include<cstring>
      #include<cmath>
      #include<algorithm>
      using namespace std;
      const int INF=0x3f3f3f3f;
      #define mem(x,y) memset(x,y,sizeof(x))
      #define SI(x) scanf("%d",&x)
      #define PI(x) printf("%d",x)
      #define P_ printf(" ")
      struct Node{
          int x,y;
          bool operator < (const Node b) const{
              if(x!=b.x)return b.x<x;
              else return b.y<y;
          }
      };
      Node dt[3];
      bool js(int a,int b,int c,int d,int e,int f){
          //printf("%d %d %d %d %d %d
      ",a,b,c,d,e,f);
          if(a==c+f&&b+d==b+e&&a==b+d)return true;
          if(a==d+e&&c==f&&a==b+d)return true;
          if(a==d+f&&c==e&&a==b+c)return true;
          if(a==c+e&&d==f&&a==b+d)return true;
          if(a==b+d+f&&a==c&&a==e)return true;
          return false;
      }
      int main(){
          int a[10];
          while(~scanf("%d%d%d%d%d%d",&dt[0].x,&dt[0].y,&dt[1].x,&dt[1].y,&dt[2].x,&dt[2].y)){
              for(int i=0;i<3;i++){
                  if(dt[i].x<dt[i].y)swap(dt[i].x,dt[i].y);
              }
              sort(dt,dt+3);
              int flot=0;
              if(js(dt[0].x,dt[0].y,dt[1].x,dt[1].y,dt[2].x,dt[2].y))puts("YES");
              else puts("NO");
          }
          return 0;
      }
      B. Cards
      time limit per test
      2 seconds
      memory limit per test
      256 megabytes
      input
      standard input
      output
      standard output

      Catherine has a deck of n cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions:

      • take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color;
      • take any two (not necessarily adjacent) cards with the same color and exchange them for a new card with that color.

      She repeats this process until there is only one card left. What are the possible colors for the final card?

      Input

      The first line of the input contains a single integer n (1 ≤ n ≤ 200) — the total number of cards.

      The next line contains a string s of length n — the colors of the cards. s contains only the characters 'B', 'G', and 'R', representing blue, green, and red, respectively.

      Output

      Print a single string of up to three characters — the possible colors of the final card (using the same symbols as the input) in alphabetical order.

      Examples
      input
      2 RB
      output
      G
      input
      3 GRG
      output
      BR
      input
      5 BBBBB
      output
      B
      题解:规律
      代码:
      #include<iostream>
      #include<cstdio>
      #include<cstring>
      #include<cmath>
      #include<algorithm>
      using namespace std;
      const int INF=0x3f3f3f3f;
      #define mem(x,y) memset(x,y,sizeof(x))
      #define SI(x) scanf("%d",&x)
      #define PI(x) printf("%d",x)
      #define P_ printf(" ")
      const int MAXN=210;
      char s[MAXN];
      int g,r,b;
      int main(){
          int n;
          while(~scanf("%d",&n)){
              scanf("%s",s);
              g=r=b=0;
              for(int i=0;s[i];i++){
                  if(s[i]=='R')r++;
                  if(s[i]=='G')g++;
                  if(s[i]=='B')b++;
              }
              if(r&&g&&b){
                  puts("BGR");continue;
              }
              if(r+g==0||r+b==0||g+b==0){
                  if(r)puts("R");
                  else if(g)puts("G");
                  else if(b)puts("B");
                  else while(1);
                  continue;
              }
              if(r+b+g==2){
                  if(!b)puts("B");
                  else if(!g)puts("G");
                  else if(!r)puts("R");
                  else while(1);
                  continue;
              }
              if(r==1||b==1||g==1){
                  if(r&&r!=1){
                      puts("BG");
                  }
                  else if(g&&g!=1)puts("BR");
                  else if(b&&b!=1)puts("GR");
                  else while(1);
                  continue;
              }
              puts("BGR");
          }
          return 0;
      }

       直接记录x+y,x-y的数量,n*(n-1)/2和就是答案了;以前做过。。。

      代码:

      #include<iostream>
      #include<cstdio>
      #include<cstring>
      #include<cmath>
      #include<algorithm>
      using namespace std;
      const int INF=0x3f3f3f3f;
      #define mem(x,y) memset(x,y,sizeof(x))
      #define SI(x) scanf("%d",&x)
      #define PI(x) printf("%d",x)
      #define P_ printf(" ")
      typedef __int64 LL;
      const int MAXN=4200;
      int vis[MAXN];
      int main(){
          int N;
          while(~scanf("%d",&N)){
              int x,y;
              mem(vis,0);
              while(N--){
                  scanf("%d%d",&x,&y);
                  vis[x+y+2100]++;
                  vis[x-y+1010]++;
              }
              LL ans=0;
              for(int i=0;i<MAXN;i++){
                  if(vis[i]){
                      ans+=(vis[i]-1)*vis[i]/2;
                  }
              }
              printf("%I64d
      ",ans);
          }
          return 0;
      }
  • 相关阅读:
    project 2013 激活 key 7YHNW-RVCQY-VBDB2-QX69Q-B96WK viso 66DNF-28W69-W4PPV-W3VYT-TJDBQ
    电脑快捷键
    Error (167005): Can't assign I/O pad "GX_TX" to PIN_AG27 because this causes failure in the placement of the other atoms in its associated channel
    学习资源
    数值孔径
    网络通信芯片
    DMD数字微镜
    运放输入阻抗
    DS18B20测温
    LED灯开关电路
  • 原文地址:https://www.cnblogs.com/handsomecui/p/5247701.html
Copyright © 2011-2022 走看看