problem 1107

   有点像那道monkey and banana ,要把图给放弃掉的。输入时过滤掉cheese小于(0,0)起点的部分,然后对cheese从大到小排序(这样(0,0)点就被放到了最后一个),m[i]表示以grid[i].x,grid[i].y为起点最多能吃到的cheese量,m[n](n是cheese大于起点的grid的数量)就是结果了。

   有个让人火大的地方,就是fatmouse居然笨到不会拐弯,FT!

Accepted1107C00:03.58660K

#include<stdio.h>
#include
<string.h>
#include
<stdlib.h>
#include
<math.h>
#define MAXN 100
struct  s
{
    
int
 cheese,x,y;
}grid[MAXN 
*
 MAXN];
int cmp(const void* a,const void*
 b)
{
    
return ((struct s*)b)->cheese - ((struct s*)a)->
cheese;
}
void solve(int n,int
 k)
{
    
int
 i,j;
    
int m[MAXN * MAXN],cnt = 1
;
    scanf(
"%d",&grid[0
].cheese);
    grid[
0].x = grid[0].y = 0
;
    
for (i = 1; i < n * n; i++
)
    {
        
int
 temp;
        scanf(
"%d",&
temp);
        
if (temp > grid[0
].cheese)
        {
            grid[cnt].x 
= i %
 n;
            grid[cnt].y 
= i /
 n;
            grid[cnt].cheese 
=
 temp;
            cnt
++
;
        }
    }
    
if (k == 0)    { printf("%d ",grid[0].cheese); return
; }
    qsort(grid,cnt,
sizeof(grid[0
]),cmp);
    
for (i = 0; i < cnt; i++
)
    {
        m[i] 
=
 grid[i].cheese;
        
for (j = 0; j < i; j++
)
        {
            
if (grid[i].cheese < grid[j].cheese && abs(grid[j].x - grid[i].x) <= k && abs(grid[j].y - grid[i].y) == 0 &&
 
                m[i] 
< m[j] +
 grid[i].cheese)
                m[i] 
= m[j] +
 grid[i].cheese;
            
if (grid[i].cheese < grid[j].cheese && abs(grid[j].x - grid[i].x) == 0 && abs(grid[j].y - grid[i].y) <= k &&

                m[i] 
< m[j] +  grid[i].cheese)
                m[i] 
= m[j] +
 grid[i].cheese;
        }
    }
    printf(
"%d/n",m[cnt - 1
]);
}
void
 main()
{
    
int
 n,k;
#ifndef ONLINE_JUDGE
    freopen(
"1107.txt","r"
,stdin);
#endif

    
while(scanf("%d%d",&n,&k) != EOF && !(k == -1 && n == -1 ))
        solve(n,k);
#ifndef ONLINE_JUDGE
    fclose(stdin);
#endif

}
ValueError Traceback (most recent call last) Cell In[13], line 101 99 algorithm.mutOper.Pm = 0.2 # 修改变异算子的变异概率 100 algorithm.recOper.XOVR = 0.9 # 修改交叉算子的交叉概率 --> 101 res = ea.optimize(algorithm, 102 verbose=True, 103 drawing=1, 104 outputMsg=True, 105 drawLog=False, 106 saveFlag=True, 107 dirName = 'D:/Desktop/煤溶胀-机器学习/代码/VD-代码/SVR预测/Final/TG' 108 ) File ~\.conda\envs\python3.9\lib\site-packages\geatpy\optimize.py:104, in optimize(algorithm, seed, prophet, verbose, drawing, outputMsg, drawLog, saveFlag, dirName, **kwargs) 102 algorithm.drawing = drawing if drawing is not None else algorithm.drawing 103 # 开始求解 --> 104 [optPop, lastPop] = algorithm.run(prophetPop) 105 # 生成结果 106 result = {} File ~\.conda\envs\python3.9\lib\site-packages\geatpy\algorithms\moeas\nsga2\moea_NSGA2_templet.py:86, in moea_NSGA2_templet.run(self, prophetPop) 84 if prophetPop is not None: 85 population = (prophetPop + population)[:NIND] # 插入先知种群 ---> 86 self.call_aimFunc(population) # 计算种群的目标函数值 87 [levels, _] = self.ndSort(population.ObjV, NIND, None, population.CV, self.problem.maxormins) # 对NIND个个体进行非支配分层 88 population.FitnV = (1 / levels).reshape(-1, 1) # 直接根据levels来计算初代个体的适应度 File ~\.conda\envs\python3.9\lib\site-packages\geatpy\Algorithm.py:209, in Algorithm.call_aimFunc(self, pop) 207 if self.problem is None: 208 raise RuntimeError('error: problem has not been initialized. (算法类中的问题对象未被初始化。)') --> 209 self.problem.evaluation(pop) # 调用问题类的evaluation() 210 self.evalsNum = self.evalsNum + pop.sizes if self.evalsNum is not None else pop.sizes # 更新评价次数 211 # 格式检查 File ~\.conda\envs\python3.9\lib\site-packages\geatpy\Problem.py:218, in Problem.evaluation(self, pop) 216 evalVarsCallFlag = True 217 if evalVarsCallFlag: --> 218 return_object = self.evalVars(pop.Phen) 219 if type(return_object) != tuple: 220 pop.ObjV = return_object Cell In[13], line 60, in MyProblem.evalVars(self, X) 54 svr_tg = SVR(kernel = 'poly' 55 , C = param_svr[tar_name[0]][0] 56 , gamma = param_svr[tar_name[0]][1] 57 , epsilon = param_svr[tar_name[0]][2] 58 ).fit(chara_scal, vd_scal.iloc[:,0]) 59 pre_tg = np.round(svr_tg.predict(x_pred_scal), 2).reshape(-1,1) ---> 60 scal_tg = tg_scal.inverse_transform(pre_tg) 62 svr_tem = SVR(kernel = 'poly' 63 , C = param_svr[tar_name[1]][0] 64 , gamma = param_svr[tar_name[1]][1] 65 , epsilon = param_svr[tar_name[1]][2] 66 ).fit(chara_scal, vd_scal.iloc[:,1]) 67 pre_tem = np.round(svr_tem.predict(x_pred_scal), 2).reshape(-1,1) File ~\.conda\envs\python3.9\lib\site-packages\sklearn\preprocessing\_data.py:1107, in StandardScaler.inverse_transform(self, X, copy) 1105 else: 1106 if self.with_std: -> 1107 X *= self.scale_ 1108 if self.with_mean: 1109 X += self.mean_ ValueError: non-broadcastable output operand with shape (500,1) doesn't match the broadcast shape (500,28)
最新发布
03-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值