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[];
int main(){
int N;
while(~scanf("%d",&N)){
int t1=N,t2=N;
long long ans=;
for(int i=;i<N;i++){
scanf("%d",&a[i]);
}
for(int i=;i<N;i++){
if(a[i]){
t1=i;break;
}
}
for(int i=N-;i>=;i--){
if(a[i]){
t2=i;break;
}
}
if(t1==N){
ans=;
printf("%d\n",);continue;
}
int temp=;
for(int i=t1+;i<=t2;i++){
if(!a[i])temp++;
else ans*=temp,temp=;
}
printf("%lld\n",ans);
}
return ;
}
  • [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[];
    bool js(int a,int b,int c,int d,int e,int f){
    //printf("%d %d %d %d %d %d\n",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[];
    while(~scanf("%d%d%d%d%d%d",&dt[].x,&dt[].y,&dt[].x,&dt[].y,&dt[].x,&dt[].y)){
    for(int i=;i<;i++){
    if(dt[i].x<dt[i].y)swap(dt[i].x,dt[i].y);
    }
    sort(dt,dt+);
    int flot=;
    if(js(dt[].x,dt[].y,dt[].x,dt[].y,dt[].x,dt[].y))puts("YES");
    else puts("NO");
    }
    return ;
    }
    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=;
    char s[MAXN];
    int g,r,b;
    int main(){
    int n;
    while(~scanf("%d",&n)){
    scanf("%s",s);
    g=r=b=;
    for(int i=;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==||r+b==||g+b==){
    if(r)puts("R");
    else if(g)puts("G");
    else if(b)puts("B");
    else while();
    continue;
    }
    if(r+b+g==){
    if(!b)puts("B");
    else if(!g)puts("G");
    else if(!r)puts("R");
    else while();
    continue;
    }
    if(r==||b==||g==){
    if(r&&r!=){
    puts("BG");
    }
    else if(g&&g!=)puts("BR");
    else if(b&&b!=)puts("GR");
    else while();
    continue;
    }
    puts("BGR");
    }
    return ;
    }

    直接记录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=;
    int vis[MAXN];
    int main(){
    int N;
    while(~scanf("%d",&N)){
    int x,y;
    mem(vis,);
    while(N--){
    scanf("%d%d",&x,&y);
    vis[x+y+]++;
    vis[x-y+]++;
    }
    LL ans=;
    for(int i=;i<MAXN;i++){
    if(vis[i]){
    ans+=(vis[i]-)*vis[i]/;
    }
    }
    printf("%I64d\n",ans);
    }
    return ;
    }

Chocolate&&木块拼接&&Cards&& Wet Shark and Bishops的更多相关文章

  1. B. Wet Shark and Bishops(思维)

    B. Wet Shark and Bishops time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  2. Codeforces 612B. Wet Shark and Bishops 模拟

    B. Wet Shark and Bishops time limit per test: 2 seconds memory limit per test: 256 megabytes input: ...

  3. Wet Shark and Bishops(思维)

    Today, Wet Shark is given n bishops on a 1000 by 1000 grid. Both rows and columns of the grid are nu ...

  4. Codeforces Round #341 Div.2 B. Wet Shark and Bishops

    题意:处在同一对角线上的主教(是这么翻译没错吧= =)会相互攻击 求互相攻击对数 由于有正负对角线 因此用两个数组分别保存每个主教写的 x-y 和 x+y 然后每个数组中扫描重复数字k ans加上kC ...

  5. 【CodeForces 621B】Wet Shark and Bishops

    题 题意 1000*1000的格子里,给你n≤200 000个点的坐标,求有多少对在一个对角线上. 分析 如果求每个点有几个共对角线的点,会超时. 考虑到对角线总共就主对角线1999条+副对角线199 ...

  6. codeforce 621B Wet Shark and Bishops

    对角线 x1+y1=x2+y2 或者x1-y1=x2-y2 #include<iostream> #include<string> #include<algorithm& ...

  7. CodeForces 621B Wet Shark and Bishops

    记录一下每个对角线上有几个,然后就可以算了 #include<cstdio> #include<cstring> #include<cmath> #include& ...

  8. Codeforces--621B--Wet Shark and Bishops(数学)

     B. Wet Shark and Bishops time limit per test 2 seconds memory limit per test 256 megabytes input ...

  9. 【CodeForces 621A】Wet Shark and Odd and Even

    题 Today, Wet Shark is given n integers. Using any of these integers no more than once, Wet Shark wan ...

随机推荐

  1. 时间TDateTime相当于是Double,即双精度数64位,终于查到它用11位表示e,53位表示精度(整数小数一起),最前面一位表示正负

    http://docwiki.embarcadero.com/RADStudio/Seattle/en/Internal_Data_Formats 关于Double的RTL函数,好像就一个:TrySt ...

  2. CSS 注意事项

    使用css缩写   使用缩写可以帮助减少你CSS文件的大小,更加容易阅读. 明确定义单位,除非值为0 忘记定义尺寸的单位是CSS新手普遍的错误.在HTML中你可以只写width="100&q ...

  3. UIView添加事件

    UIView *loadView = [[UIControl alloc]initWithFrame:CGRectMake(0,0,320,480)]; loadView.backgroundColo ...

  4. hdu 5605 geometry(几何,数学)

    Problem Description There is a point P at coordinate (x,y). A line goes through the point, and inter ...

  5. NYOJ 46-最少乘法次数(数论)

    题目地址:pid=46">NYOJ 46 思路:能够化成二进制来求解.结果是最高位的位数-1+最高位后面1的个数.比如:对于3.它的二进制代码为11,就是用这个最高位(2-1)加上后面 ...

  6. 项目总结——SqlParameter的参数设置长度(size属性)

    看到很多朋友在实例化SqlParameter时,通常都没有指定参数的长度就直接给参数赋值了.就像下面的写法: new SqlParameter("@address", SqlDbT ...

  7. Parallels destop8 无法创建bootcamp虚拟机

    创建基于Boot Camp的虚拟机时弹出“PRL_ERR_DISK_FILE_OPEN_ERROR (0x80021014)”错误提示,由于Mac系统权限错误或Boot Camp内Windows系统权 ...

  8. 如何确定Ubuntu下是否对某个CVE打了补丁

        前些日子在月赛中,拿到了一台Ubuntu14.04的服务器,但并不是root权限,需要提权.我Google了一下,找到了CVE-2015-1318,CVE-2015-1328,CVE-2015 ...

  9. URL传参中文乱码encodeURI、UrlDecode

    传递参数  encodeURI("url.aspx?str"+"汉字")-----------(是 URi  不是URL) 后台接收参数  Server.Url ...

  10. 前端开发必备的Sublime 3插件

    Sublime的大名已经无需我介绍了,首先先介绍如何启用插件安装功能: 打开Sublime 3,然后按 ctrl+` 或者在View → Show Console 在打开的窗口里黏贴这个网站上的代码( ...