A-超市
题意:苹果a元一斤,桃子b元一斤,带了n元钱,买多少斤水果
代码:
#include<bits/stdc++.h> using namespace std; typedef long long ll; void sol(){ int n,a,b;cin>>n>>a>>b; int ans=0; if(a>b){ ans+=n/b; } else{ ans+=n/a; } cout<<ans<<endl; } int main() { ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); int t=1; while(t--)sol(); return 0; }
B-雨幕
题意:有n×m的地图,*代表降雨,求有多少个2×2的区域都在降雨
分析:枚举即可
代码:
#include<bits/stdc++.h> using namespace std; typedef long long ll; void sol(){ int n,m;cin>>n>>m; char a[n+10][m+10]; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin>>a[i][j]; } } int ans=0; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(a[i][j]=='*'&&a[i+1][j]=='*'&&a[i+1][j+1]=='*'&&a[i][j+1]=='*'){ ans++; } } } cout<<ans<<endl; } int main() { ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); int t=1; while(t--)sol(); return 0; }
C-闺蜜
题意:给定长度为偶数的数组,小红先手,小紫后手,小紫可以在任何时期将自己手上的一个元素和小红的一个元素交换,只能换一次,最终谁获得胜利
代码:
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e5 + 10; ll a[1010]; int main(){ int t; cin >> t; while (t--){ int n; cin >> n; for (int i = 1; i <= n; i++){ cin >> a[i]; } sort(a + 1, a + 1 + n); ll ans1 = 0, ans2 = 0; for (int i = n; i >= 1; i--){ if (i % 2 == 0){ ans1 += a[i]; } else{ ans2 += a[i]; } } ans1 = ans1 - a[n] + a[1]; ans2 = ans2 - a[1] + a[n]; if (ans1 > ans2){ cout << "kou\n"; } else if (ans1 < ans2){ cout << "yukari\n"; } else{ cout << "draw\n"; } } return 0; }
D-医生
题意:给定n个病人和m种症状,每行输入长度为m的01串,代表每个病人的症状情况,1为有病,0为没病,有k种药,每种药也用长度m的01串表示,1代表该药可以治愈第i个部位的症状,求出治愈该病人需要开的最少的药数量
分析:用dfs找出每一种合成情况,再遍历是否能治疗该病人,如果可以取最小值
代码:
#include<bits/stdc++.h> using namespace std; typedef long long ll; map<string,int>mp; int n,m,k; string c[15]; void dfs(string d,int kk,int cnt){//0000,0,0 if(kk==k){ return; } string q; for(int i=0;i<m;i++){ q+='0'; } for(int i=0;i<m;i++){ if(d[i]=='0'&&c[kk][i]=='1')q[i]='1'; if(d[i]=='1'&&c[kk][i]=='1')q[i]='1'; if(d[i]=='1'&&c[kk][i]=='0')q[i]='1'; if(d[i]=='0'&&c[kk][i]=='0')q[i]='0'; } if(mp[q]==0)mp[q]=cnt+1; else mp[q]=min(mp[q],cnt+1); dfs(q,kk+1,cnt+1);//取 dfs(d,kk+1,cnt);//不取 } void sol(){ cin>>n>>m; string s[n+10]; for(int i=1;i<=n;i++){ cin>>s[i]; } cin>>k; for(int i=0;i<k;i++){ cin>>c[i]; } string ss; for(int i=0;i<m;i++){ ss+='0'; } dfs(ss,0,0);//0000,0,0 map<string,int>mpp; // for(auto &x:mp){ // cout<<x.first<<" "<<x.second<<endl; // } for(int i=1;i<=n;i++){ int o=0; for(int j=0;j<m;j++){ if(s[i][j]=='0'){ o++; } } if(o==m){ cout<<"0"<<endl;continue; } for(auto &x:mp){ string y=x.first; int q=0; for(int j=0;j<m;j++){ if(s[i][j]=='1'&&y[j]=='0'){ q=1; break; } } if(q==0){ if(mpp[s[i]]==0)mpp[s[i]]=x.second; else mpp[s[i]]=min(mpp[s[i]],x.second); } } if(mpp[s[i]]==0)cout<<"-1"<<endl; else cout<<mpp[s[i]]<<endl; } } int main() { ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); int t=1; while(t--)sol(); return 0; }