发网易题解,赢面试人品!

欢迎大家发自己的题解哦,牛妹会从中挑选一位送上牛客订制T恤一个~~


规则:发帖并在本帖下回复题解链接即可~~
#网易##题解#
全部评论
mark,回去发一波
点赞 回复
分享
发布于 2018-08-11 17:30
https://www.nowcoder.com/discuss/93013?type=0&order=0&pos=39&page=1
点赞 回复
分享
发布于 2018-08-11 17:46
联想
校招火热招聘中
官网直投
https://www.cnblogs.com/zzzdp/p/9460475.html 主要看字典序那题就好啦,on的解法(不是牛客的帖子挂在这边不会被删叭)
点赞 回复
分享
发布于 2018-08-11 17:57
第一题 这一题就是遍历就行。 #include <cstdlib> #include <string> #include <iostream> #include <fstream> #include <vector> #include <sstream> #include <unordered_map> #include <unordered_set> #include <map> #include <set> #include <stdio.h> #include <numeric> #include <algorithm> #include <functional> #include <stack> #include <queue> using namespace std; typedef long long ll; const int MOD = 1e9 + 7; typedef unsigned char uchar; #define G_DEBUG int dirs[8][2] = { -1, -1, -1, 0, -1, 1, 0, -1, 0, 1, 1, -1, 1, 0, 1, 1 }; int main() { #ifndef G_DEBUG int n = 0, k = 0; scanf("%d %d", &n, &k); vector<int> nums(n, 0); vector<int> t(n, 0); int result = 0; for (int i = 0; i < n; ++i) scanf("%d", &nums[i]); for (int i = 0; i < n; ++i) { scanf("%d", &t[i]); if (t[i] == 1) result += nums[i]; } #else int n = 6, k = 3; int result = 0; vector<int> nums = { 1, 3, 5, 2, 5, 4 }; vector<int> t = { 1, 1, 0, 1, 0, 0 }; for (int i = 0; i < n; ++i) { if (t[i] == 1) result += nums[i]; } #endif int add_max = 0; for (int i = 0; i <= n - k; ++i) { int temp = 0; for (int j = i; j < i+k; ++j) { if (t[j] == 0) temp += nums[j]; } add_max = max( temp, add_max ); } result += add_max; printf("%d\n", result); system("pause"); return 0; } 第二题: 这一题是后来结束之后弄出来的,之前的正方形判断写错了23333 #include <cstdlib> #include <string> #include <iostream> #include <fstream> #include <vector> #include <sstream> #include <unordered_map> #include <unordered_set> #include <map> #include <set> #include <stdio.h> #include <numeric> #include <algorithm> #include <functional> #include <stack> #include <queue> #include <cmath> using namespace std; typedef long long ll; const int MOD = 1e9 + 7; typedef unsigned char uchar; // #define G_DEBUG struct point { double x, y; } a[4]; bool cmp(point a, point b) { if (a.x != b.x) return a.x < b.x; return a.y < b.y; } double TwoPointDiatance(point a, point b) { return sqrt(pow((a.x - b.x), 2) + pow((a.y - b.y), 2)); } bool IsRightAngle(point a, point b, point c) { double x; x = (a.x - b.x)* (a.x - c.x) + (a.y - b.y)*(a.y - c.y); if (x < 0.00001) return 1; else return 0; } // 逆时针旋转90度 void trans( vector<int>& num ) { int xx = num[3] + num[2] - num[1]; int yy = num[0] - num[2] + num[3]; num[0] = xx; num[1] = yy;; } // reference : https://blog.csdn.net/qq_29567701/article/details/79676736 bool isSquare(vector<vector<int>>& nums) { double s1, s2, s3, s4; for (int i = 0; i < 4; ++i) { a[i].x = nums[i][0]; a[i].y = nums[i][1]; } sort( a, a+4, cmp ); s1 = TwoPointDiatance(a[0], a[2]); s2 = TwoPointDiatance(a[0], a[1]); s3 = TwoPointDiatance(a[3], a[1]); s4 = TwoPointDiatance(a[2], a[3]); bool ret = (s1 == s2&&s3 == s4&&s1 == s2&&s1 != 0 && IsRightAngle(a[0], a[1], a[2])); return ret; } int main() { #ifndef G_DEBUG int n = 0; scanf("%d", &n); for (int i = 0; i < n; ++i) { int result = MOD; vector<vector<int>> nums(4, vector<int>(4, 0)); for (int j = 0; j < 4; j++) { scanf("%d %d %d %d", &nums[j][0], &nums[j][1], &nums[j][2], &nums[j][3]); } //vector<vector<int>> nums = { { 1, 1, 0, 0 }, { -1, 1, 0, 0 }, { -1, 1, 0, 0 }, { -1, 1, 0, 0 } }; //vector<vector<int>> nums = { { 2, 2, 0, 1 }, { -1, 0, 0, -2 }, { 3, 0, 0, -2 }, { -1, 1, -2, 0 } }; for( int c1= 0; c1<4 ; ++c1 ) { // transform if (c1 != 0) { trans( nums[0] ); } for( int c2= 0; c2<4 ; ++c2 ) { if (c2 != 0) { trans(nums[1]); } for( int c3= 0; c3<4 ; ++c3 ) { if (c3 != 0) { trans(nums[2]); } for (int c4 = 0; c4 < 4; ++c4) { if (c4 != 0) { trans(nums[3]); } if (isSquare(nums)) { result = min( result, c1+c2+c3+c4 ); } } trans(nums[3]); } trans(nums[2]); } trans(nums[1]); } trans(nums[0]); if (result == MOD) result = -1; printf("%d\n", result); } #else vector<int> num = { 2,1,0,0 }; for (int i = 0; i < 4; i++) { trans( num ); } vector<vector<int>> nums = { { 0, 2, 0, 0 }, { 0, -1, 0, 0 }, { 3, 2, 0, 0 }, { 3,-1, 0, 0 } }; cout << isS(nums) << endl; #endif system("pause"); return 0; }
点赞 回复
分享
发布于 2018-08-11 17:58
#include<stdio.h> int find(int target, int min, int max, int *list){ //二分查找,找到目标数小于等于当前下标且大于前一个下标为止。 //e.g.2,7,9,12内找8,返回的是9的下标3,因为8<=9,且8>7 while(min<=max){ int mid=(min+max)/2;   if(target>list[mid-1]&&target<=list[mid])return mid; else if(target<=list[mid-1])max=mid-1; else min=mid+1; } return -1; } int main(){ int applePart; scanf("%d",&applePart); int *dp=new int[applePart+1](); for(int i=1;i<=applePart;i++){ //这里从1开始,下标0保留0,有用 int apple; scanf("%d",&apple); dp[i]=dp[i-1]+apple; } //上面dp数组的下标i所存的数表示的是该堆及之前所有堆的苹果总和 //比如输入2,3,4,5,6,数组里存的就是(0,)2,5,9,14,20 int question; scanf("%d",&question); for(int i=0;i<question;i++){ int rank; scanf("%d",rank); printf("%d\n",find(rank, 1, applePart, dp); } //查找思路:在上面的数组中,比如我要找第8个,那就在顺序表里找到某个下标,使得它的值大于等于8,且它前面的值小于8就行了 //问题回到开头的那个函数里 //由于每堆苹果至少1个,dp数组里没有想等的数,所以一定能查找到准确的堆(而不会指到一个空堆里) return 0; } 找苹果的那题。直接在oj上码的没保存到本地ide……不过思路就是这样
点赞 回复
分享
发布于 2018-08-11 22:18
我的详细题解,希望中个体恤,也希望牛客网markdown编辑器能早日支持编辑公式~ https://www.nowcoder.com/discuss/93285
点赞 回复
分享
发布于 2018-08-12 16:23

相关推荐

点赞 11 评论
分享
牛客网
牛客企业服务