当前位置:网站首页>CCF call auction (full mark code + problem solving ideas + skill summary) 201412 - 3
CCF call auction (full mark code + problem solving ideas + skill summary) 201412 - 3
2022-06-30 14:41:00 【A cute little monkey】
Skill summary
- When you need a pair of data to get the most value , It is not necessary to use pair For storage ( More complicated ), Maintain the current maximum value with two variables
- Pay attention to whether the data range will detonation int
- All data must be defined Don't forget to initialize
Title Description

Their thinking
- The data range is not large, only 5000, So you can choose to use violence n*2 solve
- As the title indicates the same opening volume , Choose a higher opening price , therefore The enumerated price should be the price given in the title , Because if you take the middle of the two prices in the title , Then the highest opening price of the same opening trading volume must be the price already given
- The meaning of the title is concise and comprehensive , For one Given price p, Calculate purchase price >= p Number of shares , Selling price <= p Number of shares , both Take the smaller value , Calculate the maximum of all transaction volumes , And the corresponding maximum price p
Code implementation
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 5010;
struct share
{
string character;
double price;
int number;
bool flag;
}shares[N];
int main()
{
int cnt = 0;
string a;
while(cin >> a)
{
double p = 0.0;
int n = 0;
int c = 0;
if (a == "buy")
{
cin >> p >> n;
shares[ ++ cnt] = {
"buy", p, n, true};
}
else if(a == "sell")
{
cin >> p >> n;
shares[ ++ cnt] = {
"sell", p, n, true};
}
else if (a == "cancel")
{
cin >> c;
shares[c].flag = false;
shares[ ++ cnt].flag = false;
}
}
long long s = 0; // Be sure to initialize
double p = 0;
for (int i = 1; i <= cnt; i ++)
{
if(!shares[i].flag) continue;
long long sum1 = 0;
long long sum2 = 0;
for (int j = 1; j <= cnt; j ++)
{
if(!shares[j].flag) continue;
if(shares[j].character == "buy")
{
if(shares[j].price >= shares[i].price) sum1 += shares[j].number;
}
else if(shares[j].character == "sell")
{
if(shares[j].price <= shares[i].price) sum2 += shares[j].number;
}
}
long long res = min(sum1, sum2);
if(res > s || (res == s && shares[i].price > p))
{
s = res;
p = shares[i].price;
}
}
printf("%.2f", p);
cout << " " << s;
return 0;
}
边栏推荐
- 數據恢複軟件EasyRecovery15下載
- 2021-07-15Caused by: org. quartz. ObjectAlreadyExistsException: Unable to store Job : ‘DEFAULT. TASK_ 1‘
- JS to realize simple lottery function
- Advanced usage of go language for loop break and continue
- XSS challenge (1-5) more detailed answers
- Fastcgi CGI shallow understanding
- Go language func function
- Laravel configures passport and returns token using JWT
- @Component use cases
- Thinkphp5 log file contains trick
猜你喜欢
![[geek challenge 2019] PHP problem solving record](/img/bf/038082e8ee1c91eaf6e35add39f760.jpg)
[geek challenge 2019] PHP problem solving record

Problems in QT creator (additional unknown and error lines are listed in the debug output window)

DiceCTF - knock-knock

PS cutting height 1px, Y-axis tiling background image problem

Solve the error in my QT_ thread_ global_ End(): 3 threads didn't exit

Detailed explanation of the first three passes of upload Labs

ctfshow nodejs

remote: Support for password authentication was removed on August 13, 2021. Please use a personal ac

Detailed explanation of settimeout() and setinterval()

Thinkphp5 log file contains trick
随机推荐
Why is the resolution of the image generated by PHP GD library 96? How to change it to 72
Computer screenshot how to cut the mouse in
Effect of shadow around the block after mouse over
How does hbuilder display in columns?
C language & the difference between the address pointed to and the address pointed to by the pointer
[extensive reading of papers] multimodal attribute extraction
The JSON data returned from the control layer to JS has a "\" translator. How to remove it
Minimum covering substring of two pointers
[geek challenge 2019] PHP problem solving record
PHP 2D array change key name
2021-08-07 native and package types
Go sync. WaitGroup
PHP common authentication / third-party methods
Three uses of golang underscores
1 figure to explain the difference and connection between nodejs and JS
Problem: wechat developer tool visitor mode cannot use this function
V3 01_ Welcome
Experiment 2: stack
K high frequency elements before sorting
[extensive reading of papers] a delicious recipe analysis framework for exploring multi modal recipes with variable attributes