1. 程式人生 > 資訊 >拼多多高管:業務增長由使用者數和使用者心理佔有率增長驅動

拼多多高管:業務增長由使用者數和使用者心理佔有率增長驅動

 1 #include<stdio.h>
 2 #include<iostream>
 3 #include<algorithm>
 4 using namespace std;
 5 const int m=100000;
 6 struct node 
 7 {
 8     int data, result, chance;
 9 }student[m];
10 bool cmp(node a, node b)
11 {
12     if (a.data == b.data)
13     {
14         return a.result > b.result;
15 } 16 else 17 { 18 return a.data < b.data; 19 } 20 } 21 int main(void) 22 { 23 int n; 24 cin >> n; 25 for (int i = 0; i < n; i++) 26 { 27 cin >> student[i].data >> student[i].result; 28 student[i].chance = 0; 29 } 30 sort(student, student + n, cmp);
31 //找出最大閾值準確率 32 for (int i = 0; i < n - 1; i++) 33 { 34 if (student[i].result == 0) 35 { 36 student[n - 1].chance++; 37 } 38 } 39 if (student[n - 1].result == 1) 40 { 41 student[n - 1].chance++; 42 } 43 //獲取前一個閾值的準確率 44 for
(int i = n - 1; i >= 0; i--) 45 { 46 student[i].chance = student[i + 1].chance; 47 if (student[i].result == 1) 48 { 49 student[i].chance++; 50 } 51 else 52 { 53 student[i].chance--; 54 } 55 } 56 //去重 57 for (int i = 0; i < n - 1; i++) 58 { 59 if (student[i].data == student[i + 1].data) 60 { 61 student[i + 1].chance = student[i].chance; 62 } 63 } 64 //找到閾值 65 int t = student[0].chance; 66 int max; 67 for (int i = 0; i < n; i++) 68 { 69 if (t <= student[i].chance) 70 { 71 t = student[i].chance; 72 max = student[i].data; 73 } 74 } 75 76 cout << max; 77 return 0; 78 }

參考:https://blog.csdn.net/weixin_45693289/article/details/115877445?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-0.control&spm=1001.2101.3001.4242