2023
L1-1:最好的文档
题目链接
#include<iostream>
using namespace std;
int main()
{
cout<<"Good code is its own best documentation.";
return 0;
}
L1-2:什么是机器学习
题目链接
#include<iostream>
using namespace std;
int main()
{
int a,b; cin>>a>>b;
cout<<a+b-16<<endl;
cout<<a+b-3<<endl;
cout<<a+b-1<<endl;
cout<<a+b<<endl;
return 0;
}
L1-3:程序员买包子
题目链接
#include<iostream>
using namespace std;
int main()
{
int n,m,k; string x;
cin>>n>>x>>m>>k;
if(k==n) cout<<"mei you mai "<<x<<" de";
else if(k==m) cout<<"kan dao le mai "<<x<<" de";
else cout<<"wang le zhao mai "<<x<<" de";
return 0;
}
L1-4:进化论
题目链接
#include<iostream>
using namespace std;
int main()
{
int n; cin>>n;
while(n--)
{
int a,b,c; scanf("%d%d%d",&a,&b,&c);
if(c==a*b) cout<<"Lv Yan"<<endl;
else if(c==a+b) cout<<"Tu Dou"<<endl;
else cout<<"zhe du shi sha ya!"<<endl;
}
return 0;
}
L1-5:猜帽子游戏
题目链接
#include<iostream>
using namespace std;
int a[111];
int main()
{
int n; scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%d",&a[i]);
int k; scanf("%d",&k);
while(k--)
{
int sum=0; bool f=1;
for(int i=0;i<n;i++)
{
int x; scanf("%d",&x);
if(x!=a[i]&&x!=0) f=0;
sum+=x;
}
if(sum!=0&&f) cout<<"Da Jiang!!!"<<endl;
else cout<<"Ai Ya"<<endl;
}
return 0;
}
L1-6:剪切粘贴
题目链接
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s; cin>>s;
s=" "+s;
int k; cin>>k;
while(k--)
{
int l,r; cin>>l>>r;
string q=s.substr(l,r-l+1);
s.erase(l,r-l+1);
string s1,s2; cin>>s1>>s2;
int x=s.find(s1+s2);
if(x==-1) s=s+q;
else
{
s=s.substr(0,x+s1.size())+q+s.substr(x+s1.size());
}
}
s.erase(0,1);
cout<<s<<endl;
return 0;
}
L1-7:分寝室
题目链接
#include<iostream>
using namespace std;
int ans=1e8+100;
int gac(int x)
{
if(x<=0) return -x;
else return x;
}
int main()
{
int n0,n1,n; scanf("%d%d%d",&n0,&n1,&n);
int cn0,cn1;
bool f=0;
for(int i=1;i<=n;i++)
{
double c0=i,c1=n-i;
if(c0==0||c1==0) continue;
double a=n0/c0;
double b=n1/c1;
int a1=a,b1=b;
if((a-a1==0.0)&&(b-b1==0.0))
{
if(a1==1||b1==1) continue;//不允许单人住一间寝室;
f=1;
if(gac(a1-b1)<=ans)
{
cn0=c0; cn1=c1;
ans=gac(a1-b1);
}
}
}
if(!f) printf("No Solution\n");
else printf("%d %d\n",cn0,cn1);
return 0;
}
L1-8:谁管谁叫爹
题目链接
#include<iostream>
using namespace std;
int fun(int x)
{
int sum=0;
while(x)
{
sum+=x%10;
x=x/10;
}
return sum;
}
bool cheak(int x,int y)
{
double a=x,b=y;
double z=a/b;
int z1=z;
if(z-z1==0.0) return true;
else return false;
}
int main()
{
int T; scanf("%d",&T);
while(T--)
{
int na,nb; scanf("%d%d",&na,&nb);
int sa=fun(na),sb=fun(nb);
bool f1=cheak(na,sb),f2=cheak(nb,sa);
if(f1&&!f2) {printf("A\n");}
else if(!f1&&f2) {printf("B\n");}
else if((f1&&f2)||(!f1&&!f2))
{
if(na>nb) printf("A\n");
else if(na<nb) printf("B\n");
}
}
return 0;
}
L2-1:堆宝塔
题目链接
#include <iostream>
#include <stack>
#include <algorithm>
using namespace std;
stack<int> A,B;
int main()
{
int n; scanf("%d",&n);
int x; scanf("%d",&x);
n=n-1; A.push(x);
int ma=0,cnt=0;
while(n--)
{
scanf("%d",&x);
int y=A.top();
if(x<y) A.push(x);
else
{
if(B.size()==0) B.push(x);
else if(x>B.top()) B.push(x);
else
{
int len=A.size();
ma=max(ma,len); cnt++;
while(A.size()) A.pop();
while(B.size()&&B.top()>x) {A.push(B.top()); B.pop();}
A.push(x);
}
}
}
if(A.size()!=0)
{
int len=A.size();
ma=max(ma,len); cnt++;
while(A.size()) A.pop();
}
if(B.size()!=0)
{
int len=B.size();
ma=max(ma,len); cnt++;
while(B.size()) B.pop();
}
printf("%d %d\n",cnt,ma);
return 0;
}
L2-2:天梯赛的赛场安排
题目链接
#include<iostream>
using namespace std;
const int N=5200;
int n,c;
struct xue
{
string name;//学校名字
int x;//考生人数
int y;//教练数
}a[N];
int k[N*N],cnt;
int main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>c;
for(int i=0;i<n;i++)
{
cin>>a[i].name;
cin>>a[i].x;
int t=a[i].x/c;
a[i].y=t; a[i].x-=t*c;
while(t--) {k[cnt++]=c;}
}
while(1)
{
bool f=1;
for(int i=0;i<n;i++) if(a[i].x!=0) {f=0; break;}
if(f) break;
int ma_i=0;
for(int i=1;i<n;i++)
{
if(a[i].x>a[ma_i].x) ma_i=i;
}
bool fa=0;
for(int i=0;i<cnt;i++)
{
if(c-k[i]>=a[ma_i].x) {k[i]+=a[ma_i].x; a[ma_i].y++; fa=1; a[ma_i].x=0; break;}
}
if(!fa)
{
k[cnt++]=a[ma_i].x;
a[ma_i].y++;
a[ma_i].x=0;
}
}
for(int i=0;i<n;i++) cout<<a[i].name<<" "<<a[i].y<<endl;
cout<<cnt<<endl;
return 0;
}
L2-3:锦标赛
题目链接
L2-4:寻宝图
题目链接
#include<bits/stdc++.h>
#define PII pair<int,int>
using namespace std;
const int N=1e5+10;
int dx[6]={0,0,1,-1};
int dy[6]={1,-1,0,0};
int n,m;
char g[N];
int c1,c2;
void bfs(int a)
{
int x1=a/m;
int y1=a%m;
bool f=0;
if(g[x1*m+y1]!='1'&&g[x1*m+y1]!='0') f=1;
queue<PII> q; q.push({x1,y1});
while(q.size())
{
PII t=q.front();
q.pop();
for(int i=0;i<4;i++)
{
int x2=t.first+dx[i];
int y2=t.second+dy[i];
if(x2<0||x2>=n||y2<0||y2>=m) continue;
if(g[x2*m+y2]!='1'&&g[x2*m+y2]!='0') f=1;
if(g[x2*m+y2]!='0')
{
q.push({x2,y2});
g[x2*m+y2]='0';
}
}
}
if(f) c2++;
}
int main()
{
ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=0;i<n*m;i++) cin>>g[i];
for(int i=0;i<n*m;i++)
{
if(g[i]!='0') {bfs(i); c1++;}
}
cout<<c1<<" "<<c2<<endl;
return 0;
}