日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

2019网易校招

發布時間:2024/4/15 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 2019网易校招 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

第1題?瞌睡

尺取法滑動窗口

時間復雜度O(n)

第2題 豐收

前綴和后二分

時間復雜度O(mlogn)

第3題 整理房間

暴力枚舉每團雜物4 ^ 4次旋轉

時間復雜度O(256*n)

1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 using namespace std; 5 6 struct point { 7 int x, y; 8 9 point(int _x = 0, int _y = 0) : x(_x), y(_y) {} 10 11 point operator+(const point &rhs) const { 12 return point(x + rhs.x, y + rhs.y); 13 } 14 15 point operator-(const point &rhs) const { 16 return point(x - rhs.x, y - rhs.y); 17 } 18 19 bool operator==(const point &rhs) const { 20 return x==rhs.x&&y==rhs.y; 21 } 22 23 point rotate() // 原點旋轉 24 { 25 return point(-y, x); 26 } 27 28 point rotate(const point &o) const { 29 return (*this - o).rotate() + o; 30 } 31 }; 32 33 // 判斷是否合法的正方形 34 bool check(const point& a, const point& b) {//兩條對角線向量 35 if(a.x==0&&a.y==0||b.x==0&&b.y==0)return false; 36 if(a.x*a.x+a.y*a.y!=b.x*b.x+b.y*b.y)return false;//對角線不等長 37 if(a.x*b.x+a.y*b.y!=0)return false;//對角線不垂直 38 return true; 39 } 40 41 int main() 42 { 43 int n; 44 cin>>n; 45 while(n--) 46 { 47 point p[4],o[4]; 48 for(int i=0;i<4;i++) 49 { 50 cin>>p[i].x>>p[i].y; 51 cin>>o[i].x>>o[i].y; 52 } 53 int ans=-1; 54 int x,y,z,w; 55 for(x=0;x<4;x++) 56 { 57 for(y=0;y<4;y++) 58 { 59 for(z=0;z<4;z++) 60 { 61 for(w=0;w<4;w++) 62 { 63 int cost = x+y+z+w; 64 //是否對角線,并且構成正方形 65 if(p[0]+p[1]==p[2]+p[3]&& 66 check(p[0]-p[1],p[2]-p[3])|| 67 p[0]+p[2]==p[1]+p[3]&& 68 check(p[0]-p[2],p[1]-p[3])|| 69 p[0]+p[3]==p[1]+p[2]&& 70 check(p[0]-p[3],p[1]-p[2])) 71 { 72 if(ans==-1||ans>cost)ans=cost; 73 } 74 p[3].rotate(o[3]); 75 } 76 p[2].rotate(o[2]); 77 } 78 p[1].rotate(o[1]); 79 } 80 p[0].rotate(o[0]); 81 } 82 cout<<ans<<endl; 83 } 84 85 return 0; 86 }

?

轉載于:https://www.cnblogs.com/demian/p/9469152.html

總結

以上是生活随笔為你收集整理的2019网易校招的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。