开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
master
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
项目仓库所选许可证以仓库主分支所使用许可证为准
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
master
codeLearning
/
codeLearning.cpp
codeLearning
/
codeLearning.cpp
codeLearning.cpp 17.58 KB
一键复制 编辑 原始数据 按行查看 历史
南山欣欣子 提交于 2019年04月18日 22:29 +08:00 . 增加基本几何运算
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828
// codeLearning.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <deque>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include "algorithm.h"
using namespace std;
/*
按照顺时针顺序打印矩阵
*/
void printEdge1(int*matrix,int row,int col,int topRow,int topCol,int downRow,int downCol)
{
if (topRow == downRow)//只有一行
{
for (int i = topCol; i <= downCol;i++)
{
std::cout << matrix[topRow*col + i] << " ";
}
}
else if (topCol==downCol)//只有一列时
{
for (int i = topRow; i < +downRow;i++)
{
std::cout << matrix[i*col + topCol] << " ";
}
}
else
{
int currentRow = topRow;
int currentCol = topCol;
while (currentCol!=downCol)//从左向右输出
{
std::cout << matrix[topRow*col + currentCol] <<" ";
currentCol++;
}
while (currentRow != downRow)//从上向下输出
{
std::cout << matrix[currentRow*col + downCol] << " ";
currentRow++;
}
while (currentCol!=topCol)//从右向左输出
{
std::cout << matrix[downRow*col + currentCol] << " ";
currentCol--;
}
while (currentRow!=topRow)
{
std::cout << matrix[currentRow*col + topCol] << " ";
currentRow--;
}
}
}
void TurnAroundPrintMatrix()
{
int matrix[16] = { 1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16 };
int topRow = 0;
int topCol = 0;
int downRow = 3;
int downCol = 3;
while (topRow <= downRow&&topCol <= downCol)
printEdge1(matrix, 4,4,topRow++, topCol++, downRow--, downCol--);
}
void printEdge2(int*matrix, int row, int col, int topRow, int topCol, int downRow, int downCol)
{
int startRow = topRow;
int startCol = topCol;
int deta = downCol - topCol;
int tmp=0;//用于交换
for (int i = 0; i != deta;i++)
{
tmp = matrix[topRow*col+topCol+i];
matrix[topRow*col + topCol + i] = matrix[(downRow-i)*col + topCol];
matrix[(downRow - i)*col + topCol] = matrix[downRow*col + downCol-i];
matrix[downRow*col + downCol - i] = matrix[(topRow+i)*col + downCol];
matrix[(topRow + i)*col + downCol] = tmp;
}
}
void rotateMatrix()
{
int matrix[16] = { 1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16 };
int topRow = 0;
int topCol = 0;
int downRow = 3;
int downCol = 3;
while (topRow <= downRow&&topCol <= downCol)
printEdge2(matrix, 4, 4, topRow++, topCol++, downRow--, downCol--);
for (int i = 0; i <4; i++)
{
for (int j = 0; j < 4; j++)
{
std::cout<<matrix[i*4 + j]<<" ";
}
std::cout << std::endl;
}
}
void printEdge3(int*matrix, int row, int col, int topRow, int topCol, int downRow, int downCol,bool order)
{
if (order)
{
while (topRow!=downRow+1)
{
std::cout << matrix[topRow*col + topCol] << " ";
topRow++;
topCol--;
}
}
else
{
while (downRow!=topRow-1)
{
std::cout << matrix[downRow*col + downCol] << " ";
downRow--;
downCol++;
}
}
}
//之字形打印矩阵
void ZigMatrix()
{
int matrix[16] = { 1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16 };
int row = 4, col = 4;
int endRow = 3, endCol = 3;
int topRow = 0;
int topCol = 0;
int downRow = 0;
int downCol = 0;
bool order = false;
while (topRow!=row)
{
printEdge3(matrix, row, col, topRow, topCol, downRow, downCol, order);
topRow = topCol == endCol ? topRow + 1 : topRow;
topCol = topCol == endCol ? topCol : topCol+1;
downCol = downRow == endRow ? downCol + 1 : downCol;
downRow = downRow == endRow ? downRow : downRow + 1;
order = !order;
}
}
//判断一个点是否在矩形形中(平行于坐标轴的情况)
bool isInside(double x1,double y1,double x4,double y4,double x,double y)
{
if (x <= x1)
return false;
if (x>=x4)
{
return false;
}
if (y<=y1)
{
return false;
}
if (y>=y4)
{
return false;
}
return true;
}
bool isInside(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double x, double y)
{
if (y1 == y2)
return isInside(x1, y1, x4, y4, x, y);
double l = x4 - x3;
double s = y4 - y3;
double len = std::sqrt(l*l+s*s);
double sin_ = s / len;
double cos_ = l / len;
double x1R = cos_*x1 + sin_*y1;
double y1R = -sin_*x1 + cos_*y1;
double x4R = cos_*x4 + sin_*y4;
double y4R = -sin_*x4 + cos_*y4;
double xR = cos_*x + sin_*y;
double yR = -sin_*x + cos_*y;
return isInside(x1R, y1R, x4R, y4R, xR, yR);
}
//返回两向量的叉乘
double crossProduct(const double x1,const double y1,const double x2,const double y2)
{
return x1*y2 - x2*y1;
}
//点是否在三角形中
bool isInside2(double x1, double y1, double x2, double y2,
double x3, double y3, const double x, const double y)
{
//判断三角形三个点的输入顺序是否为逆时针
if (crossProduct(x3-x1,y3-y1,x2-x1,y2-y1)>=0)
{
double tmpx = x2;
double tmpy = y2;
x2 = x3; y2 = y3;
x3 = tmpx; y3 = tmpy;
}
if (crossProduct(x3 - x1, y3 - y1, x - x1, y - y1)<0)
{
return false;
}
if (crossProduct(x1-x2,y1-y2,x-x2,y-y2)<0)
{
return false;
}
if (crossProduct(x2-x3,y2-y3,x-x3,y-y3)<0)
{
return false;
}
}
/*汉诺塔问题
有三根杆子A,B,C。A杆上有N个(N>1)穿孔圆环,盘的尺寸由下到上依次变小。要求按下列规则将所有圆盘移至C杆:
1、每次只能移动一个圆盘;
2、大盘不能叠在小盘上面。
基本步骤如下:
假设已经知道改怎么移动n-1个移动盘了
1、把n-1个圆盘从起点盘移动到没有任何圆盘的过渡盘;
2、将最后一个原盘从起点盘移动到目标盘;
3、将n-1个盘从过度盘移动到目标盘,完成汉诺塔问题;
*/
void hannoiProblem(int n, char A,char B, char C)
{
if (n==1)
{
std::cout << "move" << n << "from" << A << " to " << C << std::endl;
}
else
{
hannoiProblem(n - 1, A, C, B);
std::cout << "move" << n << "from" << A << " to " << C << std::endl;
hannoiProblem(n - 1, B, A, C);
}
}
void getMaxWindows(const int*arr_in,const int&num_in,int*arr_out,const int&num_out,const int&windows_size)
{
if (arr_in==nullptr||arr_out==nullptr||windows_size<1)
{
return;
}
int index = 0;
std::deque<int>qmax;//标记子窗口最大值的位置
for (int i = 0; i < num_in;++i)
{
while (!qmax.empty()&&arr_in[qmax.back()]<=arr_in[i])
{
qmax.pop_back();
}
qmax.push_back(i);
if (qmax.front()==(i-windows_size))
{
qmax.pop_front();
}
if (i >= (windows_size - 1))
{
arr_out[index++] = arr_in[qmax.front()];
}
}
return;
}
void replaceSpace(char *str, int length) {
if (str == nullptr || length < 0)
return;
int numOfSpace = 0;
int i = 0;
int oldLength = 0;
while (str[i] != '0円')
{
if (str[i] == ' ')
numOfSpace++;
i++;
oldLength++;
}
int newLength = oldLength + numOfSpace * 2;
if (newLength > length)
return;
while (oldLength >= 0 && oldLength < newLength)
{
if (str[oldLength] == ' ')
{
str[newLength--] = '0';
str[newLength--] = '2';
str[newLength--] = '%';
}
else
{
str[newLength--] = str[oldLength];
}
oldLength--;
}
}
int StrToInt(std::string str) {
int len = str.length();
int i = 0;
int flag = 1; bool hasFlag = false;
int num = 0;
int size_i = 1;
int size = std::pow(10, len - size_i);
while (i<len){
if (str[i] == '-' || str[i] == '+'){
size = std::pow(10, len - size_i - 1);
if (((i + 1 < len) && (str[i + 1] <= '0' || str[i + 1] > '9')) ||
(i + 1 >= len))
return 0;
flag = (str[i] == '-') ? -1 : 1;
num += ((str[i + 1] - '0')*size);
i += 2; size /= 10;
break;
}
else if (str[i]>'0' || str[i] <= '9'){
num += (str[i] - '0')*size;
++i; size /= 10;
break;
}
size_i++;
size = std::pow(10, len - size_i);;
++i;
}
while (i<len){
if (str[i]>'0'&&str[i] <= '9'){
num += (str[i] - '0')*size;
++i; size /= 10;
}
else
return 0;
}
return num*flag;
}
string ReverseSentence(string str) {
string res = str;
int len = str.length();
int end_count = len - 1;
for (int i = 0; i < len; ++i){
int i_end = i;
if (str[i_end] == ' '){
res[end_count--] = ' ';
continue;
}
while (i_end < len&&str[i_end] != ' '){
i_end++;
}
for (int j = i_end - 1; j >= i; --j){
res[end_count--] = str[j];
}
i = i_end - 1;
}
return res;
}
static bool comp(const int&a, const int&b){
return a < b;
}
bool IsContinuous(vector<int> numbers) {
sort(numbers.begin(), numbers.end(), comp);
int numberOfZero = 0;
int len = numbers.size();
for (int i = 0; i < len; ++i){
if (numbers[i] == 0)
numberOfZero += 1;
else
break;
}
int count = 0;
for (int i = numberOfZero; i < (len - 1); ++i){
int gap = numbers[i + 1] - numbers[i]-1;
if (gap < 0)
return false;
count += gap;
}
if (count <= (numberOfZero))return true;
return false;
}
int abs_by_move(int n){
return n*((n >> 31 << 1) + 1);
}
double abs_by_move(double number){
//printf("&#37;f ", number);
unsigned long long* x = (unsigned long long*)&number;
*x &= 0x7fffffffffffffff;
number = *(double *)x;
//printf("%f \n", number);
return number;
}
struct Node{
int val;
struct Node*next;
Node(int value_) : val(value_), next(nullptr) {
}
};
int LastRemaining_Solution(int n, int m)
{
if (n < 1)return 0;
Node*head = new Node(0);
Node*curNode = head;
for (int i = 1; i < n; ++i){
curNode->next = new Node(i);
curNode = curNode->next;
}
curNode->next = head;//组成环
Node*pre = curNode;//记录前一节点
Node*cur;
curNode = head;//从头节点开始
int count = -1;
while (curNode->next != curNode){
count++;
if (count == (m - 1)){
cur = curNode;//记录当前节点
curNode = curNode->next;//跳到下一节点
pre->next = curNode;
delete cur; cur = nullptr;
count = -1;
}
pre = pre->next;
curNode = curNode->next;//跳到下一节点
}
int lucky = curNode->val;
delete curNode; curNode = nullptr;
return lucky;
}
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};
ListNode* EntryNodeOfLoop(ListNode* pHead)
{
if (pHead == nullptr || pHead->next == nullptr || pHead->next->next == nullptr)
return nullptr;
ListNode* fast = pHead->next->next;
ListNode* slow = pHead;
while (fast != slow){
if (fast != nullptr&&fast->next != nullptr){
slow = slow->next;
fast = fast->next->next;
}
else
return nullptr;
}
fast = fast->next;
int count = 1;//统计环的大小
while (fast != slow){
count += 1;
fast = fast->next;
}
fast = pHead;
for (int i = 0; i < count; ++i){
fast = fast->next;
}
slow = pHead;
while (fast != slow){
fast = fast->next;
slow = slow->next;
}
return slow;
}
struct TreeNode {
int val;
struct TreeNode *left;
struct TreeNode *right;
TreeNode(int x) :
val(x), left(NULL), right(NULL) {
}
};
void Serialize(TreeNode *root, string&out) {
if (root == nullptr){
out += '#';
return;
}
out.append(to_string(root->val));
out += ',';
Serialize(root->left, out);
Serialize(root->right, out);
}
char* Serialize(TreeNode *root) {
if (root == nullptr)return nullptr;
string out;
Serialize(root, out);
char*out_char = new char[out.length() + 1]();
int size = out.length();
int i = 0;
for (; i < size; ++i){
out_char[i] = out[i];
}
out_char[i] = '0円';
return out_char;
}
TreeNode* Deserialize(char **str) {
if (**str == '#'){
++(*str);
return nullptr;
}
int num = 0;
while (**str != '/0'&&**str != ','){
num = num * 10 + ((**str) - '0');
++(*str);
}
TreeNode*root = new TreeNode(num);
if (**str == '/0')
return root;
else
++(*str);
root->left = Deserialize(str);
root->right = Deserialize(str);
return root;
}
TreeNode* Deserialize1(char *str) {
if (str == nullptr)return nullptr;
TreeNode*head = Deserialize(&str);
return head;
}
class MedianHeap {
public:
void Insert(int num)
{
//如果值比大根堆堆顶的值小,插入大根堆
if (m_max_heap.size() != 0 && num<m_max_heap.front())
HeapInsert_Max(m_max_heap, num);
else
HeapInsert_Min(m_min_heap, num);
if (abs(m_max_heap.size() - m_min_heap.size()>1))//两个堆的差大于1时
{
if (m_max_heap.size() > m_min_heap.size())
{
HeapInsert_Min(m_min_heap, HeapDelete_Max(m_max_heap));
}
else
HeapInsert_Max(m_max_heap, HeapDelete_Min(m_min_heap));
}
}
double GetMedian()
{
int size = m_max_heap.size() + m_min_heap.size();
if (size%2==0)
{
return static_cast<double>(m_max_heap.front() + m_min_heap.front()) / 2.0;
}
else{
if (m_max_heap.size() > m_min_heap.size())
return m_max_heap.front();
else
return m_min_heap.front();
}
}
void deleteTop(){
HeapDelete_Max(m_max_heap);
}
private:
void swap(std::vector<int>&heap_,const int&i, const int&j){
heap_[i] = heap_[i] ^ heap_[j];
heap_[j] = heap_[i] ^ heap_[j];
heap_[i] = heap_[i] ^ heap_[j];
}
void HeapInsert_Max(std::vector<int>&heap_, const int&value){
heap_.push_back(value);//将value值插入到堆中
int size = heap_.size();//获取当前整个数组的大小
int child = size - 1;//获取最后一个叶子结点
int parent = (child - 1) / 2;//获取父节点的值
for (int i = parent; i >= 0; --i)
{
adjustHeap_max(heap_,i);
}
}
//由上向下进行交换,把最大值交换上来
void adjustHeap_max(std::vector<int>&heap_,const int&parent_in){
int parent = parent_in;
int child = 2 * parent + 1;//获取左子节点
int tmp_value = 0;
int size = heap_.size();
while (child < size)
{
if (child + 1 < size&&heap_[child + 1] > heap_[child]){
child += 1;//右节点更大,切换到右节点
}
tmp_value = heap_[parent];
if (tmp_value >= heap_[child])
break;
swap(heap_, parent, child);
parent = child;
child = 2 * parent + 1;
}
}
void HeapInsert_Min(std::vector<int>&heap_, const int&value){
heap_.push_back(value);//将value值插入到堆中
int size = heap_.size();//获取当前整个数组的大小
int child = size - 1;//获取最后一个叶子结点
int parent = (child - 1) / 2;//获取父节点的值
for (int i = parent; i >= 0; --i)
{
adjustHeap_Min(heap_, i);
}
}
//由上向下进行交换,把最大值交换上来
void adjustHeap_Min(std::vector<int>&heap_, const int&parent_in){
int parent = parent_in;
int child = 2 * parent + 1;//获取左子节点
int tmp_value = 0;
int size = heap_.size();
while (child < size)
{
if (child + 1 < size&&heap_[child + 1] < heap_[child]){
child += 1;//右节点更小,切换到右节点
}
tmp_value = heap_[parent];
if (tmp_value <= heap_[child])
break;
swap(heap_, parent, child);
parent = child;
child = 2 * parent + 1;
}
}
//删除大根堆的最大值,并返回
int HeapDelete_Max(std::vector<int>&heap_){
int value = heap_.front();//获取大根堆最大值
int size = heap_.size();
swap(heap_, 0, size - 1);//交换大根堆堆顶与最后一个元素
heap_.erase(heap_.begin() + (size - 1));//删除最后一个节点
int child = heap_.size() - 1;//获取最后个叶子结点
int parent = (child - 1) / 2;//获取父节点的值
for (int i = parent; i >= 0; --i)
{
adjustHeap_max(heap_, i);
}
return value;
}
//删除小根堆的最小值,并返回
int HeapDelete_Min(std::vector<int>&heap_){
int value = heap_.front();//获取大根堆最大值
int size = heap_.size();
swap(heap_, 0, size - 1);//交换大根堆堆顶与最后一个元素
heap_.erase(heap_.begin() + (size - 1));//删除最后一个节点
int child = heap_.size() - 1;//获取最后个叶子结点
int parent = (child - 1) / 2;//获取父节点的值
for (int i = parent; i >= 0; --i)
{
adjustHeap_Min(heap_, i);
}
return value;
}
private:
std::vector<int>m_max_heap;
std::vector<int>m_min_heap;
};
void trimLeftTrailingSpaces(string &input) {
input.erase(input.begin(), find_if(input.begin(), input.end(), [](int ch) {
return !isspace(ch);
}));
}
void trimRightTrailingSpaces(string &input) {
input.erase(find_if(input.rbegin(), input.rend(), [](int ch) {
return !isspace(ch);
}).base(), input.end());
}
vector<int> stringToIntegerVector(string input) {
vector<int> output;
trimLeftTrailingSpaces(input);
trimRightTrailingSpaces(input);
input = input.substr(1, input.length() - 2);
stringstream ss;
ss.str(input);
string item;
char delim = ',';
while (getline(ss, item, delim)) {
output.push_back(stoi(item));
}
return output;
}
/////////////////////////////////虚函数的学习//////////////////////////////////
class Base {
public:
virtual void f() { cout << "base::f" << endl; }
virtual void g() { cout << "base::g" << endl; }
virtual void h() { cout << "base::h" << endl; }
};
class Derive : public Base{
public:
void g() { cout << "derive::g" << endl; }
};
class SolutionMedianSorted {
public:
double findMedianSortedArrays(vector<int>& A, vector<int>& B) {
int m = A.size();
int n = B.size();
if (m > n) { // to ensure m<=n
return findMedianSortedArrays(B,A);
}
int iMin = 0, iMax = m, halfLen = (m + n + 1) / 2;
while (iMin <= iMax) {
int i = (iMin + iMax) / 2;
int j = halfLen - i;
if (i < iMax && B[j - 1] > A[i]){
iMin = i + 1; // i is too small
}
else if (i > iMin && A[i - 1] > B[j]) {
iMax = i - 1; // i is too big
}
else { // i is perfect
int maxLeft = 0;
if (i == 0)
{
maxLeft = B[j - 1];
}
else if (j == 0)
{
maxLeft = A[i - 1];
}
else
{
maxLeft = max(A[i - 1], B[j - 1]);
}
if ((m + n) % 2 == 1)
{
return maxLeft;
}
int minRight = 0;
if (i == m)
{
minRight = B[j];
}
else if (j == n)
{
minRight = A[i];
}
else
{
minRight = min(B[j], A[i]);
}
return (maxLeft + minRight) / 2.0;
}
}
return 0.0;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
string line;
//while (getline(cin, line)) {
// vector<int> nums1 = stringToIntegerVector(line);
// getline(cin, line);
// vector<int> nums2 = stringToIntegerVector(line);
// double ret = SolutionMedianSorted().findMedianSortedArrays(nums1, nums2);
// string out = to_string(ret);
// cout << out << endl;
//}
//ListNode*head = new ListNode(0);
//ListNode*curNode = head;
//ListNode*enter = nullptr;
//for (int i = 1; i < 8; ++i){
// curNode->next = new ListNode(i);
// curNode = curNode->next;
// if (i == 4)
// enter = curNode;
//}
//curNode->next = enter;
//ListNode*enter_tmp=EntryNodeOfLoop(head);
//
//char str[] = { '1', ',', '2', ',', '#', '#', '3', ',', '#', '#', '0円' };
//Deserialize1(str);
//
//MedianHeap heap_tmp;
//for (int i = 0; i <20;++i)
//{
// heap_tmp.Insert(i);
//}
//heap_tmp.deleteTop();
GeometricAlgorithm::GeometricAlgorithmTest();
return 0;
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/heelong/codeLearning.git
git@gitee.com:heelong/codeLearning.git
heelong
codeLearning
codeLearning
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /