A.课程
Description
AC Code
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
long long n,m;
bool a[30]={0};
int main(){
ios::sync_with_stdio(false);cin.tie(0);
cin>>n>>m;
int ans =0;
for(int i=0;i<n;i++){
int x;
cin>>x;
a[x] = 1;
}
for(int i=0;i<m;i++){
int x;
cin>>x;
if(a[x]) ans++;
}
cout<<ans<<endl;
return 0;
}
B.序列
Description
AC Code
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
long long a[10000];
int main(){
ios::sync_with_stdio(false);cin.tie(0);
long long n,k;
cin>>n>>k;
for(int i=0;i<n;i++){
cin>>a[i];
}
long long ans =0;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(a[i]*a[j]<=k) ans++;
}
}
cout<<ans<<endl;
return 0;
}
C.子串
Description
AC Code
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
ios::sync_with_stdio(false);cin.tie(0);
long long t;
cin>>t;
while(t--){
long long n,m;
cin>>n>>m;
string a,b;
cin>>a>>b;
long long ans =0;
int la = a.length();
int lb = b.length();
for(int i=0;i<la;i++){
a[i] = tolower(a[i]);
}
for(int i=0;i<lb;i++){
b[i] = tolower(b[i]);
}
for(int i=0;i<=lb-la;i++){
int pos = i;
bool v = 1;
for(int j=0;j<la;j++,pos++){
if(a[j]!=b[pos]){
v = 0;
break;
}
}
if(v) ans++;
}
cout<<ans<<endl;
}
return 0;
}
D.打牌
Description
Solution
模拟。
对于每个人的出牌有两种可能。是否为一轮中的第一个出牌人。
AC Code
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int a[4][55] = {0};
int num[4] = {0};
long long n,m;
int pre = 1;//上家
int pos = 1;//当前出牌人
int pnum = 1;//上家出牌数量
int p = 1;//牌的大小
void cp(int pos){//一轮中的第一个出牌
pnum = 1;
for(int i=1;i<=m;i++){
if(a[pos][i] >= 1){
p = i;
a[pos][i] -= 1;
num[pos] -= 1;
break;
}
}
}
bool dp(int & pos,int & pnum,int & p){//接着上家的牌打
bool v = 0;
for(int i=p+1;i<=m;i++){
if(a[pos][i] >= pnum){
p = i;
a[pos][i] -= pnum;
num[pos] -= pnum;
v = 1;
break;
}
}
if(v==0){
int t = pnum+1;
for(int i=0;i<=m;i++){
if(a[pos][i] >= t){
p = i;
a[pos][i] -= t;
num[pos] -= t;
v = 1;
break;
}
}
if(v==1) pnum++;
}
return v;
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);
cin>>n>>m;
num[1] = num[2] = num[3] = n;
for(int i=1;i<=3;i++){
for(int j=0;j<n;j++){
int x;
cin>>x;
a[i][x]++;
}
}
while(1){
bool c;
if(pre == pos){
cp(pos);
}else{
c = dp(pos,pnum,p);
}
if(num[pos] <= 0){
cout<<pos<<endl;
return 0;
}
if(c) pre = pos;
pos++;
if(pos == 4) pos = 1;
}
return 0;
}
E.商店
Description
AC Code
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int w[100010];
int c[100010];
int main(){
ios::sync_with_stdio(false);cin.tie(0);
long long n,m;
cin>>n>>m;
for(int i=0;i<n;i++) cin>>w[i];
for(int i=0;i<m;i++) cin>>c[i];
sort(w,w+n);
sort(c,c+m);
int len;
if(n>m) len = m;
else len = n;
int x = 0,y =0;
int ans = 0;
while(x < len && y<len){
if(w[x] >= c[y]){
ans++;
x++;
y++;
}else{
x++;
}
}
cout<<ans<<endl;
return 0;
}
就做个记录。(写得有点尴尬 shui)