Chocolate&&木块拼接&&Cards&& Wet Shark and Bishops
1 second
256 megabytes
standard input
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.
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.
Print the number of ways to break the chocolate into multiple parts so that each part would contain exactly one nut.
3 0 1 0
1
5 1 0 1 0 1
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. Cardstime limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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?
InputThe 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.
OutputPrint 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.
Examplesinput2 RB
outputG
input3 GRG
outputBR
input5 BBBBB
outputB
题解:规律
代码:#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的更多相关文章
- B. Wet Shark and Bishops(思维)
B. Wet Shark and Bishops time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Codeforces 612B. Wet Shark and Bishops 模拟
B. Wet Shark and Bishops time limit per test: 2 seconds memory limit per test: 256 megabytes input: ...
- 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 ...
- Codeforces Round #341 Div.2 B. Wet Shark and Bishops
题意:处在同一对角线上的主教(是这么翻译没错吧= =)会相互攻击 求互相攻击对数 由于有正负对角线 因此用两个数组分别保存每个主教写的 x-y 和 x+y 然后每个数组中扫描重复数字k ans加上kC ...
- 【CodeForces 621B】Wet Shark and Bishops
题 题意 1000*1000的格子里,给你n≤200 000个点的坐标,求有多少对在一个对角线上. 分析 如果求每个点有几个共对角线的点,会超时. 考虑到对角线总共就主对角线1999条+副对角线199 ...
- codeforce 621B Wet Shark and Bishops
对角线 x1+y1=x2+y2 或者x1-y1=x2-y2 #include<iostream> #include<string> #include<algorithm& ...
- CodeForces 621B Wet Shark and Bishops
记录一下每个对角线上有几个,然后就可以算了 #include<cstdio> #include<cstring> #include<cmath> #include& ...
- Codeforces--621B--Wet Shark and Bishops(数学)
B. Wet Shark and Bishops time limit per test 2 seconds memory limit per test 256 megabytes input ...
- 【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 ...
随机推荐
- C#尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
安装VS2013后,win7 + .net 4 + c#程序无法连接到SQL Server2000的实例 SQLServer2012在登录远程服务器实例时报错:尝试读取或写入受保护的内存. “尝试读取 ...
- 数据挖掘之分类算法---knn算法(有matlab例子)
knn算法(k-Nearest Neighbor algorithm).是一种经典的分类算法.注意,不是聚类算法.所以这种分类算法 必然包括了训练过程. 然而和一般性的分类算法不同,knn算法是一种懒 ...
- 杭电oj 3361
Tips:字符在计算机中都是以ASCII码形式保存,直接以char形式输出ASCII码即可. #include<stdio.h> int main() { int T; scanf(&qu ...
- LSH、ITQ、SKLSH图像检索实验实现(包含源码下载地址)
原文来自我的独立blog:http://www.yuanyong.org/blog/cv/lsh-itq-sklsh-compliment 这两天寻找idea,想来思去也没想到好点的方法,于是把前段时 ...
- 剪花布条(kmp)
欢迎参加——每周六晚的BestCoder(有米!) 剪花布条 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- 2014/4月金山WPS笔试
今晚去參加了金山的笔试. 一開始还以为选C++的人不会非常多. 我去啊,一去到,好多人,一整个大教室都快满人了. 还好我算是去的比較早的了. 还拿到了一个位置. 金山还是挺不错的,对于我这类还没有实力 ...
- UVALive 6665 Dragonas Cruller
题目链接:https://icpcarchive.ecs.baylor.edu/external/66/6665.pdf 题目大意: 有一个3 * 3 的格子: 每个格子上面的数字能够朝上下左右四个方 ...
- Hibernate征途(二)之基础与核心
根据我司优良传统,必然要由上向下.逐级深入,所以在钻到Hibernate细节之前,先从宏观上行欣赏一下Hibernate.为什么说是欣赏?大家可以自行查阅一下Hibernate知识外的信息,创始人和H ...
- maven profile参数动态打入
第一: 1,如果是resources目录下文件profile参数中动态打入,在pom.xml中的build标签中加入如下配置: <resources> <resource> & ...
- 移动端的几款jq插件
移动手机用户的数量每日都在增长,人们现在都习惯于使用手机来浏览网页,看小说,读新闻.如何确保你的网站对移动用户友好,是目前你需要解决的最重要的问 题之一.这里给大家介绍10款在移动手机上使用的jQue ...