当前位置:网站首页>7-10 punch in strategy
7-10 punch in strategy
2022-07-06 16:44:00 【HBUcs2020】
Lessons of blood and tears , This seems to be the second one who made such a stupid mistake
All variables in the program must apply for space in advance , Otherwise, there will be all kinds of strange mistakes
Like this
The program runs like this
Look at another one more ridiculous :
This is the source code
This is the result of the operation :
The internal data of the array is strangely changed
Finally, it is corrected as follows :
int N,M;
cin>>N>>M;
int a[MAXSIZE][MAXSIZE];
memset(a,0,sizeof(a));
Complete code :
#include<iostream>
#include<vector>
#include<set>
#include<cstring>
//#include<bits/stdc++.h>
using namespace std;
constexpr int MAXSIZE=201;
constexpr int MAXMONEY=0x3f3f3f3f;
int main()
{
int N,M;
cin>>N>>M;
int a[MAXSIZE][MAXSIZE];
memset(a,0,sizeof(a));
int x,y,money;
for(int i=0; i<M; i++)
{
cin>>x>>y>>money;
a[x][y]=money;
a[y][x]=a[x][y];
printf(" 0-4 Whether it is :%d 4-0:%d\n",a[0][4],a[4][0]);
}
//printf("\n0-4 Whether it is :%d 4-0:%d\n",a[0][4],a[4][0]);
int fsum=MAXMONEY,f=0,num=0; // Minimum cost , At least spend the corresponding number
int k;
cin>>k;
for(int i=1; i<=k; i++)
{
int sum=0;//sum: The total cost
int b=1; // Special mark
int n;
cin>>n;
vector<int> s;
set<int> s2;
int d;
cin>>d;
int t=d;
s.push_back(d);
s2.insert(d);
// The first place is special
if(a[0][d])
sum+=a[0][d];
else
{
b=0;
// continue; //??
}
for(int j=1; j<n; j++)
{
cin>>d;
s.push_back(d);
s2.insert(d);
if(a[t][d])
sum+=a[t][d];
else
{
b=0;
continue;
}
t=d; // Be careful
}
// The end point is a special case
if(b==0)
continue;
if(a[0][t])
{
//printf(" Delete %d:%d\n",t,a[t][0]);
sum+=a[0][t];
}
else
{
b=0;
continue;
}
if(s.size()==N&&s2.size()==N)
{
num++;
//printf(" %d \n",i);
if(fsum>sum)
{
fsum=sum;
f=i;
}
}
}
//printf("\n%d\n",a[4][0]);
// Meet the number of strategies num
// Cost the least ( Select the one with the lowest serial number ) Toll f ,fsum
cout<<num<<endl;
cout<<f<<" "<<fsum<<endl;
return 0;
}
Be careful :
1.continue
2.set,vector
边栏推荐
- Li Kou leetcode 280 weekly match
- 第五章 Yarn资源调度器
- 第5章 消费者组详解
- Research Report of desktop clinical chemical analyzer industry - market status analysis and development prospect prediction
- Sublime text code formatting operation
- (lightoj - 1236) pairs forming LCM (prime unique decomposition theorem)
- Install Jupiter notebook under Anaconda
- Problem - 922D、Robot Vacuum Cleaner - Codeforces
- JS encapsulates the method of array inversion -- Feng Hao's blog
- Codeforces Global Round 19
猜你喜欢
Chapter 1 overview of MapReduce
Advancedinstaller installation package custom action open file
LeetCode 1641. Count the number of Lexicographic vowel strings
300th weekly match - leetcode
Native JS realizes the functions of all selection and inverse selection -- Feng Hao's blog
使用jq实现全选 反选 和全不选-冯浩的博客
第7章 __consumer_offsets topic
Pull branch failed, fatal: 'origin/xxx' is not a commit and a branch 'xxx' cannot be created from it
Chapter 5 detailed explanation of consumer groups
Soft music -js find the number of times that character appears in the string - Feng Hao's blog
随机推荐
(lightoj - 1370) Bi shoe and phi shoe (Euler function tabulation)
Codeforces Round #771 (Div. 2)
Bisphenol based CE Resin Industry Research Report - market status analysis and development prospect forecast
Spark的RDD(弹性分布式数据集)返回大结果集
Soft music -js find the number of times that character appears in the string - Feng Hao's blog
Research Report of desktop clinical chemical analyzer industry - market status analysis and development prospect prediction
(POJ - 3186) treatments for the cows (interval DP)
Li Kou leetcode 280 weekly match
Market trend report, technical innovation and market forecast of double-sided foam tape in China
LeetCode 1545. Find the k-th bit in the nth binary string
Chapter 2 shell operation of hfds
Research Report on market supply and demand and strategy of Chinese table lamp industry
Business system compatible database oracle/postgresql (opengauss) /mysql Trivia
Base dice (dynamic programming + matrix fast power)
Cmake error: could not create named generator visual studio 16 2019 solution
JS time function Daquan detailed explanation ----- AHAO blog
Investigation report of bench type Brinell hardness tester industry - market status analysis and development prospect prediction
Audio and video development interview questions
Problem - 922D、Robot Vacuum Cleaner - Codeforces
Solve the problem of intel12 generation core CPU [small core full, large core onlookers] (win11)