RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-422389

Stanley's questions

Martin Hope
Stan
Asked: 2024-05-16 16:32:46 +0000 UTC

绘制矢量化数据的 Logistic 回归图

  • 5

大家好。我使用不同的分类方法(例如朴素贝叶斯、对数回归)解决了垃圾邮件识别问题,从而测试哪种方法效果更好。

问题:我似乎无法绘制逻辑回归图。

完整代码。数据集取自 Kaggle。

进步:

  1. 我读取了文件并进行了数据清理。
  2. 由于数据是文本形式,所以我做了文本向量化和LabelEncoding。
  3. 我应用了对数回归函数。
  4. 我画了这样的图表:
y_pred = y_pred.squeeze()
y_prob = model.predict_proba(X_test_vectorized)

# Plot scatter plot
sns.scatterplot(x= range(len(y_pred)), y=y_pred, hue= Y_test)
plt.figure()
sns.scatterplot(x = range(len(y_pred)), y = y_prob[:,1], hue = Y_test)
plt.xlabel('Text Feature')
plt.ylabel('Predicted')
plt.legend()
plt.show()

在此输入图像描述 在此输入图像描述

python
  • 1 个回答
  • 35 Views
Martin Hope
Stan
Asked: 2024-04-14 08:10:23 +0000 UTC

使用 interpolate() 和 Mean() 函数消除 NaN 变量的问题

  • 5

通常,在执行任何数据分析任务之前,您需要验证数据。有必要防止数据集中缺少数值。为此,我使用求平均值和插值的函数。但在每种情况下我都会遇到一个问题。
当data1.mean(axis=1)我收到 TypeError: unsupported operand type(s) for +: 'int' and 'str' 时。
当data1.interpolate(method ='linear', axis = 1)我收到 TypeError: Cannot interpolate with all object-dtype columns in the DataFrame 时。尝试将至少一列设置为数字数据类型。

我尝试了不同的选项来纠正这种情况,例如,我使用 to_numeric 函数将 str 值转换为 int,但这种方式出现了越来越多的问题(神奇地出现了更多 NaN 值)。与 相同astype(int)。

数据集。这里NaN值为“-”。
在此输入图像描述

你如何解决这个问题?

pandas
  • 1 个回答
  • 32 Views
Martin Hope
Stan
Asked: 2024-03-27 05:55:01 +0000 UTC

使用KNN分类算法进行天气预报

  • 5

预测问题是一个相当耗费人力的问题,可以通过多种方式解决。我决定利用机器学习技术并在我的代码中使用 K 最近邻算法 。

训练模型后,其准确率约为 87%(不错)。在模型测试期间,我进行了标准化并输入了天气所依赖的数据。如果我理解正确的话,我应该得到天气的结果,但是我得到了array(2023)。我不明白出了什么问题。

请告诉我,如果可能的话,请批评问题本身解决方案的实施。

我从这里获取了天气数据。

машинное-обучение
  • 1 个回答
  • 20 Views
Martin Hope
Stan
Asked: 2024-02-06 23:36:38 +0000 UTC

时间序列的移动平均函数

  • 5

为了解决这个问题,我看了一篇关于时间序列的文章 。为了发现异常情况,我首先选择了本文中概述的移动平均函数。

部分数据集:
时间,dB
0.-117
0.0001.46
0.0002.-478
0.000300001.2
..........
59.9998.-208
59.9999.-95
60.-169
I首先读取文件

df = pd.read_csv("data.csv", sep=',')  
df.columns = ['Time, seconds', 'Series values, dB']

选项

我编写了一个函数来根据数据集数据绘制图表:

def plotMovingAverage(series, n):  
    rolling_mean = series.rolling(window=n).mean()  

    plt.figure(figsize=(15,5))  
    plt.title("Moving average\n window size = {}".format(n))  
    plt.plot(rolling_mean, "g", label="Rolling mean trend")  
    plt.plot(series[n:], label="Actual values")  
    plt.legend(loc="upper left")  
    plt.grid(True)  

然后调用这个函数:

plotMovingAverage(df, 60) #60 секунд 
plt.show()  

结果是这样的图表 日程

问题:
但是这个图表达了值和行数(600000)之间的关系,我需要一个时间值图。图中也不可能突出显示移动平均线本身。请告知我该怎么做?在这种情况下编写此函数的正确方法是什么?

python
  • 2 个回答
  • 73 Views
Martin Hope
Stan
Asked: 2024-02-06 04:29:41 +0000 UTC

2 列中的数字分布。熊猫

  • 6

有一个 csv 文件,其中的数字以“,”分隔,所有这些数字都在一列中。为了方便进一步的工作,我想把它分成2个单独的列。但我就是不知道该怎么做。对于字符串来说很简单,需要使用.str.split(',')机制,但是如果所有值都是数字怎么办?

我已经尝试使用众所周知的方案将所有数字转换为字符串,但在我看来有更好的选择。

示例数据:
“时间,秒”,“系列值,dB”
0,-117
0.0001,46
0.0002,-478
0.000300001,2
0.000400001,4
0.000500001,-218
0.000600001,-322

我已经尝试了很多事情。你能帮我吗?

python
  • 2 个回答
  • 33 Views
Martin Hope
Stan
Asked: 2023-09-10 20:27:04 +0000 UTC

我无法将网站部署到 Vercel

  • 5

我只是无法部署我的 html项目。虽然我似乎已经写下了必要的vercel.jsonand package.json,但它仍然显示错误

404: NOT_FOUND
Code: NOT_FOUND
ID: arn1::2fj29-1694347415771-1a9a2d0aaae6

如果您熟悉 Vercel 并且知道错误在哪里,请告诉我出了什么问题。
Vercel.json:

{
  "builds": [
    {
      "src": "Space.mp4",
      "use": "@now/static"
    },
    {
      "src": "fotka.PNG",
      "use": "@now/static"
    },
    {
      "src": "style.css",
      "use": "@now/node"
    },
    {
      "src": "chart.js",
      "use": "@now/node"
    },
    {
      "src": "map.js",
      "use": "@now/node"
    },
    {
      "src": "index.html",
      "use": "@now/static"
    }
  ]
}
frontend
  • 1 个回答
  • 19 Views
Martin Hope
Trevi
Asked: 2022-12-13 22:02:50 +0000 UTC

计算一个点的多项式

  • 5

我正在编写一个程序来计算一个点的多项式。我使用霍纳的方案。像往常一样,我分配内存。在分配内存的时候,除了构造函数,我把析构函数和赋值运算符写出来,还使用引用来避免创建对象的副本。一切似乎都是合法的。但最后程序输出 free(): invalid pointer。大概又错过了什么。你能告诉我哪里出了问题吗?

#include<iostream>
using namespace std;

class Polynom{
int x, n, *data, result; 
public:
Polynom(){
    x = 0; n = 0;
    }
Polynom(int N, int X){
    n = N;
    x = X;
    data = new int[n];
    }
    
~Polynom(){
    delete[] data;
    }

void scan(){
    
    cout << "Input coeff:"<<endl;
    for(int i = 0; i < n; i++){
        cin >> data[i];
    } 
}

void print(){
        cout << result;
}

Polynom &operator =(const Polynom &ob){
    if(this == &ob) return *this;
    
    if(data) delete[] data;
    
    n = ob.n;
    x = ob.x;
    
    data = new int[n];
    for(int i = 0; i < n; i++)
        data[i] = ob.data[i];

    return *this;
}

int poli(){
    result = data[0];
    
    for(int i = n-1; i > 0; i--){
        result=result*x + data[i];
    }
    return result;
}

friend Polynom operator -=(const Polynom &ob1, const Polynom &ob2);
};
/*Polynom operator -=(const Polynom &ob1, const Polynom &ob2){
    Polynom temp;
    ob1.data[i] -= ob2.data[i];
    return temp;    
}
*/

int main(){
    int n, x;
    cout << "Input n and x:";
    cin >> n >> x;
    
    Polynom ob1(n,x), ob2;
    ob1.scan();
    ob1.poli();
}
c++
  • 1 个回答
  • 27 Views
Martin Hope
Stanley
Asked: 2022-09-27 02:41:06 +0000 UTC

折线自相交

  • 3

在写这个问题之前,我读了一篇类似于 SO 的文章,但我有兴趣了解我的问题到底是什么。

我正在编写代码来确定折线是否自相交。
如果多段线的至少两个链接相交(在它们的内部点),则称为自相交。
首先,我编写了一个函数来确定两个相交线段的交点。在那里我使用学校直线公式y = kx + b。

然后是函数 f,在这里我检查 2 个线段的每 2 个点是否相交。原则上,一切正常,但是当折线的某些部分不完全相交时,代码会中断,而只是“接触”该折线的其他部分。例如,在测试中: 测试:

4   
0 0   
2 2   
2 1   
1 1  

编码:

#include <iostream>
#include <fstream>
using namespace std;

ifstream fin("input.txt");
ofstream fout("output.txt");

class peresec{
    public:
        double x,y;
};

int intersect(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
{
    double k1, k2, b1, b2, x, y, tmp;

    if(x1>=x2) {tmp=x1; x1=x2; x2=tmp; tmp=y1; y1=y2; y2=tmp;}
    if(x3>=x4) {tmp=x3; x3=x4; x4=tmp; tmp=y3; y3=y4; y4=tmp;}

    if(y1==y2) k1=0; else k1 =  ( y2 - y1 ) / ( x2 - x1 );
    if(y3==y4) k2=0; else k2 =  ( y4 - y3 ) / ( x4 - x3 );
    if(k1 == k2) return 0;
   
    b1=y1-k1*x1;
    b2=y3-k2*x3;

    x = (b2-b1)/(k1-k2);
    y = k1*x + b1;

    if(x1<=x && x3<=x && x2>=x && x4>=x && !((x==x1 && y==y1) || (x==x2 && y==y2) || (x==x3 && y==y3) || (x==x4 && y==y4)))
        {return 1;}
    else
        return 0;
}

void f(peresec *a, int n)
{
    int flag;

    for (int i=0; i<n; i++)
        for (int j=0; j<n; j++)
        {
            flag=intersect(a[i].x, a[i].y, a[(i + 1) % n].x, a[(i + 1) % n].y, a[j].x, a[j].y, a[(j + 1) % n].x, a[(j + 1) % n].y);
            if(flag==1) {fout << 1; return;}
        }
    if(flag == 0){fout << 0; return;}
}

int main()
{
    long long count;
    peresec *a;
     if( !(fin >> count)){fout<<0; return 0;}
     fin.seekg(0);
    
    
     fin >> count;
     if(count == 0) {fout<<0; return 0;}
    
     a = new peresec[count];
    for(int  i = 0; i < count; i++){ fin >> a[i].x; fin >> a[i].y;}

    f(a,count);

    return 0;
}

此外,在这段代码遇到故障后,我决定更改 intersect 函数的逻辑并执行以下操作:

bool intersect(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
{
    double v1, v2, v3, v4;
    v1=(x4-x3)*(y1-y3)-(y4-y3)*(x1-x3);
    v2=(x4-x3)*(y2-y3)-(y4-y3)*(x2-x3);
    v3=(x2-x1)*(y3-y1)-(y2-y1)*(x3-x1);
    v4=(x2-x1)*(y4-y1)-(y2-y1)*(x4-x1);
    if((v1*v2<0) && (v3*v4<0)) return true;
    else return false;
}

但即使在这里,代码也会在这个测试中中断。应该显示 1,否则显示 0。因为如果交叉,应该显示 1。

问题很可能出在函数的循环中f以及我经过哪些顶点。我已经尝试了一切。

你能解释为什么代码会中断吗???

c++
  • 1 个回答
  • 110 Views
Martin Hope
Stanley
Asked: 2022-09-21 16:17:28 +0000 UTC

检查文件是否为空 C++

  • -4

我解决了确定数组对称性的问题,或者换句话说,它是否是一个多项式。如果是对称的,那么我输出1,否则输出0。首先在文件中输入数组元素的个数,然后只有一个数字序列。

问题是没有办法正确检查文件是否为空。如果文件完全为空,则输出 0。

我已经使用了两者if(!(fin >> number)) fout << 0;和if(fin.tellg() == 0)其他。
但在这种情况下,答案是不正确的。即使我在文件中输入了对称的数字序列,它也会输出 0。

建议点别的。

#include <iostream>
#include <fstream>
using namespace std;

bool symmetry(int array[], int begin, int end){
    {
        return (begin >= end) || ((array[begin] == array[end]) && (symmetry(array, begin + 1, end - 1)));
    }
    return 0;
}

int main(){
    ifstream fin("input.txt");
    ofstream fout("output.txt");
    int number, count = 0, size, a = 0;
        
    if(!(fin >> number)) {fout << 0; return 0;} //проверка на пустоту

    while(fin >> number){a++;}
    fin.clear();
    fin.seekg(0, ios::beg);
        
    fin >> number;
    size = number;
    int array[size];
    if (size == 0){fout << 0; return 0;}
    
    if(size <= (a-1)){
    for(int i = 0; i < size; i++) {fin >> number; array[count++] = number;}
    }
    else{
    for(int i = 0; i < a-1; i++) {fin >> number; array[count++] = number;}
    }
    
    for(int i = 0; i < count; i++){cout << array[i];}

    if(symmetry(array, 0, count-1) == true) fout<< 1;
    else fout<< 0;
    
    fin.close();
    fout.close();
    return 0;
}
c++
  • 0 个回答
  • 0 Views
Martin Hope
Stanley
Asked: 2022-09-11 07:17:06 +0000 UTC

100 数字系统和程序中存在的错误

  • 0

有段时间我一直在为班级解题,这次解了一个关于100进制数的问题,这个问题完全解决了,所有的测试都通过了。

但据说节目中有一些“失误”。一些发现,纠正。但还有更多。尽管该程序可以运行,但我认为没有任何原因会导致内存泄漏或其他问题。赋值运算符,似乎写得对,在运算符的重载中我写的不是对象作为参数,而是它的地址,所以最终没有创建对象的副本,没有泄漏,复制构造函数不需要,我就不写了。析构函数已编写。

我不明白会有什么样的失误。它似乎一直在正常学习课程。如果你知道,我们来讨论。

#include <iostream>
#include <cmath>
using namespace std;


class Sto{

    int *data;
    int size, sign;
    public:
    
    Sto(int asize)
    { 
        size=asize; 
        data = new int[size];
        sign=1;
    }
    
    ~Sto()
    {
        delete[] data;
        size = sign = 0;
    }
        
    Sto& operator=(const Sto& ob)
        {
            
            if (this == &ob)
            return *this;
            
            if (data) delete[] data;
            
            size=ob.size;
            sign=ob.sign;
            
            data=new int[size]; 
            for(int i=0;i<size;i++)
            data[i]=ob.data[i];
    
            return *this;
        }
        
    friend Sto operator+(const Sto &x, const Sto &y);
    friend Sto operator*(const Sto &x, const int &chislo);
            
    void scan()
    {   
        int x_p=0;
        cout<<"Vvedite "<<size<<" cifri\n";

        for(int i=0; i<size; i++)
            cin>>*(data+i);

        while(data[x_p]==0) x_p++; 

        sign = (data[x_p] > 0) - (data[x_p] < 0);
        data[x_p]=abs(data[x_p]);
    }
        
    void print(){
        int x_p=0;
        while(data[x_p]==0) x_p++; 

        cout<<sign*data[x_p]<<" ";
        for(int i=x_p+1; i<size; i++) 
            cout<<data[i]<<" ";
    }
};

Sto operator+(const Sto &x, const Sto &y)
{
    Sto z(max(x.size,y.size)+1);
    int x_i=x.size-1, y_i=y.size-1, z_i=z.size-1, tmp1=0, tmp2=0, major=1, x_p=0, y_p=0;
    
    while(x.data[x_p]==0) x_p++; 
    while(y.data[y_p]==0) y_p++; 
    
    if(x.sign!=y.sign && x.size - x_p <= y.size - y_p)
    {
        if(x.size - x_p < y.size - y_p) major = -1;
        else
        {
            for(int i=x_p, j=y_p; i<x.size; i++, j++) 
                if(x.data[i] < y.data[j]) { major = -1; break; }
        }
    }

    if(x.sign == y.sign && x.sign==-1 || x.sign==-1 && major==1 || y.sign==-1 && major==-1) z.sign=-1;

    while(z_i>=0)
    {
        tmp1 = 0; z.data[z_i] =0;
        
        if(x_i>=x_p) z.data[z_i] += major * x.data[x_i];
        if(y_i>=y_p) z.data[z_i] += major * (x.sign * y.sign) * y.data[y_i];
    
        if(x.sign==y.sign)
        {
            if(y_i>=y_p-1 && y_i<y.size-1) tmp1 += y.data[y_i+1];
            if(x_i>=x_p-1 && x_i<x.size-1) tmp1 += x.data[x_i+1];
            z.data[z_i]+= tmp1/100;
    
            if(z_i==1 && z.data[1]>=100) 
                z.data[0] = z.data[1]/100;
            z.data[z_i] %=100;          
        }
        else
        {
            z.data[z_i]-=tmp2;  
            if(z.data[z_i] < 0) {z.data[z_i]+=100; tmp2 = 1;} else tmp2=0;
        }
    
        x_i--; y_i--; z_i--;
    }   
    
return z;
}

Sto operator*(const Sto &x, const int &chislo)
{

    Sto z(x.size + 1 + log(abs(chislo))/log(100) + 1);
    int x_i=x.size-1, z_i=z.size-1, temp=0, x_p=0;
    
    z.sign=1; if(x.sign * chislo < 0) z.sign=-1;
    
    while(x.data[x_p]==0) x_p++; 
    
    while(z_i>=0)
    {
        z.data[z_i] = temp;
        if(x_i>=x_p) z.data[z_i] += x.data[x_i]*abs(chislo);
    
        temp = z.data[z_i]/100;
        z.data[z_i] = z.data[z_i]%100;
        
        x_i--; z_i--;
    }
    
return z;
}

int main()
{
    int size_x, size_y, number;
    
    cout<<"Vvedite razmer 1-go massiva"<<endl;
    cin>>size_x;
    Sto ob1(size_x);
    ob1.scan();
    
    cout<<"\nVvedite razmer 2-go massiva"<<endl;
    cin>>size_y;
    Sto ob2(size_y);
    ob2.scan();
    
    Sto ob3(max(size_x,size_y)+1);
    ob3 = ob1 + ob2;

    cout<<"\nVvedite konstantu"<<endl;
    cin>>number;

    Sto ob4(size_x + 1 + log(abs(number))/log(100)+1);
    ob4 = ob1 * number;
    
    cout<<"\nSlojeniye dvux storichnix chisel: "; ob3.print();
    cout<<"\nUmnojeniye ob1 na konstantu: "; ob4.print();
    
return 0;
}
c++
  • 0 个回答
  • 0 Views
Martin Hope
Stanley
Asked: 2022-08-19 03:45:19 +0000 UTC

C ++中的复制和交换习语

  • 0

这不是我第一次提出关于折线问题的问题。这次我想在我的代码中讨论“C++ 中的复制和交换成语”。如果您有兴趣,可以在此处阅读问题说明。

因此,在我的代码中,我实现了 Copy-and-Swap 习惯用法:

void swap(Loman& a) {
        std::swap(size, a.size);
        std::swap(data, a.data);
    }
 
    Loman& operator=(const Loman& a)
    {
            Loman tmp(a);
            swap(tmp);
        return *this;
    }

但在我看来,这段代码中有一个逻辑错字,实际上应该这样写:

void swap(Loman& first, Loman& second) {
        std::swap(first.size, second.size);
        std::swap(first.data, second.data);
    }
 
    Loman& operator=(const Loman& a)
    {
            Loman tmp(a);
            swap(*this, tmp);
        return *this;
    }

在我看来, + 运算符中还有一个不必要的操作this-> size = size。如果我删除它,什么都不会改变。

这是整个代码:

#include <iostream>
using namespace std;
class Loman
{
private:
    int i=0;
    int size;
    int* data;
public:
    Loman(int asize) {
        size = 2*asize;
        data = new int[size];
    }
    ~Loman(){
        delete[] data;
        cout<<"Object destroyed\n";
    }
    Loman(const Loman &ob)
    {
        size = ob.size;
        data = new int [size];
        for(int i=0; i<ob.size; i++)
            data[i] = ob.data[i];
    }
    void print(){
        for(i=0; i<size; i++){
            cout<<*(data+i)<<" ";
        }
        cout<<endl;
    }
 
    void scan(){
        cout<<"Input "<<size/2<<" coordinates\n";
        for(int i=0; i<size; i++){
            cin>>*(data+i);
        }
    }
    Loman operator+(Loman& ob){
        this->size = size;
        Loman tmp((size + ob.size)/2);
        for(i=0; i<size; i++)
        {
            tmp.data[i]=*(data + i);//this->data[i]=data[i];
        }
        for(i=size; i<size + ob.size; i++) tmp.data[i] = ob.data[i-size];
        return tmp;
    }
    void swap(Loman& a) {
        std::swap(size, a.size);
        std::swap(data, a.data);
    }
 
    Loman& operator=(const Loman& a)
    {
            Loman tmp(a);
            swap(tmp);
        return *this;
    }
};
int main(){
    Loman first(3);
    Loman second(2);
    first.scan();
    second.scan();
    Loman third(5);
    third=first+second;
    third.print();
    return 0;
}

问题:我关于“+”运算符和交换函数的假设是否正确,如果不是,为什么不呢?
我错过了任何其他错误吗?
是否需要在swap函数中写using std::swap;

c++ классы
  • 1 个回答
  • 60 Views
Martin Hope
Stanley
Asked: 2022-09-08 16:12:09 +0000 UTC

“飞机上的折线”类

  • 0

问题的条件和陈述:平面上的折线由一系列坐标对给出,这些坐标确定了该折线的点在坐标平面上的位置。对于两条折线,求和 - 一条折线,依次由第一条折线和第二条折线的点组成。在几何上,这可以通过将第一条折线的最后一点和第二条折线的第一点用线段连接起来来表示。编写类“平面上的折线”和算子“折线之和”;

作为代码,我执行了以下操作:输入 2 个任意长度的数组,然后通过重载“+”运算符将它们组合起来。但是,出现错误“在 tcache 2 中检测到双重释放”。

#include <iostream>
using namespace std;
int i=0;
class Array
{
private:
    int size;
   unsigned int* data;
public:
// конструктор
    Array(){}
    Array(int asize) {
        size=asize;
        data=(unsigned int*)new int[size];
        if(data) cout<<"Massiv inicializir\n";
        else cout<<"ne hvatka pamiati\n";
    }
~Array(){
    delete[] data;
    cout<<"Object uni4tojen\n";
}
        //Далее методы
Array(const Array &ob)   //Определение конструктора //копирования
{                           
 size=ob.size;
 data=(unsigned int*)new int [size];
 for(int i=0;i<ob.size;i++)
  data[i]=ob.data[i];
}
void print(){
    for(i=0;i<size;i++){
    cout<<*(data+i)<<" ";
}
cout<<endl;
}

void scan(){
cout<<"Vvedite massiv iz:"<<size<<"simvolov \n";
for(int i=0;i<size;i++){
cin>>*(data+i);
}
}
Array operator+(const Array& ob){
    this->size=size;
    Array tmp(size+ob.size);
    for(i=0;i<size;i++) 
    {
        tmp.data[i]=*(data+i);//this->data[i]=data[i];
    }
    for(i=size;i<size+ob.size;i++) tmp.data[i]=ob.data[i-size];
 return tmp;
}
};
int main(){
    Array first(3);
    Array second(2);
    first.scan();
    second.scan();
    Array third(5);
    third=first+second;
    third.print();
 return 0;
}

请解释为什么会发生这个错误(很可能是由于分配了额外的内存)以及如何修复它。谢谢你。

对了,我之前问了一个关于Lomanaya的问题,条件一样,但是代码不适合,所以我决定单独问这个问题,但是用我需要的代码。

c++
  • 1 个回答
  • 71 Views
Martin Hope
Stanley
Asked: 2022-05-07 03:09:31 +0000 UTC

2 路队列。(12 月)

  • 2

我正在研究数据结构,遇到了一篇名为Deque Data Structure的文章。
本文附上甲板的实现和理论。
我主要写优点,一时不太清楚,即getRear()函数;

int Deque::getRear() {
  if (isEmpty() || rear < 0) {
    cout << " Deque is Empty"<< endl;
    return -1;
  }
  return *(arr+rear);
}

问题到底是什么?
1.不明白为什么在这个函数中,检查空的时候,rear<0被赋值,没有它可以吗?
原则上,大致上,我理解为什么会这样,但是如果你从另一边看, 为什么不在构造函数中立即属性rear = -1,而不是0?
我还可以参考 DeleteRear(); 函数,其中当最后一个元素被删除时,rear=-1 和 front=-1。但是我很困惑,有时,在我的判断中,最好听听别人的意见。

c++
  • 1 个回答
  • 10 Views
Martin Hope
Stanley
Asked: 2022-08-23 17:31:57 +0000 UTC

E-Olymp 的问题:Function-3 [关闭]

  • -2
关闭 这个问题是题外话。目前不接受回复。

寻求调试帮助的问题(“为什么这段代码不起作用? ”)应该包括期望的行为、具体的问题或错误,以及在问题中重现它的最少代码。没有明确描述问题的问题对其他访问者毫无用处。请参阅如何创建一个最小的、独立的和可重现的示例。

1 年前关闭。

改进问题

链接到任务。原则上,我为这个任务写了一个程序,但是有一个条件,你需要为每个测试在单独的行中显示函数的值。而我只有1个测试和1个值=程序不接受。如何正确书写,以使一切根据条件为真?

#include <stdio.h>
#include <math.h>
double f(double x,double y){
return x*x +sin(x*y)-y*y;
}
int main()
{
double x,y;
scanf("%lf %lf",&x,&y);
f(x,y);
printf("%.4lf",f(x,y));
return 0;
}
c
  • 1 个回答
  • 10 Views
Martin Hope
Stanley
Asked: 2022-08-13 00:15:59 +0000 UTC

E-Olymp:多边形区域

  • 1

问题链接 我用梯形公式解决了这个问题,但是有些测试是不正确的,我不知道错误在哪里。

#include <stdio.h>  
#define MAX 1002  
int x[MAX], y[MAX],n;  
double findArea(int *x, int *y)  
{  
double s = 0;  
x[n] = x[0]; y[n] = y[0];  
for(int i = 0; i < n; i++)  
s += (y[i+1] + y[i]) * (x[i+1] - x[i])/2.0;  
return (s < 0) ? -s : s;  
}  
int main(void){  
scanf("%d",&n);  
for(int i = 0; i < n; i++){  
scanf("%d %d",&x[i],&y[i]);}  
printf("%.3lf\n",findArea(x,y));  
}  
c++
  • 2 个回答
  • 10 Views
Martin Hope
Stanley
Asked: 2022-07-03 11:50:38 +0000 UTC

E-Olymp 的问题:金字塔的面积和体积

  • 1

任务链接

#include <stdio.h>  
#include <math.h>  
int main(void)  
{  
float p,d,H,h,S,V;  
scanf("%f %f",&d,&p);  
S=d*d + 2*d*sqrt(p*p-(d*d)/4);  
H=sqrt(p*p - (d*d)/2);  
V=d*d*H/3;  
printf("%.3f %.3f",S,V);  
}  

查了很多遍,都没有发现错误,求助!

c
  • 2 个回答
  • 10 Views
Martin Hope
Stanley
Asked: 2022-06-05 23:55:38 +0000 UTC

E-Olymp 的问题:购买光盘的最低金额

  • 3

任务条件:

空白 CD 以三种类型的包装出售。一包 100 个光盘的价格为 100 UAH,20 个光盘的价格为 30 UAH,一张光盘的价格为 2 UAH。购买 n 个这样的光盘需要花费的最低金额是多少?

似乎任务已解决,测试执行正确,但 e-olymp 不算 100%。问题是什么?

#include <stdio.h>

int main(void) {
    int n;
    scanf("%d", &n);
    printf("%d",( n / 100 * 100 ) + ( n % 100 / 20 * 30 ) + ( n % 100 % 20 * 2));
    return 0;
}
c++
  • 1 个回答
  • 10 Views
Martin Hope
Stanley
Asked: 2022-05-10 19:07:34 +0000 UTC

简单的几何拼图

  • 0

这个任务来自E-Olymp.https://www.e-olymp.com/ru/problems/924
原则上我什么都做了,但是程序运行不正常。对于任何值,它一直显示1,尽管事实上,所有必要的东西都已经写好了(在我看来)。我不明白错误在哪里。

#include"stdio.h"   
#include"stdlib.h"  
#include"math.h" 
 
int main(){   
    float Skol,R,r;   
    scanf("%f",&Skol);
    scanf("%f",&R);  
    r=pow(R*R- Skol/M_PI,1/2);  
    printf("%.2f\n",r);  
    return 0;   
}   
c++
  • 1 个回答
  • 10 Views
Martin Hope
Stanley
Asked: 2022-05-05 12:23:51 +0000 UTC

Hermite 三次样条

  • 1

我无法理解表达式 3.23。更准确地说,它来自哪里?他是怎么被带出来的?这样做的原因是什么?你如何证明它的合理性?可以看出这里用到了微分,Pf这个数列我有些熟悉,但我不能肯定。请帮帮我。 在此处输入图像描述

математика
  • 1 个回答
  • 10 Views
Martin Hope
Stanley
Asked: 2022-05-03 03:02:50 +0000 UTC

线性回归

  • 1

我有一个关于第 3.26 段的问题,这个问题有最低限度吗?如果是这样,它是唯一的吗?由于线性回归包括y = ax + b形式的方程,这是直线方程。直线没有最小值,但不知道我的问题的确切证明,我不敢马上回答。我觉得还是听听更有经验的程序员——数学家的意见比较好。
在此处输入图像描述

математика
  • 1 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5