A : R!!G!!B!!
问题描述
msy 的显示器被 yhf 借走了,于是 msy 需要一个新的显示器。他买来了许多 LED 小灯,每个小灯只能发出红、绿、蓝三种颜色光的其中一种。msy 需要三个不同颜色的小灯来拼成一个像素(像素之间并不能共用小灯),但是他并不知道每种颜色的小灯具体有多少个,只知道每个小灯的颜色。msy 想知道他用手头上的小灯可以拼出多少个像素,但是一个个数太麻烦了,他希望你来用程序解决这个问题。
输入格式
第一行输入一个数
n
n,表示所有小灯的数量。
第二行输入一个长度为
n
n 的字符串,表示每个小灯的颜色。颜色使用R、G、B三种字母表示。
输出格式
输出一个整数,表示 msy 可以拼出的像素的个数。
样例输入
8
RGBRGBRG
样例输出
2
评测用例规模与约定
1
≤
n
≤
1
0
5
1≤n≤10
5
#include<cmath>
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
char s[100001];
int sumr=0;
int sumg=0;
int sumb=0;
for(int i=0;i<n;i++){
cin>>s[i];
if(s[i]=='R'){
sumr=sumr+1;
}
if(s[i]=='G'){
sumg=sumg+1;
}
if(s[i]=='B'){
sumb=sumb+1;
}
}
cout<<min(sumr,min(sumg,sumb))<<endl;
return 0;
}
B : 密码强弱度
题目描述
在很多的交互式网站中,都需要通过使用用户名与密码进行登录,为了正确的评估一个密码的强弱,机智的 lzh 想出了一个评价方案。
这里研究的密码只有数字与大小写字母组成。具体的评价方案如下:
如果一个密码的长度小于
6
6,则这个密码的强度为
0
0。
对于长度大于等于
6
6 的密码,根据字符的种类(字符分为三类:数字,小写字母,大写字母),将连续的同种类的密码划分为一段,其段数即为密码的强弱程度。例如,密码 asd123As2d 可以分为 asd、123、A、s、2、d 6段,所以这个密码的强度为6。
输入描述
输入一行一个字符串
s
s,
1
≤
∣
s
∣
≤
1
0
6
1≤∣s∣≤10
6
,表示密码。
输出描述
输出一行一个整数,表示密码的强弱程度。
Case 1
Input
1VIpuVNOv8
Output
6
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str;
cin>>str;
int length=str.length();
int count=1;
if(length<6)
cout<<0<<endl;
else
{
for (int i=0;i<length-1;i++)
{
if( ('a'<=str[i]&&str[i]<='z') && (str[i+1]>'z'||str[i+1]<'a') )
count++;
if( ('A'<=str[i]&&str[i]<='Z') && (str[i+1]>'Z'||str[i+1]<'A'))
count++;
if( ('0'<=str[i]&&str[i]<='9') && (str[i+1]<'0'||str[i+1]>'9'))
count++;
}
cout<<count<<endl;
}
}
C : 拉面馆
题目描述
TT 的家门外有一家味道很好的拉面馆,每天都有很多人在拉面馆内喝拉面。拉面有
k
k 种配料,分别记为
1
,
2
,
.
.
.
,
k
1,2,…,k,每种配料都有着独特的风味。为了应对短时间内大量人群用餐需求,面馆的老板会在有客人到来之前,提前做好配有各种配料的拉面
n
n 碗(之后不再制作新的拉面),每碗面都会有
k
k 种配料中的一种或多种。每一碗面都有一个制作完成的时间点
t
i
t
i
,每碗面的制作完成的时间点都是唯一的。
有
m
m 位客人陆续到店吃面,第
i
i 位客人在
s
i
s
i
时间到店,且有自己喜爱的一些配料
c
1
,
.
.
.
,
c
C
i
c
1
,…,c
C
i
,也就是说,这位客人会买一份至少含有配料
c
1
,
.
.
.
,
c
C
i
c
1
,…,c
C
i
的面(可以含有其他种类的配料,但不能缺少喜爱的配料)。当满足条件的面有很多碗时,这位客人会挑选完成时间距离自己的到店时间最近的面,若这碗面是第
j
j 碗,则顾客会产生
s
i
−
t
j
s
i
−t
j
的不满意度;当含有
c
i
c
i
的面不存在时,顾客会直接愤怒离开。
今天热心的 TT 要帮老板记录客人的情况,请你帮他写一个程序完成上述要求。
输入描述
输入的第一行三个数
n
,
m
,
k
n,m,k,
(
1
≤
n
,
m
≤
2
×
1
0
5
,
1
≤
k
≤
3
)
(1≤n,m≤2×10
5
,1≤k≤3),分别表示制作的面的数量,顾客的数量与配料的种类数。
接下来一行
n
n 个数,表示
t
i
t
i
,保证输入的
t
i
t
i
是递增的。
接下来
n
n 行,表示每碗面含有的材料。第一个数字为
K
i
(
K
i
≥
1
)
K
i
(K
i
≥1) 表示第
i
i 碗面中含有的配料的种类数,接下来
K
i
K
i
个数,表示这碗面含有的配料编号,保证编号不会重复。
接下来一行
m
m 个数,表示
s
i
s
i
,保证
s
i
s
i
是递增的,且
∀
i
,
j
∀i,j,
1
≤
t
i
<
s
j
≤
1
0
9
1≤t
i
<s
j
≤10
9
。
接下来
m
m 行,表示每位顾客的喜好。第一个数字为
C
i
(
C
i
≥
1
)
C
i
(C
i
≥1) 表示第
i
i 个顾客喜爱配料的种类数,接下来
C
i
C
i
个数,表示顾客喜爱的配料编号,保证编号不会重复。
输出描述
输出包含
m
m 行,每行表示一个顾客的状态,若顾客吃到了面,则输出顾客的不满意度;若顾客愤怒离开,则输出Angry。
子任务
存在
20
%
20% 的数据,满足
k
1
k=1;
存在
30
%
30% 的数据,满足
n
,
m
≤
5000
n,m≤5000;
存在
30
%
30% 的数据,满足
k
2
k=2;
提示
可以尝试使用二进制位表示每种配料的有无。
#include <iostream>
#include <vector>
#include<algorithm>
#include <string>
#include <list>
#include <queue>
using namespace std;
struct noodle{
int t=0;
int content[4]= {0,0,0,0};
friend bool operator < (noodle a, noodle b){
return a.t>b.t;
}
};
struct guest{
int s;
vector<int>like;
friend bool operator <(guest a, guest b){
return a.s<b.s;
}
};
list<noodle> noodles;
list<guest> guests;
int main(){
int n, m, k;
scanf("%d %d %d",&n,&m,&k);
//cin>>n>>m>>k;
vector<int> times;
for(int i=0; i<n; i++){
int t;
scanf("%d", &t);
//cin>>t;
times.push_back(t);
}
//read n kind of noodle made in different time
for(int i=0; i<n; i++){
int typenum;
scanf("%d", &typenum);
//cin>>typenum;
noodle temp;
temp.t = times[i];
//read n kind of contents
while(typenum--){
int index;
scanf("%d", &index);
//cin>>index;
temp.content[index]=1;
}
noodles.push_front(temp);
}
vector<int> s;
for(int i=0; i<m; i++){
int temp;
cin>>temp;
s.push_back(temp);
}
//read m likeness
for(int i=0; i<m; i++){
int c;
scanf("%d",&c);
//cin>>c;
guest temp;
temp.s = s[i];
//read the likeness of the m th costomer
while(c--){
int temp2;
scanf("%d",&temp2);
//cin>>temp2;
temp.like.push_back(temp2);
}
guests.push_back(temp);
}
//process______________________________
while(!guests.empty()){
list<guest>::iterator it = guests.begin();
int isfound = 0;
for(auto i = noodles.begin(); i!=noodles.end(); i++){
//check the like
int valid = 1;
for(auto ii:it->like){
if(i->content[ii]!=1){
valid = 0;
break;
}
}
if(!valid){
//no this noodle!
continue;
}
else{
printf("%d\n",it->s-i->t);
//cout<<it->s-i->t<<endl;
noodles.erase(i);
isfound = 1;
break;
}
}
if(!isfound)
printf("Angry\n");
//cout<<"Angry"<<endl;
guests.erase(it);
}
//cout<<"********************"<<endl;
}
思路
R!!G!!B!!
遍历一遍,统计三种小灯的数目,取最小值即可
密码强弱度
如果一个密码的长度小于 6,则这个密码的强度为 0。
对于长度大于等于 6 的密码,根据字符的种类(字符分为三类:数字,小写字母,大写字母),每次遇到和前一个相同的则继续往下,遇到和前一个不同的则数目+1;段数即为密码的强弱程度。
.关于list容器
list是一种序列式容器。list容器完成的功能实际上和数据结构中的双向链表是极其相似的,list中的数据元素是通过链表指针串连成逻辑意义上的线性表。
list是数据结构中的双向链表(根据sgi stl源代码),因此它的内存空间是不连续的,通过指针来进行数据的访问,这个特点使得它的随即存取变的非常没有效率,因此它没有提供[]操作符的重载。但由于链表的特点,它可以以很好的效率支持任意地方的删除和插入。
第三题用到的list,会方便。但当时不会做
这里有详细用法