problem 1170

    好简单!不用调就OK了,要是每题都不用调就好了。。。。。。
Accepted1170C00:00.00388K
#include<stdio.h>
#include
<string.h>
char str1[20],str2[20 ];
int gcd(int a,int
 b)
{
    
if (b == 0)    return
 a;
    
else    gcd(b,a %
 b);
}
void
 solve()
{
    
int
 i,j,cnt;
    
int len1 =
 strlen(str1);
    
int len2 =
 strlen(str2);
    
int max = 0
;
    
for (i = 0; i < len1; i++
)
    {
        cnt 
= 0
;
        j 
=
 i;
        
while (j >= 0 && len2 - i - 1 + j >= 0
)
        {
            
if (str2[len2 - i - 1 + j] == str1[j])    cnt++
;
            j
--
;
        }
        
if (cnt > max)    max =
 cnt;
    }
    
for (i = 0; i < len2; i++
)
    {
        cnt 
= 0
;
        j 
=
 i;
        
while (j >= 0 && len1 - i - 1 + j >= 0
)
        {
            
if (str1[len1 - i - 1 + j] == str2[j])    cnt++
;
            j
--
;
        }
        
if (cnt > max)    max =
 cnt;
    }
    
if (max == 0) printf("0/n"
);
    
else if(2 * max % (len1 + len2) == 0
)
        printf(
"%d/n",2 * max / (len1 +
 len2));
    
else
 
    {
        
int temp = gcd(2 * max,len1 +
 len2);
        printf(
"%d/%d/n",2 * max / temp,(len1 + len2) /
 temp);
    }
    
}
void
 main()
{
#ifndef ONLINE_JUDGE
    freopen(
"1170.txt","r"
,stdin);
#endif

    
while(scanf("%s%s",str1,str2) != EOF && strcmp("-1",str1) != 0 )
    {
        printf(
"appx(%s,%s) = "
,str1,str2);
        solve();
    }
#ifndef ONLINE_JUDGE
    fclose(stdin);
#endif

}
D:\py\.venv\Scripts\python.exe D:\py\水风光储.py =============================================================================== CVXPY v1.6.5 =============================================================================== (CVXPY) May 14 06:31:42 PM: Your problem has 2 variables, 5 constraints, and 0 parameters. (CVXPY) May 14 06:31:42 PM: It is compliant with the following grammars: DCP, DQCP (CVXPY) May 14 06:31:42 PM: (If you need to solve this problem multiple times, but with different data, consider using parameters.) (CVXPY) May 14 06:31:42 PM: CVXPY will first compile your problem; then, it will invoke a numerical solver to obtain a solution. (CVXPY) May 14 06:31:42 PM: Your problem is compiled with the CPP canonicalization backend. Traceback (most recent call last): File "D:\py\水风光储.py", line 23, in <module> prob.solve(solver='GLPK_MI', verbose=True) ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\py\.venv\Lib\site-packages\cvxpy\problems\problem.py", line 600, in solve return solve_func(self, *args, **kwargs) File "D:\py\.venv\Lib\site-packages\cvxpy\problems\problem.py", line 1170, in _solve data, solving_chain, inverse_data = self.get_problem_data( ~~~~~~~~~~~~~~~~~~~~~^ solver, gp, enforce_dpp, ignore_dpp, verbose, canon_backend, kwargs ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "D:\py\.venv\Lib\site-packages\cvxpy\problems\problem.py", line 743, in get_problem_data solving_chain = self._construct_chain( solver=solver, gp=gp, ...<2 lines>... canon_backend=canon_backend, solver_opts=solver_opts) File "D:\py\.venv\Lib\site-packages\cvxpy\problems\problem.py", line 992, in _construct_chain candidate_solvers = self._find_candidate_solvers(solver=solver, gp=gp) File "D:\py\.venv\Lib\site-packages\cvxpy\problems\problem.py", line 855, in _find_candidate_solvers raise error.SolverError("The solver %s is not installed." % solver) cvxpy.error.SolverError: The solver GLPK_MI is not installed. 这个报错应该怎么解决
最新发布
05-15
我的代码如下 import numpy as np import cvxpy as cp n = int(input()) adjacent = np.array([list(map(float, input().split(','))) for _ in range(n)]) number = np.array([list(map(float, input().split(',')))]) neighborhoods = cp.Variable((n, 1), 'neighborhoods', integer=True) adjacent_neighborhoods = cp.Variable((1, n), 'adjacent_neighborhoods', integer=True) proxy_points = cp.multiply(cp.multiply(adjacent, neighborhoods), adjacent_neighborhoods) objective = cp.Maximize(cp.sum(cp.multiply(number, proxy_points)) + cp.sum(cp.multiply(number.T, proxy_points))) constraints = [ 0 <= neighborhoods, neighborhoods <= 1, 0 <= adjacent_neighborhoods, adjacent_neighborhoods <= 1, cp.sum(neighborhoods) == 2, cp.sum(adjacent_neighborhoods) >= 1, cp.sum(adjacent_neighborhoods) <= 2, cp.sum(proxy_points) == 2 ] problem = cp.Problem(objective, constraints) problem.solve(solver='ECOS') print(int(round(objective.value))) 我的报错日志如下 "D:\develop\Python\Python 3.13.2\python.exe" D:\develop\Python\PythonProject\PythonLearning.py 7 0,1,1,0,0,0,0 0,0,1,1,1,0,0 0,0,0,1,0,0,0 0,0,0,0,1,1,1 0,0,0,0,0,1,0 0,0,0,0,0,0,1 0,0,0,0,0,0,0 34, 29, 42, 21, 56, 18, 71 Traceback (most recent call last): File "D:\develop\Python\PythonProject\PythonLearning.py", line 24, in <module> problem.solve(solver='ECOS') ~~~~~~~~~~~~~^^^^^^^^^^^^^^^ File "D:\develop\Python\Python 3.13.2\Lib\site-packages\cvxpy\problems\problem.py", line 600, in solve return solve_func(self, *args, **kwargs) File "D:\develop\Python\Python 3.13.2\Lib\site-packages\cvxpy\problems\problem.py", line 1170, in _solve data, solving_chain, inverse_data = self.get_problem_data( ~~~~~~~~~~~~~~~~~~~~~^ solver, gp, enforce_dpp, ignore_dpp, verbose, canon_backend, kwargs ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "D:\develop\Python\Python 3.13.2\Lib\site-packages\cvxpy\problems\problem.py", line 743, in get_problem_data solving_chain = self._construct_chain( solver=solver, gp=gp, ...<2 lines>... canon_backend=canon_backend, solver_opts=solver_opts) File "D:\develop\Python\Python 3.13.2\Lib\site-packages\cvxpy\problems\problem.py", line 992, in _construct_chain candidate_solvers = self._find_candidate_solvers(solver=solver, gp=gp) File "D:\develop\Python\Python 3.13.2\Lib\site-packages\cvxpy\problems\problem.py", line 908, in _find_candidate_solvers raise error.SolverError( ...<3 lines>... candidates['conic_solvers'])) cvxpy.error.SolverError: Problem is mixed-integer, but candidate QP/Conic solvers ([]) are not MIP-capable. 进程已结束,退出代码为 1 请你指出我的代码中的问题所在。
03-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值