360笔试编程题解,参考

C卷
第一题:大概是个原题,之前做过链接:

https://www.luogu.org/problemnew/solution/P1187

#include<bits/stdc++.h>
using namespace std;
#define maxn 1000+100
int a[maxn][maxn];
int main(){
  int n,m;
  cin>>n>>m;
  for(int j=1;j<=n;j++){
     for(int k=1;k<=m;k++){
        int x;
        cin>>x;
        a[j][k]=x;
     }
  }
  long long ans=0;
  for(int j=1;j<=n;j++){
     for(int k=1;k<=m;k++){
        ans+=6*a[j][k];
        if(a[j][k]>1){
           ans-=(a[j][k]-1)*2;
        }
        ans-=min(a[j][k],a[j-1][k]);
        ans-=min(a[j][k],a[j+1][k]);
        ans-=min(a[j][k],a[j][k-1]);
        ans-=min(a[j][k],a[j][k+1]);
     }
  }
  cout<<ans<<endl;

  return 0;
}

第二题,我直接暴力解,先排序,然后贪心,这题复杂度太假了,最后偶尔能过100% 有点卡常

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int t1[100010],t2[100010];
int tmp[100010],tot=0;
int main()
{
    int n,m;scanf("%d%d",&n,&m);
    multiset<int> s1,s2;
    for(int i=1;i<=n;i++){
        int tmp;scanf("%d",&tmp);s1.insert(tmp);
    }
    for(int i=1;i<=n;i++){
        int tmp;scanf("%d",&tmp);s2.insert(tmp);
    }
    for(int i=m-1;i>=0;i--){
        tot=0;
        for(multiset<int>::iterator j=s1.begin();j!=s1.end();++j){
            if(s2.find((i-(*j)+m)%m)!=s2.end()){
                tmp[tot++]=*j;
                s2.erase(s2.find((i-(*j)+m)%m));
                printf("%d ",i);
            }
        }
        for(int j=0;j<tot;j++){
            s1.erase(s1.find(tmp[j]));
        }
    }


    return 0;
}
#360公司##题解##笔试题目##春招#
全部评论
你这遇事不决 a[maxn][maxn]有点浪费空间啊
点赞 回复
分享
发布于 2019-08-15 21:34
牛皮
点赞 回复
分享
发布于 2019-08-15 21:11
联想
校招火热招聘中
官网直投
这都是些什么神仙
点赞 回复
分享
发布于 2019-08-15 21:16
tql
点赞 回复
分享
发布于 2019-08-15 21:16
大佬,能不能解释下第二题的思路呢?排完序然后呢?
点赞 回复
分享
发布于 2019-08-15 21:26
你第二题好像过不了这种数据 100000 100000 00000000...0 00000000...0
点赞 回复
分享
发布于 2019-08-15 21:54
牛皮啊
点赞 回复
分享
发布于 2019-08-15 22:04
第二题莫名其妙一直卡在18% 然后RuntimeError了 ???? 思路和楼主差不多,也是multiset,排序,贪心。 很难过
点赞 回复
分享
发布于 2019-08-15 22:21
import java.util.*; public class Test2 {     public static void main(String[] args) {      Scanner sc=new Scanner(System.in);      int n=sc.nextInt();         int m=sc.nextInt(); //        int[] a=new int[n];         int[] b=new int[n];         Queue<Integer> aqueue=new LinkedList<Integer>();         for(int i=0;i<n;i++) {          aqueue.offer(sc.nextInt());         } //        Queue<Integer> bqueue=new LinkedList<Integer>();         for(int i=0;i<n;i++) {          b[i]=sc.nextInt();         }         int target=m-1;         Queue<Integer> queue=new LinkedList<Integer>();         while(target>=0&&!aqueue.isEmpty()) {//&&!aqueue.isEmpty()&&!bqueue.isEmpty()          for(int i=0;i<n;i++) {          if(aqueue.contains((target-b[i]+m)%m)){              aqueue.remove((target-b[i]+m)%m);              queue.offer(target);              }          }                    target--;         }         while(!queue.isEmpty()) {      System.out.print(queue.poll()+" ");      }         sc.close();      //     Queue<Integer> queue=new LinkedList<Integer>(); //     queue.offer(3); //     queue.offer(3); //     queue.offer(4); //     queue.offer(2); //     queue.offer(3); //     queue.remove(3); //     System.out.println(queue.size());          } } 不知道这个答案能不能通过
点赞 回复
分享
发布于 2019-08-16 00:07

相关推荐

3 24 评论
分享
牛客网
牛客企业服务