当前位置:网站首页>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
边栏推荐
- 新手必会的静态站点生成器——Gridsome
- Local visualization tools are connected to redis of Alibaba cloud CentOS server
- Spark的RDD(弹性分布式数据集)返回大结果集
- Raspberry pie 4b64 bit system installation miniconda (it took a few days to finally solve it)
- Li Kou - 298th weekly match
- 第6章 Rebalance详解
- 软通乐学-js求字符串中字符串当中那个字符出现的次数多 -冯浩的博客
- LeetCode 1557. The minimum number of points that can reach all points
- js封装数组反转的方法--冯浩的博客
- js时间函数大全 详细的讲解 -----阿浩博客
猜你喜欢

图像处理一百题(1-10)

LeetCode 1020. Number of enclaves

第一章 MapReduce概述

Chapter 7__ consumer_ offsets topic

LeetCode 1552. Magnetic force between two balls

QT simulates mouse events and realizes clicking, double clicking, moving and dragging

简单尝试DeepFaceLab(DeepFake)的新AMP模型

Ffmpeg command line use

Submit several problem records of spark application (sparklauncher with cluster deploy mode)

Native JS realizes the functions of all selection and inverse selection -- Feng Hao's blog
随机推荐
CMake速成
js封装数组反转的方法--冯浩的博客
LeetCode 1020. Number of enclaves
Codeforces Round #802(Div. 2)A~D
Research Report on market supply and demand and strategy of China's four flat leadless (QFN) packaging industry
Spark's RDD (elastic distributed data set) returns a large result set
How to insert mathematical formulas in CSDN blog
Solve the single thread scheduling problem of intel12 generation core CPU (II)
软通乐学-js求字符串中字符串当中那个字符出现的次数多 -冯浩的博客
LeetCode 1447. Simplest fraction
LeetCode 1561. The maximum number of coins you can get
ByteDance new programmer's growth secret: those glittering treasures mentors
QT style settings of qcobobox controls (rounded corners, drop-down boxes, up expansion, editable, internal layout, etc.)
Audio and video development interview questions
7-4 harmonic average
Submit several problem records of spark application (sparklauncher with cluster deploy mode)
One hundred questions of image processing (1-10)
Log statistics (double pointer)
Li Kou - 298th weekly match
Summary of game theory