网易4.11笔试 40米大刀

#include<iostream>
#include<vector>
#include<math.h>
#include<algorithm>
#include<unordered_map>
using namespace std;
double Dist(int x1,int y1,int x2,int y2){
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main(){
    int T;
    cin>>T;
    for(int i=0;i<T;i++){
        int M;
		long long L;
        cin>>M;
		cin>>L;
		long long result=0;
        vector<vector<int> > A(M,vector<int> (M));
        vector<pair<double,int>> B(M*M,{0,0});
        for(int j=0;j<M;j++){
            for(int k=0;k<M;k++){
                int p;
                cin>>p;
                A[j][k]=p;
            }
        }
        int X,Y;
        cin>>X>>Y;
        long long sum=0;
		for(int j=0;j<M;j++){
			for(int k=0;k<M;k++)
			{
				double first=Dist(j,k,X,Y);
				int second=A[j][k];
				B.emplace_back(first,second);
			}
		}
		sort(B.begin(),B.end());
		vector<pair<double,int>>::iterator it;
		for(it=B.begin();it!=B.end();it++){
			if(it->first<=L){
				L+=it->second;
			}
		}
		cout<<L<<endl;   
    }
}

#网易游戏2020春招开始了##网易##笔试题目#
全部评论
佳爷威武
点赞 回复
分享
发布于 2020-04-12 11:53
你不是说要去衡阳联通吗?
点赞 回复
分享
发布于 2020-04-12 12:03
滴滴
校招火热招聘中
官网直投

相关推荐

6 2 评论
分享
牛客网
牛客企业服务