网易雷火3.26笔试
1,2,3题a了,第4题 用了二分+bfs 超时了 过了16%
第一题
#include<bits/stdc++.h> using namespace std; int n,m,x,y; int a[105][105]; int main() { cin>>n>>m; cin>>x>>y; int ans=0; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { cin>>a[i][j]; if(x==i&&j==y)ans+=1; else ans+=a[i][j]; } } cout<<ans<<endl; return 0; }第二题
#include<bits/stdc++.h> using namespace std; int t,n; int a[10],b[10],num1[10],num2[10],ans[10]={1,15000,8000,300,150,40,20,6,4,2}; map<int,int>m1,m2; int fun() { if(num1[5])return 1; if(num2[5]) { if((a[0]+1)==a[1]&&(a[0]+2)==a[2]&&(a[0]+3)==a[3]&&(a[0]+4)==a[4])return 2; } if(num2[5])return 3; if(num1[4])return 4; if(num1[3]&&num1[2])return 5; if(n==5&&(a[0]+1)==a[1]&&(a[0]+2)==a[2]&&(a[0]+3)==a[3]&&(a[0]+4)==a[4])return 6; if(num1[3])return 7; if(num1[2]==2)return 8; if(num1[2]==1)return 9; return 0; } int main() { while(cin>>t) { while(t--) { m1.clear(); m2.clear(); memset(num1,0,sizeof(num1)); memset(num2,0,sizeof(num2)); cin>>n; for(int i=0;i<n;i++) { cin>>a[i]; if(m1.count(a[i])==0) { m1[a[i]]=1; } else m1[a[i]]++; } for(int i=0;i<n;i++) { char x; cin>>x; b[i]=x-'A'; if(m2.count(b[i])==0) { m2[b[i]]=1; } else m2[b[i]]++; } for(auto x:m1) { num1[x.second]++; } for(auto x:m2) { num2[x.second]++; } sort(a,a+n); int k=fun(); cout<<ans[k]<<endl; } } return 0; }第三题
#include<bits/stdc++.h> using namespace std; int n,m; string s; int fun(const char s) { if(s<='Z'&&s>='A')return 0; if(s<='z'&&s>='a')return 0; return 1; } int main() { cin>>n>>m; getchar(); getline(cin,s); stringstream ss; ss<<s; string str; string ans=""; vector<string>v; ss>>ans; while(ss>>str) { int k=ans.size()+str.size()+1; int f=fun(str[str.size()-1]); if(k<=n||ans.size()+1<n&&k<=n+m+f)ans=ans+" "+str; else { v.push_back(ans); ans=str; } } if(ans.size()>0)v.push_back(ans); cout<<v.size()<<endl; for(auto x:v)cout<<x<<endl; return 0; }