# 0001, 2024-11-02 10:03:00, PPPPPPPPPP-----P-----P-- (50%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i;
string mode;
cin >> n >> mode;
float x[n],y[n];
for(i=0;i<n;i++)
{
cin >> x[i] >> y[i];
}
float m ,b , sumxy = 0 , sumx = 0 , sumy=0 , sumx2=0;
for(i=1;i<=n;i++)
{
sumxy += x[i-1]*y[i-1];
}
for(i=1;i<=n;i++)
{
sumx += x[i-1];
}
for(i=1;i<=n;i++)
{
sumy += y[i-1];
}
for(i=1;i<=n;i++)
{
sumx2 += pow(x[i-1],2);
}
m = ((n *sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
b = (sumy - m*sumx)/n;
if(mode == "mb")
{
cout << round(m*1e3)/1e3 <<endl<< round(b*1e3)/1e3;
}
else if(mode == "func")
{
if(m==0)
{
cout << "y = " << b;
}
else if(m != 0 && b==0)
{
cout << "y = " << m << 'x';
}
else if(m != 0 && b != 0)
{
cout << "y = " << m << x << " + " << b;
}
}
} | # 0002, 2024-11-02 10:10:39, PPPPPPPPPP-----PP----P-- (54%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i;
string mode;
cin >> n >> mode;
float x[n],y[n];
for(i=0;i<n;i++)
{
cin >> x[i] >> y[i];
}
float m ,b , sumxy = 0 , sumx = 0 , sumy=0 , sumx2=0;
for(i=1;i<=n;i++)
{
sumxy += x[i-1]*y[i-1];
}
for(i=1;i<=n;i++)
{
sumx += x[i-1];
}
for(i=1;i<=n;i++)
{
sumy += y[i-1];
}
for(i=1;i<=n;i++)
{
sumx2 += pow(x[i-1],2);
}
m = ((n *sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
b = (sumy - m*sumx)/n;
if(mode == "mb")
{
cout << round(m*1e3)/1e3 <<endl<< round(b*1e3)/1e3;
}
else if(mode == "func")
{
if(round(m*1e3)/1e3 == 0 || round(m*1e3)/1e3 == -0)
{
cout << "y = " << b;
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 == 0)
{
cout << "y = " << m << 'x';
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 != 0)
{
cout << "y = " << m << 'x' << " + " << b;
}
}
} | # 0003, 2024-11-02 10:13:33, PPPPPPPPPP-----PP-PP-P-- (62%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i;
string mode;
cin >> n >> mode;
float x[n],y[n];
for(i=0;i<n;i++)
{
cin >> x[i] >> y[i];
}
float m ,b , sumxy = 0 , sumx = 0 , sumy=0 , sumx2=0;
for(i=1;i<=n;i++)
{
sumxy += x[i-1]*y[i-1];
}
for(i=1;i<=n;i++)
{
sumx += x[i-1];
}
for(i=1;i<=n;i++)
{
sumy += y[i-1];
}
for(i=1;i<=n;i++)
{
sumx2 += pow(x[i-1],2);
}
m = ((n *sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
b = (sumy - m*sumx)/n;
if(mode == "mb")
{
cout << round(m*1e3)/1e3 <<endl<< round(b*1e3)/1e3;
}
else if(mode == "func")
{
if(round(m*1e3)/1e3 == 0 || round(m*1e3)/1e3 == -0)
{
cout << "y = " << b;
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 == 0)
{
if(round(m*1e3)/1e3 == 1)cout << "y = x";
else if(round(m*1e3)/1e3 == -1)cout << "y = -x";
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3;
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 != 0)
{
cout << "y = " << m << 'x' << " + " << b;
}
}
} | # 0004, 2024-11-02 10:16:47, PPPPPPPPPP-----PPPPPPPPP (79%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i;
string mode;
cin >> n >> mode;
float x[n],y[n];
for(i=0;i<n;i++)
{
cin >> x[i] >> y[i];
}
float m ,b , sumxy = 0 , sumx = 0 , sumy=0 , sumx2=0;
for(i=1;i<=n;i++)
{
sumxy += x[i-1]*y[i-1];
}
for(i=1;i<=n;i++)
{
sumx += x[i-1];
}
for(i=1;i<=n;i++)
{
sumy += y[i-1];
}
for(i=1;i<=n;i++)
{
sumx2 += pow(x[i-1],2);
}
m = ((n *sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
b = (sumy - m*sumx)/n;
if(mode == "mb")
{
cout << round(m*1e3)/1e3 <<endl<< round(b*1e3)/1e3;
}
else if(mode == "func")
{
if(round(m*1e3)/1e3 == 0 || round(m*1e3)/1e3 == -0)
{
cout << "y = " << b;
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 == 0)
{
if(round(m*1e3)/1e3 == 1)cout << "y = x";
else if(round(m*1e3)/1e3 == -1)cout << "y = -x";
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3;
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 != 0)
{
if(round(b*1e3)/1e3 < 0)
{
if(round(m*1e3)/1e3 == 1)cout << "y = x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 << " - " << abs(round(b*1e3)/1e3);
}
else
{
if(round(m*1e3)/1e3 == 1)cout << "y = x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 << " + " << abs(round(b*1e3)/1e3);
}
}
}
} | # 0005, 2024-11-02 10:21:27, PPPPPPPPPP-----PPPPPPPPP (79%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i;
string mode;
cin >> n >> mode;
float x[n],y[n];
for(i=0;i<n;i++)
{
cin >> x[i] >> y[i];
}
float m ,b , sumxy = 0 , sumx = 0 , sumy=0 , sumx2=0;
for(i=1;i<=n;i++)
{
sumxy += x[i-1]*y[i-1];
}
for(i=1;i<=n;i++)
{
sumx += x[i-1];
}
for(i=1;i<=n;i++)
{
sumy += y[i-1];
}
for(i=1;i<=n;i++)
{
sumx2 += pow(x[i-1],2);
}
m = ((n *sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
b = (sumy - m*sumx)/n;
if(mode == "mb")
{
cout << round(m*1e3)/1e3 <<endl<< round(b*1e3)/1e3;
}
else if(mode == "func")
{
if(round(m*1e3)/1e3 == 0 || round(m*1e3)/1e3 == -0)
{
cout << "y = " << b;
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 == 0)
{
if(round(m*1e3)/1e3 == 1)cout << "y = x";
else if(round(m*1e3)/1e3 == -1)cout << "y = -x";
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3;
else cout << "y = " << round(m*1e3)/1e3 << 'x';
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 != 0)
{
if(round(b*1e3)/1e3 < 0)
{
if(round(m*1e3)/1e3 == 1)cout << "y = x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 << " - " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3 << " - " << round(b*1e3)/1e3;
}
else
{
if(round(m*1e3)/1e3 == 1)cout << "y = x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 << " + " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3 << " + " << round(b*1e3)/1e3;
}
}
}
} | # 0006, 2024-11-02 10:22:26, PPPPPPPPPP-----PPPPPPPPP (79%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i;
string mode;
cin >> n >> mode;
float x[n],y[n];
for(i=0;i<n;i++)
{
cin >> x[i] >> y[i];
}
float m ,b , sumxy = 0 , sumx = 0 , sumy=0 , sumx2=0;
for(i=1;i<=n;i++)
{
sumxy += x[i-1]*y[i-1];
}
for(i=1;i<=n;i++)
{
sumx += x[i-1];
}
for(i=1;i<=n;i++)
{
sumy += y[i-1];
}
for(i=1;i<=n;i++)
{
sumx2 += pow(x[i-1],2);
}
m = ((n *sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
b = (sumy - m*sumx)/n;
if(mode == "mb")
{
cout << round(m*1e3)/1e3 <<endl<< round(b*1e3)/1e3;
}
else if(mode == "func")
{
if(round(m*1e3)/1e3 == 0 || round(m*1e3)/1e3 == -0)
{
cout << "y = " << b;
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 == 0)
{
if(round(m*1e3)/1e3 == 1)cout << "y = x";
else if(round(m*1e3)/1e3 == -1)cout << "y = -x";
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3;
else cout << "y = " << round(m*1e3)/1e3 << 'x';
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 != 0)
{
if(round(b*1e3)/1e3 < 0)
{
if(round(m*1e3)/1e3 == 1)cout << "y = x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 << " - " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3 << " - " << abs(round(b*1e3)/1e3);
}
else
{
if(round(m*1e3)/1e3 == 1)cout << "y = x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 << " + " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3 << " + " << round(b*1e3)/1e3;
}
}
}
} | # 0007, 2024-11-02 10:24:25, PPPPPPPPPPPP---PPPPPPPPP (87%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i;
string mode;
cin >> n >> mode;
float x[n],y[n];
for(i=0;i<n;i++)
{
cin >> x[i] >> y[i];
}
float m ,b , sumxy = 0 , sumx = 0 , sumy=0 , sumx2=0;
for(i=1;i<=n;i++)
{
sumxy += x[i-1]*y[i-1];
}
for(i=1;i<=n;i++)
{
sumx += x[i-1];
}
for(i=1;i<=n;i++)
{
sumy += y[i-1];
}
for(i=1;i<=n;i++)
{
sumx2 += pow(x[i-1],2);
}
m = ((n *sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
b = (sumy - m*sumx)/n;
if(mode == "mb")
{
cout << round(m*1e3)/1e3 <<endl<< round(b*1e3)/1e3;
}
else if(mode == "func")
{
if(round(m*1e3)/1e3 == 0 || round(m*1e3)/1e3 == -0)
{
cout << "y = " << b;
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 == 0)
{
if(round(m*1e3)/1e3 == 1)cout << "y = x";
else if(round(m*1e3)/1e3 == -1)cout << "y = -x";
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 << 'x';
else cout << "y = " << round(m*1e3)/1e3 << 'x';
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 != 0)
{
if(round(b*1e3)/1e3 < 0)
{
if(round(m*1e3)/1e3 == 1)cout << "y = x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " - " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3<<'x'<< " - " << abs(round(b*1e3)/1e3);
}
else
{
if(round(m*1e3)/1e3 == 1)cout << "y = x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " + " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3 << 'x'<< " + " << round(b*1e3)/1e3;
}
}
}
} | # 0008, 2024-11-02 10:25:37, PPPPPPPPPPPP---PPPPPPPPP (87%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i;
string mode;
cin >> n >> mode;
float x[n],y[n];
for(i=0;i<n;i++)
{
cin >> x[i] >> y[i];
}
float m ,b , sumxy = 0 , sumx = 0 , sumy=0 , sumx2=0;
for(i=1;i<=n;i++)
{
sumxy += x[i-1]*y[i-1];
}
for(i=1;i<=n;i++)
{
sumx += x[i-1];
}
for(i=1;i<=n;i++)
{
sumy += y[i-1];
}
for(i=1;i<=n;i++)
{
sumx2 += pow(x[i-1],2);
}
m = ((n *sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
b = (sumy - m*sumx)/n;
if(mode == "mb")
{
cout << round(m*1e3)/1e3 <<endl<< round(b*1e3)/1e3;
}
else if(mode == "func")
{
if(round(m*1e3)/1e3 == 0 || round(m*1e3)/1e3 == -0)
{
cout << "y = " << b;
}
else if(round(m*1e3)/1e3 != 0 && (round(b*1e3)/1e3 == 0 || round(b*1e3)/1e3 == -0))
{
if(round(m*1e3)/1e3 == 1)cout << "y = x";
else if(round(m*1e3)/1e3 == -1)cout << "y = -x";
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 << 'x';
else cout << "y = " << round(m*1e3)/1e3 << 'x';
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 != 0)
{
if(round(b*1e3)/1e3 < 0)
{
if(round(m*1e3)/1e3 == 1)cout << "y = x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " - " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3<<'x'<< " - " << abs(round(b*1e3)/1e3);
}
else
{
if(round(m*1e3)/1e3 == 1)cout << "y = x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " + " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3 << 'x'<< " + " << round(b*1e3)/1e3;
}
}
}
} | # 0009, 2024-11-02 10:28:53, ----------PP---PPPPPPPPP (45%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i;
string mode;
cin >> n >> mode;
float x[n],y[n];
for(i=0;i<n;i++)
{
cin >> x[i] >> y[i];
}
float m ,b , sumxy = 0 , sumx = 0 , sumy=0 , sumx2=0;
for(i=1;i<=n;i++)
{
sumxy += x[i-1]*y[i-1];
}
for(i=1;i<=n;i++)
{
sumx += x[i-1];
}
for(i=1;i<=n;i++)
{
sumy += y[i-1];
}
for(i=1;i<=n;i++)
{
sumx2 += pow(x[i-1],2);
}
m = ((n *sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
b = (sumy - m*sumx)/n;
if(mode == "mb")
{
cout << round(m*1e3)/1e3 <<endl<< round(b*1e3)/1e3 << "l";
}
else if(mode == "func")
{
if(round(m*1e3)/1e3 == 0 || round(m*1e3)/1e3 == -0)
{
cout << "y = " << b;
}
else if(round(m*1e3)/1e3 != 0 && (round(b*1e3)/1e3 == 0 || round(b*1e3)/1e3 == -0))
{
if(round(m*1e3)/1e3 == 1)cout << "y = x";
else if(round(m*1e3)/1e3 == -1)cout << "y = -x";
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 << 'x';
else cout << "y = " << round(m*1e3)/1e3 << 'x';
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 != 0)
{
if(round(b*1e3)/1e3 < 0)
{
if(round(m*1e3)/1e3 == 1)cout << "y = x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " - " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3<<'x'<< " - " << abs(round(b*1e3)/1e3);
}
else
{
if(round(m*1e3)/1e3 == 1)cout << "y = x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " + " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3 << 'x'<< " + " << round(b*1e3)/1e3;
}
}
}
} | # 0010, 2024-11-02 10:29:10, PPPPPPPPPPPP---PPPPPPPPP (87%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i;
string mode;
cin >> n >> mode;
float x[n],y[n];
for(i=0;i<n;i++)
{
cin >> x[i] >> y[i];
}
float m ,b , sumxy = 0 , sumx = 0 , sumy=0 , sumx2=0;
for(i=1;i<=n;i++)
{
sumxy += x[i-1]*y[i-1];
}
for(i=1;i<=n;i++)
{
sumx += x[i-1];
}
for(i=1;i<=n;i++)
{
sumy += y[i-1];
}
for(i=1;i<=n;i++)
{
sumx2 += pow(x[i-1],2);
}
m = ((n *sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
b = (sumy - m*sumx)/n;
if(mode == "mb")
{
cout << round(m*1e3)/1e3 <<endl<< round(b*1e3)/1e3;
}
else if(mode == "func")
{
if(round(m*1e3)/1e3 == 0 || round(m*1e3)/1e3 == -0)
{
cout << "y = " << b;
}
else if(round(m*1e3)/1e3 != 0 && (round(b*1e3)/1e3 == 0 || round(b*1e3)/1e3 == -0))
{
if(round(m*1e3)/1e3 == 1)cout << "y = x";
else if(round(m*1e3)/1e3 == -1)cout << "y = -x";
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 << 'x';
else cout << "y = " << round(m*1e3)/1e3 << 'x';
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 != 0)
{
if(round(b*1e3)/1e3 < 0)
{
if(round(m*1e3)/1e3 == 1)cout << "y = x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " - " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3<<'x'<< " - " << abs(round(b*1e3)/1e3);
}
else
{
if(round(m*1e3)/1e3 == 1)cout << "y = x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " + " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3 << 'x'<< " + " << round(b*1e3)/1e3;
}
}
}
} | # 0011, 2024-11-02 10:31:30, PPPPPPPPPPPP-----PPPP-PP (75%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i;
string mode;
cin >> n >> mode;
float x[n],y[n];
for(i=0;i<n;i++)
{
cin >> x[i] >> y[i];
}
float m ,b , sumxy = 0 , sumx = 0 , sumy=0 , sumx2=0;
for(i=1;i<=n;i++)
{
sumxy += x[i-1]*y[i-1];
}
for(i=1;i<=n;i++)
{
sumx += x[i-1];
}
for(i=1;i<=n;i++)
{
sumy += y[i-1];
}
for(i=1;i<=n;i++)
{
sumx2 += pow(x[i-1],2);
}
m = ((n *sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
b = (sumy - m*sumx)/n;
if(mode == "mb")
{
cout << round(m*1e3)/1e3 <<endl<< round(b*1e3)/1e3;
}
else if(mode == "func")
{
if(round(m*1e3)/1e3 == 0 || round(m*1e3)/1e3 == -0)
{
cout << "y = " << b << "l";
}
else if(round(m*1e3)/1e3 != 0 && (round(b*1e3)/1e3 == 0 || round(b*1e3)/1e3 == -0))
{
if(round(m*1e3)/1e3 == 1)cout << "y = x";
else if(round(m*1e3)/1e3 == -1)cout << "y = -x";
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 << 'x';
else cout << "y = " << round(m*1e3)/1e3 << 'x';
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 != 0)
{
if(round(b*1e3)/1e3 < 0)
{
if(round(m*1e3)/1e3 == 1)cout << "y = x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " - " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3<<'x'<< " - " << abs(round(b*1e3)/1e3);
}
else
{
if(round(m*1e3)/1e3 == 1)cout << "y = x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " + " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3 << 'x'<< " + " << round(b*1e3)/1e3;
}
}
}
} | # 0012, 2024-11-02 10:31:47, Compilation error (0%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i;
string mode;
cin >> n >> mode;
float x[n],y[n];
for(i=0;i<n;i++)
{
cin >> x[i] >> y[i];
}
float m ,b , sumxy = 0 , sumx = 0 , sumy=0 , sumx2=0;
for(i=1;i<=n;i++)
{
sumxy += x[i-1]*y[i-1];
}
for(i=1;i<=n;i++)
{
sumx += x[i-1];
}
for(i=1;i<=n;i++)
{
sumy += y[i-1];
}
for(i=1;i<=n;i++)
{
sumx2 += pow(x[i-1],2);
}
m = ((n *sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
b = (sumy - m*sumx)/n;
if(mode == "mb")
{
cout << round(m*1e3)/1e3 <<endl<< round(b*1e3)/1e3;
}
else if(mode == "func")
{
if(round(m*1e3)/1e3 == 0 || round(m*1e3)/1e3 == -0)
{
cout << "y = " << b;
}
else if(round(m*1e3)/1e3 != 0 && (round(b*1e3)/1e3 == 0 || round(b*1e3)/1e3 == -0))
{
if(round(m*1e3)/1e3 == 1)cout << "y = x";
else if(round(m*1e3)/1e3 == -1)cout << "y = -x";
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 << 'x';
else cout << "y = " << round(m*1e3)/1e3 << 'x';
cout << "l"
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 != 0)
{
if(round(b*1e3)/1e3 < 0)
{
if(round(m*1e3)/1e3 == 1)cout << "y = x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " - " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3<<'x'<< " - " << abs(round(b*1e3)/1e3);
}
else
{
if(round(m*1e3)/1e3 == 1)cout << "y = x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " + " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3 << 'x'<< " + " << round(b*1e3)/1e3;
}
}
}
} | # 0013, 2024-11-02 10:31:55, PPPPPPPPPPPP---PPP--PPPP (79%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i;
string mode;
cin >> n >> mode;
float x[n],y[n];
for(i=0;i<n;i++)
{
cin >> x[i] >> y[i];
}
float m ,b , sumxy = 0 , sumx = 0 , sumy=0 , sumx2=0;
for(i=1;i<=n;i++)
{
sumxy += x[i-1]*y[i-1];
}
for(i=1;i<=n;i++)
{
sumx += x[i-1];
}
for(i=1;i<=n;i++)
{
sumy += y[i-1];
}
for(i=1;i<=n;i++)
{
sumx2 += pow(x[i-1],2);
}
m = ((n *sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
b = (sumy - m*sumx)/n;
if(mode == "mb")
{
cout << round(m*1e3)/1e3 <<endl<< round(b*1e3)/1e3;
}
else if(mode == "func")
{
if(round(m*1e3)/1e3 == 0 || round(m*1e3)/1e3 == -0)
{
cout << "y = " << b;
}
else if(round(m*1e3)/1e3 != 0 && (round(b*1e3)/1e3 == 0 || round(b*1e3)/1e3 == -0))
{
if(round(m*1e3)/1e3 == 1)cout << "y = x";
else if(round(m*1e3)/1e3 == -1)cout << "y = -x";
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 << 'x';
else cout << "y = " << round(m*1e3)/1e3 << 'x';
cout << "l";
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 != 0)
{
if(round(b*1e3)/1e3 < 0)
{
if(round(m*1e3)/1e3 == 1)cout << "y = x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " - " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3<<'x'<< " - " << abs(round(b*1e3)/1e3);
}
else
{
if(round(m*1e3)/1e3 == 1)cout << "y = x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " + " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3 << 'x'<< " + " << round(b*1e3)/1e3;
}
}
}
} | # 0014, 2024-11-02 10:32:14, PPPPPPPPPPP----PPPPPPP-- (75%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i;
string mode;
cin >> n >> mode;
float x[n],y[n];
for(i=0;i<n;i++)
{
cin >> x[i] >> y[i];
}
float m ,b , sumxy = 0 , sumx = 0 , sumy=0 , sumx2=0;
for(i=1;i<=n;i++)
{
sumxy += x[i-1]*y[i-1];
}
for(i=1;i<=n;i++)
{
sumx += x[i-1];
}
for(i=1;i<=n;i++)
{
sumy += y[i-1];
}
for(i=1;i<=n;i++)
{
sumx2 += pow(x[i-1],2);
}
m = ((n *sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
b = (sumy - m*sumx)/n;
if(mode == "mb")
{
cout << round(m*1e3)/1e3 <<endl<< round(b*1e3)/1e3;
}
else if(mode == "func")
{
if(round(m*1e3)/1e3 == 0 || round(m*1e3)/1e3 == -0)
{
cout << "y = " << b;
}
else if(round(m*1e3)/1e3 != 0 && (round(b*1e3)/1e3 == 0 || round(b*1e3)/1e3 == -0))
{
if(round(m*1e3)/1e3 == 1)cout << "y = x";
else if(round(m*1e3)/1e3 == -1)cout << "y = -x";
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 << 'x';
else cout << "y = " << round(m*1e3)/1e3 << 'x';
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 != 0)
{
if(round(b*1e3)/1e3 < 0)
{
if(round(m*1e3)/1e3 == 1)cout << "y = x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " - " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3<<'x'<< " - " << abs(round(b*1e3)/1e3);
cout << "l";
}
else
{
if(round(m*1e3)/1e3 == 1)cout << "y = x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " + " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3 << 'x'<< " + " << round(b*1e3)/1e3;
}
}
}
} | # 0015, 2024-11-02 10:32:27, PPPPPPPPPP-P---PP-PP-PPP (75%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i;
string mode;
cin >> n >> mode;
float x[n],y[n];
for(i=0;i<n;i++)
{
cin >> x[i] >> y[i];
}
float m ,b , sumxy = 0 , sumx = 0 , sumy=0 , sumx2=0;
for(i=1;i<=n;i++)
{
sumxy += x[i-1]*y[i-1];
}
for(i=1;i<=n;i++)
{
sumx += x[i-1];
}
for(i=1;i<=n;i++)
{
sumy += y[i-1];
}
for(i=1;i<=n;i++)
{
sumx2 += pow(x[i-1],2);
}
m = ((n *sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
b = (sumy - m*sumx)/n;
if(mode == "mb")
{
cout << round(m*1e3)/1e3 <<endl<< round(b*1e3)/1e3;
}
else if(mode == "func")
{
if(round(m*1e3)/1e3 == 0 || round(m*1e3)/1e3 == -0)
{
cout << "y = " << b;
}
else if(round(m*1e3)/1e3 != 0 && (round(b*1e3)/1e3 == 0 || round(b*1e3)/1e3 == -0))
{
if(round(m*1e3)/1e3 == 1)cout << "y = x";
else if(round(m*1e3)/1e3 == -1)cout << "y = -x";
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 << 'x';
else cout << "y = " << round(m*1e3)/1e3 << 'x';
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 != 0)
{
if(round(b*1e3)/1e3 < 0)
{
if(round(m*1e3)/1e3 == 1)cout << "y = x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " - " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3<<'x'<< " - " << abs(round(b*1e3)/1e3);
}
else
{
if(round(m*1e3)/1e3 == 1)cout << "y = x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " + " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3 << 'x'<< " + " << round(b*1e3)/1e3;
cout << "l";
}
}
}
} | # 0016, 2024-11-02 10:32:52, PPPPPPPPPPPP---PPPPPPP-P (83%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i;
string mode;
cin >> n >> mode;
float x[n],y[n];
for(i=0;i<n;i++)
{
cin >> x[i] >> y[i];
}
float m ,b , sumxy = 0 , sumx = 0 , sumy=0 , sumx2=0;
for(i=1;i<=n;i++)
{
sumxy += x[i-1]*y[i-1];
}
for(i=1;i<=n;i++)
{
sumx += x[i-1];
}
for(i=1;i<=n;i++)
{
sumy += y[i-1];
}
for(i=1;i<=n;i++)
{
sumx2 += pow(x[i-1],2);
}
m = ((n *sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
b = (sumy - m*sumx)/n;
if(mode == "mb")
{
cout << round(m*1e3)/1e3 <<endl<< round(b*1e3)/1e3;
}
else if(mode == "func")
{
if(round(m*1e3)/1e3 == 0 || round(m*1e3)/1e3 == -0)
{
cout << "y = " << b;
}
else if(round(m*1e3)/1e3 != 0 && (round(b*1e3)/1e3 == 0 || round(b*1e3)/1e3 == -0))
{
if(round(m*1e3)/1e3 == 1)cout << "y = x";
else if(round(m*1e3)/1e3 == -1)cout << "y = -x";
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 << 'x';
else cout << "y = " << round(m*1e3)/1e3 << 'x';
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 != 0)
{
if(round(b*1e3)/1e3 < 0)
{
if(round(m*1e3)/1e3 == 1)cout << "y = x - " << abs(round(b*1e3)/1e3) << "l";
else if(round(m*1e3)/1e3 == -1)cout << "y = -x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " - " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3<<'x'<< " - " << abs(round(b*1e3)/1e3);
}
else
{
if(round(m*1e3)/1e3 == 1)cout << "y = x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " + " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3 << 'x'<< " + " << round(b*1e3)/1e3;
}
}
}
} | # 0017, 2024-11-02 10:33:06, PPPPPPPPPPPP---PPP-PPPPP (83%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i;
string mode;
cin >> n >> mode;
float x[n],y[n];
for(i=0;i<n;i++)
{
cin >> x[i] >> y[i];
}
float m ,b , sumxy = 0 , sumx = 0 , sumy=0 , sumx2=0;
for(i=1;i<=n;i++)
{
sumxy += x[i-1]*y[i-1];
}
for(i=1;i<=n;i++)
{
sumx += x[i-1];
}
for(i=1;i<=n;i++)
{
sumy += y[i-1];
}
for(i=1;i<=n;i++)
{
sumx2 += pow(x[i-1],2);
}
m = ((n *sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
b = (sumy - m*sumx)/n;
if(mode == "mb")
{
cout << round(m*1e3)/1e3 <<endl<< round(b*1e3)/1e3;
}
else if(mode == "func")
{
if(round(m*1e3)/1e3 == 0 || round(m*1e3)/1e3 == -0)
{
cout << "y = " << b;
}
else if(round(m*1e3)/1e3 != 0 && (round(b*1e3)/1e3 == 0 || round(b*1e3)/1e3 == -0))
{
if(round(m*1e3)/1e3 == 1)cout << "y = x" << "l";
else if(round(m*1e3)/1e3 == -1)cout << "y = -x";
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 << 'x';
else cout << "y = " << round(m*1e3)/1e3 << 'x';
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 != 0)
{
if(round(b*1e3)/1e3 < 0)
{
if(round(m*1e3)/1e3 == 1)cout << "y = x - " << abs(round(b*1e3)/1e3) ;
else if(round(m*1e3)/1e3 == -1)cout << "y = -x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " - " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3<<'x'<< " - " << abs(round(b*1e3)/1e3);
}
else
{
if(round(m*1e3)/1e3 == 1)cout << "y = x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " + " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3 << 'x'<< " + " << round(b*1e3)/1e3;
}
}
}
} | # 0018, 2024-11-02 10:33:39, Compilation error (0%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i;
string mode;
cin >> n >> mode;
float x[n],y[n];
for(i=0;i<n;i++)
{
cin >> x[i] >> y[i];
}
float m ,b , sumxy = 0 , sumx = 0 , sumy=0 , sumx2=0;
for(i=1;i<=n;i++)
{
sumxy += x[i-1]*y[i-1];
}
for(i=1;i<=n;i++)
{
sumx += x[i-1];
}
for(i=1;i<=n;i++)
{
sumy += y[i-1];
}
for(i=1;i<=n;i++)
{
sumx2 += pow(x[i-1],2);
}
m = ((n *sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
b = (sumy - m*sumx)/n;
if(mode == "mb")
{
cout << round(m*1e3)/1e3 <<endl<< round(b*1e3)/1e3 << "l";
}
else if(mode == "func")
{
if(round(m*1e3)/1e3 == 0 || round(m*1e3)/1e3 == -0)
{
cout << "y = " << b;
}
else if(round(m*1e3)/1e3 != 0 && (round(b*1e3)/1e3 == 0 || round(b*1e3)/1e3 == -0))
{
if(round(m*1e3)/1e3 == 1)cout << "y = x";
else if(round(m*1e3)/1e3 == -1)cout << "y = -x" << l;
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 << 'x';
else cout << "y = " << round(m*1e3)/1e3 << 'x';
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 != 0)
{
if(round(b*1e3)/1e3 < 0)
{
if(round(m*1e3)/1e3 == 1)cout << "y = x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " - " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3<<'x'<< " - " << abs(round(b*1e3)/1e3);
}
else
{
if(round(m*1e3)/1e3 == 1)cout << "y = x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " + " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3 << 'x'<< " + " << round(b*1e3)/1e3;
}
}
}
} | # 0019, 2024-11-02 10:33:46, ----------PP---PPPP-PPPP (41%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i;
string mode;
cin >> n >> mode;
float x[n],y[n];
for(i=0;i<n;i++)
{
cin >> x[i] >> y[i];
}
float m ,b , sumxy = 0 , sumx = 0 , sumy=0 , sumx2=0;
for(i=1;i<=n;i++)
{
sumxy += x[i-1]*y[i-1];
}
for(i=1;i<=n;i++)
{
sumx += x[i-1];
}
for(i=1;i<=n;i++)
{
sumy += y[i-1];
}
for(i=1;i<=n;i++)
{
sumx2 += pow(x[i-1],2);
}
m = ((n *sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
b = (sumy - m*sumx)/n;
if(mode == "mb")
{
cout << round(m*1e3)/1e3 <<endl<< round(b*1e3)/1e3 << "l";
}
else if(mode == "func")
{
if(round(m*1e3)/1e3 == 0 || round(m*1e3)/1e3 == -0)
{
cout << "y = " << b;
}
else if(round(m*1e3)/1e3 != 0 && (round(b*1e3)/1e3 == 0 || round(b*1e3)/1e3 == -0))
{
if(round(m*1e3)/1e3 == 1)cout << "y = x";
else if(round(m*1e3)/1e3 == -1)cout << "y = -x" << "l";
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 << 'x';
else cout << "y = " << round(m*1e3)/1e3 << 'x';
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 != 0)
{
if(round(b*1e3)/1e3 < 0)
{
if(round(m*1e3)/1e3 == 1)cout << "y = x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " - " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3<<'x'<< " - " << abs(round(b*1e3)/1e3);
}
else
{
if(round(m*1e3)/1e3 == 1)cout << "y = x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " + " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3 << 'x'<< " + " << round(b*1e3)/1e3;
}
}
}
} | # 0020, 2024-11-02 10:34:05, ----------PP---PPPPPPPPP (45%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i;
string mode;
cin >> n >> mode;
float x[n],y[n];
for(i=0;i<n;i++)
{
cin >> x[i] >> y[i];
}
float m ,b , sumxy = 0 , sumx = 0 , sumy=0 , sumx2=0;
for(i=1;i<=n;i++)
{
sumxy += x[i-1]*y[i-1];
}
for(i=1;i<=n;i++)
{
sumx += x[i-1];
}
for(i=1;i<=n;i++)
{
sumy += y[i-1];
}
for(i=1;i<=n;i++)
{
sumx2 += pow(x[i-1],2);
}
m = ((n *sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
b = (sumy - m*sumx)/n;
if(mode == "mb")
{
cout << round(m*1e3)/1e3 <<endl<< round(b*1e3)/1e3 << "l";
}
else if(mode == "func")
{
if(round(m*1e3)/1e3 == 0 || round(m*1e3)/1e3 == -0)
{
cout << "y = " << b;
}
else if(round(m*1e3)/1e3 != 0 && (round(b*1e3)/1e3 == 0 || round(b*1e3)/1e3 == -0))
{
if(round(m*1e3)/1e3 == 1)cout << "y = x";
else if(round(m*1e3)/1e3 == -1)cout << "y = -x";
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 << 'x' << "l";
else cout << "y = " << round(m*1e3)/1e3 << 'x';
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 != 0)
{
if(round(b*1e3)/1e3 < 0)
{
if(round(m*1e3)/1e3 == 1)cout << "y = x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " - " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3<<'x'<< " - " << abs(round(b*1e3)/1e3);
}
else
{
if(round(m*1e3)/1e3 == 1)cout << "y = x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " + " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3 << 'x'<< " + " << round(b*1e3)/1e3;
}
}
}
} | # 0021, 2024-11-02 10:34:17, ----------PP---PPPPPPPPP (45%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i;
string mode;
cin >> n >> mode;
float x[n],y[n];
for(i=0;i<n;i++)
{
cin >> x[i] >> y[i];
}
float m ,b , sumxy = 0 , sumx = 0 , sumy=0 , sumx2=0;
for(i=1;i<=n;i++)
{
sumxy += x[i-1]*y[i-1];
}
for(i=1;i<=n;i++)
{
sumx += x[i-1];
}
for(i=1;i<=n;i++)
{
sumy += y[i-1];
}
for(i=1;i<=n;i++)
{
sumx2 += pow(x[i-1],2);
}
m = ((n *sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
b = (sumy - m*sumx)/n;
if(mode == "mb")
{
cout << round(m*1e3)/1e3 <<endl<< round(b*1e3)/1e3 << "l";
}
else if(mode == "func")
{
if(round(m*1e3)/1e3 == 0 || round(m*1e3)/1e3 == -0)
{
cout << "y = " << b;
}
else if(round(m*1e3)/1e3 != 0 && (round(b*1e3)/1e3 == 0 || round(b*1e3)/1e3 == -0))
{
if(round(m*1e3)/1e3 == 1)cout << "y = x";
else if(round(m*1e3)/1e3 == -1)cout << "y = -x";
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 << 'x';
else cout << "y = " << round(m*1e3)/1e3 << 'x';
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 != 0)
{
if(round(b*1e3)/1e3 < 0)
{
if(round(m*1e3)/1e3 == 1)cout << "y = x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " - " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3<<'x'<< " - " << abs(round(b*1e3)/1e3);
}
else
{
if(round(m*1e3)/1e3 == 1)cout << "y = x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " + " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3 << 'x'<< " + " << round(b*1e3)/1e3;
}
}
}
} | # 0022, 2024-11-02 10:34:31, PPPPPPPPPPPP---PPPPPPPPP (87%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i;
string mode;
cin >> n >> mode;
float x[n],y[n];
for(i=0;i<n;i++)
{
cin >> x[i] >> y[i];
}
float m ,b , sumxy = 0 , sumx = 0 , sumy=0 , sumx2=0;
for(i=1;i<=n;i++)
{
sumxy += x[i-1]*y[i-1];
}
for(i=1;i<=n;i++)
{
sumx += x[i-1];
}
for(i=1;i<=n;i++)
{
sumy += y[i-1];
}
for(i=1;i<=n;i++)
{
sumx2 += pow(x[i-1],2);
}
m = ((n *sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
b = (sumy - m*sumx)/n;
if(mode == "mb")
{
cout << round(m*1e3)/1e3 <<endl<< round(b*1e3)/1e3;
}
else if(mode == "func")
{
if(round(m*1e3)/1e3 == 0 || round(m*1e3)/1e3 == -0)
{
cout << "y = " << b;
}
else if(round(m*1e3)/1e3 != 0 && (round(b*1e3)/1e3 == 0 || round(b*1e3)/1e3 == -0))
{
if(round(m*1e3)/1e3 == 1)cout << "y = x";
else if(round(m*1e3)/1e3 == -1)cout << "y = -x";
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 << 'x';
else cout << "y = " << round(m*1e3)/1e3 << 'x';
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 != 0)
{
if(round(b*1e3)/1e3 < 0)
{
if(round(m*1e3)/1e3 == 1)cout << "y = x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " - " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3<<'x'<< " - " << abs(round(b*1e3)/1e3);
}
else
{
if(round(m*1e3)/1e3 == 1)cout << "y = x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " + " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3 << 'x'<< " + " << round(b*1e3)/1e3;
}
}
}
} | # 0023, 2024-11-02 10:34:45, PPPPPPPPPPPP---PPPPPPPPP (87%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i;
string mode;
cin >> n >> mode;
float x[n],y[n];
for(i=0;i<n;i++)
{
cin >> x[i] >> y[i];
}
float m ,b , sumxy = 0 , sumx = 0 , sumy=0 , sumx2=0;
for(i=1;i<=n;i++)
{
sumxy += x[i-1]*y[i-1];
}
for(i=1;i<=n;i++)
{
sumx += x[i-1];
}
for(i=1;i<=n;i++)
{
sumy += y[i-1];
}
for(i=1;i<=n;i++)
{
sumx2 += pow(x[i-1],2);
}
m = ((n *sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
b = (sumy - m*sumx)/n;
if(mode == "mb")
{
cout << round(m*1e3)/1e3 <<endl<< round(b*1e3)/1e3;
}
else if(mode == "func")
{
if(round(m*1e3)/1e3 == 0 || round(m*1e3)/1e3 == -0)
{
cout << "y = " << b;
}
else if(round(m*1e3)/1e3 != 0 && (round(b*1e3)/1e3 == 0 || round(b*1e3)/1e3 == -0))
{
if(round(m*1e3)/1e3 == 1)cout << "y = x";
else if(round(m*1e3)/1e3 == -1)cout << "y = -x";
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 << 'x';
else cout << "y = " << round(m*1e3)/1e3 << 'x' << "l";
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 != 0)
{
if(round(b*1e3)/1e3 < 0)
{
if(round(m*1e3)/1e3 == 1)cout << "y = x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " - " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3<<'x'<< " - " << abs(round(b*1e3)/1e3);
}
else
{
if(round(m*1e3)/1e3 == 1)cout << "y = x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " + " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3 << 'x'<< " + " << round(b*1e3)/1e3;
}
}
}
} | # 0024, 2024-11-02 10:35:09, PPPPPPPPPPPP---PPPPPPPPP (87%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i;
string mode;
cin >> n >> mode;
float x[n],y[n];
for(i=0;i<n;i++)
{
cin >> x[i] >> y[i];
}
float m ,b , sumxy = 0 , sumx = 0 , sumy=0 , sumx2=0;
for(i=1;i<=n;i++)
{
sumxy += x[i-1]*y[i-1];
}
for(i=1;i<=n;i++)
{
sumx += x[i-1];
}
for(i=1;i<=n;i++)
{
sumy += y[i-1];
}
for(i=1;i<=n;i++)
{
sumx2 += pow(x[i-1],2);
}
m = ((n *sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
b = (sumy - m*sumx)/n;
if(mode == "mb")
{
cout << round(m*1e3)/1e3 <<endl<< round(b*1e3)/1e3;
}
else if(mode == "func")
{
if(round(m*1e3)/1e3 == 0 || round(m*1e3)/1e3 == -0)
{
cout << "y = " << b;
}
else if(round(m*1e3)/1e3 != 0 && (round(b*1e3)/1e3 == 0 || round(b*1e3)/1e3 == -0))
{
if(round(m*1e3)/1e3 == 1)cout << "y = x";
else if(round(m*1e3)/1e3 == -1)cout << "y = -x";
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 << 'x' << "l";
else cout << "y = " << round(m*1e3)/1e3 << 'x' ;
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 != 0)
{
if(round(b*1e3)/1e3 < 0)
{
if(round(m*1e3)/1e3 == 1)cout << "y = x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " - " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3<<'x'<< " - " << abs(round(b*1e3)/1e3);
}
else
{
if(round(m*1e3)/1e3 == 1)cout << "y = x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " + " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3 << 'x'<< " + " << round(b*1e3)/1e3;
}
}
}
} | # 0025, 2024-11-02 10:35:40, PPPPPPPPPPPP---PPPPPPPPP (87%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i;
string mode;
cin >> n >> mode;
float x[n],y[n];
for(i=0;i<n;i++)
{
cin >> x[i] >> y[i];
}
float m ,b , sumxy = 0 , sumx = 0 , sumy=0 , sumx2=0;
for(i=1;i<=n;i++)
{
sumxy += x[i-1]*y[i-1];
}
for(i=1;i<=n;i++)
{
sumx += x[i-1];
}
for(i=1;i<=n;i++)
{
sumy += y[i-1];
}
for(i=1;i<=n;i++)
{
sumx2 += pow(x[i-1],2);
}
m = ((n *sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
b = (sumy - m*sumx)/n;
if(mode == "mb")
{
cout << round(m*1e3)/1e3 <<endl<< round(b*1e3)/1e3;
}
else if(mode == "func")
{
if(round(m*1e3)/1e3 == 0 || round(m*1e3)/1e3 == -0)
{
cout << "y = " << b;
}
else if(round(m*1e3)/1e3 != 0 && (round(b*1e3)/1e3 == 0 || round(b*1e3)/1e3 == -0))
{
if(round(m*1e3)/1e3 == 1)cout << "y = x";
else if(round(m*1e3)/1e3 == -1)cout << "y = -x";
else if(round(m*1e3)/1e3 <0)cout << "y = - " << round(m*1e3)/1e3 << 'x';
else cout << "y = " << round(m*1e3)/1e3 << 'x' ;
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 != 0)
{
if(round(b*1e3)/1e3 < 0)
{
if(round(m*1e3)/1e3 == 1)cout << "y = x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " - " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3<<'x'<< " - " << abs(round(b*1e3)/1e3);
}
else
{
if(round(m*1e3)/1e3 == 1)cout << "y = x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 <0)cout << "y = -" << round(m*1e3)/1e3 <<'x'<< " + " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3 << 'x'<< " + " << round(b*1e3)/1e3;
}
}
}
} | # 0026, 2024-11-02 10:36:47, ----------PPPPPPPPPPPPPP (58%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i;
string mode;
cin >> n >> mode;
float x[n],y[n];
for(i=0;i<n;i++)
{
cin >> x[i] >> y[i];
}
float m ,b , sumxy = 0 , sumx = 0 , sumy=0 , sumx2=0;
for(i=1;i<=n;i++)
{
sumxy += x[i-1]*y[i-1];
}
for(i=1;i<=n;i++)
{
sumx += x[i-1];
}
for(i=1;i<=n;i++)
{
sumy += y[i-1];
}
for(i=1;i<=n;i++)
{
sumx2 += pow(x[i-1],2);
}
m = ((n *sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
b = (sumy - m*sumx)/n;
if(mode == "mb")
{
cout << round(m*1e3)/1e3 <<endl<< round(b*1e3)/1e3 << "l";
}
else if(mode == "func")
{
if(round(m*1e3)/1e3 == 0 || round(m*1e3)/1e3 == -0)
{
cout << "y = " << b;
}
else if(round(m*1e3)/1e3 != 0 && (round(b*1e3)/1e3 == 0 || round(b*1e3)/1e3 == -0))
{
if(round(m*1e3)/1e3 == 1)cout << "y = x";
else if(round(m*1e3)/1e3 == -1)cout << "y = -x";
else cout << "y = " << round(m*1e3)/1e3 << 'x';
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 != 0)
{
if(round(b*1e3)/1e3 < 0)
{
if(round(m*1e3)/1e3 == 1)cout << "y = x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x - " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3<<'x'<< " - " << abs(round(b*1e3)/1e3);
}
else
{
if(round(m*1e3)/1e3 == 1)cout << "y = x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x + " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3 << 'x'<< " + " << round(b*1e3)/1e3;
}
}
}
} | # 0027, 2024-11-02 10:36:58, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i;
string mode;
cin >> n >> mode;
float x[n],y[n];
for(i=0;i<n;i++)
{
cin >> x[i] >> y[i];
}
float m ,b , sumxy = 0 , sumx = 0 , sumy=0 , sumx2=0;
for(i=1;i<=n;i++)
{
sumxy += x[i-1]*y[i-1];
}
for(i=1;i<=n;i++)
{
sumx += x[i-1];
}
for(i=1;i<=n;i++)
{
sumy += y[i-1];
}
for(i=1;i<=n;i++)
{
sumx2 += pow(x[i-1],2);
}
m = ((n *sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
b = (sumy - m*sumx)/n;
if(mode == "mb")
{
cout << round(m*1e3)/1e3 <<endl<< round(b*1e3)/1e3;
}
else if(mode == "func")
{
if(round(m*1e3)/1e3 == 0 || round(m*1e3)/1e3 == -0)
{
cout << "y = " << b;
}
else if(round(m*1e3)/1e3 != 0 && (round(b*1e3)/1e3 == 0 || round(b*1e3)/1e3 == -0))
{
if(round(m*1e3)/1e3 == 1)cout << "y = x";
else if(round(m*1e3)/1e3 == -1)cout << "y = -x";
else cout << "y = " << round(m*1e3)/1e3 << 'x';
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 != 0)
{
if(round(b*1e3)/1e3 < 0)
{
if(round(m*1e3)/1e3 == 1)cout << "y = x - " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x - " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3<<'x'<< " - " << abs(round(b*1e3)/1e3);
}
else
{
if(round(m*1e3)/1e3 == 1)cout << "y = x + " << abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3 == -1)cout << "y = -x + " << abs(round(b*1e3)/1e3);
else cout << "y = " << round(m*1e3)/1e3 << 'x'<< " + " << round(b*1e3)/1e3;
}
}
}
} |
# 0028, 2024-11-02 09:48:01, PPPPPPPPPP-----P---P-P-- (54%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
string command; cin >> command;
float xi,yi;
map<float,float> x_y;
for (int i=0;i<n;i++) {
cin >> xi >> yi;
x_y[xi] = yi;
}
float m,b;
float sum_m = 0;
for (auto n:x_y) {
sum_m += n.first*n.second;
}
sum_m*=n;
float sum_1 = 0;
float sum_2 = 0;
for (auto n:x_y) {
sum_1 += n.first;
sum_2 += n.second;
}
sum_m = sum_m-(sum_1*sum_2);
float sum_1_divied = 0;
float sum_2_divied = 0;
for (auto n:x_y) {
sum_1_divied += (n.first*n.first);
sum_2_divied += n.first;
}
sum_1_divied*=n;
sum_2_divied = sum_2_divied*sum_2_divied;
float sum_m_divied;
sum_m_divied = sum_1_divied-sum_2_divied;
m = sum_m/sum_m_divied;
//-------------------------------------------------------
//find b
float sum_b = 0;
float sum_b_1 = 0;
float sum_b_2 = 0;
for (auto n:x_y) {
sum_b_1 += n.second;
}
for (auto n:x_y) {
sum_b_2 += n.first;
}
sum_b_2*=m;
sum_b = sum_b_1-sum_b_2;
b = sum_b/n;
if (command == "mb") {
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
if (command == "func") {
if (m == 0 && b == 0) cout << "y = 0";
else if (m == 0) cout << "y = " << b;
else if (b == 0 && m == -1) cout << "y = " << "-x";
else if (b == 0) cout << "y = " << m << "x";
else if (b < 0) cout << "y = " << m << "x " << b;
else if (b > 0) cout << "y = " << m << "x + " << b;
}
} | # 0029, 2024-11-02 09:49:24, PPPPPPPPPP-----P---P-P-- (54%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
string command; cin >> command;
float xi,yi;
map<float,float> x_y;
for (int i=0;i<n;i++) {
cin >> xi >> yi;
x_y[xi] = yi;
}
float m,b;
float sum_m = 0;
for (auto n:x_y) {
sum_m += n.first*n.second;
}
sum_m*=n;
float sum_1 = 0;
float sum_2 = 0;
for (auto n:x_y) {
sum_1 += n.first;
sum_2 += n.second;
}
sum_m = sum_m-(sum_1*sum_2);
float sum_1_divied = 0;
float sum_2_divied = 0;
for (auto n:x_y) {
sum_1_divied += (n.first*n.first);
sum_2_divied += n.first;
}
sum_1_divied*=n;
sum_2_divied = sum_2_divied*sum_2_divied;
float sum_m_divied;
sum_m_divied = sum_1_divied-sum_2_divied;
m = sum_m/sum_m_divied;
//-------------------------------------------------------
//find b
float sum_b = 0;
float sum_b_1 = 0;
float sum_b_2 = 0;
for (auto n:x_y) {
sum_b_1 += n.second;
}
for (auto n:x_y) {
sum_b_2 += n.first;
}
sum_b_2*=m;
sum_b = sum_b_1-sum_b_2;
b = sum_b/n;
if (command == "mb") {
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
if (command == "func") {
if (m == 0 && b == 0) cout << "y = 0";
else if (m == 0) cout << "y = " << b;
else if (b == 0 && m == -1) cout << "y = " << "-x";
else if (b == 0) cout << "y = " << m << "x";
else if (b < 0) cout << "y = " << m << "x - " << abs(b);
else if (b > 0) cout << "y = " << m << "x + " << b;
}
} | # 0030, 2024-11-02 09:50:44, PPPPPPPPPPPPPPPP---P-P-- (75%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
string command; cin >> command;
float xi,yi;
map<float,float> x_y;
for (int i=0;i<n;i++) {
cin >> xi >> yi;
x_y[xi] = yi;
}
float m,b;
float sum_m = 0;
for (auto n:x_y) {
sum_m += n.first*n.second;
}
sum_m*=n;
float sum_1 = 0;
float sum_2 = 0;
for (auto n:x_y) {
sum_1 += n.first;
sum_2 += n.second;
}
sum_m = sum_m-(sum_1*sum_2);
float sum_1_divied = 0;
float sum_2_divied = 0;
for (auto n:x_y) {
sum_1_divied += (n.first*n.first);
sum_2_divied += n.first;
}
sum_1_divied*=n;
sum_2_divied = sum_2_divied*sum_2_divied;
float sum_m_divied;
sum_m_divied = sum_1_divied-sum_2_divied;
m = sum_m/sum_m_divied;
//-------------------------------------------------------
//find b
float sum_b = 0;
float sum_b_1 = 0;
float sum_b_2 = 0;
for (auto n:x_y) {
sum_b_1 += n.second;
}
for (auto n:x_y) {
sum_b_2 += n.first;
}
sum_b_2*=m;
sum_b = sum_b_1-sum_b_2;
b = sum_b/n;
if (command == "mb") {
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
if (command == "func") {
if (m == 0 && b == 0) cout << "y = 0";
else if (m == 0) cout << "y = " << round(b*1e3)/1e3;
else if (b == 0 && m == -1) cout << "y = " << "-x";
else if (b == 0) cout << "y = " << round(m*1e3)/1e3 << "x";
else if (b < 0) cout << "y = " << round(m*1e3)/1e3 << "x - " << abs(round(b*1e3)/1e3);
else if (b > 0) cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
} | # 0031, 2024-11-02 09:52:40, PPPPPPPPPPPPPPPPP--P-P-- (79%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
string command; cin >> command;
float xi,yi;
map<float,float> x_y;
for (int i=0;i<n;i++) {
cin >> xi >> yi;
x_y[xi] = yi;
}
float m,b;
float sum_m = 0;
for (auto n:x_y) {
sum_m += n.first*n.second;
}
sum_m*=n;
float sum_1 = 0;
float sum_2 = 0;
for (auto n:x_y) {
sum_1 += n.first;
sum_2 += n.second;
}
sum_m = sum_m-(sum_1*sum_2);
float sum_1_divied = 0;
float sum_2_divied = 0;
for (auto n:x_y) {
sum_1_divied += (n.first*n.first);
sum_2_divied += n.first;
}
sum_1_divied*=n;
sum_2_divied = sum_2_divied*sum_2_divied;
float sum_m_divied;
sum_m_divied = sum_1_divied-sum_2_divied;
m = sum_m/sum_m_divied;
//-------------------------------------------------------
//find b
float sum_b = 0;
float sum_b_1 = 0;
float sum_b_2 = 0;
for (auto n:x_y) {
sum_b_1 += n.second;
}
for (auto n:x_y) {
sum_b_2 += n.first;
}
sum_b_2*=m;
sum_b = sum_b_1-sum_b_2;
b = sum_b/n;
if (command == "mb") {
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
if (command == "func") {
if (round(m*1e3)/1e3 == 0 && round(b*1e3)/1e3 == 0) cout << "y = 0";
else if (round(m*1e3)/1e3 == 0) cout << "y = " << round(b*1e3)/1e3;
else if (round(b*1e3)/1e3 == 0 && round(m*1e3)/1e3 == -1) cout << "y = " << "-x";
else if (round(b*1e3)/1e3 == 0) cout << "y = " << round(m*1e3)/1e3 << "x";
else if (round(b*1e3)/1e3 < 0) cout << "y = " << round(m*1e3)/1e3 << "x - " << abs(round(b*1e3)/1e3);
else if (round(b*1e3)/1e3 > 0) cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
} | # 0032, 2024-11-02 09:53:52, PPPPPPPPPPPPPPPPP--P-P-- (79%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
string command; cin >> command;
float xi,yi;
map<float,float> x_y;
for (int i=0;i<n;i++) {
cin >> xi >> yi;
x_y[xi] = yi;
}
float m,b;
float sum_m = 0;
for (auto n:x_y) {
sum_m += n.first*n.second;
}
sum_m*=n;
float sum_1 = 0;
float sum_2 = 0;
for (auto n:x_y) {
sum_1 += n.first;
sum_2 += n.second;
}
sum_m = sum_m-(sum_1*sum_2);
float sum_1_divied = 0;
float sum_2_divied = 0;
for (auto n:x_y) {
sum_1_divied += (n.first*n.first);
sum_2_divied += n.first;
}
sum_1_divied*=n;
sum_2_divied = sum_2_divied*sum_2_divied;
float sum_m_divied;
sum_m_divied = sum_1_divied-sum_2_divied;
m = sum_m/sum_m_divied;
//-------------------------------------------------------
//find b
float sum_b = 0;
float sum_b_1 = 0;
float sum_b_2 = 0;
for (auto n:x_y) {
sum_b_1 += n.second;
}
for (auto n:x_y) {
sum_b_2 += n.first;
}
sum_b_2*=m;
sum_b = sum_b_1-sum_b_2;
b = sum_b/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (command == "mb") {
cout << m << endl << b;
}
if (command == "func") {
if (m == 0 && b == 0) cout << "y = 0";
else if (m == 0) cout << "y = " << b;
else if (b == 0 && m == -1) cout << "y = " << "-x";
else if (b != 0 && m == -1) cout << "y = " << "-x";
else if (b == 0) cout << "y = " << m << "x";
else if (b < 0) cout << "y = " << m << "x - " << abs(b);
else if (b > 0) cout << "y = " << m << "x + " << b;
}
} | # 0033, 2024-11-02 09:55:41, PPPPPPPPPPPPPPPPP--PPP-P (87%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
string command; cin >> command;
float xi,yi;
map<float,float> x_y;
for (int i=0;i<n;i++) {
cin >> xi >> yi;
x_y[xi] = yi;
}
float m,b;
float sum_m = 0;
for (auto n:x_y) {
sum_m += n.first*n.second;
}
sum_m*=n;
float sum_1 = 0;
float sum_2 = 0;
for (auto n:x_y) {
sum_1 += n.first;
sum_2 += n.second;
}
sum_m = sum_m-(sum_1*sum_2);
float sum_1_divied = 0;
float sum_2_divied = 0;
for (auto n:x_y) {
sum_1_divied += (n.first*n.first);
sum_2_divied += n.first;
}
sum_1_divied*=n;
sum_2_divied = sum_2_divied*sum_2_divied;
float sum_m_divied;
sum_m_divied = sum_1_divied-sum_2_divied;
m = sum_m/sum_m_divied;
//-------------------------------------------------------
//find b
float sum_b = 0;
float sum_b_1 = 0;
float sum_b_2 = 0;
for (auto n:x_y) {
sum_b_1 += n.second;
}
for (auto n:x_y) {
sum_b_2 += n.first;
}
sum_b_2*=m;
sum_b = sum_b_1-sum_b_2;
b = sum_b/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (command == "mb") {
cout << m << endl << b;
}
if (command == "func") {
if (m == 0 && b == 0) cout << "y = 0";
else if (m == 0) cout << "y = " << b;
else if (b == 0 && m == -1) cout << "y = " << "-x";
else if (b < 0 && m == -1) cout << "y = " << "-x - " << abs(b);
else if (b > 0 && m == -1) cout << "y = " << "-x + " << b;
else if (b == 0) cout << "y = " << m << "x";
else if (b < 0) cout << "y = " << m << "x - " << abs(b);
else if (b > 0) cout << "y = " << m << "x + " << b;
}
} | # 0034, 2024-11-02 09:56:49, PPPPPPPPPPPPPPPPP--PPP-P (87%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
string command; cin >> command;
float xi,yi;
map<float,float> x_y;
for (int i=0;i<n;i++) {
cin >> xi >> yi;
x_y[xi] = yi;
}
float m,b;
float sum_m = 0;
for (auto n:x_y) {
sum_m += n.first*n.second;
}
sum_m*=n;
float sum_1 = 0;
float sum_2 = 0;
for (auto n:x_y) {
sum_1 += n.first;
sum_2 += n.second;
}
sum_m = sum_m-(sum_1*sum_2);
float sum_1_divied = 0;
float sum_2_divied = 0;
for (auto n:x_y) {
sum_1_divied += (n.first*n.first);
sum_2_divied += n.first;
}
sum_1_divied*=n;
sum_2_divied = sum_2_divied*sum_2_divied;
float sum_m_divied;
sum_m_divied = sum_1_divied-sum_2_divied;
m = sum_m/sum_m_divied;
//-------------------------------------------------------
//find b
float sum_b = 0;
float sum_b_1 = 0;
float sum_b_2 = 0;
for (auto n:x_y) {
sum_b_1 += n.second;
}
for (auto n:x_y) {
sum_b_2 += n.first;
}
sum_b_2*=m;
sum_b = sum_b_1-sum_b_2;
b = sum_b/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (command == "mb") {
cout << m << endl << b;
}
if (command == "func") {
if (m == 0 && b == 0) cout << "y = 0";
else if (b == 0 && m == -1) cout << "y = " << "-x";
else if (b < 0 && m == -1) cout << "y = " << "-x - " << abs(b);
else if (b > 0 && m == -1) cout << "y = " << "-x + " << b;
else if (b == 0) cout << "y = " << m << "x";
else if (m == 0) cout << "y = " << b;
else if (b < 0) cout << "y = " << m << "x - " << abs(b);
else if (b > 0) cout << "y = " << m << "x + " << b;
}
} | # 0035, 2024-11-02 10:39:50, PPPPPPPPPPPPPPPPP--PPP-P (87%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
string command; cin >> command;
float xi,yi;
map<float,float> x_y;
for (int i=0;i<n;i++) {
cin >> xi >> yi;
x_y[xi] = yi;
}
float m,b;
float sum_m = 0;
for (auto n:x_y) {
sum_m += n.first*n.second;
}
sum_m*=n;
float sum_1 = 0;
float sum_2 = 0;
for (auto n:x_y) {
sum_1 += n.first;
sum_2 += n.second;
}
sum_m = sum_m-(sum_1*sum_2);
float sum_1_divied = 0;
float sum_2_divied = 0;
for (auto n:x_y) {
sum_1_divied += (n.first*n.first);
sum_2_divied += n.first;
}
sum_1_divied*=n;
sum_2_divied = sum_2_divied*sum_2_divied;
float sum_m_divied;
sum_m_divied = sum_1_divied-sum_2_divied;
m = sum_m/sum_m_divied;
//-------------------------------------------------------
//find b
float sum_b = 0;
float sum_b_1 = 0;
float sum_b_2 = 0;
for (auto n:x_y) {
sum_b_1 += n.second;
}
for (auto n:x_y) {
sum_b_2 += n.first;
}
sum_b_2*=m;
sum_b = sum_b_1-sum_b_2;
b = sum_b/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (command == "mb") {
cout << m << endl << b;
}
if (command == "func") {
if (m == 0 && b == 0) cout << "y = 0";
else if (b == 0 && m == -1) cout << "y = " << "-x";
else if (b < 0 && m == -1) cout << "y = " << "-x - " << abs(b);
else if (b > 0 && m == -1) cout << "y = " << "-x + " << b;
else if (m == 0) cout << "y = " << b;
else if (b == 0) cout << "y = " << m << "x";
else if (b < 0) cout << "y = " << m << "x - " << abs(b);
else if (b > 0) cout << "y = " << m << "x + " << b;
}
} | # 0036, 2024-11-02 11:18:52, PPPPPPPPPPPPPPPPP--PPP-P (87%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
string command; cin >> command;
float xi,yi;
map<float,float> x_y;
for (int i=0;i<n;i++) {
cin >> xi >> yi;
x_y[xi] = yi;
}
float m,b;
float sum_m = 0;
for (auto n:x_y) {
sum_m += n.first*n.second;
}
sum_m*=n;
float sum_1 = 0;
float sum_2 = 0;
for (auto n:x_y) {
sum_1 += n.first;
sum_2 += n.second;
}
sum_m = sum_m-(sum_1*sum_2);
float sum_1_divied = 0;
float sum_2_divied = 0;
for (auto n:x_y) {
sum_1_divied += (n.first*n.first);
sum_2_divied += n.first;
}
sum_1_divied*=n;
sum_2_divied = sum_2_divied*sum_2_divied;
float sum_m_divied;
sum_m_divied = sum_1_divied-sum_2_divied;
m = sum_m/sum_m_divied;
//-------------------------------------------------------
//find b
float sum_b = 0;
float sum_b_1 = 0;
float sum_b_2 = 0;
for (auto n:x_y) {
sum_b_1 += n.second;
}
for (auto n:x_y) {
sum_b_2 += n.first;
}
sum_b_2*=m;
sum_b = sum_b_1-sum_b_2;
b = sum_b/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (command == "mb") {
cout << m << endl << b;
}
if (command == "func") {
if (m == 0 && b == 0) cout << "y = 0";
else if (b == 0 && m == -1) cout << "y = " << "-x";
else if (b < 0 && m == -1) cout << "y = " << "-x - " << abs(b);
else if (b > 0 && m == -1) cout << "y = " << "-x + " << b;
else if (m == 0) cout << "y = " << b;
else if (b == 0) cout << "y = " << m << "x";
else if (m != 0 && b < 0) cout << "y = " << m << "x - " << abs(b);
else if (m != 0 && b > 0) cout << "y = " << m << "x + " << b;
}
} | # 0037, 2024-11-02 11:19:29, PPPPPPPPPPPPPPPPP--PPP-P (87%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
string command; cin >> command;
float xi,yi;
map<float,float> x_y;
for (int i=0;i<n;i++) {
cin >> xi >> yi;
x_y[xi] = yi;
}
float m,b;
float sum_m = 0;
for (auto n:x_y) {
sum_m += n.first*n.second;
}
sum_m*=n;
float sum_1 = 0;
float sum_2 = 0;
for (auto n:x_y) {
sum_1 += n.first;
sum_2 += n.second;
}
sum_m = sum_m-(sum_1*sum_2);
float sum_1_divied = 0;
float sum_2_divied = 0;
for (auto n:x_y) {
sum_1_divied += (n.first*n.first);
sum_2_divied += n.first;
}
sum_1_divied*=n;
sum_2_divied = sum_2_divied*sum_2_divied;
float sum_m_divied;
sum_m_divied = sum_1_divied-sum_2_divied;
m = sum_m/sum_m_divied;
//-------------------------------------------------------
//find b
float sum_b = 0;
float sum_b_1 = 0;
float sum_b_2 = 0;
for (auto n:x_y) {
sum_b_1 += n.second;
}
for (auto n:x_y) {
sum_b_2 += n.first;
}
sum_b_2*=m;
sum_b = sum_b_1-sum_b_2;
b = sum_b/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (command == "mb") {
cout << m << endl << b;
}
if (command == "func") {
if (m == 0 && b == 0) cout << "y = 0";
else if (b == 0 && m == -1) cout << "y = " << "-x";
else if (b < 0 && m == -1) cout << "y = " << "-x - " << abs(b);
else if (b > 0 && m == -1) cout << "y = " << "-x + " << b;
else if (m == 0 && b != 0) cout << "y = " << b;
else if (b == 0 && m != 0) cout << "y = " << m << "x";
else if (m != 0 && b < 0) cout << "y = " << m << "x - " << abs(b);
else if (m != 0 && b > 0) cout << "y = " << m << "x + " << b;
}
} | # 0038, 2024-11-02 11:22:40, PPPPPPPPPPPPPPPPP--P-P-- (79%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
string command; cin >> command;
float xi,yi;
map<float,float> x_y;
for (int i=0;i<n;i++) {
cin >> xi >> yi;
x_y[xi] = yi;
}
float m,b;
float sum_m = 0;
for (auto n:x_y) {
sum_m += n.first*n.second;
}
sum_m*=n;
float sum_1 = 0;
float sum_2 = 0;
for (auto n:x_y) {
sum_1 += n.first;
sum_2 += n.second;
}
sum_m = sum_m-(sum_1*sum_2);
float sum_1_divied = 0;
float sum_2_divied = 0;
for (auto n:x_y) {
sum_1_divied += (n.first*n.first);
sum_2_divied += n.first;
}
sum_1_divied*=n;
sum_2_divied = sum_2_divied*sum_2_divied;
float sum_m_divied;
sum_m_divied = sum_1_divied-sum_2_divied;
m = sum_m/sum_m_divied;
//-------------------------------------------------------
//find b
float sum_b = 0;
float sum_b_1 = 0;
float sum_b_2 = 0;
for (auto n:x_y) {
sum_b_1 += n.second;
}
for (auto n:x_y) {
sum_b_2 += n.first;
}
sum_b_2*=m;
sum_b = sum_b_1-sum_b_2;
b = sum_b/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (command == "mb") {
cout << m << endl << b;
}
if (command == "func") {
if (m == 0 && b == 0) cout << "y = 0";
else if (b == 0 && m == -1) cout << "y = " << "-x";
else if (m != 0 && b < 0) cout << "y = " << m << "x - " << abs(b);
else if (m != 0 && b > 0) cout << "y = " << m << "x + " << b;
else if (m == 0 && b != 0) cout << "y = " << b;
else if (b == 0 && m != 0) cout << "y = " << m << "x";
else if (b < 0 && m == -1) cout << "y = " << "-x - " << abs(b);
else if (b > 0 && m == -1) cout << "y = " << "-x + " << b;
}
} | # 0039, 2024-11-02 11:22:55, PPPPPPPPPPPPPPPPP--PPP-P (87%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
string command; cin >> command;
float xi,yi;
map<float,float> x_y;
for (int i=0;i<n;i++) {
cin >> xi >> yi;
x_y[xi] = yi;
}
float m,b;
float sum_m = 0;
for (auto n:x_y) {
sum_m += n.first*n.second;
}
sum_m*=n;
float sum_1 = 0;
float sum_2 = 0;
for (auto n:x_y) {
sum_1 += n.first;
sum_2 += n.second;
}
sum_m = sum_m-(sum_1*sum_2);
float sum_1_divied = 0;
float sum_2_divied = 0;
for (auto n:x_y) {
sum_1_divied += (n.first*n.first);
sum_2_divied += n.first;
}
sum_1_divied*=n;
sum_2_divied = sum_2_divied*sum_2_divied;
float sum_m_divied;
sum_m_divied = sum_1_divied-sum_2_divied;
m = sum_m/sum_m_divied;
//-------------------------------------------------------
//find b
float sum_b = 0;
float sum_b_1 = 0;
float sum_b_2 = 0;
for (auto n:x_y) {
sum_b_1 += n.second;
}
for (auto n:x_y) {
sum_b_2 += n.first;
}
sum_b_2*=m;
sum_b = sum_b_1-sum_b_2;
b = sum_b/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (command == "mb") {
cout << m << endl << b;
}
if (command == "func") {
if (m == 0 && b == 0) cout << "y = 0";
else if (b == 0 && m == -1) cout << "y = " << "-x";
else if (b < 0 && m == -1) cout << "y = " << "-x - " << abs(b);
else if (b > 0 && m == -1) cout << "y = " << "-x + " << b;
else if (m == 0 && b != 0) cout << "y = " << b;
else if (b == 0 && m != 0) cout << "y = " << m << "x";
else if (m != 0 && b < 0) cout << "y = " << m << "x - " << abs(b);
else if (m != 0 && b > 0) cout << "y = " << m << "x + " << b;
}
} | # 0040, 2024-11-02 11:25:25, PPPPPPPPPPPPPPPPP--PPP-P (87%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
string command; cin >> command;
float xi,yi;
map<float,float> x_y;
for (int i=0;i<n;i++) {
cin >> xi >> yi;
x_y[xi] = yi;
}
float m,b;
float sum_m = 0;
for (auto n:x_y) {
sum_m += n.first*n.second;
}
sum_m*=n;
float sum_1 = 0;
float sum_2 = 0;
for (auto n:x_y) {
sum_1 += n.first;
sum_2 += n.second;
}
sum_m = sum_m-(sum_1*sum_2);
float sum_1_divied = 0;
float sum_2_divied = 0;
for (auto n:x_y) {
sum_1_divied += (n.first*n.first);
sum_2_divied += n.first;
}
sum_1_divied*=n;
sum_2_divied = sum_2_divied*sum_2_divied;
float sum_m_divied;
sum_m_divied = sum_1_divied-sum_2_divied;
m = sum_m/sum_m_divied;
//-------------------------------------------------------
//find b
float sum_b = 0;
float sum_b_1 = 0;
float sum_b_2 = 0;
for (auto n:x_y) {
sum_b_1 += n.second;
}
for (auto n:x_y) {
sum_b_2 += n.first;
}
sum_b_2*=m;
sum_b = sum_b_1-sum_b_2;
b = sum_b/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (command == "mb") {
cout << m << endl << b;
}
if (command == "func") {
if (m == 0 && b == 0) cout << "y = 0";
else if (b == 0 && m == -1) cout << "y = " << "-x";
else if (b < 0 && m == -1) cout << "y = " << "-x - " << abs(b);
else if (b > 0 && m == -1) cout << "y = " << "-x + " << b;
else if (b != 0 && m == 0) cout << "y = " << b;
else if (b == 0 && m != 0) cout << "y = " << m << "x";
else if (b < 0 && m != 0) cout << "y = " << m << "x - " << abs(b);
else if (b > 0 && m != 0) cout << "y = " << m << "x + " << b;
}
} | # 0041, 2024-11-02 11:26:15, PPPPPPPPPPPPPPPPP--PPP-P (87%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
string command; cin >> command;
float xi,yi;
map<float,float> x_y;
for (int i=0;i<n;i++) {
cin >> xi >> yi;
x_y[xi] = yi;
}
float m,b;
float sum_m = 0;
for (auto n:x_y) {
sum_m += n.first*n.second;
}
sum_m*=n;
float sum_1 = 0;
float sum_2 = 0;
for (auto n:x_y) {
sum_1 += n.first;
sum_2 += n.second;
}
sum_m = sum_m-(sum_1*sum_2);
float sum_1_divied = 0;
float sum_2_divied = 0;
for (auto n:x_y) {
sum_1_divied += (n.first*n.first);
sum_2_divied += n.first;
}
sum_1_divied*=n;
sum_2_divied = sum_2_divied*sum_2_divied;
float sum_m_divied;
sum_m_divied = sum_1_divied-sum_2_divied;
m = sum_m/sum_m_divied;
//-------------------------------------------------------
//find b
float sum_b = 0;
float sum_b_1 = 0;
float sum_b_2 = 0;
for (auto n:x_y) {
sum_b_1 += n.second;
}
for (auto n:x_y) {
sum_b_2 += n.first;
}
sum_b_2*=m;
sum_b = sum_b_1-sum_b_2;
b = sum_b/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (command == "mb") {
cout << m << endl << b;
}
if (command == "func") {
if (b == 0 && m == 0) cout << "y = 0";
else if (b != 0 && m == 0) cout << "y = " << b;
else if (b == 0 && m == -1) cout << "y = " << "-x";
else if (b < 0 && m == -1) cout << "y = " << "-x - " << abs(b);
else if (b > 0 && m == -1) cout << "y = " << "-x + " << b;
else if (b == 0 && m != 0) cout << "y = " << m << "x";
else if (b < 0 && m != 0) cout << "y = " << m << "x - " << abs(b);
else if (b > 0 && m != 0) cout << "y = " << m << "x + " << b;
}
} | # 0042, 2024-11-02 11:26:40, PPPPPPPPPPPPPPPPP--PPP-P (87%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
string command; cin >> command;
float xi,yi;
map<float,float> x_y;
for (int i=0;i<n;i++) {
cin >> xi >> yi;
x_y[xi] = yi;
}
float m,b;
float sum_m = 0;
for (auto n:x_y) {
sum_m += n.first*n.second;
}
sum_m*=n;
float sum_1 = 0;
float sum_2 = 0;
for (auto n:x_y) {
sum_1 += n.first;
sum_2 += n.second;
}
sum_m = sum_m-(sum_1*sum_2);
float sum_1_divied = 0;
float sum_2_divied = 0;
for (auto n:x_y) {
sum_1_divied += (n.first*n.first);
sum_2_divied += n.first;
}
sum_1_divied*=n;
sum_2_divied = sum_2_divied*sum_2_divied;
float sum_m_divied;
sum_m_divied = sum_1_divied-sum_2_divied;
m = sum_m/sum_m_divied;
//-------------------------------------------------------
//find b
float sum_b = 0;
float sum_b_1 = 0;
float sum_b_2 = 0;
for (auto n:x_y) {
sum_b_1 += n.second;
}
for (auto n:x_y) {
sum_b_2 += n.first;
}
sum_b_2*=m;
sum_b = sum_b_1-sum_b_2;
b = sum_b/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (command == "mb") {
cout << m << endl << b;
}
if (command == "func") {
if (b == 0 && m == 0) cout << "y = 0";
else if (b != 0 && m == 0) cout << "y = " << b;
else if (b == 0 && m == -1) cout << "y = " << "-x";
else if (b == 0 && m != 0) cout << "y = " << m << "x";
else if (b < 0 && m == -1) cout << "y = " << "-x - " << abs(b);
else if (b > 0 && m == -1) cout << "y = " << "-x + " << b;
else if (b < 0 && m != 0) cout << "y = " << m << "x - " << abs(b);
else if (b > 0 && m != 0) cout << "y = " << m << "x + " << b;
}
} | # 0043, 2024-11-02 11:27:07, PPPPPPPPPPPPPPPPP--PPP-P (87%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
string command; cin >> command;
float xi,yi;
map<float,float> x_y;
for (int i=0;i<n;i++) {
cin >> xi >> yi;
x_y[xi] = yi;
}
float m,b;
float sum_m = 0;
for (auto n:x_y) {
sum_m += n.first*n.second;
}
sum_m*=n;
float sum_1 = 0;
float sum_2 = 0;
for (auto n:x_y) {
sum_1 += n.first;
sum_2 += n.second;
}
sum_m = sum_m-(sum_1*sum_2);
float sum_1_divied = 0;
float sum_2_divied = 0;
for (auto n:x_y) {
sum_1_divied += (n.first*n.first);
sum_2_divied += n.first;
}
sum_1_divied*=n;
sum_2_divied = sum_2_divied*sum_2_divied;
float sum_m_divied;
sum_m_divied = sum_1_divied-sum_2_divied;
m = sum_m/sum_m_divied;
//-------------------------------------------------------
//find b
float sum_b = 0;
float sum_b_1 = 0;
float sum_b_2 = 0;
for (auto n:x_y) {
sum_b_1 += n.second;
}
for (auto n:x_y) {
sum_b_2 += n.first;
}
sum_b_2*=m;
sum_b = sum_b_1-sum_b_2;
b = sum_b/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (command == "mb") {
cout << m << endl << b;
}
if (command == "func") {
if (b == 0 && m == 0) cout << "y = 0";
else if (b != 0 && m == 0) cout << "y = " << b;
else if (b == 0 && m == -1) cout << "y = " << "-x";
else if (b == 0 && m != 0) cout << "y = " << m << "x";
else if (b < 0 && m == -1) cout << "y = " << "-x - " << abs(b);
else if (b < 0 && m != 0) cout << "y = " << m << "x - " << abs(b);
else if (b > 0 && m == -1) cout << "y = " << "-x + " << b;
else if (b > 0 && m != 0) cout << "y = " << m << "x + " << b;
}
} | # 0044, 2024-11-02 11:33:12, ------------------------ (0%)
#include<bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
vector<int> vec_x_q1,vec_y_q1;
vector<int> vec_x_q2,vec_y_q2;
vector<int> vec_x_q3,vec_y_q3;
vector<int> vec_x_q4,vec_y_q4;
int x,y;
for (int i=0;i<n;i++) {
cin >> x >> y;
if (x == 0 || y == 0) {
continue;
} else if (x > 0 && y > 0) {
vec_x_q1.push_back(x);
vec_y_q1.push_back(y);
} else if (x < 0 && y > 0) {
vec_x_q2.push_back(x);
vec_y_q2.push_back(y);
} else if (x < 0 && y < 0) {
vec_x_q3.push_back(x);
vec_y_q3.push_back(y);
} else if (x > 0 && y < 0) {
vec_x_q4.push_back(x);
vec_y_q4.push_back(y);
}
}
if (vec_x_q1.size() == 0 && vec_x_q2.size() == 0 && vec_x_q3.size() == 0 && vec_x_q4.size() == 0) {
cout << "No point in any quadrant";
return 0;
}
sort(vec_x_q1.begin(),vec_x_q1.end());
sort(vec_y_q1.begin(),vec_y_q1.end());
sort(vec_x_q2.begin(),vec_x_q2.end());
sort(vec_y_q2.begin(),vec_y_q2.end());
sort(vec_x_q3.begin(),vec_x_q3.end());
sort(vec_y_q3.begin(),vec_y_q3.end());
sort(vec_x_q4.begin(),vec_x_q4.end());
sort(vec_y_q4.begin(),vec_y_q4.end());
int max_x_q1 = vec_x_q1[vec_x_q1.size()-1];
int max_y_q1 = vec_y_q1[vec_y_q1.size()-1];
int min_x_q1 = vec_x_q1[0];
int min_y_q1 = vec_y_q1[0];
int area_1 = (max_y_q1-min_y_q1)*(max_x_q1-min_x_q1);
int max_x_q2 = vec_x_q2[vec_x_q2.size()-1];
int max_y_q2 = vec_y_q2[vec_y_q2.size()-1];
int min_x_q2 = vec_x_q2[0];
int min_y_q2 = vec_y_q2[0];
int area_2 = (max_y_q2-min_y_q2)*(max_x_q2-min_x_q2);
int max_x_q3 = vec_x_q3[vec_x_q3.size()-1];
int max_y_q3 = vec_y_q3[vec_y_q3.size()-1];
int min_x_q3 = vec_x_q3[0];
int min_y_q3 = vec_y_q3[0];
int area_3 = (max_y_q3-min_y_q3)*(max_x_q3-min_x_q3);
int max_x_q4 = vec_x_q4[vec_x_q4.size()-1];
int max_y_q4 = vec_y_q4[vec_y_q4.size()-1];
int min_x_q4 = vec_x_q4[0];
int min_y_q4 = vec_y_q4[0];
int area_4 = (max_y_q4-min_y_q4)*(max_x_q4-min_x_q4);
if (vec_x_q1.size() == 0 && vec_x_q2.size() == 0 && vec_x_q3.size() == 0 && vec_x_q4.size() == 0) {
cout << "No point in any quadrant";
} else if (vec_x_q1.size() != 0 && vec_x_q2.size() != 0 && vec_x_q3.size() != 0 && vec_x_q4.size() !=0) {
cout << "Q1: (" << min_x_q1 << ", " << min_y_q1 << ") (" << max_x_q1 << ", " << max_y_q1 << ") " << area_1 << endl;
cout << "Q2: (" << min_x_q2 << ", " << min_y_q2 << ") (" << max_x_q2 << ", " << max_y_q2 << ") " << area_2 << endl;
cout << "Q3: (" << min_x_q3 << ", " << min_y_q3 << ") (" << max_x_q3 << ", " << max_y_q3 << ") " << area_3 << endl;
cout << "Q4: (" << min_x_q4 << ", " << min_y_q4 << ") (" << max_x_q4 << ", " << max_y_q4 << ") " << area_4 << endl;
} else if (vec_x_q1.size() == 0 && vec_x_q2.size() != 0 && vec_x_q3.size() != 0 && vec_x_q4.size() !=0) {
cout << "Q2: (" << min_x_q2 << ", " << min_y_q2 << ") (" << max_x_q2 << ", " << max_y_q2 << ") " << area_2 << endl;
cout << "Q3: (" << min_x_q3 << ", " << min_y_q3 << ") (" << max_x_q3 << ", " << max_y_q3 << ") " << area_3 << endl;
cout << "Q4: (" << min_x_q4 << ", " << min_y_q4 << ") (" << max_x_q4 << ", " << max_y_q4 << ") " << area_4 << endl;
} else if (vec_x_q1.size() != 0 && vec_x_q2.size() == 0 && vec_x_q3.size() != 0 && vec_x_q4.size() !=0) {
cout << "Q1: (" << min_x_q1 << ", " << min_y_q1 << ") (" << max_x_q1 << ", " << max_y_q1 << ") " << area_1 << endl;
cout << "Q3: (" << min_x_q3 << ", " << min_y_q3 << ") (" << max_x_q3 << ", " << max_y_q3 << ") " << area_3 << endl;
cout << "Q4: (" << min_x_q4 << ", " << min_y_q4 << ") (" << max_x_q4 << ", " << max_y_q4 << ") " << area_4 << endl;
} else if (vec_x_q1.size() != 0 && vec_x_q2.size() != 0 && vec_x_q3.size() == 0 && vec_x_q4.size() !=0) {
cout << "Q1: (" << min_x_q1 << ", " << min_y_q1 << ") (" << max_x_q1 << ", " << max_y_q1 << ") " << area_1 << endl;
cout << "Q2: (" << min_x_q2 << ", " << min_y_q2 << ") (" << max_x_q2 << ", " << max_y_q2 << ") " << area_2 << endl;
cout << "Q4: (" << min_x_q4 << ", " << min_y_q4 << ") (" << max_x_q4 << ", " << max_y_q4 << ") " << area_4 << endl;
} else if (vec_x_q1.size() != 0 && vec_x_q2.size() != 0 && vec_x_q3.size() != 0 && vec_x_q4.size() ==0) {
cout << "Q1: (" << min_x_q1 << ", " << min_y_q1 << ") (" << max_x_q1 << ", " << max_y_q1 << ") " << area_1 << endl;
cout << "Q2: (" << min_x_q2 << ", " << min_y_q2 << ") (" << max_x_q2 << ", " << max_y_q2 << ") " << area_2 << endl;
cout << "Q3: (" << min_x_q3 << ", " << min_y_q3 << ") (" << max_x_q3 << ", " << max_y_q3 << ") " << area_3 << endl;
} else if (vec_x_q1.size() == 0 && vec_x_q2.size() == 0 && vec_x_q3.size() != 0 && vec_x_q4.size() !=0) { //---------------------
cout << "Q3: (" << min_x_q3 << ", " << min_y_q3 << ") (" << max_x_q3 << ", " << max_y_q3 << ") " << area_3 << endl;
cout << "Q4: (" << min_x_q4 << ", " << min_y_q4 << ") (" << max_x_q4 << ", " << max_y_q4 << ") " << area_4 << endl;
} else if (vec_x_q1.size() == 0 && vec_x_q2.size() != 0 && vec_x_q3.size() == 0 && vec_x_q4.size() !=0) {
cout << "Q2: (" << min_x_q2 << ", " << min_y_q2 << ") (" << max_x_q2 << ", " << max_y_q2 << ") " << area_2 << endl;
cout << "Q4: (" << min_x_q4 << ", " << min_y_q4 << ") (" << max_x_q4 << ", " << max_y_q4 << ") " << area_4 << endl;
} else if (vec_x_q1.size() == 0 && vec_x_q2.size() != 0 && vec_x_q3.size() != 0 && vec_x_q4.size() ==0) {
cout << "Q2: (" << min_x_q2 << ", " << min_y_q2 << ") (" << max_x_q2 << ", " << max_y_q2 << ") " << area_2 << endl;
cout << "Q3: (" << min_x_q3 << ", " << min_y_q3 << ") (" << max_x_q3 << ", " << max_y_q3 << ") " << area_3 << endl;
} else if (vec_x_q1.size() != 0 && vec_x_q2.size() == 0 && vec_x_q3.size() == 0 && vec_x_q4.size() !=0) {
cout << "Q2: (" << min_x_q2 << ", " << min_y_q2 << ") (" << max_x_q2 << ", " << max_y_q2 << ") " << area_2 << endl;
cout << "Q3: (" << min_x_q3 << ", " << min_y_q3 << ") (" << max_x_q3 << ", " << max_y_q3 << ") " << area_3 << endl;
} else if (vec_x_q1.size() != 0 && vec_x_q2.size() == 0 && vec_x_q3.size() != 0 && vec_x_q4.size() ==0) {
cout << "Q2: (" << min_x_q2 << ", " << min_y_q2 << ") (" << max_x_q2 << ", " << max_y_q2 << ") " << area_2 << endl;
cout << "Q4: (" << min_x_q4 << ", " << min_y_q4 << ") (" << max_x_q4 << ", " << max_y_q4 << ") " << area_4 << endl;
} else if (vec_x_q1.size() != 0 && vec_x_q2.size() != 0 && vec_x_q3.size() == 0 && vec_x_q4.size() ==0) {
cout << "Q3: (" << min_x_q3 << ", " << min_y_q3 << ") (" << max_x_q3 << ", " << max_y_q3 << ") " << area_3 << endl;
cout << "Q4: (" << min_x_q4 << ", " << min_y_q4 << ") (" << max_x_q4 << ", " << max_y_q4 << ") " << area_4 << endl;
}
} | # 0045, 2024-11-02 11:33:43, ------------------------ (0%)
#include<bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
vector<int> vec_x_q1,vec_y_q1;
vector<int> vec_x_q2,vec_y_q2;
vector<int> vec_x_q3,vec_y_q3;
vector<int> vec_x_q4,vec_y_q4;
int x,y;
for (int i=0;i<n;i++) {
cin >> x >> y;
if (x == 0 || y == 0) {
continue;
} else if (x > 0 && y > 0) {
vec_x_q1.push_back(x);
vec_y_q1.push_back(y);
} else if (x < 0 && y > 0) {
vec_x_q2.push_back(x);
vec_y_q2.push_back(y);
} else if (x < 0 && y < 0) {
vec_x_q3.push_back(x);
vec_y_q3.push_back(y);
} else if (x > 0 && y < 0) {
vec_x_q4.push_back(x);
vec_y_q4.push_back(y);
}
}
if (vec_x_q1.size() == 0 && vec_x_q2.size() == 0 && vec_x_q3.size() == 0 && vec_x_q4.size() == 0) {
cout << "No point in any quadrant";
return 0;
}
sort(vec_x_q1.begin(),vec_x_q1.end());
sort(vec_y_q1.begin(),vec_y_q1.end());
sort(vec_x_q2.begin(),vec_x_q2.end());
sort(vec_y_q2.begin(),vec_y_q2.end());
sort(vec_x_q3.begin(),vec_x_q3.end());
sort(vec_y_q3.begin(),vec_y_q3.end());
sort(vec_x_q4.begin(),vec_x_q4.end());
sort(vec_y_q4.begin(),vec_y_q4.end());
int max_x_q1 = vec_x_q1[vec_x_q1.size()-1];
int max_y_q1 = vec_y_q1[vec_y_q1.size()-1];
int min_x_q1 = vec_x_q1[0];
int min_y_q1 = vec_y_q1[0];
int area_1 = (max_y_q1-min_y_q1)*(max_x_q1-min_x_q1);
int max_x_q2 = vec_x_q2[vec_x_q2.size()-1];
int max_y_q2 = vec_y_q2[vec_y_q2.size()-1];
int min_x_q2 = vec_x_q2[0];
int min_y_q2 = vec_y_q2[0];
int area_2 = (max_y_q2-min_y_q2)*(max_x_q2-min_x_q2);
int max_x_q3 = vec_x_q3[vec_x_q3.size()-1];
int max_y_q3 = vec_y_q3[vec_y_q3.size()-1];
int min_x_q3 = vec_x_q3[0];
int min_y_q3 = vec_y_q3[0];
int area_3 = (max_y_q3-min_y_q3)*(max_x_q3-min_x_q3);
int max_x_q4 = vec_x_q4[vec_x_q4.size()-1];
int max_y_q4 = vec_y_q4[vec_y_q4.size()-1];
int min_x_q4 = vec_x_q4[0];
int min_y_q4 = vec_y_q4[0];
int area_4 = (max_y_q4-min_y_q4)*(max_x_q4-min_x_q4);
if (vec_x_q1.size() == 0 && vec_x_q2.size() == 0 && vec_x_q3.size() == 0 && vec_x_q4.size() == 0) {
cout << "No point in any quadrant";
} else if (vec_x_q1.size() != 0 && vec_x_q2.size() != 0 && vec_x_q3.size() != 0 && vec_x_q4.size() !=0) {
cout << "Q1: (" << min_x_q1 << ", " << min_y_q1 << ") (" << max_x_q1 << ", " << max_y_q1 << ") " << area_1 << endl;
cout << "Q2: (" << min_x_q2 << ", " << min_y_q2 << ") (" << max_x_q2 << ", " << max_y_q2 << ") " << area_2 << endl;
cout << "Q3: (" << min_x_q3 << ", " << min_y_q3 << ") (" << max_x_q3 << ", " << max_y_q3 << ") " << area_3 << endl;
cout << "Q4: (" << min_x_q4 << ", " << min_y_q4 << ") (" << max_x_q4 << ", " << max_y_q4 << ") " << area_4 << endl;
} else if (vec_x_q1.size() == 0 && vec_x_q2.size() != 0 && vec_x_q3.size() != 0 && vec_x_q4.size() !=0) {
cout << "Q2: (" << min_x_q2 << ", " << min_y_q2 << ") (" << max_x_q2 << ", " << max_y_q2 << ") " << area_2 << endl;
cout << "Q3: (" << min_x_q3 << ", " << min_y_q3 << ") (" << max_x_q3 << ", " << max_y_q3 << ") " << area_3 << endl;
cout << "Q4: (" << min_x_q4 << ", " << min_y_q4 << ") (" << max_x_q4 << ", " << max_y_q4 << ") " << area_4 << endl;
} else if (vec_x_q1.size() != 0 && vec_x_q2.size() == 0 && vec_x_q3.size() != 0 && vec_x_q4.size() !=0) {
cout << "Q1: (" << min_x_q1 << ", " << min_y_q1 << ") (" << max_x_q1 << ", " << max_y_q1 << ") " << area_1 << endl;
cout << "Q3: (" << min_x_q3 << ", " << min_y_q3 << ") (" << max_x_q3 << ", " << max_y_q3 << ") " << area_3 << endl;
cout << "Q4: (" << min_x_q4 << ", " << min_y_q4 << ") (" << max_x_q4 << ", " << max_y_q4 << ") " << area_4 << endl;
} else if (vec_x_q1.size() != 0 && vec_x_q2.size() != 0 && vec_x_q3.size() == 0 && vec_x_q4.size() !=0) {
cout << "Q1: (" << min_x_q1 << ", " << min_y_q1 << ") (" << max_x_q1 << ", " << max_y_q1 << ") " << area_1 << endl;
cout << "Q2: (" << min_x_q2 << ", " << min_y_q2 << ") (" << max_x_q2 << ", " << max_y_q2 << ") " << area_2 << endl;
cout << "Q4: (" << min_x_q4 << ", " << min_y_q4 << ") (" << max_x_q4 << ", " << max_y_q4 << ") " << area_4 << endl;
} else if (vec_x_q1.size() != 0 && vec_x_q2.size() != 0 && vec_x_q3.size() != 0 && vec_x_q4.size() ==0) {
cout << "Q1: (" << min_x_q1 << ", " << min_y_q1 << ") (" << max_x_q1 << ", " << max_y_q1 << ") " << area_1 << endl;
cout << "Q2: (" << min_x_q2 << ", " << min_y_q2 << ") (" << max_x_q2 << ", " << max_y_q2 << ") " << area_2 << endl;
cout << "Q3: (" << min_x_q3 << ", " << min_y_q3 << ") (" << max_x_q3 << ", " << max_y_q3 << ") " << area_3 << endl;
} //else if (vec_x_q1.size() == 0 && vec_x_q2.size() == 0 && vec_x_q3.size() != 0 && vec_x_q4.size() !=0) { //---------------------
// cout << "Q3: (" << min_x_q3 << ", " << min_y_q3 << ") (" << max_x_q3 << ", " << max_y_q3 << ") " << area_3 << endl;
// cout << "Q4: (" << min_x_q4 << ", " << min_y_q4 << ") (" << max_x_q4 << ", " << max_y_q4 << ") " << area_4 << endl;
// } else if (vec_x_q1.size() == 0 && vec_x_q2.size() != 0 && vec_x_q3.size() == 0 && vec_x_q4.size() !=0) {
// cout << "Q2: (" << min_x_q2 << ", " << min_y_q2 << ") (" << max_x_q2 << ", " << max_y_q2 << ") " << area_2 << endl;
// cout << "Q4: (" << min_x_q4 << ", " << min_y_q4 << ") (" << max_x_q4 << ", " << max_y_q4 << ") " << area_4 << endl;
// } else if (vec_x_q1.size() == 0 && vec_x_q2.size() != 0 && vec_x_q3.size() != 0 && vec_x_q4.size() ==0) {
// cout << "Q2: (" << min_x_q2 << ", " << min_y_q2 << ") (" << max_x_q2 << ", " << max_y_q2 << ") " << area_2 << endl;
// cout << "Q3: (" << min_x_q3 << ", " << min_y_q3 << ") (" << max_x_q3 << ", " << max_y_q3 << ") " << area_3 << endl;
// } else if (vec_x_q1.size() != 0 && vec_x_q2.size() == 0 && vec_x_q3.size() == 0 && vec_x_q4.size() !=0) {
// cout << "Q2: (" << min_x_q2 << ", " << min_y_q2 << ") (" << max_x_q2 << ", " << max_y_q2 << ") " << area_2 << endl;
// cout << "Q3: (" << min_x_q3 << ", " << min_y_q3 << ") (" << max_x_q3 << ", " << max_y_q3 << ") " << area_3 << endl;
// } else if (vec_x_q1.size() != 0 && vec_x_q2.size() == 0 && vec_x_q3.size() != 0 && vec_x_q4.size() ==0) {
// cout << "Q2: (" << min_x_q2 << ", " << min_y_q2 << ") (" << max_x_q2 << ", " << max_y_q2 << ") " << area_2 << endl;
// cout << "Q4: (" << min_x_q4 << ", " << min_y_q4 << ") (" << max_x_q4 << ", " << max_y_q4 << ") " << area_4 << endl;
// } else if (vec_x_q1.size() != 0 && vec_x_q2.size() != 0 && vec_x_q3.size() == 0 && vec_x_q4.size() ==0) {
// cout << "Q3: (" << min_x_q3 << ", " << min_y_q3 << ") (" << max_x_q3 << ", " << max_y_q3 << ") " << area_3 << endl;
// cout << "Q4: (" << min_x_q4 << ", " << min_y_q4 << ") (" << max_x_q4 << ", " << max_y_q4 << ") " << area_4 << endl;
// }
} | # 0046, 2024-11-02 11:43:15, PPPPPPPPPPPPPPPPP--PPP-P (87%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
string command; cin >> command;
float xi,yi;
map<float,float> x_y;
for (int i=0;i<n;i++) {
cin >> xi >> yi;
x_y[xi] = yi;
}
float m,b;
float sum_m = 0;
for (auto n:x_y) {
sum_m += n.first*n.second;
}
sum_m*=n;
float sum_1 = 0;
float sum_2 = 0;
for (auto n:x_y) {
sum_1 += n.first;
sum_2 += n.second;
}
sum_m = sum_m-(sum_1*sum_2);
float sum_1_divied = 0;
float sum_2_divied = 0;
for (auto n:x_y) {
sum_1_divied += (n.first*n.first);
sum_2_divied += n.first;
}
sum_1_divied*=n;
sum_2_divied = sum_2_divied*sum_2_divied;
float sum_m_divied;
sum_m_divied = sum_1_divied-sum_2_divied;
m = sum_m/sum_m_divied;
//-------------------------------------------------------
//find b
float sum_b = 0;
float sum_b_1 = 0;
float sum_b_2 = 0;
for (auto n:x_y) {
sum_b_1 += n.second;
}
for (auto n:x_y) {
sum_b_2 += n.first;
}
sum_b_2*=m;
sum_b = sum_b_1-sum_b_2;
b = sum_b/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (command == "mb") {
cout << m << endl << b;
}
if (command == "func") {
if (b == 0 && m == 0) cout << "y = 0";
else if (b != 0 && m == 0) cout << "y = " << b;
else if (b == 0 && m == -1) cout << "y = " << "-x";
else if (b == 0 && m != 0) cout << "y = " << m << "x";
else if (b < 0 && m == -1) cout << "y = " << "-x - " << abs(b);
else if (b < 0 && m != 0) cout << "y = " << m << "x - " << abs(b);
else if (b > 0 && m == -1) cout << "y = " << "-x + " << b;
else if (b > 0 && m != 0) cout << "y = " << m << "x + " << b;
}
} | # 0047, 2024-11-02 11:47:40, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
string command; cin >> command;
float xi,yi;
map<float,float> x_y;
for (int i=0;i<n;i++) {
cin >> xi >> yi;
x_y[xi] = yi;
}
float m,b;
float sum_m = 0;
for (auto n:x_y) {
sum_m += n.first*n.second;
}
sum_m*=n;
float sum_1 = 0;
float sum_2 = 0;
for (auto n:x_y) {
sum_1 += n.first;
sum_2 += n.second;
}
sum_m = sum_m-(sum_1*sum_2);
float sum_1_divied = 0;
float sum_2_divied = 0;
for (auto n:x_y) {
sum_1_divied += (n.first*n.first);
sum_2_divied += n.first;
}
sum_1_divied*=n;
sum_2_divied = sum_2_divied*sum_2_divied;
float sum_m_divied;
sum_m_divied = sum_1_divied-sum_2_divied;
m = sum_m/sum_m_divied;
//-------------------------------------------------------
//find b
float sum_b = 0;
float sum_b_1 = 0;
float sum_b_2 = 0;
for (auto n:x_y) {
sum_b_1 += n.second;
}
for (auto n:x_y) {
sum_b_2 += n.first;
}
sum_b_2*=m;
sum_b = sum_b_1-sum_b_2;
b = sum_b/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (command == "mb") {
cout << m << endl << b;
}
if (command == "func") {
if (b == 0 && m == 0) cout << "y = 0";
else if (b != 0 && m == 0) cout << "y = " << b;
else if (b == 0 && m == -1) cout << "y = " << "-x";
else if (b == 0 && m == 1) cout << "y = " << "x";
else if (b == 0 && m != 0) cout << "y = " << m << "x";
else if (b < 0 && m == -1) cout << "y = " << "-x - " << abs(b);
else if (b < 0 && m == 1) cout << "y = " << "x - " << abs(b);
else if (b < 0 && m != 0) cout << "y = " << m << "x - " << abs(b);
else if (b > 0 && m == -1) cout << "y = " << "-x + " << b;
else if (b > 0 && m == 1) cout << "y = " << "x + " << b;
else if (b > 0 && m != 0) cout << "y = " << m << "x + " << b;
}
} |
# 0048, 2024-11-02 12:51:53, -----PPPPP-------------- (20%)
#include <bits/stdc++.h>
using namespace std;
int main()
{ int num ;
float x,y , font = 0 , back_x = 0, back_y = 0,pow_x = 0 , m ,b;
string order ;
vector <float> x_vec ;
vector <float> y_vec ;
cin >> num >> order ;
for ( int i = 0 ; i < num ; i++)
{
cin >> x >> y;
x_vec.emplace_back(x) ;
y_vec.emplace_back(y) ;
}
if (order == "mb")
{
font = 0 ;
for(int i =0 ; i< num ; i++)
{
font += x_vec[i] * y_vec[i] ;
}
font = num * font ;
back_x = 0 ;
for (int i = 0 ;i < num ; i++)
{
back_x += x_vec[i] ;
}
back_y = 0 ;
for (int i =0 ; i< num ; i++)
{
back_y += y_vec[i] ;
}
pow_x = 0;
for (int i = 0 ; i < num ; i ++)
{
pow_x += pow(x_vec[i],2) ;
}
pow_x = num * pow_x ;
m = (font - (back_x * back_y)) / (pow_x - pow(back_x,2)) ;
b = (back_y - (m * back_x)) / num ;
cout << m <<"\n" << b ;
}
} | # 0049, 2024-11-02 12:52:50, PPPPPPPPPP-------------- (41%)
#include <bits/stdc++.h>
using namespace std;
int main()
{ int num ;
float x,y , font = 0 , back_x = 0, back_y = 0,pow_x = 0 , m ,b;
string order ;
vector <float> x_vec ;
vector <float> y_vec ;
cin >> num >> order ;
for ( int i = 0 ; i < num ; i++)
{
cin >> x >> y;
x_vec.emplace_back(x) ;
y_vec.emplace_back(y) ;
}
if (order == "mb")
{
font = 0 ;
for(int i =0 ; i< num ; i++)
{
font += x_vec[i] * y_vec[i] ;
}
font = num * font ;
back_x = 0 ;
for (int i = 0 ;i < num ; i++)
{
back_x += x_vec[i] ;
}
back_y = 0 ;
for (int i =0 ; i< num ; i++)
{
back_y += y_vec[i] ;
}
pow_x = 0;
for (int i = 0 ; i < num ; i ++)
{
pow_x += pow(x_vec[i],2) ;
}
pow_x = num * pow_x ;
m = (font - (back_x * back_y)) / (pow_x - pow(back_x,2)) ;
b = (back_y - (m * back_x)) / num ;
cout << round(m*1e3)/1e3 <<"\n" << round(b*1e3)/1e3 ;
}
} | # 0050, 2024-11-02 13:06:49, PPPPPPPPPP-----P---P-P-- (54%)
#include <bits/stdc++.h>
using namespace std;
int main()
{ int num ;
float x,y , font = 0 , back_x = 0, back_y = 0,pow_x = 0 , m ,b;
string order ;
vector <float> x_vec ;
vector <float> y_vec ;
cin >> num >> order ;
for ( int i = 0 ; i < num ; i++)
{
cin >> x >> y;
x_vec.emplace_back(x) ;
y_vec.emplace_back(y) ;
}
if (order == "mb")
{
font = 0 ;
for(int i =0 ; i< num ; i++)
{
font += x_vec[i] * y_vec[i] ;
}
font = num * font ;
back_x = 0 ;
for (int i = 0 ;i < num ; i++)
{
back_x += x_vec[i] ;
}
back_y = 0 ;
for (int i =0 ; i< num ; i++)
{
back_y += y_vec[i] ;
}
pow_x = 0;
for (int i = 0 ; i < num ; i ++)
{
pow_x += pow(x_vec[i],2) ;
}
pow_x = num * pow_x ;
m = (font - (back_x * back_y)) / (pow_x - pow(back_x,2)) ;
b = (back_y - (m * back_x)) / num ;
cout << round(m*1e3)/1e3 <<"\n" << round(b*1e3)/1e3 ;
} else
{
font = 0 ;
for(int i =0 ; i< num ; i++)
{
font += x_vec[i] * y_vec[i] ;
}
font = num * font ;
back_x = 0 ;
for (int i = 0 ;i < num ; i++)
{
back_x += x_vec[i] ;
}
back_y = 0 ;
for (int i =0 ; i< num ; i++)
{
back_y += y_vec[i] ;
}
pow_x = 0;
for (int i = 0 ; i < num ; i ++)
{
pow_x += pow(x_vec[i],2) ;
}
pow_x = num * pow_x ;
m = (font - (back_x * back_y)) / (pow_x - pow(back_x,2)) ;
b = (back_y - (m * back_x)) / num ;
float out_b = abs(b) ;
if (m == 0)
{
cout << "y = " << round(b*1e3)/1e3 ;
} else if ( m == -1)
{
cout << "y = -x " << ( b == 0 ? "": b>= 1 ? "+ ": "- ") ;
if (b != 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}
}
} | # 0051, 2024-11-02 13:11:32, PPPPPPPPPP-------------- (41%)
#include <bits/stdc++.h>
using namespace std;
int main()
{ int num ;
float x,y , font = 0 , back_x = 0, back_y = 0,pow_x = 0 , m ,b;
string order ;
vector <float> x_vec ;
vector <float> y_vec ;
cin >> num >> order ;
for ( int i = 0 ; i < num ; i++)
{
cin >> x >> y;
x_vec.emplace_back(x) ;
y_vec.emplace_back(y) ;
}
if (order == "mb")
{
font = 0 ;
for(int i =0 ; i< num ; i++)
{
font += x_vec[i] * y_vec[i] ;
}
font = num * font ;
back_x = 0 ;
for (int i = 0 ;i < num ; i++)
{
back_x += x_vec[i] ;
}
back_y = 0 ;
for (int i =0 ; i< num ; i++)
{
back_y += y_vec[i] ;
}
pow_x = 0;
for (int i = 0 ; i < num ; i ++)
{
pow_x += pow(x_vec[i],2) ;
}
pow_x = num * pow_x ;
m = (font - (back_x * back_y)) / (pow_x - pow(back_x,2)) ;
b = (back_y - (m * back_x)) / num ;
cout << round(m*1e3)/1e3 <<"\n" << round(b*1e3)/1e3 ;
} else
{
font = 0 ;
for(int i =0 ; i< num ; i++)
{
font += x_vec[i] * y_vec[i] ;
}
font = num * font ;
back_x = 0 ;
for (int i = 0 ;i < num ; i++)
{
back_x += x_vec[i] ;
}
back_y = 0 ;
for (int i =0 ; i< num ; i++)
{
back_y += y_vec[i] ;
}
pow_x = 0;
for (int i = 0 ; i < num ; i ++)
{
pow_x += pow(x_vec[i],2) ;
}
pow_x = num * pow_x ;
m = (font - (back_x * back_y)) / (pow_x - pow(back_x,2)) ;
b = (back_y - (m * back_x)) / num ;
cout << m << b;
float out_b = abs(b) ;
if (m == 0)
{
cout << "y = " << round(b*1e3)/1e3 ;
} else if ( m == -1)
{
cout << "y = -x " << ( b == 0 ? "": b>= 1 ? "+ ": "- ") ;
if (b != 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}
}
} | # 0052, 2024-11-02 13:12:21, PPPPPPPPPP-------------- (41%)
#include <bits/stdc++.h>
using namespace std;
int main()
{ int num ;
float x,y , font = 0 , back_x = 0, back_y = 0,pow_x = 0 , m ,b;
string order ;
vector <float> x_vec ;
vector <float> y_vec ;
cin >> num >> order ;
for ( int i = 0 ; i < num ; i++)
{
cin >> x >> y;
x_vec.emplace_back(x) ;
y_vec.emplace_back(y) ;
}
if (order == "mb")
{
font = 0 ;
for(int i =0 ; i< num ; i++)
{
font += x_vec[i] * y_vec[i] ;
}
font = num * font ;
back_x = 0 ;
for (int i = 0 ;i < num ; i++)
{
back_x += x_vec[i] ;
}
back_y = 0 ;
for (int i =0 ; i< num ; i++)
{
back_y += y_vec[i] ;
}
pow_x = 0;
for (int i = 0 ; i < num ; i ++)
{
pow_x += pow(x_vec[i],2) ;
}
pow_x = num * pow_x ;
m = (font - (back_x * back_y)) / (pow_x - pow(back_x,2)) ;
b = (back_y - (m * back_x)) / num ;
cout << round(m*1e3)/1e3 <<"\n" << round(b*1e3)/1e3 ;
} else
{
font = 0 ;
for(int i =0 ; i< num ; i++)
{
font += x_vec[i] * y_vec[i] ;
}
font = num * font ;
back_x = 0 ;
for (int i = 0 ;i < num ; i++)
{
back_x += x_vec[i] ;
}
back_y = 0 ;
for (int i =0 ; i< num ; i++)
{
back_y += y_vec[i] ;
}
pow_x = 0;
for (int i = 0 ; i < num ; i ++)
{
pow_x += pow(x_vec[i],2) ;
}
pow_x = num * pow_x ;
m = (font - (back_x * back_y)) / (pow_x - pow(back_x,2)) ;
b = (back_y - (m * back_x)) / num ;
cout << m << b;
float out_b = abs(b) ;
if (m == 0)
{
cout << "y = " << round(b*1e3)/1e3 ;
} else if ( m == -1)
{
cout << "y = -x " << ( b == 0 ? "": b>= 1 ? "+ ": "- ") ;
if (b != 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}
}
} | # 0053, 2024-11-02 13:13:14, PPPPPPPPPP-----P---P-P-- (54%)
#include <bits/stdc++.h>
using namespace std;
int main()
{ int num ;
float x,y , font = 0 , back_x = 0, back_y = 0,pow_x = 0 , m ,b;
string order ;
vector <float> x_vec ;
vector <float> y_vec ;
cin >> num >> order ;
for ( int i = 0 ; i < num ; i++)
{
cin >> x >> y;
x_vec.emplace_back(x) ;
y_vec.emplace_back(y) ;
}
if (order == "mb")
{
font = 0 ;
for(int i =0 ; i< num ; i++)
{
font += x_vec[i] * y_vec[i] ;
}
font = num * font ;
back_x = 0 ;
for (int i = 0 ;i < num ; i++)
{
back_x += x_vec[i] ;
}
back_y = 0 ;
for (int i =0 ; i< num ; i++)
{
back_y += y_vec[i] ;
}
pow_x = 0;
for (int i = 0 ; i < num ; i ++)
{
pow_x += pow(x_vec[i],2) ;
}
pow_x = num * pow_x ;
m = (font - (back_x * back_y)) / (pow_x - pow(back_x,2)) ;
b = (back_y - (m * back_x)) / num ;
cout << round(m*1e3)/1e3 <<"\n" << round(b*1e3)/1e3 ;
} else
{
font = 0 ;
for(int i =0 ; i< num ; i++)
{
font += x_vec[i] * y_vec[i] ;
}
font = num * font ;
back_x = 0 ;
for (int i = 0 ;i < num ; i++)
{
back_x += x_vec[i] ;
}
back_y = 0 ;
for (int i =0 ; i< num ; i++)
{
back_y += y_vec[i] ;
}
pow_x = 0;
for (int i = 0 ; i < num ; i ++)
{
pow_x += pow(x_vec[i],2) ;
}
pow_x = num * pow_x ;
m = (font - (back_x * back_y)) / (pow_x - pow(back_x,2)) ;
b = (back_y - (m * back_x)) / num ;
float out_b = abs(b) ;
if (m == 0)
{
cout << "y = " << round(b*1e3)/1e3 ;
} else if ( m == -1)
{
cout << "y = -x " << ( b == 0 ? "": b>= 1 ? "+ ": "- ") ;
if (b != 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}
}
} | # 0054, 2024-11-02 13:18:08, Compilation error (0%)
#include <bits/stdc++.h>
using namespace std;
int main()
{ int num ;
float x,y , font = 0 , back_x = 0, back_y = 0,pow_x = 0 , m ,b;
string order ;
vector <float> x_vec ;
vector <float> y_vec ;
cin >> num >> order ;
for ( int i = 0 ; i < num ; i++)
{
cin >> x >> y;
x_vec.emplace_back(x) ;
y_vec.emplace_back(y) ;
}
if (order == "mb")
{
font = 0 ;
for(int i =0 ; i< num ; i++)
{
font += x_vec[i] * y_vec[i] ;
}
font = num * font ;
back_x = 0 ;
for (int i = 0 ;i < num ; i++)
{
back_x += x_vec[i] ;
}
back_y = 0 ;
for (int i =0 ; i< num ; i++)
{
back_y += y_vec[i] ;
}
pow_x = 0;
for (int i = 0 ; i < num ; i ++)
{
pow_x += pow(x_vec[i],2) ;
}
pow_x = num * pow_x ;
m = (font - (back_x * back_y)) / (pow_x - pow(back_x,2)) ;
b = (back_y - (m * back_x)) / num ;
cout << round(m*1e3)/1e3 <<"\n" << round(b*1e3)/1e3 ;
} else
{
font = 0 ;
for(int i =0 ; i< num ; i++)
{
font += x_vec[i] * y_vec[i] ;
}
font = num * font ;
back_x = 0 ;
for (int i = 0 ;i < num ; i++)
{
back_x += x_vec[i] ;
}
back_y = 0 ;
for (int i =0 ; i< num ; i++)
{
back_y += y_vec[i] ;
}
pow_x = 0;
for (int i = 0 ; i < num ; i ++)
{
pow_x += pow(x_vec[i],2) ;
}
pow_x = num * pow_x ;
m = (font - (back_x * back_y)) / (pow_x - pow(back_x,2)) ;
b = (back_y - (m * back_x)) / num ;
float out_b = abs(b) ;
if (m == 0)
{
cout << "y = " << round(b*1e3)/1e3 ;
} else if ( m == -1)
{
cout << "y = -x " << ( b == 0 ? "": b>= 1 ? "+ ": "- ") ;
if (b != 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}else if ( m == 1)
{
cout << "y = x " << ( b == 0 ? "": b>= 1 ? "+ ": "- ") ;
if (b != 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}else
{
cout << "y = "<< round(out_m*1e3)/1e3 <<"x " << ( b == 0 ? "": b>= 1 ? "+ ": "- ") ;
if (b != 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}
}
} | # 0055, 2024-11-02 13:18:31, PPPPPPPPPPPPPPPP--PP-PP- (83%)
#include <bits/stdc++.h>
using namespace std;
int main()
{ int num ;
float x,y , font = 0 , back_x = 0, back_y = 0,pow_x = 0 , m ,b;
string order ;
vector <float> x_vec ;
vector <float> y_vec ;
cin >> num >> order ;
for ( int i = 0 ; i < num ; i++)
{
cin >> x >> y;
x_vec.emplace_back(x) ;
y_vec.emplace_back(y) ;
}
if (order == "mb")
{
font = 0 ;
for(int i =0 ; i< num ; i++)
{
font += x_vec[i] * y_vec[i] ;
}
font = num * font ;
back_x = 0 ;
for (int i = 0 ;i < num ; i++)
{
back_x += x_vec[i] ;
}
back_y = 0 ;
for (int i =0 ; i< num ; i++)
{
back_y += y_vec[i] ;
}
pow_x = 0;
for (int i = 0 ; i < num ; i ++)
{
pow_x += pow(x_vec[i],2) ;
}
pow_x = num * pow_x ;
m = (font - (back_x * back_y)) / (pow_x - pow(back_x,2)) ;
b = (back_y - (m * back_x)) / num ;
cout << round(m*1e3)/1e3 <<"\n" << round(b*1e3)/1e3 ;
} else
{
font = 0 ;
for(int i =0 ; i< num ; i++)
{
font += x_vec[i] * y_vec[i] ;
}
font = num * font ;
back_x = 0 ;
for (int i = 0 ;i < num ; i++)
{
back_x += x_vec[i] ;
}
back_y = 0 ;
for (int i =0 ; i< num ; i++)
{
back_y += y_vec[i] ;
}
pow_x = 0;
for (int i = 0 ; i < num ; i ++)
{
pow_x += pow(x_vec[i],2) ;
}
pow_x = num * pow_x ;
m = (font - (back_x * back_y)) / (pow_x - pow(back_x,2)) ;
b = (back_y - (m * back_x)) / num ;
float out_b = abs(b) ;
if (m == 0)
{
cout << "y = " << round(b*1e3)/1e3 ;
} else if ( m == -1)
{
cout << "y = -x " << ( b == 0 ? "": b>= 1 ? "+ ": "- ") ;
if (b != 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}else if ( m == 1)
{
cout << "y = x " << ( b == 0 ? "": b>= 1 ? "+ ": "- ") ;
if (b != 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}else
{
cout << "y = "<< round(m*1e3)/1e3 <<"x " << ( b == 0 ? "": b>= 1 ? "+ ": "- ") ;
if (b != 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}
}
} | # 0056, 2024-11-02 13:22:11, PPPPPPPPPPPPPPPPP-PP-PP- (87%)
#include <bits/stdc++.h>
using namespace std;
int main()
{ int num ;
float x,y , font = 0 , back_x = 0, back_y = 0,pow_x = 0 , m ,b;
string order ;
vector <float> x_vec ;
vector <float> y_vec ;
cin >> num >> order ;
for ( int i = 0 ; i < num ; i++)
{
cin >> x >> y;
x_vec.emplace_back(x) ;
y_vec.emplace_back(y) ;
}
if (order == "mb")
{
font = 0 ;
for(int i =0 ; i< num ; i++)
{
font += x_vec[i] * y_vec[i] ;
}
font = num * font ;
back_x = 0 ;
for (int i = 0 ;i < num ; i++)
{
back_x += x_vec[i] ;
}
back_y = 0 ;
for (int i =0 ; i< num ; i++)
{
back_y += y_vec[i] ;
}
pow_x = 0;
for (int i = 0 ; i < num ; i ++)
{
pow_x += pow(x_vec[i],2) ;
}
pow_x = num * pow_x ;
m = (font - (back_x * back_y)) / (pow_x - pow(back_x,2)) ;
b = (back_y - (m * back_x)) / num ;
cout << round(m*1e3)/1e3 <<"\n" << round(b*1e3)/1e3 ;
} else
{
font = 0 ;
for(int i =0 ; i< num ; i++)
{
font += x_vec[i] * y_vec[i] ;
}
font = num * font ;
back_x = 0 ;
for (int i = 0 ;i < num ; i++)
{
back_x += x_vec[i] ;
}
back_y = 0 ;
for (int i =0 ; i< num ; i++)
{
back_y += y_vec[i] ;
}
pow_x = 0;
for (int i = 0 ; i < num ; i ++)
{
pow_x += pow(x_vec[i],2) ;
}
pow_x = num * pow_x ;
m = (font - (back_x * back_y)) / (pow_x - pow(back_x,2)) ;
b = (back_y - (m * back_x)) / num ;
float out_b = abs(b) ;
if (round(m*1e3)/1e3 == 0)
{
cout << "y = " << round(b*1e3)/1e3 ;
} else if ( m == -1)
{
cout << "y = -x " << ( b == 0 ? "": b>= 1 ? "+ ": "- ") ;
if (b != 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}else if ( m == 1)
{
cout << "y = x " << ( b == 0 ? "": b>= 1 ? "+ ": "- ") ;
if (b != 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}else
{
cout << "y = "<< round(m*1e3)/1e3 <<"x " << ( b == 0 ? "": b>= 1 ? "+ ": "- ") ;
if (b != 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}
}
} | # 0057, 2024-11-02 13:23:09, PPPPPPPPPPPPPPPPP----P-- (75%)
#include <bits/stdc++.h>
using namespace std;
int main()
{ int num ;
float x,y , font = 0 , back_x = 0, back_y = 0,pow_x = 0 , m ,b;
string order ;
vector <float> x_vec ;
vector <float> y_vec ;
cin >> num >> order ;
for ( int i = 0 ; i < num ; i++)
{
cin >> x >> y;
x_vec.emplace_back(x) ;
y_vec.emplace_back(y) ;
}
if (order == "mb")
{
font = 0 ;
for(int i =0 ; i< num ; i++)
{
font += x_vec[i] * y_vec[i] ;
}
font = num * font ;
back_x = 0 ;
for (int i = 0 ;i < num ; i++)
{
back_x += x_vec[i] ;
}
back_y = 0 ;
for (int i =0 ; i< num ; i++)
{
back_y += y_vec[i] ;
}
pow_x = 0;
for (int i = 0 ; i < num ; i ++)
{
pow_x += pow(x_vec[i],2) ;
}
pow_x = num * pow_x ;
m = (font - (back_x * back_y)) / (pow_x - pow(back_x,2)) ;
b = (back_y - (m * back_x)) / num ;
cout << round(m*1e3)/1e3 <<"\n" << round(b*1e3)/1e3 ;
} else
{
font = 0 ;
for(int i =0 ; i< num ; i++)
{
font += x_vec[i] * y_vec[i] ;
}
font = num * font ;
back_x = 0 ;
for (int i = 0 ;i < num ; i++)
{
back_x += x_vec[i] ;
}
back_y = 0 ;
for (int i =0 ; i< num ; i++)
{
back_y += y_vec[i] ;
}
pow_x = 0;
for (int i = 0 ; i < num ; i ++)
{
pow_x += pow(x_vec[i],2) ;
}
pow_x = num * pow_x ;
m = (font - (back_x * back_y)) / (pow_x - pow(back_x,2)) ;
b = (back_y - (m * back_x)) / num ;
float out_b = abs(b) ;
if (round(m*1e3)/1e3 == 0)
{
cout << "y = " << round(b*1e3)/1e3 ;
} else if ( round(m*1e3) == -1)
{
cout << "y = -x " << ( b == 0 ? "": b>= 1 ? "+ ": "- ") ;
if (b != 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}else if ( round(m*1e3) == 1)
{
cout << "y = x " << ( b == 0 ? "": b>= 1 ? "+ ": "- ") ;
if (b != 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}else
{
cout << "y = "<< round(m*1e3)/1e3 <<"x " << ( b == 0 ? "": b>= 1 ? "+ ": "- ") ;
if (b != 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}
}
} | # 0058, 2024-11-02 13:23:27, PPPPPPPPPPPPPPPPP-P--PP- (83%)
#include <bits/stdc++.h>
using namespace std;
int main()
{ int num ;
float x,y , font = 0 , back_x = 0, back_y = 0,pow_x = 0 , m ,b;
string order ;
vector <float> x_vec ;
vector <float> y_vec ;
cin >> num >> order ;
for ( int i = 0 ; i < num ; i++)
{
cin >> x >> y;
x_vec.emplace_back(x) ;
y_vec.emplace_back(y) ;
}
if (order == "mb")
{
font = 0 ;
for(int i =0 ; i< num ; i++)
{
font += x_vec[i] * y_vec[i] ;
}
font = num * font ;
back_x = 0 ;
for (int i = 0 ;i < num ; i++)
{
back_x += x_vec[i] ;
}
back_y = 0 ;
for (int i =0 ; i< num ; i++)
{
back_y += y_vec[i] ;
}
pow_x = 0;
for (int i = 0 ; i < num ; i ++)
{
pow_x += pow(x_vec[i],2) ;
}
pow_x = num * pow_x ;
m = (font - (back_x * back_y)) / (pow_x - pow(back_x,2)) ;
b = (back_y - (m * back_x)) / num ;
cout << round(m*1e3)/1e3 <<"\n" << round(b*1e3)/1e3 ;
} else
{
font = 0 ;
for(int i =0 ; i< num ; i++)
{
font += x_vec[i] * y_vec[i] ;
}
font = num * font ;
back_x = 0 ;
for (int i = 0 ;i < num ; i++)
{
back_x += x_vec[i] ;
}
back_y = 0 ;
for (int i =0 ; i< num ; i++)
{
back_y += y_vec[i] ;
}
pow_x = 0;
for (int i = 0 ; i < num ; i ++)
{
pow_x += pow(x_vec[i],2) ;
}
pow_x = num * pow_x ;
m = (font - (back_x * back_y)) / (pow_x - pow(back_x,2)) ;
b = (back_y - (m * back_x)) / num ;
float out_b = abs(b) ;
if (round(m*1e3)/1e3 == 0)
{
cout << "y = " << round(b*1e3)/1e3 ;
} else if ( round(m*1e3) == -1)
{
cout << "y = -x " << ( b == 0 ? "": b>= 1 ? "+ ": "- ") ;
if (b != 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}else if ( m == 1)
{
cout << "y = x " << ( b == 0 ? "": b>= 1 ? "+ ": "- ") ;
if (b != 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}else
{
cout << "y = "<< round(m*1e3)/1e3 <<"x " << ( b == 0 ? "": b>= 1 ? "+ ": "- ") ;
if (b != 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}
}
} | # 0059, 2024-11-02 13:23:53, PPPPPPPPPPPPPPPPP-PP-PP- (87%)
#include <bits/stdc++.h>
using namespace std;
int main()
{ int num ;
float x,y , font = 0 , back_x = 0, back_y = 0,pow_x = 0 , m ,b;
string order ;
vector <float> x_vec ;
vector <float> y_vec ;
cin >> num >> order ;
for ( int i = 0 ; i < num ; i++)
{
cin >> x >> y;
x_vec.emplace_back(x) ;
y_vec.emplace_back(y) ;
}
if (order == "mb")
{
font = 0 ;
for(int i =0 ; i< num ; i++)
{
font += x_vec[i] * y_vec[i] ;
}
font = num * font ;
back_x = 0 ;
for (int i = 0 ;i < num ; i++)
{
back_x += x_vec[i] ;
}
back_y = 0 ;
for (int i =0 ; i< num ; i++)
{
back_y += y_vec[i] ;
}
pow_x = 0;
for (int i = 0 ; i < num ; i ++)
{
pow_x += pow(x_vec[i],2) ;
}
pow_x = num * pow_x ;
m = (font - (back_x * back_y)) / (pow_x - pow(back_x,2)) ;
b = (back_y - (m * back_x)) / num ;
cout << round(m*1e3)/1e3 <<"\n" << round(b*1e3)/1e3 ;
} else
{
font = 0 ;
for(int i =0 ; i< num ; i++)
{
font += x_vec[i] * y_vec[i] ;
}
font = num * font ;
back_x = 0 ;
for (int i = 0 ;i < num ; i++)
{
back_x += x_vec[i] ;
}
back_y = 0 ;
for (int i =0 ; i< num ; i++)
{
back_y += y_vec[i] ;
}
pow_x = 0;
for (int i = 0 ; i < num ; i ++)
{
pow_x += pow(x_vec[i],2) ;
}
pow_x = num * pow_x ;
m = (font - (back_x * back_y)) / (pow_x - pow(back_x,2)) ;
b = (back_y - (m * back_x)) / num ;
float out_b = abs(b) ;
if (round(m*1e3)/1e3 == 0)
{
cout << "y = " << round(b*1e3)/1e3 ;
} else if ( m == -1)
{
cout << "y = -x " << ( b == 0 ? "": b>= 1 ? "+ ": "- ") ;
if (b != 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}else if ( m == 1)
{
cout << "y = x " << ( b == 0 ? "": b>= 1 ? "+ ": "- ") ;
if (b != 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}else
{
cout << "y = "<< round(m*1e3)/1e3 <<"x " << ( b == 0 ? "": b>= 1 ? "+ ": "- ") ;
if (b != 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}
}
} | # 0060, 2024-11-02 13:25:02, PPPPPPPPPPPPPPPPP-PP-PP- (87%)
#include <bits/stdc++.h>
using namespace std;
int main()
{ int num ;
float x,y , font = 0 , back_x = 0, back_y = 0,pow_x = 0 , m ,b;
string order ;
vector <float> x_vec ;
vector <float> y_vec ;
cin >> num >> order ;
for ( int i = 0 ; i < num ; i++)
{
cin >> x >> y;
x_vec.emplace_back(x) ;
y_vec.emplace_back(y) ;
}
if (order == "mb")
{
font = 0 ;
for(int i =0 ; i< num ; i++)
{
font += x_vec[i] * y_vec[i] ;
}
font = num * font ;
back_x = 0 ;
for (int i = 0 ;i < num ; i++)
{
back_x += x_vec[i] ;
}
back_y = 0 ;
for (int i =0 ; i< num ; i++)
{
back_y += y_vec[i] ;
}
pow_x = 0;
for (int i = 0 ; i < num ; i ++)
{
pow_x += pow(x_vec[i],2) ;
}
pow_x = num * pow_x ;
m = (font - (back_x * back_y)) / (pow_x - pow(back_x,2)) ;
b = (back_y - (m * back_x)) / num ;
cout << round(m*1e3)/1e3 <<"\n" << round(b*1e3)/1e3 ;
} else
{
font = 0 ;
for(int i =0 ; i< num ; i++)
{
font += x_vec[i] * y_vec[i] ;
}
font = num * font ;
back_x = 0 ;
for (int i = 0 ;i < num ; i++)
{
back_x += x_vec[i] ;
}
back_y = 0 ;
for (int i =0 ; i< num ; i++)
{
back_y += y_vec[i] ;
}
pow_x = 0;
for (int i = 0 ; i < num ; i ++)
{
pow_x += pow(x_vec[i],2) ;
}
pow_x = num * pow_x ;
m = (font - (back_x * back_y)) / (pow_x - pow(back_x,2)) ;
b = (back_y - (m * back_x)) / num ;
float out_b = abs(b) ;
if (round(m*1e3)/1e3 == 0)
{
cout << "y = " << round(b*1e3)/1e3 ;
} else if ( m == -1)
{
cout << "y = -x " << ( b == 0 ? "": b>= 1 ? "+ ": "- ") ;
if ( round(b*1e3)!= 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}else if ( m == 1)
{
cout << "y = x " << ( b == 0 ? "": b>= 1 ? "+ ": "- ") ;
if (round(b*1e3) != 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}else
{
cout << "y = "<< round(m*1e3)/1e3 <<"x " << ( b == 0 ? "": b>= 1 ? "+ ": "- ") ;
if (round(b*1e3) != 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}
}
} | # 0061, 2024-11-02 13:25:56, PPPPPPPPPPPPPPPPP-PP-PP- (87%)
#include <bits/stdc++.h>
using namespace std;
int main()
{ int num ;
float x,y , font = 0 , back_x = 0, back_y = 0,pow_x = 0 , m ,b;
string order ;
vector <float> x_vec ;
vector <float> y_vec ;
cin >> num >> order ;
for ( int i = 0 ; i < num ; i++)
{
cin >> x >> y;
x_vec.emplace_back(x) ;
y_vec.emplace_back(y) ;
}
if (order == "mb")
{
font = 0 ;
for(int i =0 ; i< num ; i++)
{
font += x_vec[i] * y_vec[i] ;
}
font = num * font ;
back_x = 0 ;
for (int i = 0 ;i < num ; i++)
{
back_x += x_vec[i] ;
}
back_y = 0 ;
for (int i =0 ; i< num ; i++)
{
back_y += y_vec[i] ;
}
pow_x = 0;
for (int i = 0 ; i < num ; i ++)
{
pow_x += pow(x_vec[i],2) ;
}
pow_x = num * pow_x ;
m = (font - (back_x * back_y)) / (pow_x - pow(back_x,2)) ;
b = (back_y - (m * back_x)) / num ;
cout << round(m*1e3)/1e3 <<"\n" << round(b*1e3)/1e3 ;
} else
{
font = 0 ;
for(int i =0 ; i< num ; i++)
{
font += x_vec[i] * y_vec[i] ;
}
font = num * font ;
back_x = 0 ;
for (int i = 0 ;i < num ; i++)
{
back_x += x_vec[i] ;
}
back_y = 0 ;
for (int i =0 ; i< num ; i++)
{
back_y += y_vec[i] ;
}
pow_x = 0;
for (int i = 0 ; i < num ; i ++)
{
pow_x += pow(x_vec[i],2) ;
}
pow_x = num * pow_x ;
m = (font - (back_x * back_y)) / (pow_x - pow(back_x,2)) ;
b = (back_y - (m * back_x)) / num ;
float out_b = abs(b) ;
if (round(m*1e3)/1e3 == 0)
{
cout << "y = " << round(b*1e3)/1e3 ;
} else if ( m == -1)
{
cout << "y = -x " << ( round(b*1e3) == 0 ? "": round(b*1e3)>= 1 ? "+ ": "- ") ;
if ( round(b*1e3)!= 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}else if ( m == 1)
{
cout << "y = x " << ( round(b*1e3) == 0 ? "": round(b*1e3)>= 1 ? "+ ": "- ") ;
if (round(b*1e3) != 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}else
{
cout << "y = "<< round(m*1e3)/1e3 <<"x " << ( round(b*1e3) == 0 ? "": round(b*1e3)>= 1 ? "+ ": "- ") ;
if (round(b*1e3) != 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}
}
} | # 0062, 2024-11-02 13:26:54, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
int main()
{ int num ;
float x,y , font = 0 , back_x = 0, back_y = 0,pow_x = 0 , m ,b;
string order ;
vector <float> x_vec ;
vector <float> y_vec ;
cin >> num >> order ;
for ( int i = 0 ; i < num ; i++)
{
cin >> x >> y;
x_vec.emplace_back(x) ;
y_vec.emplace_back(y) ;
}
if (order == "mb")
{
font = 0 ;
for(int i =0 ; i< num ; i++)
{
font += x_vec[i] * y_vec[i] ;
}
font = num * font ;
back_x = 0 ;
for (int i = 0 ;i < num ; i++)
{
back_x += x_vec[i] ;
}
back_y = 0 ;
for (int i =0 ; i< num ; i++)
{
back_y += y_vec[i] ;
}
pow_x = 0;
for (int i = 0 ; i < num ; i ++)
{
pow_x += pow(x_vec[i],2) ;
}
pow_x = num * pow_x ;
m = (font - (back_x * back_y)) / (pow_x - pow(back_x,2)) ;
b = (back_y - (m * back_x)) / num ;
cout << round(m*1e3)/1e3 <<"\n" << round(b*1e3)/1e3 ;
} else
{
font = 0 ;
for(int i =0 ; i< num ; i++)
{
font += x_vec[i] * y_vec[i] ;
}
font = num * font ;
back_x = 0 ;
for (int i = 0 ;i < num ; i++)
{
back_x += x_vec[i] ;
}
back_y = 0 ;
for (int i =0 ; i< num ; i++)
{
back_y += y_vec[i] ;
}
pow_x = 0;
for (int i = 0 ; i < num ; i ++)
{
pow_x += pow(x_vec[i],2) ;
}
pow_x = num * pow_x ;
m = (font - (back_x * back_y)) / (pow_x - pow(back_x,2)) ;
b = (back_y - (m * back_x)) / num ;
float out_b = abs(b) ;
if (round(m*1e3)/1e3 == 0)
{
cout << "y = " << round(b*1e3)/1e3 ;
} else if ( round(m*1e3)/1e3 == -1)
{
cout << "y = -x " << ( round(b*1e3) == 0 ? "": round(b*1e3)>= 1 ? "+ ": "- ") ;
if ( round(b*1e3)!= 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}else if ( round(m*1e3)/1e3 == 1)
{
cout << "y = x " << ( round(b*1e3) == 0 ? "": round(b*1e3)>= 1 ? "+ ": "- ") ;
if (round(b*1e3) != 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}else
{
cout << "y = "<< round(m*1e3)/1e3 <<"x " << ( round(b*1e3) == 0 ? "": round(b*1e3)>= 1 ? "+ ": "- ") ;
if (round(b*1e3) != 0)
{
cout << round(out_b*1e3)/1e3 ;
}
}
}
} |
# 0063, 2024-11-02 12:55:46, PPPPPPPPPPPPPPPP--PP---- (75%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string comm;
float x,y,m,b;
float X=0,Y=0,X2=0,XY=0;
cin>>n>>comm;
for(int i=1;i<=n;i++){
cin>>x>>y;
X+=x;
Y+=y;
X2+=x*x;
XY+=x*y;
}
m=(n*XY-X*Y)/(n*X2-X*X);
b=(Y-m*X)/n;
if(comm=="func"){
cout<<"y = ";
if(m==0){
if(b>0)cout<<round(b*1e3)/1e3;
else if(b==0)cout<<"0";
else cout<<"- "<<abs(round(b*1e3)/1e3);
return 0;
}
else if(m==1)cout<<"x ";
else if(m==-1)cout<<"-x ";
else cout<<round(m*1e3)/1e3<<"x ";
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0) cout<<"- "<<abs(round(b*1e3)/1e3);
}
else{
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
return 0;
} | # 0064, 2024-11-02 14:30:16, ----------PPPPPP--PP---- (33%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string comm;
float x,y,m,b;
float X=0,Y=0,X2=0,XY=0;
cin>>n>>comm;
for(int i=1;i<=n;i++){
cin>>x>>y;
X+=x;
Y+=y;
X2+=x*x;
XY+=x*y;
}
m=(n*XY-X*Y)/(n*X2-X*X);
b=(Y-m*X)/n;
if(comm=="func"){
cout<<"y = ";
if(m==0){
if(b>0)cout<<round(b*1e3)/1e3;
else if(b==0)cout<<"0";
else cout<<"- "<<abs(round(b*1e3)/1e3);
return 0;
}
else if(m==1)cout<<"x ";
else if(m==-1)cout<<"-x ";
else cout<<round(m*1e3)/1e3<<"x ";
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0) cout<<"- "<<abs(round(b*1e3)/1e3);
}
/*else{
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}*/
return 0;
} | # 0065, 2024-11-02 14:30:53, PPPPPPPPPPPPPPPP--PP---- (75%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string comm;
float x,y,m,b;
float X=0,Y=0,X2=0,XY=0;
cin>>n>>comm;
for(int i=1;i<=n;i++){
cin>>x>>y;
X+=x;
Y+=y;
X2+=x*x;
XY+=x*y;
}
m=(n*XY-X*Y)/(n*X2-X*X);
b=(Y-m*X)/n;
if(comm=="func"){
cout<<"y = ";
if(m==0){
if(b>0)cout<<round(b*1e3)/1e3;
else if(b==0)cout<<"0";
else cout<<"- "<<abs(round(b*1e3)/1e3);
return 0;
}
else if(m==1)cout<<"x ";
else if(m==-1)cout<<"-x ";
else cout<<round(m*1e3)/1e3<<"x ";
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0) cout<<"- "<<abs(round(b*1e3)/1e3);
}
else{
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
return 0;
} | # 0066, 2024-11-02 14:35:23, Compilation error (0%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string comm;
float x,y,m,b;
float X=0,Y=0,X2=0,XY=0;
cin>>n>>comm;
for(int i=1;i<=n;i++){
cin>>x>>y;
X+=x;
Y+=y;
X2+=x*x;
XY+=x*y;
}
m=(n*XY-X*Y)/(n*X2-X*X);
b=(Y-m*X)/n;
if(comm=="func"){
cout<<"y = ";
if(m==0){
if(b>0)cout<<round(b*1e3)/1e3;
else if(b==0)cout<<"0";
else cout<<"- "<<abs(round(b*1e3)/1e3);
return 0;
}
else if(m==1)return 0;cout<<"x ";
else if(m==-1)return 0;cout<<"-x ";
else cout<<round(m*1e3)/1e3<<"x ";
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0) cout<<"- "<<abs(round(b*1e3)/1e3);
}
else{
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
return 0;
} | # 0067, 2024-11-02 14:35:40, PPPPPPPPPPPPPPPP-------- (66%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string comm;
float x,y,m,b;
float X=0,Y=0,X2=0,XY=0;
cin>>n>>comm;
for(int i=1;i<=n;i++){
cin>>x>>y;
X+=x;
Y+=y;
X2+=x*x;
XY+=x*y;
}
m=(n*XY-X*Y)/(n*X2-X*X);
b=(Y-m*X)/n;
if(comm=="func"){
cout<<"y = ";
if(m==0){
if(b>0)cout<<round(b*1e3)/1e3;
else if(b==0)cout<<"0";
else cout<<"- "<<abs(round(b*1e3)/1e3);
return 0;
}
else if(m==1)return 0;
else if(m==-1)return 0;
else cout<<round(m*1e3)/1e3<<"x ";
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0) cout<<"- "<<abs(round(b*1e3)/1e3);
}
else{
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
return 0;
} | # 0068, 2024-11-02 14:36:06, PPPPPPPPPPPPPPPP--P----- (70%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string comm;
float x,y,m,b;
float X=0,Y=0,X2=0,XY=0;
cin>>n>>comm;
for(int i=1;i<=n;i++){
cin>>x>>y;
X+=x;
Y+=y;
X2+=x*x;
XY+=x*y;
}
m=(n*XY-X*Y)/(n*X2-X*X);
b=(Y-m*X)/n;
if(comm=="func"){
cout<<"y = ";
if(m==0){
if(b>0)cout<<round(b*1e3)/1e3;
else if(b==0)cout<<"0";
else cout<<"- "<<abs(round(b*1e3)/1e3);
return 0;
}
else if(m==1)cout<<"x ";
else if(m==-1)return 0;
else cout<<round(m*1e3)/1e3<<"x ";
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0) cout<<"- "<<abs(round(b*1e3)/1e3);
}
else{
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
return 0;
} | # 0069, 2024-11-02 14:36:34, PPPPPPPPPPPPPPPP--PP---- (75%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string comm;
float x,y,m,b;
float X=0,Y=0,X2=0,XY=0;
cin>>n>>comm;
for(int i=1;i<=n;i++){
cin>>x>>y;
X+=x;
Y+=y;
X2+=x*x;
XY+=x*y;
}
m=(n*XY-X*Y)/(n*X2-X*X);
b=(Y-m*X)/n;
if(comm=="func"){
cout<<"y = ";
if(m==0){
if(b>0)cout<<round(b*1e3)/1e3;
else if(b==0)cout<<"0";
else cout<<"- "<<abs(round(b*1e3)/1e3);
return 0;
}
else if(m==1)cout<<"x ";
else if(m==-1)cout<<"-x ";
else cout<<round(m*1e3)/1e3<<"x ";
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0) cout<<"- "<<abs(round(b*1e3)/1e3);
}
else{
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
return 0;
} | # 0070, 2024-11-02 14:37:01, Compilation error (0%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string comm;
float x,y,m,b;
float X=0,Y=0,X2=0,XY=0;
cin>>n>>comm;
for(int i=1;i<=n;i++){
cin>>x>>y;
X+=x;
Y+=y;
X2+=x*x;
XY+=x*y;
}
m=(n*XY-X*Y)/(n*X2-X*X);
b=(Y-m*X)/n;
if(comm=="func"){
cout<<"y = ";
if(m==0){
if(b>0)cout<<round(b*1e3)/1e3;
else if(b==0)cout<<"0";
else cout<<"- "<<abs(round(b*1e3)/1e3);
return 0;
}
else if(m==1)cout<<"x";
else if(m==-1)cout<<"-x ;
else cout<<round(m*1e3)/1e3<<"x";
if(b>0)cout<<" + "<<round(b*1e3)/1e3;
else if(b<0) cout<<"- "<<abs(round(b*1e3)/1e3);
}
else{
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
return 0;
} | # 0071, 2024-11-02 14:37:17, PPPPPPPPPPPPPPPP--PP---- (75%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string comm;
float x,y,m,b;
float X=0,Y=0,X2=0,XY=0;
cin>>n>>comm;
for(int i=1;i<=n;i++){
cin>>x>>y;
X+=x;
Y+=y;
X2+=x*x;
XY+=x*y;
}
m=(n*XY-X*Y)/(n*X2-X*X);
b=(Y-m*X)/n;
if(comm=="func"){
cout<<"y = ";
if(m==0){
if(b>0)cout<<round(b*1e3)/1e3;
else if(b==0)cout<<"0";
else cout<<"- "<<abs(round(b*1e3)/1e3);
return 0;
}
else if(m==1)cout<<"x";
else if(m==-1)cout<<"-x" ;
else cout<<round(m*1e3)/1e3<<"x";
if(b>0)cout<<" + "<<round(b*1e3)/1e3;
else if(b<0) cout<<" - "<<abs(round(b*1e3)/1e3);
}
else{
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
return 0;
} | # 0072, 2024-11-02 15:01:37, PPPPPPPPPPPPPPPP-PPPP-PP (91%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string comm;
float x,y,m,b;
float X=0,Y=0,X2=0,XY=0;
cin>>n>>comm;
for(int i=1;i<=n;i++){
cin>>x>>y;
X+=x;
Y+=y;
X2+=x*x;
XY+=x*y;
}
m=(n*XY-X*Y)/(n*X2-X*X);
b=(Y-m*X)/n;
if(comm=="func"){
cout<<"y = ";
if(m==0){
if(b>0)cout<<round(b*1e3)/1e3;
else if(b==0)cout<<"0";
else cout<<"- "<<abs(round(b*1e3)/1e3);
return 0;
}
else if(round(m*1e3)/1e3==1)cout<<"x";
else if(round(m*1e3)/1e3==-1)cout<<"-x" ;
else cout<<round(m*1e3)/1e3<<"x";
if(b>0)cout<<" + "<<round(b*1e3)/1e3;
else if(b<0) cout<<" - "<<abs(round(b*1e3)/1e3);
}
else{
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
return 0;
} | # 0073, 2024-11-02 15:02:16, PPPPPPPPPPPPPPPP-PPPP-PP (91%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string comm;
float x,y,m,b;
float X=0,Y=0,X2=0,XY=0;
cin>>n>>comm;
for(int i=1;i<=n;i++){
cin>>x>>y;
X+=x;
Y+=y;
X2+=x*x;
XY+=x*y;
}
m=(n*XY-X*Y)/(n*X2-X*X);
b=(Y-m*X)/n;
if(comm=="func"){
cout<<"y = ";
if(m==0){
if(b>0)cout<<round(b*1e3)/1e3;
else if(b==0)cout<<"0";
else cout<<"- "<<abs(round(b*1e3)/1e3);
return 0;
}
else if(round(m*1e3)/1e3==1)cout<<"x";
else if(round(m*1e3)/1e3==-1)cout<<"-x" ;
else cout<<round(m*1e3)/1e3<<"x";
if(round(b*1e3)/1e3>0)cout<<" + "<<round(b*1e3)/1e3;
else if(round(b*1e3)/1e3<0) cout<<" - "<<abs(round(b*1e3)/1e3);
}
else{
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
return 0;
} | # 0074, 2024-11-02 15:04:40, PPPPPPPPPPPPPPPPPPPPP-PP (95%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string comm;
float x,y,m,b;
float X=0,Y=0,X2=0,XY=0;
cin>>n>>comm;
for(int i=1;i<=n;i++){
cin>>x>>y;
X+=x;
Y+=y;
X2+=x*x;
XY+=x*y;
}
m=(n*XY-X*Y)/(n*X2-X*X);
b=(Y-m*X)/n;
if(comm=="func"){
cout<<"y = ";
if(round(m*1e3)/1e3==0){
if(round(b*1e3)/1e3>0)cout<<round(b*1e3)/1e3;
else if(round(b*1e3)/1e3==0)cout<<"0";
else cout<<"- "<<abs(round(b*1e3)/1e3);
return 0;
}
else if(round(m*1e3)/1e3==1)cout<<"x";
else if(round(m*1e3)/1e3==-1)cout<<"-x" ;
else cout<<round(m*1e3)/1e3<<"x";
if(round(b*1e3)/1e3>0)cout<<" + "<<round(b*1e3)/1e3;
else if(round(b*1e3)/1e3<0) cout<<" - "<<abs(round(b*1e3)/1e3);
}
else{
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
return 0;
} | # 0075, 2024-11-02 15:06:12, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string comm;
float x,y,m,b;
float X=0,Y=0,X2=0,XY=0;
cin>>n>>comm;
for(int i=1;i<=n;i++){
cin>>x>>y;
X+=x;
Y+=y;
X2+=x*x;
XY+=x*y;
}
m=(n*XY-X*Y)/(n*X2-X*X);
b=(Y-m*X)/n;
if(comm=="func"){
cout<<"y = ";
if(round(m*1e3)/1e3==0){
if(round(b*1e3)/1e3>0)cout<<round(b*1e3)/1e3;
else if(round(b*1e3)/1e3==0)cout<<"0";
else cout<<"-"<<abs(round(b*1e3)/1e3);
return 0;
}
else if(round(m*1e3)/1e3==1)cout<<"x";
else if(round(m*1e3)/1e3==-1)cout<<"-x" ;
else cout<<round(m*1e3)/1e3<<"x";
if(round(b*1e3)/1e3>0)cout<<" + "<<round(b*1e3)/1e3;
else if(round(b*1e3)/1e3<0) cout<<" - "<<abs(round(b*1e3)/1e3);
}
else{
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
return 0;
} |
# 0076, 2024-11-02 09:58:44, -----PPP---------------- (12%)
//linear regression
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
float n;
string com;
cin >> n >> com;
vector<pair<float,float>> v1;
int round=n;
while(round--){
float x,y;
cin >> x >> y;
v1.push_back(make_pair(x,y));
}
float m1=0, m2=0, m3=0, m4=0 ,m5=0;
for(int i=1;i<=n;i++){
m1+=(v1[i].first)*(v1[i].second);
m2+=(v1[i].first);
m3+= (v1[i].second);
m4+= pow((v1[i].first),2);
}
m1 = n*m1;
m4 = n*m4;
m5 = pow(m2,2);
float m = (m1-(m2*m3))/(m4-m5);
float b1=0,b2=0;
for(int i=1;i<=n;i++){
b1+=v1[i].second;
b2+=v1[i].first;
}
b2 = m*b2;
float b = (b1-b2)/n;
if(com=="mb"){
cout << m << endl ;
cout << b << endl;
}else if(com=="func"){
}
} | # 0077, 2024-11-02 10:07:13, -----PPP---------------- (12%)
//linear regression
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
float n;
string com;
cin >> n >> com;
vector<pair<float,float>> v1;
int roun=n;
while(roun--){
float x,y;
cin >> x >> y;
v1.push_back(make_pair(x,y));
}
float m1=0, m2=0, m3=0, m4=0 ,m5=0;
for(int i=1;i<=n;i++){
m1+=(v1[i].first)*(v1[i].second);
m2+=(v1[i].first);
m3+= (v1[i].second);
m4+= pow((v1[i].first),2);
}
m1 = n*m1;
m4 = n*m4;
m5 = pow(m2,2);
float m = (m1-(m2*m3))/(m4-m5);
float b1=0,b2=0;
for(int i=1;i<=n;i++){
b1+=v1[i].second;
b2+=v1[i].first;
}
b2 = m*b2;
float b3=n;
float b = (b1-b2)/b3;
if(com=="mb"){
cout << round(m*1e3)/1e3 << endl ;
cout << round(b*1e3)/1e3 << endl;
}else if(com=="func"){
}
} | # 0078, 2024-11-02 10:09:44, -----PPP---------------- (12%)
//linear regression
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
float n;
string com;
cin >> n >> com;
vector<pair<float,float>> v1;
int roun=n;
while(roun--){
float x,y;
cin >> x >> y;
v1.push_back(make_pair(x,y));
}
float m1=0, m2=0, m3=0, m4=0 ,m5=0;
for(int i=1;i<=n;i++){
m1+=(v1[i].first)*(v1[i].second);
m2+=(v1[i].first);
m3+= (v1[i].second);
m4+= pow((v1[i].first),2);
}
m1 = n*m1;
m4 = n*m4;
m5 = pow(m2,2);
float m = (m1-(m2*m3))/(m4-m5);
float b1=0,b2=0;
for(int i=1;i<=n;i++){
b1+=v1[i].second;
b2+=v1[i].first;
}
b2 = m*b2;
float b3=n;
float b = (b1-b2)/b3;
if(com=="mb"){
cout << round(m*1e3)/1e3 << endl ;
cout << round(b*1e3)/1e3 << endl;
}else if(com=="func"){
cout << "y = " << m << "x + " << b;
}
} | # 0079, 2024-11-02 10:10:31, -----PPP---------------- (12%)
//linear regression
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
float n;
string com;
cin >> n >> com;
vector<pair<float,float>> v1;
int roun=n;
while(roun--){
float x,y;
cin >> x >> y;
v1.push_back(make_pair(x,y));
}
float m1=0, m2=0, m3=0, m4=0 ,m5=0;
for(int i=1;i<=n;i++){
m1+=(v1[i].first)*(v1[i].second);
m2+=(v1[i].first);
m3+= (v1[i].second);
m4+= pow((v1[i].first),2);
}
m1 = n*m1;
m4 = n*m4;
m5 = pow(m2,2);
float m = (m1-(m2*m3))/(m4-m5);
float b1=0,b2=0;
for(int i=1;i<=n;i++){
b1+=v1[i].second;
b2+=v1[i].first;
}
b2 = m*b2;
float b3=n;
float b = (b1-b2)/b3;
if(com=="mb"){
cout << round(m*1e3)/1e3 << endl ;
cout << round(b*1e3)/1e3 << endl;
}else if(com=="func"){
cout << "y = " << round(m*1e3) << "x + " << round(b*1e3);
}
} | # 0080, 2024-11-02 10:19:33, -----PPP---------------- (12%)
//linear regression
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
float n;
string com;
cin >> n >> com;
vector<pair<float,float>> v1;
int roun=n;
while(roun--){
float x,y;
cin >> x >> y;
v1.push_back(make_pair(x,y));
}
float m1=0, m2=0, m3=0, m4=0 ,m5=0;
for(int i=1;i<=n;i++){
m1+=(v1[i].first)*(v1[i].second);
m2+=(v1[i].first);
m3+= (v1[i].second);
m4+= pow((v1[i].first),2);
}
m1 = n*m1;
m4 = n*m4;
m5 = pow(m2,2);
float m = (m1-(m2*m3))/(m4-m5);
float b1=0,b2=0;
for(int i=1;i<=n;i++){
b1+=v1[i].second;
b2+=v1[i].first;
}
b2 = m*b2;
float b3=n;
float b = (b1-b2)/b3;
if(com=="mb"){
cout << round(m*1e3)/1e3 << endl ;
cout << round(b*1e3)/1e3 << endl;
}else if(com=="func"){
cout << "y = ";
if(abs(m)!=1 && b!=0 && b>=0){
cout << round(m*1e3) << "x + " << round(b*1e3);
}else if(abs(m)!=1 && b!=0 && b<=0){
cout << round(m*1e3) << "x " << round(b*1e3);
}else if(m==1 && b!=0 && b>=0){
cout << "x + " << round(b*1e3);
}else if(m==-1 && b!=0 && b<=0){
cout << "-x " << round(b*1e3);
}else if(m==0 && b!=0 && b>=0){
cout << round(b*1e3);
}else if(m==0 &&b!=0 && b<=0){
cout << round(b*1e3);
}
}
} | # 0081, 2024-11-02 10:42:16, PPPPPPPPPP-------------- (41%)
//linear regression
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
float n;
string com;
cin >> n >> com;
//vector<pair<float,float>> v1;
float m1=0, m2=0, m3=0, m4=0 ,m5=0,b1=0,b2=0;
int roun=n;
while(roun--){
float x,y;
cin >> x >> y;
// v1.push_back(make_pair(x,y));
m1+= x*y;
m2+=x;
m3+=y;
m4+=pow(x,2);
b1+=y;
b2+=x;
}
// float m1=0, m2=0, m3=0, m4=0 ,m5=0;
// for(int i=1;i<=n;i++){
// m1+=(v1[i].first)*(v1[i].second);
// m2+=(v1[i].first);
// m3+= (v1[i].second);
// m4+= pow((v1[i].first),2);
// }
m1 = n*m1;
m4 = n*m4;
m5 = pow(m2,2);
float m = (m1-(m2*m3))/(m4-m5);
// float b1=0,b2=0;
// for(int i=1;i<=n;i++){
// b1+=v1[i].second;
// b2+=v1[i].first;
// }
b2 = m*b2;
float b3=n;
float b = (b1-b2)/b3;
if(com=="mb"){
cout << round(m*1e3)/1e3 << endl ;
cout << round(b*1e3)/1e3 << endl;
}else if(com=="func"){
cout << "y = ";
if(abs(m)!=1 && b!=0 && b>=0){
cout << round(m*1e3) << "x + " << round(b*1e3);
}else if(abs(m)!=1 && b!=0 && b<=0){
cout << round(m*1e3) << "x " << round(b*1e3);
}else if(m==1 && b!=0 && b>=0){
cout << "x + " << round(b*1e3);
}else if(m==-1 && b!=0 && b<=0){
cout << "-x " << round(b*1e3);
}else if(m==0 && b!=0 && b>=0){
cout << round(b*1e3);
}else if(m==0 &&b!=0 && b<=0){
cout << round(b*1e3);
}
}
} | # 0082, 2024-11-02 10:43:19, PPPPPPPPPP-------------- (41%)
//linear regression
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
float n;
string com;
cin >> n >> com;
//vector<pair<float,float>> v1;
float m1=0, m2=0, m3=0, m4=0 ,m5=0,b1=0,b2=0;
int roun=n;
while(roun--){
float x,y;
cin >> x >> y;
// v1.push_back(make_pair(x,y));
m1+= x*y;
m2+=x;
m3+=y;
m4+=pow(x,2);
b1+=y;
b2+=x;
}
// float m1=0, m2=0, m3=0, m4=0 ,m5=0;
// for(int i=1;i<=n;i++){
// m1+=(v1[i].first)*(v1[i].second);
// m2+=(v1[i].first);
// m3+= (v1[i].second);
// m4+= pow((v1[i].first),2);
// }
m1 = n*m1;
m4 = n*m4;
m5 = pow(m2,2);
float m = (m1-(m2*m3))/(m4-m5);
// float b1=0,b2=0;
// for(int i=1;i<=n;i++){
// b1+=v1[i].second;
// b2+=v1[i].first;
// }
b2 = m*b2;
float b3=n;
float b = (b1-b2)/b3;
if(com=="mb"){
cout << round(m*1e3)/1e3 << endl ;
cout << round(b*1e3)/1e3 << endl;
}
} | # 0083, 2024-11-02 10:43:25, PPPPPPPPPP-------------- (41%)
//linear regression
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
float n;
string com;
cin >> n >> com;
//vector<pair<float,float>> v1;
float m1=0, m2=0, m3=0, m4=0 ,m5=0,b1=0,b2=0;
int roun=n;
while(roun--){
float x,y;
cin >> x >> y;
// v1.push_back(make_pair(x,y));
m1+= x*y;
m2+=x;
m3+=y;
m4+=pow(x,2);
b1+=y;
b2+=x;
}
// float m1=0, m2=0, m3=0, m4=0 ,m5=0;
// for(int i=1;i<=n;i++){
// m1+=(v1[i].first)*(v1[i].second);
// m2+=(v1[i].first);
// m3+= (v1[i].second);
// m4+= pow((v1[i].first),2);
// }
m1 = n*m1;
m4 = n*m4;
m5 = pow(m2,2);
float m = (m1-(m2*m3))/(m4-m5);
// float b1=0,b2=0;
// for(int i=1;i<=n;i++){
// b1+=v1[i].second;
// b2+=v1[i].first;
// }
b2 = m*b2;
float b3=n;
float b = (b1-b2)/b3;
if(com=="mb"){
cout << round(m*1e3)/1e3 << endl ;
cout << round(b*1e3)/1e3 << endl;
}
} | # 0084, 2024-11-02 10:46:13, PPPPPPPPPP-------------- (41%)
//linear regression
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
float n;
string com;
cin >> n >> com;
//vector<pair<float,float>> v1;
float m1=0, m2=0, m3=0, m4=0 ,m5=0,b1=0,b2=0;
int roun=n;
while(roun--){
float x,y;
cin >> x >> y;
// v1.push_back(make_pair(x,y));
m1+= x*y;
m2+=x;
m3+=y;
m4+=pow(x,2);
b1+=y;
b2+=x;
}
// float m1=0, m2=0, m3=0, m4=0 ,m5=0;
// for(int i=1;i<=n;i++){
// m1+=(v1[i].first)*(v1[i].second);
// m2+=(v1[i].first);
// m3+= (v1[i].second);
// m4+= pow((v1[i].first),2);
// }
m1 = n*m1;
m4 = n*m4;
m5 = pow(m2,2);
float m = (m1-(m2*m3))/(m4-m5);
// float b1=0,b2=0;
// for(int i=1;i<=n;i++){
// b1+=v1[i].second;
// b2+=v1[i].first;
// }
b2 = m*b2;
float b3=n;
float b = (b1-b2)/b3;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(com=="mb"){
cout << m << endl ;
cout << b << endl;
}else if(com=="func"){
cout << "y = ";
// if(abs(m)!=1 && b!=0 && b>=0){
// cout << round(m*1e3) << "x + " << round(b*1e3);
// }else if(abs(m)!=1 && b!=0 && b<=0){
// cout << round(m*1e3) << "x " << round(b*1e3);
// }else if(m==1 && b!=0 && b>=0){
// cout << "x + " << round(b*1e3);
// }else if(m==-1 && b!=0 && b<=0){
// cout << "-x " << round(b*1e3);
// }else if(m==0 && b!=0 && b>=0){
// cout << round(b*1e3);
// }else if(m==0 &&b!=0 && b<=0){
// cout << round(b*1e3);
// }
if(b==0){
cout << m <<"x";
}
}
} | # 0085, 2024-11-02 10:56:24, PPPPPPPPPP-------------- (41%)
//linear regression
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
float n;
string com;
cin >> n >> com;
//vector<pair<float,float>> v1;
float m1=0, m2=0, m3=0, m4=0 ,m5=0,b1=0,b2=0;
int roun=n;
while(roun--){
float x,y;
cin >> x >> y;
// v1.push_back(make_pair(x,y));
m1+= x*y;
m2+=x;
m3+=y;
m4+=pow(x,2);
b1+=y;
b2+=x;
}
// float m1=0, m2=0, m3=0, m4=0 ,m5=0;
// for(int i=1;i<=n;i++){
// m1+=(v1[i].first)*(v1[i].second);
// m2+=(v1[i].first);
// m3+= (v1[i].second);
// m4+= pow((v1[i].first),2);
// }
m1 = n*m1;
m4 = n*m4;
m5 = pow(m2,2);
float m = (m1-(m2*m3))/(m4-m5);
// float b1=0,b2=0;
// for(int i=1;i<=n;i++){
// b1+=v1[i].second;
// b2+=v1[i].first;
// }
b2 = m*b2;
float b3=n;
float b = (b1-b2)/b3;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(com=="mb"){
cout << m << endl ;
cout << b << endl;
}else if(com=="func"){
cout << "y = ";
// if(abs(m)!=1 && b!=0 && b>=0){
// cout << round(m*1e3) << "x + " << round(b*1e3);
// }else if(abs(m)!=1 && b!=0 && b<=0){
// cout << round(m*1e3) << "x " << round(b*1e3);
// }else if(m==1 && b!=0 && b>=0){
// cout << "x + " << round(b*1e3);
// }else if(m==-1 && b!=0 && b<=0){
// cout << "-x " << round(b*1e3);
// }else if(m==0 && b!=0 && b>=0){
// cout << round(b*1e3);
// }else if(m==0 &&b!=0 && b<=0){
// cout << round(b*1e3);
// }
//only m
if(b==0 && m!=0){
if(m==1){
cout << "y = x";
}else if(m==-1){
cout << "y = -x";
}
else{
cout <<"y = " << m <<"x";
}
}
//only b
else if(b!=0 && m==0){
cout << "y = " << b;
}else if(b==0 && m==0){
cout << "y = 0";
}
else if(b!=0 && m!=0){
}
}
} | # 0086, 2024-11-02 11:01:01, PPPPPPPPPP-------------- (41%)
//linear regression
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
float n;
string com;
cin >> n >> com;
//vector<pair<float,float>> v1;
float m1=0, m2=0, m3=0, m4=0 ,m5=0,b1=0,b2=0;
int roun=n;
while(roun--){
float x,y;
cin >> x >> y;
// v1.push_back(make_pair(x,y));
m1+= x*y;
m2+=x;
m3+=y;
m4+=pow(x,2);
b1+=y;
b2+=x;
}
// float m1=0, m2=0, m3=0, m4=0 ,m5=0;
// for(int i=1;i<=n;i++){
// m1+=(v1[i].first)*(v1[i].second);
// m2+=(v1[i].first);
// m3+= (v1[i].second);
// m4+= pow((v1[i].first),2);
// }
m1 = n*m1;
m4 = n*m4;
m5 = pow(m2,2);
float m = (m1-(m2*m3))/(m4-m5);
// float b1=0,b2=0;
// for(int i=1;i<=n;i++){
// b1+=v1[i].second;
// b2+=v1[i].first;
// }
b2 = m*b2;
float b3=n;
float b = (b1-b2)/b3;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(com=="mb"){
cout << m << endl ;
cout << b << endl;
}else if(com=="func"){
cout << "y = ";
// if(abs(m)!=1 && b!=0 && b>=0){
// cout << round(m*1e3) << "x + " << round(b*1e3);
// }else if(abs(m)!=1 && b!=0 && b<=0){
// cout << round(m*1e3) << "x " << round(b*1e3);
// }else if(m==1 && b!=0 && b>=0){
// cout << "x + " << round(b*1e3);
// }else if(m==-1 && b!=0 && b<=0){
// cout << "-x " << round(b*1e3);
// }else if(m==0 && b!=0 && b>=0){
// cout << round(b*1e3);
// }else if(m==0 &&b!=0 && b<=0){
// cout << round(b*1e3);
// }
//only m
if(b==0 && m!=0){
if(m==1){
cout << "y = x";
}else if(m==-1){
cout << "y = -x";
}
else{
cout <<"y = " << m <<"x";
}
}
//only b
else if(b!=0 && m==0){
cout << "y = " << b;
}else if(b==0 && m==0){
cout << "y = 0";
}
else if(b!=0 && m!=0){
//m part
if(m==1){
cout << "y = x";
}else if(m==-1){
cout << "y = -x";
}else{
cout << "y = " << m <<"x";
}
//b part
if(b>0){
cout << " + " << b;
}
else if(b<0){
cout << " - " <<-b;
}
}
}
} | # 0087, 2024-11-02 11:02:49, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
//linear regression
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
float n;
string com;
cin >> n >> com;
//vector<pair<float,float>> v1;
float m1=0, m2=0, m3=0, m4=0 ,m5=0,b1=0,b2=0;
int roun=n;
while(roun--){
float x,y;
cin >> x >> y;
// v1.push_back(make_pair(x,y));
m1+= x*y;
m2+=x;
m3+=y;
m4+=pow(x,2);
b1+=y;
b2+=x;
}
// float m1=0, m2=0, m3=0, m4=0 ,m5=0;
// for(int i=1;i<=n;i++){
// m1+=(v1[i].first)*(v1[i].second);
// m2+=(v1[i].first);
// m3+= (v1[i].second);
// m4+= pow((v1[i].first),2);
// }
m1 = n*m1;
m4 = n*m4;
m5 = pow(m2,2);
float m = (m1-(m2*m3))/(m4-m5);
// float b1=0,b2=0;
// for(int i=1;i<=n;i++){
// b1+=v1[i].second;
// b2+=v1[i].first;
// }
b2 = m*b2;
float b3=n;
float b = (b1-b2)/b3;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(com=="mb"){
cout << m << endl ;
cout << b << endl;
}else if(com=="func"){
// cout << "y = ";
// if(abs(m)!=1 && b!=0 && b>=0){
// cout << round(m*1e3) << "x + " << round(b*1e3);
// }else if(abs(m)!=1 && b!=0 && b<=0){
// cout << round(m*1e3) << "x " << round(b*1e3);
// }else if(m==1 && b!=0 && b>=0){
// cout << "x + " << round(b*1e3);
// }else if(m==-1 && b!=0 && b<=0){
// cout << "-x " << round(b*1e3);
// }else if(m==0 && b!=0 && b>=0){
// cout << round(b*1e3);
// }else if(m==0 &&b!=0 && b<=0){
// cout << round(b*1e3);
// }
//only m
if(b==0 && m!=0){
if(m==1){
cout << "y = x";
}else if(m==-1){
cout << "y = -x";
}
else{
cout <<"y = " << m <<"x";
}
}
//only b
else if(b!=0 && m==0){
cout << "y = " << b;
}else if(b==0 && m==0){
cout << "y = 0";
}
else if(b!=0 && m!=0){
//m part
if(m==1){
cout << "y = x";
}else if(m==-1){
cout << "y = -x";
}else{
cout << "y = " << m <<"x";
}
//b part
if(b>0){
cout << " + " << b;
}
else if(b<0){
cout << " - " <<-b;
}
}
}
} |
# 0088, 2024-11-02 10:44:24, -----PPPPPPPPPP-------P- (45%)
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define F first
#define S second
vector<pair<float,float>> vec;
long long n;
string func;
float M(){
float sum1=0;
float sum2=0;
float sum3=0;
float sum4=0;
for(int i=0;i<n;i++){
sum1+=(vec[i].F*vec[i].S);
}
for(int i=0;i<n;i++){
sum2+=vec[i].F;
}
for(int i=0;i<n;i++){
sum3+=vec[i].S;
}
for(int i=0;i<n;i++){
sum4+=pow(vec[i].F,2);
}
return ((n*sum1)-(sum2*sum3)) / ((n*sum4) - pow(sum2,2));
}
float B(float m){
float sum2=0;
float sum3=0;
for(int i=0;i<n;i++){
sum2+=vec[i].F;
}
for(int i=0;i<n;i++){
sum3+=vec[i].S;
}
return (sum3 - (m*sum2))/n;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
float m,b;
float x,y;
cin>>n>>func;
vec.resize(n);
for(int i=0;i<n;i++){
cin>>vec[i].F>>vec[i].S;
}
if(func=="mb"){
m = M();
b=B(m);
cout<<m<<endl;
cout<<b;
}else{
m = M();
b=B(m);
cout<<"y = ";
if(m==-1){
cout<<"-";
}else if(m==1){
}else{
cout<<round(m*1e3)/1e3;
}
cout<<"x ";
if(b>=0){
cout<<"+ "<< round(b*1e3)/1e3;
}else{
cout<<"- "<< round(abs(b)*1e3)/1e3;
}
}
return 0;
} | # 0089, 2024-11-02 10:44:57, Compilation error (0%)
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define F first
#define S second
vector<pair<float,float>> vec;
long long n;
string func;
float M(){
float sum1=0;
float sum2=0;
float sum3=0;
float sum4=0;
for(int i=0;i<n;i++){
sum1+=(vec[i].F*vec[i].S);
}
for(int i=0;i<n;i++){
sum2+=vec[i].F;
}
for(int i=0;i<n;i++){
sum3+=vec[i].S;
}
for(int i=0;i<n;i++){
sum4+=pow(vec[i].F,2);
}
return ((n*sum1)-(sum2*sum3)) / ((n*sum4) - pow(sum2,2));
}
float B(float m){
float sum2=0;
float sum3=0;
for(int i=0;i<n;i++){
sum2+=vec[i].F;
}
for(int i=0;i<n;i++){
sum3+=vec[i].S;
}
return (sum3 - (m*sum2))/n;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
float m,b;
float x,y;
cin>>n>>func;
vec.resize(n);
for(int i=0;i<n;i++){
cin>>vec[i].F>>vec[i].S;
}
if(func=="mb"){
m = M();
b=B(m);
cout<<m<<endl;
cout<<b;
}else{
return0;
m = M();
b=B(m);
cout<<"y = ";
if(m==-1){
cout<<"-";
}else if(m==1){
}else{
cout<<round(m*1e3)/1e3;
}
cout<<"x ";
if(b>=0){
cout<<"+ "<< round(b*1e3)/1e3;
}else{
cout<<"- "<< round(abs(b)*1e3)/1e3;
}
}
return 0;
} | # 0090, 2024-11-02 10:45:13, -----PPPPP-------------- (20%)
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define F first
#define S second
vector<pair<float,float>> vec;
long long n;
string func;
float M(){
float sum1=0;
float sum2=0;
float sum3=0;
float sum4=0;
for(int i=0;i<n;i++){
sum1+=(vec[i].F*vec[i].S);
}
for(int i=0;i<n;i++){
sum2+=vec[i].F;
}
for(int i=0;i<n;i++){
sum3+=vec[i].S;
}
for(int i=0;i<n;i++){
sum4+=pow(vec[i].F,2);
}
return ((n*sum1)-(sum2*sum3)) / ((n*sum4) - pow(sum2,2));
}
float B(float m){
float sum2=0;
float sum3=0;
for(int i=0;i<n;i++){
sum2+=vec[i].F;
}
for(int i=0;i<n;i++){
sum3+=vec[i].S;
}
return (sum3 - (m*sum2))/n;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
float m,b;
float x,y;
cin>>n>>func;
vec.resize(n);
for(int i=0;i<n;i++){
cin>>vec[i].F>>vec[i].S;
}
if(func=="mb"){
m = M();
b=B(m);
cout<<m<<endl;
cout<<b;
}else{
return 0;
m = M();
b=B(m);
cout<<"y = ";
if(m==-1){
cout<<"-";
}else if(m==1){
}else{
cout<<round(m*1e3)/1e3;
}
cout<<"x ";
if(b>=0){
cout<<"+ "<< round(b*1e3)/1e3;
}else{
cout<<"- "<< round(abs(b)*1e3)/1e3;
}
}
return 0;
} | # 0091, 2024-11-02 10:46:25, Compilation error (0%)
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define F first
#define S second
vector<pair<float,float>> vec;
long long n;
string func;
float M(){
float sum1=0;
float sum2=0;
float sum3=0;
float sum4=0;
for(int i=0;i<n;i++){
sum1+=(vec[i].F*vec[i].S);
}
for(int i=0;i<n;i++){
sum2+=vec[i].F;
}
for(int i=0;i<n;i++){
sum3+=vec[i].S;
}
for(int i=0;i<n;i++){
sum4+=pow(vec[i].F,2);
}
return ((n*sum1)-(sum2*sum3)) / ((n*sum4) - pow(sum2,2));
}
float B(float m){
float sum2=0;
float sum3=0;
for(int i=0;i<n;i++){
sum2+=vec[i].F;
}
for(int i=0;i<n;i++){
sum3+=vec[i].S;
}
return (sum3 - (m*sum2))/n;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
float m,b;
float x,y;
cin>>n>>func;
vec.resize(n);
for(int i=0;i<n;i++){
cin>>vec[i].F>>vec[i].S;
}
if(func=="mb"){
m = M();
b=B(m);
cout<<round(m*1e3)/1e3;<<endl;
cout<<round(b*1e3)/1e3;;
}else{
m = M();
b=B(m);
cout<<"y = ";
if(m==-1){
cout<<"-";
}else if(m==1){
}else{
cout<<round(m*1e3)/1e3;
}
cout<<"x ";
if(b>=0){
cout<<"+ "<< round(b*1e3)/1e3;
}else{
cout<<"- "<< round(abs(b)*1e3)/1e3;
}
}
return 0;
} | # 0092, 2024-11-02 10:46:40, PPPPPPPPPPPPPPP-------P- (66%)
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define F first
#define S second
vector<pair<float,float>> vec;
long long n;
string func;
float M(){
float sum1=0;
float sum2=0;
float sum3=0;
float sum4=0;
for(int i=0;i<n;i++){
sum1+=(vec[i].F*vec[i].S);
}
for(int i=0;i<n;i++){
sum2+=vec[i].F;
}
for(int i=0;i<n;i++){
sum3+=vec[i].S;
}
for(int i=0;i<n;i++){
sum4+=pow(vec[i].F,2);
}
return ((n*sum1)-(sum2*sum3)) / ((n*sum4) - pow(sum2,2));
}
float B(float m){
float sum2=0;
float sum3=0;
for(int i=0;i<n;i++){
sum2+=vec[i].F;
}
for(int i=0;i<n;i++){
sum3+=vec[i].S;
}
return (sum3 - (m*sum2))/n;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
float m,b;
float x,y;
cin>>n>>func;
vec.resize(n);
for(int i=0;i<n;i++){
cin>>vec[i].F>>vec[i].S;
}
if(func=="mb"){
m = M();
b=B(m);
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3;
}else{
m = M();
b=B(m);
cout<<"y = ";
if(m==-1){
cout<<"-";
}else if(m==1){
}else{
cout<<round(m*1e3)/1e3;
}
cout<<"x ";
if(b>=0){
cout<<"+ "<< round(b*1e3)/1e3;
}else{
cout<<"- "<< round(abs(b)*1e3)/1e3;
}
}
return 0;
} | # 0093, 2024-11-02 10:49:26, PPPPPPPPPPPPPPPP--PP--P- (79%)
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define F first
#define S second
vector<pair<float,float>> vec;
long long n;
string func;
float M(){
float sum1=0;
float sum2=0;
float sum3=0;
float sum4=0;
for(int i=0;i<n;i++){
sum1+=(vec[i].F*vec[i].S);
}
for(int i=0;i<n;i++){
sum2+=vec[i].F;
}
for(int i=0;i<n;i++){
sum3+=vec[i].S;
}
for(int i=0;i<n;i++){
sum4+=pow(vec[i].F,2);
}
return ((n*sum1)-(sum2*sum3)) / ((n*sum4) - pow(sum2,2));
}
float B(float m){
float sum2=0;
float sum3=0;
for(int i=0;i<n;i++){
sum2+=vec[i].F;
}
for(int i=0;i<n;i++){
sum3+=vec[i].S;
}
return (sum3 - (m*sum2))/n;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
float m,b;
float x,y;
cin>>n>>func;
vec.resize(n);
for(int i=0;i<n;i++){
cin>>vec[i].F>>vec[i].S;
}
if(func=="mb"){
m = M();
b=B(m);
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3;
}else{
m = M();
b=B(m);
cout<<"y = ";
if(m==-1){
cout<<"-";
}else if(m==1){
}else{
cout<<round(m*1e3)/1e3;
}
if(m!=0){
cout<<"x ";
}
if(b>0){
cout<<"+ "<< round(b*1e3)/1e3;
}else if(b<0){
cout<<"- "<< round(abs(b)*1e3)/1e3;
}
}
return 0;
} | # 0094, 2024-11-02 10:52:31, PPPPPPPPPPPPPPPP-PPPP-PP (91%)
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define F first
#define S second
vector<pair<float,float>> vec;
long long n;
string func;
float M(){
float sum1=0;
float sum2=0;
float sum3=0;
float sum4=0;
for(int i=0;i<n;i++){
sum1+=(vec[i].F*vec[i].S);
}
for(int i=0;i<n;i++){
sum2+=vec[i].F;
}
for(int i=0;i<n;i++){
sum3+=vec[i].S;
}
for(int i=0;i<n;i++){
sum4+=pow(vec[i].F,2);
}
return ((n*sum1)-(sum2*sum3)) / ((n*sum4) - pow(sum2,2));
}
float B(float m){
float sum2=0;
float sum3=0;
for(int i=0;i<n;i++){
sum2+=vec[i].F;
}
for(int i=0;i<n;i++){
sum3+=vec[i].S;
}
return (sum3 - (m*sum2))/n;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
float m,b;
float x,y;
cin>>n>>func;
vec.resize(n);
for(int i=0;i<n;i++){
cin>>vec[i].F>>vec[i].S;
}
if(func=="mb"){
m = M();
b=B(m);
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3;
}else{
m = M();
b=B(m);
cout<<"y = ";
if(round(m*1e3)/1e3==-1){
cout<<"-";
}else if(round(m*1e3)/1e3==1){
}else{
cout<<round(m*1e3)/1e3;
}
if(round(m*1e3)/1e3!=0){
cout<<"x ";
}
if(round(b*1e3)/1e3>0){
cout<<"+ "<< round(b*1e3)/1e3;
}else if(round(b*1e3)/1e3<0){
cout<<"- "<< round(abs(b)*1e3)/1e3;
}
}
return 0;
} | # 0095, 2024-11-02 11:01:11, PPPPPPPPPPPPPPP-P----P-- (70%)
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define F first
#define S second
vector<pair<float,float>> vec;
long long n;
string func;
float M(){
float sum1=0;
float sum2=0;
float sum3=0;
float sum4=0;
for(int i=0;i<n;i++){
sum1+=(vec[i].F*vec[i].S);
}
for(int i=0;i<n;i++){
sum2+=vec[i].F;
}
for(int i=0;i<n;i++){
sum3+=vec[i].S;
}
for(int i=0;i<n;i++){
sum4+=pow(vec[i].F,2);
}
return ((n*sum1)-(sum2*sum3)) / ((n*sum4) - pow(sum2,2));
}
float B(float m){
float sum2=0;
float sum3=0;
for(int i=0;i<n;i++){
sum2+=vec[i].F;
}
for(int i=0;i<n;i++){
sum3+=vec[i].S;
}
return (sum3 - (m*sum2))/n;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
float m,b;
float x,y;
cin>>n>>func;
vec.resize(n);
for(int i=0;i<n;i++){
cin>>vec[i].F>>vec[i].S;
}
if(func=="mb"){
m = M();
b=B(m);
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3;
}else{
m = M();
b=B(m);
cout<<"y = ";
if(round(m*1e3)/1e3==-1){
cout<<"-";
}else if(round(m*1e3)/1e3==1){
}else{
if(round(m*1e3)/1e3!=0){
cout<<round(m*1e3)/1e3;
cout<<"x ";
}
}
if(round(m*1e3)/1e3!=0){
if(round(b*1e3)/1e3>0){
cout<<"+ "<< round(b*1e3)/1e3;
}else if(round(b*1e3)/1e3<0){
cout<<"- "<< round(abs(b)*1e3)/1e3;
}
}else{
if(round(b*1e3)/1e3>0){
cout<< round(b*1e3)/1e3;
}else if(round(b*1e3)/1e3<0){
cout<<"-"<< round(abs(b)*1e3)/1e3;
}
}
}
return 0;
}
/*
3 func
1.0 -3.0
2.0 -3.0
4.4 -3.0*/ | # 0096, 2024-11-02 11:01:45, PPPPPPPPPPPPPPP--------- (62%)
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define F first
#define S second
vector<pair<float,float>> vec;
long long n;
string func;
float M(){
float sum1=0;
float sum2=0;
float sum3=0;
float sum4=0;
for(int i=0;i<n;i++){
sum1+=(vec[i].F*vec[i].S);
}
for(int i=0;i<n;i++){
sum2+=vec[i].F;
}
for(int i=0;i<n;i++){
sum3+=vec[i].S;
}
for(int i=0;i<n;i++){
sum4+=pow(vec[i].F,2);
}
return ((n*sum1)-(sum2*sum3)) / ((n*sum4) - pow(sum2,2));
}
float B(float m){
float sum2=0;
float sum3=0;
for(int i=0;i<n;i++){
sum2+=vec[i].F;
}
for(int i=0;i<n;i++){
sum3+=vec[i].S;
}
return (sum3 - (m*sum2))/n;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
float m,b;
float x,y;
cin>>n>>func;
vec.resize(n);
for(int i=0;i<n;i++){
cin>>vec[i].F>>vec[i].S;
}
if(func=="mb"){
m = M();
b=B(m);
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3;
}else{
m = M();
b=B(m);
cout<<"y = ";
if(round(m*1e3)/1e3==-1){
cout<<"-";
}else if(round(m*1e3)/1e3==1){
}else{
if(round(m*1e3)/1e3!=0){
cout<<round(m*1e3)/1e3;
cout<<"x ";
}
}
if(round(b*1e3)/1e3>0){
cout<<"+ "<< round(b*1e3)/1e3;
}else if(round(b*1e3)/1e3<0){
cout<<"- "<< round(abs(b)*1e3)/1e3;
}
}
return 0;
}
/*
3 func
1.0 -3.0
2.0 -3.0
4.4 -3.0*/ | # 0097, 2024-11-02 11:02:18, PPPPPPPPPPPPPPPP-PPPP-PP (91%)
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define F first
#define S second
vector<pair<float,float>> vec;
long long n;
string func;
float M(){
float sum1=0;
float sum2=0;
float sum3=0;
float sum4=0;
for(int i=0;i<n;i++){
sum1+=(vec[i].F*vec[i].S);
}
for(int i=0;i<n;i++){
sum2+=vec[i].F;
}
for(int i=0;i<n;i++){
sum3+=vec[i].S;
}
for(int i=0;i<n;i++){
sum4+=pow(vec[i].F,2);
}
return ((n*sum1)-(sum2*sum3)) / ((n*sum4) - pow(sum2,2));
}
float B(float m){
float sum2=0;
float sum3=0;
for(int i=0;i<n;i++){
sum2+=vec[i].F;
}
for(int i=0;i<n;i++){
sum3+=vec[i].S;
}
return (sum3 - (m*sum2))/n;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
float m,b;
float x,y;
cin>>n>>func;
vec.resize(n);
for(int i=0;i<n;i++){
cin>>vec[i].F>>vec[i].S;
}
if(func=="mb"){
m = M();
b=B(m);
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3;
}else{
m = M();
b=B(m);
cout<<"y = ";
if(round(m*1e3)/1e3==-1){
cout<<"-";
}else if(round(m*1e3)/1e3==1){
}else{
cout<<round(m*1e3)/1e3;
}
if(round(m*1e3)/1e3!=0){
cout<<"x ";
}
if(round(b*1e3)/1e3>0){
cout<<"+ "<< round(b*1e3)/1e3;
}else if(round(b*1e3)/1e3<0){
cout<<"- "<< round(abs(b)*1e3)/1e3;
}
}
return 0;
}
/*
3 func
1.0 -3.0
2.0 -3.0
4.4 -3.0*/ | # 0098, 2024-11-02 11:06:22, PPPPPPPPPPPPPPP-PPPPPPPP (95%)
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define F first
#define S second
vector<pair<float,float>> vec;
long long n;
string func;
float M(){
float sum1=0;
float sum2=0;
float sum3=0;
float sum4=0;
for(int i=0;i<n;i++){
sum1+=(vec[i].F*vec[i].S);
}
for(int i=0;i<n;i++){
sum2+=vec[i].F;
}
for(int i=0;i<n;i++){
sum3+=vec[i].S;
}
for(int i=0;i<n;i++){
sum4+=pow(vec[i].F,2);
}
return ((n*sum1)-(sum2*sum3)) / ((n*sum4) - pow(sum2,2));
}
float B(float m){
float sum2=0;
float sum3=0;
for(int i=0;i<n;i++){
sum2+=vec[i].F;
}
for(int i=0;i<n;i++){
sum3+=vec[i].S;
}
return (sum3 - (m*sum2))/n;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
float m,b;
float x,y;
cin>>n>>func;
vec.resize(n);
for(int i=0;i<n;i++){
cin>>vec[i].F>>vec[i].S;
}
if(func=="mb"){
m = M();
b=B(m);
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3;
}else{
m = M();
b=B(m);
cout<<"y = ";
if(round(m*1e3)/1e3==-1){
cout<<"-x ";
}else if(round(m*1e3)/1e3==0){
if(round(b*1e3)/1e3>0){
cout<< round(b*1e3)/1e3;
}else if(round(b*1e3)/1e3<0){
cout<<"-"<< round(abs(b)*1e3)/1e3;
}
return 0;
}else if(round(m*1e3)/1e3==1){
cout<<"x ";
}else{
cout<<round(m*1e3)/1e3;
cout<<"x ";
}
if(round(b*1e3)/1e3>0){
cout<<"+ "<< round(b*1e3)/1e3;
}else if(round(b*1e3)/1e3<0){
cout<<"- "<< round(abs(b)*1e3)/1e3;
}
}
return 0;
}
/*
3 func
1.0 -3.0
2.0 -3.0
4.4 -3.0*/ | # 0099, 2024-11-02 11:08:36, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define F first
#define S second
vector<pair<float,float>> vec;
long long n;
string func;
float M(){
float sum1=0;
float sum2=0;
float sum3=0;
float sum4=0;
for(int i=0;i<n;i++){
sum1+=(vec[i].F*vec[i].S);
}
for(int i=0;i<n;i++){
sum2+=vec[i].F;
}
for(int i=0;i<n;i++){
sum3+=vec[i].S;
}
for(int i=0;i<n;i++){
sum4+=pow(vec[i].F,2);
}
return ((n*sum1)-(sum2*sum3)) / ((n*sum4) - pow(sum2,2));
}
float B(float m){
float sum2=0;
float sum3=0;
for(int i=0;i<n;i++){
sum2+=vec[i].F;
}
for(int i=0;i<n;i++){
sum3+=vec[i].S;
}
return (sum3 - (m*sum2))/n;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
float m,b;
float x,y;
cin>>n>>func;
vec.resize(n);
for(int i=0;i<n;i++){
cin>>vec[i].F>>vec[i].S;
}
if(func=="mb"){
m = M();
b=B(m);
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3;
}else{
m = M();
b=B(m);
cout<<"y = ";
if(round(m*1e3)/1e3==-1){
cout<<"-x ";
}else if(round(m*1e3)/1e3==0){
if(round(b*1e3)/1e3>0){
cout<< round(b*1e3)/1e3;
}else if(round(b*1e3)/1e3<0){
cout<<"-"<< round(abs(b)*1e3)/1e3;
}else{
cout<<0;
}
return 0;
}else if(round(m*1e3)/1e3==1){
cout<<"x ";
}else{
cout<<round(m*1e3)/1e3;
cout<<"x ";
}
if(round(b*1e3)/1e3>0){
cout<<"+ "<< round(b*1e3)/1e3;
}else if(round(b*1e3)/1e3<0){
cout<<"- "<< round(abs(b)*1e3)/1e3;
}
}
return 0;
}
/*
3 func
1.0 -3.0
2.0 -3.0
4.4 -3.0*/ |
# 0100, 2024-11-02 09:56:11, Compilation error (0%)
#include<iostream>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
double x[n],y[n];
for(int i=0;i<n;i++) {
cin >> x[i] >> y[i];
}
float b_1=0,b_2=0;
float m_1=0,m_2=0,m_3=0,m_4=0;
float m_2a=0,m_2b=0
for(int i=0;i<n;i++) {
m_1+=x[i]*y[i];
m_2a+=x[i];
m_2b+=y[i];
m_3+=x[i]*x[i];
m_4+=x[i];
b_1+=y[i];
b_2+=x[i];
}
m_1*=n;
m_3*=n;
m_2=m_2a*m_2b;
m_4=m_4*m_4;
float m=(m_1-m_2)/(m_3-m_4);
float b=(b_1-m*b_2)/n;
if(s=="mb") {
cout << m << endl;
cout << b;
}else {
if(m==0 && b==0) {
cout << "y = 0";
}else if(m==0) {
cout << "y = " << b;
}else if(b==0) {
if(m!=1 && m!=-1) cout << "y = " << m << "x";
else if(m==1) cout << "y = x";
else if(m==-1) cout << "y = -x";
}else {
if(m!=1 && m!=-1) cout << "y = " << m << "x + " << b;
else if(m==1) cout << "y = x + " << b;
else if(m==-1) cout << "y = -x + " << b;
}
}
} | # 0101, 2024-11-02 09:56:44, -----PPPPP-----P--PP-P-- (37%)
#include<iostream>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
double x[n],y[n];
for(int i=0;i<n;i++) {
cin >> x[i] >> y[i];
}
float b_1=0,b_2=0;
float m_1=0,m_2=0,m_3=0,m_4=0;
float m_2a=0,m_2b=0;
for(int i=0;i<n;i++) {
m_1+=x[i]*y[i];
m_2a+=x[i];
m_2b+=y[i];
m_3+=x[i]*x[i];
m_4+=x[i];
b_1+=y[i];
b_2+=x[i];
}
m_1*=n;
m_3*=n;
m_2=m_2a*m_2b;
m_4=m_4*m_4;
float m=(m_1-m_2)/(m_3-m_4);
float b=(b_1-m*b_2)/n;
if(s=="mb") {
cout << m << endl;
cout << b;
}else {
if(m==0 && b==0) {
cout << "y = 0";
}else if(m==0) {
cout << "y = " << b;
}else if(b==0) {
if(m!=1 && m!=-1) cout << "y = " << m << "x";
else if(m==1) cout << "y = x";
else if(m==-1) cout << "y = -x";
}else {
if(m!=1 && m!=-1) cout << "y = " << m << "x + " << b;
else if(m==1) cout << "y = x + " << b;
else if(m==-1) cout << "y = -x + " << b;
}
}
} | # 0102, 2024-11-02 09:58:54, -----PPPPP-----P--PP-P-- (37%)
#include<iostream>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
double x[n],y[n];
for(int i=0;i<n;i++) {
cin >> x[i] >> y[i];
}
float b_1=0,b_2=0;
float m_1=0,m_2=0,m_3=0,m_4=0;
float m_2a=0,m_2b=0;
for(int i=0;i<n;i++) {
m_1+=x[i]*y[i];
m_2a+=x[i];
m_2b+=y[i];
m_3+=x[i]*x[i];
m_4+=x[i];
b_1+=y[i];
b_2+=x[i];
}
m_1*=n;
m_3*=n;
m_2=m_2a*m_2b;
m_4=m_4*m_4;
float m=(m_1-m_2)/(m_3-m_4);
float b=(b_1-m*b_2)/n;
if(s=="mb") {
cout << m << endl;
cout << b;
}else {
if(m==0 && b==0) {
cout << "y = 0";
}else if(m==0) {
cout << "y = " << b;
}else if(b==0) {
if(m!=1 && m!=-1) cout << "y = " << m << "x";
else if(m==1) cout << "y = x";
else if(m==-1) cout << "y = -x";
}else {
if(m!=1 && m!=-1 && b<0) cout << "y = " << m << "x - " << b;
else if(m!=1 && m!=-1 && b>0) cout << "y = " << m << "x + " << b;
else if(m==1 && b>0) cout << "y = x + " << b;
else if(m==-1 && b>0) cout << "y = -x + " << b;
else if(m==1 && b<0) cout << "y = x - " << -b;
else if(m==-1 && b<0) cout << "y = -x - " << -b;
}
}
} | # 0103, 2024-11-02 10:00:14, Compilation error (0%)
#include<iostream>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
double x[n],y[n];
for(int i=0;i<n;i++) {
cin >> x[i] >> y[i];
}
float b_1=0,b_2=0;
float m_1=0,m_2=0,m_3=0,m_4=0;
float m_2a=0,m_2b=0;
for(int i=0;i<n;i++) {
m_1+=x[i]*y[i];
m_2a+=x[i];
m_2b+=y[i];
m_3+=x[i]*x[i];
m_4+=x[i];
b_1+=y[i];
b_2+=x[i];
}
m_1*=n;
m_3*=n;
m_2=m_2a*m_2b;
m_4=m_4*m_4;
float m=round((m_1-m_2)/(m_3-m_4) * 1e3)/1e3;
float b=round((b_1-m*b_2)/n * 1e3)/1e3;
if(s=="mb") {
cout << m << endl;
cout << b;
}else {
if(m==0 && b==0) {
cout << "y = 0";
}else if(m==0) {
cout << "y = " << b;
}else if(b==0) {
if(m!=1 && m!=-1) cout << "y = " << m << "x";
else if(m==1) cout << "y = x";
else if(m==-1) cout << "y = -x";
}else {
if(m!=1 && m!=-1 && b<0) cout << "y = " << m << "x - " << b;
else if(m!=1 && m!=-1 && b>0) cout << "y = " << m << "x + " << b;
else if(m==1 && b>0) cout << "y = x + " << b;
else if(m==-1 && b>0) cout << "y = -x + " << b;
else if(m==1 && b<0) cout << "y = x - " << -b;
else if(m==-1 && b<0) cout << "y = -x - " << -b;
}
}
} | # 0104, 2024-11-02 10:00:45, -----PPPPP-----PPPPPPPPP (58%)
#include<iostream>
#include<cmath>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
double x[n],y[n];
for(int i=0;i<n;i++) {
cin >> x[i] >> y[i];
}
float b_1=0,b_2=0;
float m_1=0,m_2=0,m_3=0,m_4=0;
float m_2a=0,m_2b=0;
for(int i=0;i<n;i++) {
m_1+=x[i]*y[i];
m_2a+=x[i];
m_2b+=y[i];
m_3+=x[i]*x[i];
m_4+=x[i];
b_1+=y[i];
b_2+=x[i];
}
m_1*=n;
m_3*=n;
m_2=m_2a*m_2b;
m_4=m_4*m_4;
float m=round((m_1-m_2)/(m_3-m_4) * 1e3)/1e3;
float b=round((b_1-m*b_2)/n * 1e3)/1e3;
if(s=="mb") {
cout << m << endl;
cout << b;
}else {
if(m==0 && b==0) {
cout << "y = 0";
}else if(m==0) {
cout << "y = " << b;
}else if(b==0) {
if(m!=1 && m!=-1) cout << "y = " << m << "x";
else if(m==1) cout << "y = x";
else if(m==-1) cout << "y = -x";
}else {
if(m!=1 && m!=-1 && b<0) cout << "y = " << m << "x - " << b;
else if(m!=1 && m!=-1 && b>0) cout << "y = " << m << "x + " << b;
else if(m==1 && b>0) cout << "y = x + " << b;
else if(m==-1 && b>0) cout << "y = -x + " << b;
else if(m==1 && b<0) cout << "y = x - " << -b;
else if(m==-1 && b<0) cout << "y = -x - " << -b;
}
}
} | # 0105, 2024-11-02 10:23:55, -----PPPPP-----PPPPPPPPP (58%)
#include<iostream>
#include<cmath>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
double x[n],y[n];
for(int i=0;i<n;i++) {
cin >> x[i] >> y[i];
}
float b_1=0,b_2=0;
float m_1=0,m_2=0,m_3=0,m_4=0;
float m_2a=0,m_2b=0;
for(int i=0;i<n;i++) {
m_1+=x[i]*y[i];
m_2a+=x[i];
m_2b+=y[i];
m_3+=x[i]*x[i];
m_4+=x[i];
b_1+=y[i];
b_2+=x[i];
}
m_1*=n;
m_3*=n;
m_2=m_2a*m_2b;
m_4=m_4*m_4;
float m=round((m_1-m_2)/(m_3-m_4) * 1e3)/1e3;
float b=round((b_1-m*b_2)/n * 1e3)/1e3;
if(s=="mb") {
cout << m << endl;
cout << b;
}else {
if(m==0 && b==0) {
cout << "y = 0";
}else if(m==0) {
cout << "y = " << b;
}else if(b==0) {
if(m!=1 && m!=-1) cout << "y = " << m << "x";
else if(m==1) cout << "y = x";
else if(m==-1) cout << "y = -x";
}else {
if(m!=1 && m!=-1 && b<0) cout << "y = " << m << "x - " << -b;
else if(m!=1 && m!=-1 && b>0) cout << "y = " << m << "x + " << b;
else if(m==1 && b>0) cout << "y = x + " << b;
else if(m==-1 && b>0) cout << "y = -x + " << b;
else if(m==1 && b<0) cout << "y = x - " << -b;
else if(m==-1 && b<0) cout << "y = -x - " << -b;
}
}
} | # 0106, 2024-11-02 11:15:04, -----PPPPP-----PPPPPPPPP (58%)
#include<iostream>
#include<cmath>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
double x[n],y[n];
for(int i=0;i<n;i++) {
cin >> x[i] >> y[i];
}
float b_1=0,b_2=0;
float m_1=0,m_2=0,m_3=0,m_4=0;
float m_2a=0,m_2b=0;
for(int i=0;i<n;i++) {
m_1+=x[i]*y[i];
m_2a+=x[i];
m_2b+=y[i];
m_3+=x[i]*x[i];
m_4+=x[i];
b_1+=y[i];
b_2+=x[i];
}
m_1*=n;
m_3*=n;
m_2=m_2a*m_2b;
m_4=m_4*m_4;
float m=round((m_1-m_2)/(m_3-m_4) * 1e3)/1e3;
float b=round((b_1-m*b_2)/n * 1e3)/1e3;
if(s=="mb") {
cout << m << endl;
cout << b << endl;
}else {
if(m==0 && b==0) {
cout << "y = 0";
}else if(m==0) {
cout << "y = " << b;
}else if(b==0) {
if(m!=1 && m!=-1) cout << "y = " << m << "x";
else if(m==1) cout << "y = x";
else if(m==-1) cout << "y = -x";
}else {
if(m!=1 && m!=-1 && b<0) cout << "y = " << m << "x - " << -b;
else if(m!=1 && m!=-1 && b>0) cout << "y = " << m << "x + " << b;
else if(m==1 && b>0) cout << "y = x + " << b;
else if(m==-1 && b>0) cout << "y = -x + " << b;
else if(m==1 && b<0) cout << "y = x - " << -b;
else if(m==-1 && b<0) cout << "y = -x - " << -b;
}
}
} | # 0107, 2024-11-02 11:16:30, -----P---------P-------- (8%)
#include<iostream>
#include<cmath>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
double x[n],y[n];
for(int i=0;i<n;i++) {
cin >> x[i] >> y[i];
}
float b_1=0,b_2=0;
float m_1=0,m_2=0,m_3=0,m_4=0;
float m_2a=0,m_2b=0;
for(int i=0;i<n;i++) {
m_1+=x[i]*y[i];
m_2a+=x[i];
m_2b+=y[i];
m_3+=x[i]*x[i];
m_4+=x[i];
b_1+=y[i];
b_2+=x[i];
}
m_1*=n;
m_3*=n;
m_2=m_2a*m_2b;
m_4=m_4*m_4;
float m=(m_1-m_2)/(m_3-m_4);
float b=(b_1-m*b_2)/n;
m=round(m*1e3)/1e3;
b=round(m*1e3)/1e3;
if(s=="mb") {
cout << m << endl;
cout << b << endl;
}else {
if(m==0 && b==0) {
cout << "y = 0";
}else if(m==0) {
cout << "y = " << b;
}else if(b==0) {
if(m!=1 && m!=-1) cout << "y = " << m << "x";
else if(m==1) cout << "y = x";
else if(m==-1) cout << "y = -x";
}else {
if(m!=1 && m!=-1 && b<0) cout << "y = " << m << "x - " << -b;
else if(m!=1 && m!=-1 && b>0) cout << "y = " << m << "x + " << b;
else if(m==1 && b>0) cout << "y = x + " << b;
else if(m==-1 && b>0) cout << "y = -x + " << b;
else if(m==1 && b<0) cout << "y = x - " << -b;
else if(m==-1 && b<0) cout << "y = -x - " << -b;
}
}
} | # 0108, 2024-11-02 11:16:59, -----PPPPP-----PPPPPPPPP (58%)
#include<iostream>
#include<cmath>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
double x[n],y[n];
for(int i=0;i<n;i++) {
cin >> x[i] >> y[i];
}
float b_1=0,b_2=0;
float m_1=0,m_2=0,m_3=0,m_4=0;
float m_2a=0,m_2b=0;
for(int i=0;i<n;i++) {
m_1+=x[i]*y[i];
m_2a+=x[i];
m_2b+=y[i];
m_3+=x[i]*x[i];
m_4+=x[i];
b_1+=y[i];
b_2+=x[i];
}
m_1*=n;
m_3*=n;
m_2=m_2a*m_2b;
m_4=m_4*m_4;
float m=round((m_1-m_2)/(m_3-m_4) * 1e3)/1e3;
float b=round((b_1-m*b_2)/n * 1e3)/1e3;
if(s=="mb") {
cout << m << endl;
cout << b << endl;
}else {
if(m==0 && b==0) {
cout << "y = 0";
}else if(m==0) {
cout << "y = " << b;
}else if(b==0) {
if(m!=1 && m!=-1) cout << "y = " << m << "x";
else if(m==1) cout << "y = x";
else if(m==-1) cout << "y = -x";
}else {
if(m!=1 && m!=-1 && b<0) cout << "y = " << m << "x - " << -b;
else if(m!=1 && m!=-1 && b>0) cout << "y = " << m << "x + " << b;
else if(m==1 && b>0) cout << "y = x + " << b;
else if(m==-1 && b>0) cout << "y = -x + " << b;
else if(m==1 && b<0) cout << "y = x - " << -b;
else if(m==-1 && b<0) cout << "y = -x - " << -b;
}
}
} | # 0109, 2024-11-02 11:25:31, Compilation error (0%)
#include<iostream>
#include<cmath>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
double x[n],y[n];
for(int i=0;i<n;i++) {
cin >> x[i] >> y[i];
}
float b_1=0,b_2=0;
float m_1=0,m_2=0,m_3=0;
float m_2a=0,m_2b=0;
for(int i=0;i<n;i++) {
m_1+=x[i]*y[i];
m_2a+=x[i];
m_2b+=y[i];
m_3+=x[i]*x[i];
}
m_1*=n;
m_3*=n;
m_2=m_2a*m_2b;
float q=(m_1-m_2)/(m_3-(m_2a*m_2a));
float r=(m_2b-m*m_2a)/n;
float m=round(q * 1e3)/1e3;
float b=round(r * 1e3)/1e3;
if(s=="mb") {
cout << m << endl;
cout << b << endl;
}else {
if(m==0 && b==0) {
cout << "y = 0";
}else if(m==0) {
cout << "y = " << b;
}else if(b==0) {
if(m!=1 && m!=-1) cout << "y = " << m << "x";
else if(m==1) cout << "y = x";
else if(m==-1) cout << "y = -x";
}else {
if(m!=1 && m!=-1 && b<0) cout << "y = " << m << "x - " << -b;
else if(m!=1 && m!=-1 && b>0) cout << "y = " << m << "x + " << b;
else if(m==1 && b>0) cout << "y = x + " << b;
else if(m==-1 && b>0) cout << "y = -x + " << b;
else if(m==1 && b<0) cout << "y = x - " << -b;
else if(m==-1 && b<0) cout << "y = -x - " << -b;
}
}
} | # 0110, 2024-11-02 11:25:53, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<iostream>
#include<cmath>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
double x[n],y[n];
for(int i=0;i<n;i++) {
cin >> x[i] >> y[i];
}
float b_1=0,b_2=0;
float m_1=0,m_2=0,m_3=0;
float m_2a=0,m_2b=0;
for(int i=0;i<n;i++) {
m_1+=x[i]*y[i];
m_2a+=x[i];
m_2b+=y[i];
m_3+=x[i]*x[i];
}
m_1*=n;
m_3*=n;
m_2=m_2a*m_2b;
float q=(m_1-m_2)/(m_3-(m_2a*m_2a));
float r=(m_2b-q*m_2a)/n;
float m=round(q * 1e3)/1e3;
float b=round(r * 1e3)/1e3;
if(s=="mb") {
cout << m << endl;
cout << b << endl;
}else {
if(m==0 && b==0) {
cout << "y = 0";
}else if(m==0) {
cout << "y = " << b;
}else if(b==0) {
if(m!=1 && m!=-1) cout << "y = " << m << "x";
else if(m==1) cout << "y = x";
else if(m==-1) cout << "y = -x";
}else {
if(m!=1 && m!=-1 && b<0) cout << "y = " << m << "x - " << -b;
else if(m!=1 && m!=-1 && b>0) cout << "y = " << m << "x + " << b;
else if(m==1 && b>0) cout << "y = x + " << b;
else if(m==-1 && b>0) cout << "y = -x + " << b;
else if(m==1 && b<0) cout << "y = x - " << -b;
else if(m==-1 && b<0) cout << "y = -x - " << -b;
}
}
} |
# 0111, 2024-11-02 13:03:33, -----PPPPP--------P--P-- (29%)
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n,m=0,b=0;
cin >> n;
string type;
cin >> type;
float F, S;
float SumMul = 0, SumF = 0, SumS = 0, Sumsq = 0;
for(int i=0 ; i < n ; i++) {
cin >> F >> S;
SumMul += F*S;
SumF += F;
SumS += S;
Sumsq += F*F;
}
m = (n*SumMul - SumF*SumS)/(n*Sumsq - SumF*SumF);
b = (SumS - m*SumF)/n;
if(type == "mb") {
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(type == "func") {
cout << "y = ";
if(m != 0) {
if(m != 1)
cout << round(m*1e3)/1e3;
cout << "x";
}
if(b != 0) {
cout << round(b*1e3)/1e3;
}
}
} | # 0112, 2024-11-02 13:08:56, PPPPPPPPPP-----P--P--P-- (54%)
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n;
float m=1,b=1;
cin >> n;
string type;
cin >> type;
float F, S;
float SumMul = 0, SumX = 0, SumY = 0, Sumsq = 0;
for(int i=0 ; i < n ; i++) {
cin >> F >> S;
SumMul += F*S;
SumX += F;
SumY += S;
Sumsq += F*F;
}
m = (n*SumMul - SumX*SumY)/(n*Sumsq - SumX*SumX);
b = (SumY - m*SumX)/n;
if(type == "mb") {
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(type == "func") {
cout << "y = ";
if(m != 0) {
if(m != 1) {
cout << round(m*1e3)/1e3;
}
if(m == 1) {
cout << "x";
}
if(b != 0) {
cout << round(b*1e3)/1e3;
}
}
else {
cout << round(b*1e3)/1e3;
}
}
} | # 0113, 2024-11-02 13:11:46, PPPPPPPPPP-P-PP--------- (54%)
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n;
float m=0,b=0;
cin >> n;
string type;
cin >> type;
float F, S;
float SumMul = 0, SumX = 0, SumY = 0, Sumsq = 0;
for(int i=0 ; i < n ; i++) {
cin >> F >> S;
SumMul += F*S;
SumX += F;
SumY += S;
Sumsq += F*F;
}
m = (n*SumMul - SumX*SumY)/(n*Sumsq - SumX*SumX);
b = (SumY - m*SumX)/n;
if(type == "mb") {
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(type == "func") {
cout << "y = ";
if(m != 0) {
if(m != 1) {
cout << round(m*1e3)/1e3 << "x ";
}
if(b != 0) {
if(round(b*1e3)/1e3 > 0) {
cout << round(b*1e3)/1e3;
}
else {
cout << "- " << -round(b*1e3)/1e3;
}
}
}
else {
if(round(b*1e3)/1e3 > 0) {
cout << round(b*1e3)/1e3;
}
else {
cout << "- " << -round(b*1e3)/1e3;
}
}
}
} | # 0114, 2024-11-02 13:16:49, PPPPPPPPPP-P-PP---PP---- (62%)
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n;
float m=0,b=0;
cin >> n;
string type;
cin >> type;
float F, S;
float SumMul = 0, SumX = 0, SumY = 0, Sumsq = 0;
for(int i=0 ; i < n ; i++) {
cin >> F >> S;
SumMul += F*S;
SumX += F;
SumY += S;
Sumsq += F*F;
}
m = (n*SumMul - SumX*SumY)/(n*Sumsq - SumX*SumX);
b = (SumY - m*SumX)/n;
if(type == "mb") {
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(type == "func") {
cout << "y = ";
if(m != 0) {
if(m < 0) {
cout << "-";
}
if(abs(m) != 1) {
cout << abs(round(m*1e3)/1e3);
}
cout << "x ";
if(b != 0) {
if(round(b*1e3)/1e3 > 0) {
cout << round(b*1e3)/1e3;
}
else {
cout << "- " << -round(b*1e3)/1e3;
}
}
}
else {
if(b != 0) {
if(round(b*1e3)/1e3 > 0) {
cout << round(b*1e3)/1e3;
}
else {
cout << "- " << -round(b*1e3)/1e3;
}
}
}
}
} | # 0115, 2024-11-02 13:17:43, PPPPPPPPPPPPPPP---PP---- (70%)
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n;
float m=0,b=0;
cin >> n;
string type;
cin >> type;
float F, S;
float SumMul = 0, SumX = 0, SumY = 0, Sumsq = 0;
for(int i=0 ; i < n ; i++) {
cin >> F >> S;
SumMul += F*S;
SumX += F;
SumY += S;
Sumsq += F*F;
}
m = (n*SumMul - SumX*SumY)/(n*Sumsq - SumX*SumX);
b = (SumY - m*SumX)/n;
if(type == "mb") {
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(type == "func") {
cout << "y = ";
if(m != 0) {
if(m < 0) {
cout << "-";
}
if(abs(m) != 1) {
cout << abs(round(m*1e3)/1e3);
}
cout << "x ";
if(b != 0) {
if(round(b*1e3)/1e3 > 0) {
cout << "+ " << round(b*1e3)/1e3;
}
else {
cout << "- " << -round(b*1e3)/1e3;
}
}
}
else {
if(b != 0) {
if(round(b*1e3)/1e3 > 0) {
cout << "+ " << round(b*1e3)/1e3;
}
else {
cout << "- " << -round(b*1e3)/1e3;
}
}
}
}
} | # 0116, 2024-11-02 13:21:24, PPPPPPPPPP--------PP---- (50%)
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n;
float m=0,b=0;
cin >> n;
string type;
cin >> type;
float F, S;
float SumMul = 0, SumX = 0, SumY = 0, Sumsq = 0;
for(int i=0 ; i < n ; i++) {
cin >> F >> S;
SumMul += F*S;
SumX += F;
SumY += S;
Sumsq += F*F;
}
m = (n*SumMul - SumX*SumY)/(n*Sumsq - SumX*SumX);
b = (SumY - m*SumX)/n;
if(type == "mb") {
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(type == "func") {
cout << "y = ";
if(m != 0) {
if(m == -1) {
cout << "-";
}
if(m != -1 && m != 1) {
cout << round(b*1e3)/1e3;
}
cout << "x ";
if(b != 0) {
if(round(b*1e3)/1e3 > 0) {
cout << "+ " << round(b*1e3)/1e3;
}
else {
cout << "- " << -round(b*1e3)/1e3;
}
}
}
else {
if(b != 0) {
if(round(b*1e3)/1e3 > 0) {
cout << "+ " << round(b*1e3)/1e3;
}
else {
cout << "- " << -round(b*1e3)/1e3;
}
}
}
}
} | # 0117, 2024-11-02 13:22:09, PPPPPPPPPPPPPPP---PP---- (70%)
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n;
float m=0,b=0;
cin >> n;
string type;
cin >> type;
float F, S;
float SumMul = 0, SumX = 0, SumY = 0, Sumsq = 0;
for(int i=0 ; i < n ; i++) {
cin >> F >> S;
SumMul += F*S;
SumX += F;
SumY += S;
Sumsq += F*F;
}
m = (n*SumMul - SumX*SumY)/(n*Sumsq - SumX*SumX);
b = (SumY - m*SumX)/n;
if(type == "mb") {
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(type == "func") {
cout << "y = ";
if(m != 0) {
if(m == -1) {
cout << "-";
}
if(m != -1 && m != 1) {
cout << round(m*1e3)/1e3;
}
cout << "x ";
if(b != 0) {
if(round(b*1e3)/1e3 > 0) {
cout << "+ " << round(b*1e3)/1e3;
}
else {
cout << "- " << -round(b*1e3)/1e3;
}
}
}
else {
if(b != 0) {
if(round(b*1e3)/1e3 > 0) {
cout << "+ " << round(b*1e3)/1e3;
}
else {
cout << "- " << -round(b*1e3)/1e3;
}
}
}
}
} | # 0118, 2024-11-02 13:27:48, PPPPPPPPPPPPPPP-P-PP-P-- (79%)
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n;
float m=0,b=0;
cin >> n;
string type;
cin >> type;
float F, S;
float SumMul = 0, SumX = 0, SumY = 0, Sumsq = 0;
for(int i=0 ; i < n ; i++) {
cin >> F >> S;
SumMul += F*S;
SumX += F;
SumY += S;
Sumsq += F*F;
}
m = (n*SumMul - SumX*SumY)/(n*Sumsq - SumX*SumX);
b = (SumY - m*SumX)/n;
if(type == "mb") {
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(type == "func") {
cout << "y = ";
if(round(m*1e3)/1e3 != 0) {
if(m == -1) {
cout << "-";
}
if(m != -1 && m != 1) {
cout << round(m*1e3)/1e3;
}
cout << "x ";
if(b != 0) {
if(round(b*1e3)/1e3 > 0) {
cout << "+ " << round(b*1e3)/1e3;
}
else {
cout << "- " << -round(b*1e3)/1e3;
}
}
}
else if(round(m*1e3)/1e3 == 0) {
if(b != 0) {
cout << round(b*1e3)/1e3;
}
}
}
} | # 0119, 2024-11-02 14:35:11, PPPPPPPPPPPPPPP-P-PP-P-- (79%)
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n;
float m=0,b=0;
cin >> n;
string type;
cin >> type;
float F, S;
float SumMul = 0, SumX = 0, SumY = 0, Sumsq = 0;
for(int i=0 ; i < n ; i++) {
cin >> F >> S;
SumMul += F*S;
SumX += F;
SumY += S;
Sumsq += F*F;
}
m = (n*SumMul - SumX*SumY)/(n*Sumsq - SumX*SumX);
b = (SumY - m*SumX)/n;
if(type == "mb") {
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(type == "func") {
cout << "y = ";
if(round(m*1e3)/1e3 != 0) {
if(m == -1) {
cout << "-";
}
if(m != -1 && m != 1) {
cout << round(m*1e3)/1e3;
}
cout << "x ";
if(round(b*1e3)/1e3 != 0) {
if(round(b*1e3)/1e3 > 0) {
cout << "+ " << round(b*1e3)/1e3;
}
else {
cout << "- " << -round(b*1e3)/1e3;
}
}
}
else if(round(m*1e3)/1e3 == 0) {
if(round(b*1e3)/1e3 != 0) {
cout << round(b*1e3)/1e3;
}
}
}
} | # 0120, 2024-11-02 14:40:26, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n;
float m=0,b=0;
cin >> n;
string type;
cin >> type;
float F, S;
float SumMul = 0, SumX = 0, SumY = 0, Sumsq = 0;
for(int i=0 ; i < n ; i++) {
cin >> F >> S;
SumMul += F*S;
SumX += F;
SumY += S;
Sumsq += F*F;
}
m = (n*SumMul - SumX*SumY)/(n*Sumsq - SumX*SumX);
b = (SumY - m*SumX)/n;
if(type == "mb") {
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(type == "func") {
cout << "y = ";
if(m != 0) {
if(m == -1) {
cout << "-";
}
else if(m != 1){
cout << round(m*1e3)/1e3;
}
cout << "x ";
if(b < 0) {
cout << "- " << -round(b*1e3)/1e3;
}
else if(b > 0){
cout << "+ " << round(b*1e3)/1e3;
}
}
else {
cout << round(b*1e3)/1e3;
}
}
} | # 0121, 2024-11-02 14:41:57, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n;
float m=0,b=0;
cin >> n;
string type;
cin >> type;
float F, S;
float SumMul = 0, SumX = 0, SumY = 0, Sumsq = 0;
for(int i=0 ; i < n ; i++) {
cin >> F >> S;
SumMul += F*S;
SumX += F;
SumY += S;
Sumsq += F*F;
}
m = (n*SumMul - SumX*SumY)/(n*Sumsq - SumX*SumX);
b = (SumY - m*SumX)/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(type == "mb") {
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(type == "func") {
cout << "y = ";
if(m != 0) {
if(m == -1) {
cout << "-";
}
else if(m != 1){
cout << round(m*1e3)/1e3;
}
cout << "x";
if(b < 0) {
cout << " - " << -round(b*1e3)/1e3;
}
else if(b > 0){
cout << " + " << round(b*1e3)/1e3;
}
}
else {
cout << round(b*1e3)/1e3;
}
}
} |
# 0122, 2024-11-02 13:59:11, ---------------PP----P-- (12%)
#include <bits/stdc++.h>
using namespace std;
int main(){
float N = 0;
float m,b;
float x,y;
float xy = 0,xi = 0,yi = 0,x2 = 0;
string func;
cin >> N >> func;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
xi += x;
yi += y;
xy += x*y;
x2 += pow(x,2);
}
m = ((N * xy) - (xi * yi)) / (x2 - pow(xi,2));
b = (yi - (m * xi)) / N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(func == "mb")
{
cout << m << endl << b;
}
else if(func == "func")
{
if(m == 0)
{
cout << "y = " << b;
}
else if(m == 1 && b == 0) cout << "y = x";
else if(m != 1 && b == 0) cout << "y = " << m <<"x";
else if(m != 1 && b != 0) cout << "y " << m << "x +" << b;
}
} | # 0123, 2024-11-02 14:00:37, PPPPPPPPPP-----PP-P--P-- (58%)
#include <bits/stdc++.h>
using namespace std;
int main(){
float N = 0;
float m,b;
float x,y;
float xy = 0,xi = 0,yi = 0,x2 = 0;
string func;
cin >> N >> func;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
xi += x;
yi += y;
xy += x*y;
x2 += pow(x,2);
}
m = ((N * xy) - (xi * yi)) / ((N *x2) - pow(xi,2));
b = (yi - (m * xi)) / N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(func == "mb")
{
cout << m << endl << b;
}
else if(func == "func")
{
if(m == 0)
{
cout << "y = " << b;
}
else if(m == 1 && b == 0) cout << "y = x";
else if(m != 1 && b == 0) cout << "y = " << m <<"x";
else if(m != 1 && b != 0) cout << "y " << m << "x +" << b;
}
} | # 0124, 2024-11-02 14:02:33, PPPPPPPPPP-----PP-P--P-- (58%)
#include <bits/stdc++.h>
using namespace std;
int main(){
float N = 0;
float m,b;
float x,y;
float xy = 0,xi = 0,yi = 0,x2 = 0;
string func;
cin >> N >> func;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
xi += x;
yi += y;
xy += x*y;
x2 += pow(x,2);
}
m = ((N * xy) - (xi * yi)) / ((N *x2) - pow(xi,2));
b = (yi - (m * xi)) / N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(func == "mb")
{
cout << m << endl << b;
}
else if(func == "func")
{
if(m == 0)
{
cout << "y = " << b;
}
else if(m == 1 && b == 0) cout << "y = x";
else if(m == 1 && b != 0) cout << "y = x +" << b;
else if(m != 1 && b == 0) cout << "y = " << m <<"x";
else if(m != 1 && b != 0) cout << "y " << m << "x +" << b;
}
} | # 0125, 2024-11-02 14:03:18, PPPPPPPPPP-----PP-P--P-- (58%)
#include <bits/stdc++.h>
using namespace std;
int main(){
float N = 0;
float m,b;
float x,y;
float xy = 0,xi = 0,yi = 0,x2 = 0;
string func;
cin >> N >> func;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
xi += x;
yi += y;
xy += x*y;
x2 += pow(x,2);
}
m = ((N * xy) - (xi * yi)) / ((N *x2) - pow(xi,2));
b = (yi - (m * xi)) / N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(func == "mb")
{
cout << m << endl << b;
}
else if(func == "func")
{
if(m == 0)
{
cout << "y = " << b;
}
else if(m == 1 && b == 0) cout << "y = x";
else if(m == 1 && b != 0) cout << "y = x +" << b;
else if(m == -1 && b == 0) cout << "y = x";
else if(m == -1 && b != 0) cout << "y = x +" << b;
else if(m != 1 && b == 0) cout << "y = " << m <<"x";
else if(m != 1 && b != 0) cout << "y " << m << "x +" << b;
}
} | # 0126, 2024-11-02 14:03:49, PPPPPPPPPP-----PP-PP-P-- (62%)
#include <bits/stdc++.h>
using namespace std;
int main(){
float N = 0;
float m,b;
float x,y;
float xy = 0,xi = 0,yi = 0,x2 = 0;
string func;
cin >> N >> func;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
xi += x;
yi += y;
xy += x*y;
x2 += pow(x,2);
}
m = ((N * xy) - (xi * yi)) / ((N *x2) - pow(xi,2));
b = (yi - (m * xi)) / N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(func == "mb")
{
cout << m << endl << b;
}
else if(func == "func")
{
if(m == 0)
{
cout << "y = " << b;
}
else if(m == 1 && b == 0) cout << "y = x";
else if(m == 1 && b != 0) cout << "y = x +" << b;
else if(m == -1 && b == 0) cout << "y = -x";
else if(m == -1 && b != 0) cout << "y = -x +" << b;
else if(m != 1 && b == 0) cout << "y = " << m <<"x";
else if(m != 1 && b != 0) cout << "y " << m << "x +" << b;
}
} | # 0127, 2024-11-02 14:05:20, PPPPPPPPPP-----PP-PP-P-- (62%)
#include <bits/stdc++.h>
using namespace std;
int main(){
float N = 0;
float m,b;
float x,y;
float xy = 0,xi = 0,yi = 0,x2 = 0;
string func;
cin >> N >> func;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
xi += x;
yi += y;
xy += x*y;
x2 += pow(x,2);
}
m = ((N * xy) - (xi * yi)) / ((N *x2) - pow(xi,2));
b = (yi - (m * xi)) / N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(func == "mb")
{
cout << m << endl << b;
}
else if(func == "func")
{
if(m == 0)
{
cout << "y = " << b;
}
else if(m == 1 && b == 0) cout << "y = x";
else if(m == 1 && b >= 0) cout << "y = x +" << b;
else if(m == 1 && b < 0) cout << "y = x -" << b;
else if(m == -1 && b == 0) cout << "y = -x";
else if(m == -1 && b >= 0) cout << "y = -x +" << b;
else if(m == -1 && b < 0) cout << "y = -x -" << b;
else if(m != 1 && b == 0) cout << "y = " << m <<"x";
else if(m != 1 && b >= 0) cout << "y " << m << "x +" << b;
else if(m != 1 && b < 0) cout << "y " << m << "x -" << b;
}
} | # 0128, 2024-11-02 14:05:56, PPPPPPPPPP-----PP-PP-P-- (62%)
#include <bits/stdc++.h>
using namespace std;
int main(){
float N = 0;
float m,b;
float x,y;
float xy = 0,xi = 0,yi = 0,x2 = 0;
string func;
cin >> N >> func;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
xi += x;
yi += y;
xy += x*y;
x2 += pow(x,2);
}
m = ((N * xy) - (xi * yi)) / ((N *x2) - pow(xi,2));
b = (yi - (m * xi)) / N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(func == "mb")
{
cout << m << endl << b;
}
else if(func == "func")
{
if(m == 0)
{
cout << "y = " << b;
}
else if(m == 1 && b == 0) cout << "y = x";
else if(m == 1 && b >= 0) cout << "y = x +" << b;
else if(m == 1 && b < 0) cout << "y = x " << b;
else if(m == -1 && b == 0) cout << "y = -x";
else if(m == -1 && b >= 0) cout << "y = -x +" << b;
else if(m == -1 && b < 0) cout << "y = -x " << b;
else if(m != 1 && b == 0) cout << "y = " << m <<"x";
else if(m != 1 && b >= 0) cout << "y " << m << "x +" << b;
else if(m != 1 && b < 0) cout << "y " << m << "x " << b;
}
} | # 0129, 2024-11-02 14:06:47, PPPPPPPPPP-----PP-PP-PPP (70%)
#include <bits/stdc++.h>
using namespace std;
int main(){
float N = 0;
float m,b;
float x,y;
float xy = 0,xi = 0,yi = 0,x2 = 0;
string func;
cin >> N >> func;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
xi += x;
yi += y;
xy += x*y;
x2 += pow(x,2);
}
m = ((N * xy) - (xi * yi)) / ((N *x2) - pow(xi,2));
b = (yi - (m * xi)) / N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(func == "mb")
{
cout << m << endl << b;
}
else if(func == "func")
{
if(m == 0)
{
cout << "y = " << b;
}
else if(m == 1 && b == 0) cout << "y = x";
else if(m == 1 && b >= 0) cout << "y = x +" << b;
else if(m == 1 && b < 0) cout << "y = x - " << abs(b);
else if(m == -1 && b == 0) cout << "y = -x";
else if(m == -1 && b >= 0) cout << "y = -x +" << b;
else if(m == -1 && b < 0) cout << "y = -x - " << abs(b);
else if(m != 1 && b == 0) cout << "y = " << m <<"x";
else if(m != 1 && b >= 0) cout << "y " << m << "x +" << b;
else if(m != 1 && b < 0) cout << "y " << m << "x - " << abs(b);
}
} | # 0130, 2024-11-02 14:07:34, PPPPPPPPPP-P-PPPP-PP-PPP (83%)
#include <bits/stdc++.h>
using namespace std;
int main(){
float N = 0;
float m,b;
float x,y;
float xy = 0,xi = 0,yi = 0,x2 = 0;
string func;
cin >> N >> func;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
xi += x;
yi += y;
xy += x*y;
x2 += pow(x,2);
}
m = ((N * xy) - (xi * yi)) / ((N *x2) - pow(xi,2));
b = (yi - (m * xi)) / N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(func == "mb")
{
cout << m << endl << b;
}
else if(func == "func")
{
if(m == 0)
{
cout << "y = " << b;
}
else if(m == 1 && b == 0) cout << "y = x";
else if(m == 1 && b >= 0) cout << "y = x +" << b;
else if(m == 1 && b < 0) cout << "y = x - " << abs(b);
else if(m == -1 && b == 0) cout << "y = -x";
else if(m == -1 && b >= 0) cout << "y = -x +" << b;
else if(m == -1 && b < 0) cout << "y = -x - " << abs(b);
else if(m != 1 && b == 0) cout << "y = " << m <<"x";
else if(m != 1 && b >= 0) cout << "y = " << m << "x +" << b;
else if(m != 1 && b < 0) cout << "y = " << m << "x - " << abs(b);
}
} | # 0131, 2024-11-02 14:10:25, PPPPPPPPPP-P-PPPP-PP-PPP (83%)
#include <bits/stdc++.h>
using namespace std;
int main(){
float N = 0;
float m,b;
float x,y;
float xy = 0,xi = 0,yi = 0,x2 = 0;
string func;
cin >> N >> func;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
xi += x;
yi += y;
xy += x*y;
x2 += pow(x,2);
}
m = ((N * xy) - (xi * yi)) / ((N *x2) - pow(xi,2));
b = (yi - (m * xi)) / N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(func == "mb")
{
cout << m << endl << b;
}
else if(func == "func")
{
if(m == 0)
{
cout << "y = " << b;
}
else if(m == 1 && b == 0) cout << "y = x";
else if(m == 1 && b > 0) cout << "y = x +" << b;
else if(m == 1 && b < 0) cout << "y = x - " << abs(b);
else if(m == -1 && b == 0) cout << "y = -x";
else if(m == -1 && b > 0) cout << "y = -x +" << b;
else if(m == -1 && b < 0) cout << "y = -x - " << abs(b);
else if(m != 1 && b == 0) cout << "y = " << m <<"x";
else if(m != 1 && b > 0) cout << "y = " << m << "x +" << b;
else if(m != 1 && b < 0) cout << "y = " << m << "x - " << abs(b);
}
} | # 0132, 2024-11-02 14:13:02, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
int main(){
float N = 0;
float m,b;
float x,y;
float xy = 0,xi = 0,yi = 0,x2 = 0;
string func;
cin >> N >> func;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
xi += x;
yi += y;
xy += x*y;
x2 += pow(x,2);
}
m = ((N * xy) - (xi * yi)) / ((N *x2) - pow(xi,2));
b = (yi - (m * xi)) / N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(func == "mb")
{
cout << m << endl << b;
}
else if(func == "func")
{
if(m == 0)
{
cout << "y = " << b;
}
else if(m == 1 && b == 0) cout << "y = x";
else if(m == 1 && b > 0) cout << "y = x + " << b;
else if(m == 1 && b < 0) cout << "y = x - " << abs(b);
else if(m == -1 && b == 0) cout << "y = -x";
else if(m == -1 && b > 0) cout << "y = -x + " << b;
else if(m == -1 && b < 0) cout << "y = -x - " << abs(b);
else if(m != 1 && b == 0) cout << "y = " << m <<"x";
else if(m != 1 && b > 0) cout << "y = " << m << "x + " << b;
else if(m != 1 && b < 0) cout << "y = " << m << "x - " << abs(b);
}
} |
# 0133, 2024-11-02 09:55:52, -----PPPPP-------------- (20%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n ;
cin >> n ;
float m , b ;
string cmd ;
cin >> cmd ;
vector<float> x , y ;
for(int i = 0 ; i < n ; i++){
float xi , yi ;
cin >> xi >> yi ;
x.push_back(xi); y.push_back(yi);
}
float sum_xiyi = 0 ;
for( int i = 0 ; i < n ; i++ ){
sum_xiyi += x[i]*y[i] ;
}
float n_t_sum_xiyi = n * sum_xiyi ;
////////////////////////////////
float sum_xi = 0 ;
for( int i = 0 ; i < n ;i++){
sum_xi += x[i] ;
}
float sum_yi = 0 ;
for( int i = 0 ; i < n ; i++ ){
sum_yi += y[i] ;
}
float sum_x_t_sum_y = sum_xi * sum_yi ;
//////////////////////////////////
float sum_xsqr = 0 ;
for( int i = 0 ; i < n ;i++){
sum_xsqr += x[i]*x[i] ;
}
///dont forget * n
m = ( n_t_sum_xiyi - sum_x_t_sum_y )/ ((n*sum_xsqr ) - (sum_xi * sum_xi)) ;
b = (sum_yi - m* sum_xi ) / float(n) ;
if( cmd == "mb"){
cout << m << "\n" << b ;
}
} | # 0134, 2024-11-02 09:58:26, PPPPPPPPPP-------------- (41%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n ;
cin >> n ;
float m , b ;
string cmd ;
cin >> cmd ;
vector<float> x , y ;
for(int i = 0 ; i < n ; i++){
float xi , yi ;
cin >> xi >> yi ;
x.push_back(xi); y.push_back(yi);
}
float sum_xiyi = 0 ;
for( int i = 0 ; i < n ; i++ ){
sum_xiyi += x[i]*y[i] ;
}
float n_t_sum_xiyi = n * sum_xiyi ;
////////////////////////////////
float sum_xi = 0 ;
for( int i = 0 ; i < n ;i++){
sum_xi += x[i] ;
}
float sum_yi = 0 ;
for( int i = 0 ; i < n ; i++ ){
sum_yi += y[i] ;
}
float sum_x_t_sum_y = sum_xi * sum_yi ;
//////////////////////////////////
float sum_xsqr = 0 ;
for( int i = 0 ; i < n ;i++){
sum_xsqr += x[i]*x[i] ;
}
///dont forget * n
m = ( n_t_sum_xiyi - sum_x_t_sum_y )/ ((n*sum_xsqr ) - (sum_xi * sum_xi)) ;
b = (sum_yi - m* sum_xi ) / float(n) ;
if( cmd == "mb"){
cout << round(m*1e3)/1e3 << "\n" << round(b*1e3)/1e3 << "\n" ;
}
} | # 0135, 2024-11-02 10:11:14, PPPPPPPPPP-----P--PP-P-- (58%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n ;
cin >> n ;
float m , b ;
string cmd ;
cin >> cmd ;
vector<float> x , y ;
for(int i = 0 ; i < n ; i++){
float xi , yi ;
cin >> xi >> yi ;
x.push_back(xi); y.push_back(yi);
}
float sum_xiyi = 0 ;
for( int i = 0 ; i < n ; i++ ){
sum_xiyi += x[i]*y[i] ;
}
float n_t_sum_xiyi = n * sum_xiyi ;
////////////////////////////////
float sum_xi = 0 ;
for( int i = 0 ; i < n ;i++){
sum_xi += x[i] ;
}
float sum_yi = 0 ;
for( int i = 0 ; i < n ; i++ ){
sum_yi += y[i] ;
}
float sum_x_t_sum_y = sum_xi * sum_yi ;
//////////////////////////////////
float sum_xsqr = 0 ;
for( int i = 0 ; i < n ;i++){
sum_xsqr += x[i]*x[i] ;
}
///dont forget * n
m = ( n_t_sum_xiyi - sum_x_t_sum_y )/ ((n*sum_xsqr ) - (sum_xi * sum_xi)) ;
b = (sum_yi - m* sum_xi ) / float(n) ;
float yy = 0 ;
if( cmd == "mb"){
cout << round(m*1e3)/1e3 << "\n" << round(b*1e3)/1e3 << "\n" ;
}else if (cmd == "func"){
if( m == 0 && b == 0 ){
cout << "y = 0 " << "\n";
}else if( m == 0 && b != 0 ){
cout << "y = " << b << "\n";
}else if( m == 1 && b == 0){
cout << "y = " << "x" << "\n";
}else if (m == -1 && b == 0 ){
cout << "y = " << "-x" << "\n" ;
}else if( m == 1 && b != 0){
cout << "y = " << "x + " << b << "\n";
}else if (m == -1 && b != 0 ){
cout << "y = " << "-x + " << b << "\n";
}else{
cout << "y = " << m << "x + " << b << "\n";
}
}
} | # 0136, 2024-11-02 10:18:54, PPPPPPPPPP-----P--PP-P-- (58%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n ;
cin >> n ;
float m , b ;
string cmd ;
cin >> cmd ;
vector<float> x , y ;
for(int i = 0 ; i < n ; i++){
float xi , yi ;
cin >> xi >> yi ;
x.push_back(xi); y.push_back(yi);
}
float sum_xiyi = 0 ;
for( int i = 0 ; i < n ; i++ ){
sum_xiyi += x[i]*y[i] ;
}
float n_t_sum_xiyi = n * sum_xiyi ;
////////////////////////////////
float sum_xi = 0 ;
for( int i = 0 ; i < n ;i++){
sum_xi += x[i] ;
}
float sum_yi = 0 ;
for( int i = 0 ; i < n ; i++ ){
sum_yi += y[i] ;
}
float sum_x_t_sum_y = sum_xi * sum_yi ;
//////////////////////////////////
float sum_xsqr = 0 ;
for( int i = 0 ; i < n ;i++){
sum_xsqr += x[i]*x[i] ;
}
///dont forget * n
m = ( n_t_sum_xiyi - sum_x_t_sum_y )/ ((n*sum_xsqr ) - (sum_xi * sum_xi)) ;
b = (sum_yi - m* sum_xi ) / float(n) ;
if( cmd == "mb"){
cout << round(m*1e3)/1e3 << "\n" << round(b*1e3)/1e3 << "\n" ;
}else if (cmd == "func"){
if( m == 0 && b == 0 ){
cout << "y = 0 " << "\n";
}else if( m == 0 && b != 0 ){
cout << "y = " << b << "\n";
}else if( m == 1 && b == 0){
cout << "y = " << "x" << "\n";
}else if (m == -1 && b == 0 ){
cout << "y = " << "-x" << "\n" ;
}else if( m == 1 && b < 0){
cout << "y = " << "x - " << -b << "\n";
}else if (m == 1 && b > 0 ){
cout << "y = " << "x + " << b << "\n" ;
}else if (m == -1 && b < 0 ){
cout << "y = " << "-x - " << -b << "\n";
}else if (m == -1 && b > 0 ){
cout << "y = " << "-x + " << b << "\n";
}else if( b < 0 ){
cout << "y = " << m << "x - " << -b << "\n";
}else{
cout << "y = " << m << "x + " << +b << "\n";
}
}
} | # 0137, 2024-11-02 10:20:54, -----P---------P-------- (8%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n ;
cin >> n ;
float m , b ;
string cmd ;
cin >> cmd ;
vector<float> x , y ;
for(int i = 0 ; i < n ; i++){
float xi , yi ;
cin >> xi >> yi ;
x.push_back(xi); y.push_back(yi);
}
float sum_xiyi = 0 ;
for( int i = 0 ; i < n ; i++ ){
sum_xiyi += x[i]*y[i] ;
}
float n_t_sum_xiyi = n * sum_xiyi ;
////////////////////////////////
float sum_xi = 0 ;
for( int i = 0 ; i < n ;i++){
sum_xi += x[i] ;
}
float sum_yi = 0 ;
for( int i = 0 ; i < n ; i++ ){
sum_yi += y[i] ;
}
float sum_x_t_sum_y = sum_xi * sum_yi ;
//////////////////////////////////
float sum_xsqr = 0 ;
for( int i = 0 ; i < n ;i++){
sum_xsqr += x[i]*x[i] ;
}
///dont forget * n
m = ( n_t_sum_xiyi - sum_x_t_sum_y )/ ((n*sum_xsqr ) - (sum_xi * sum_xi)) ;
m = round(m*1e3) ;
b = (sum_yi - m* sum_xi ) / float(n) ;
b = round(b*1e3) ;
if( cmd == "mb"){
cout << round(m*1e3)/1e3 << "\n" << round(b*1e3)/1e3 << "\n" ;
}else if (cmd == "func"){
if( m == 0 && b == 0 ){
cout << "y = 0 " << "\n";
}else if( m == 0 && b != 0 ){
cout << "y = " << b << "\n";
}else if( m == 1 && b == 0){
cout << "y = " << "x" << "\n";
}else if (m == -1 && b == 0 ){
cout << "y = " << "-x" << "\n" ;
}else if( m == 1 && b < 0){
cout << "y = " << "x - " << -b << "\n";
}else if (m == 1 && b > 0 ){
cout << "y = " << "x + " << b << "\n" ;
}else if (m == -1 && b < 0 ){
cout << "y = " << "-x - " << -b << "\n";
}else if (m == -1 && b > 0 ){
cout << "y = " << "-x + " << b << "\n";
}else if( b < 0 ){
cout << "y = " << m << "x - " << -b << "\n";
}else{
cout << "y = " << m << "x + " << +b << "\n";
}
}
} | # 0138, 2024-11-02 10:24:47, PPPPPPPPPP-----P--PP-P-- (58%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n ;
cin >> n ;
float m , b ;
string cmd ;
cin >> cmd ;
vector<float> x , y ;
for(int i = 0 ; i < n ; i++){
float xi , yi ;
cin >> xi >> yi ;
x.push_back(xi); y.push_back(yi);
}
float sum_xiyi = 0 ;
for( int i = 0 ; i < n ; i++ ){
sum_xiyi += x[i]*y[i] ;
}
float n_t_sum_xiyi = n * sum_xiyi ;
////////////////////////////////
float sum_xi = 0 ;
for( int i = 0 ; i < n ;i++){
sum_xi += x[i] ;
}
float sum_yi = 0 ;
for( int i = 0 ; i < n ; i++ ){
sum_yi += y[i] ;
}
float sum_x_t_sum_y = sum_xi * sum_yi ;
//////////////////////////////////
float sum_xsqr = 0 ;
for( int i = 0 ; i < n ;i++){
sum_xsqr += x[i]*x[i] ;
}
///dont forget * n
m = ( n_t_sum_xiyi - sum_x_t_sum_y )/ ((n*sum_xsqr ) - (sum_xi * sum_xi)) ;
b = (sum_yi - m* sum_xi ) / float(n) ;
if( cmd == "mb"){
cout << round(m*1e3)/1e3 << "\n" << round(b*1e3)/1e3 << "\n" ;
}else if (cmd == "func"){
if( m == 0 && b == 0 ){
cout << "y = 0 " << "\n";
}else if( m == 0 && b != 0 ){
cout << "y = " << b << "\n";
}else if( m == 1 && b == 0){
cout << "y = " << "x" << "\n";
}else if (m == -1 && b == 0 ){
cout << "y = " << "-x" << "\n" ;
}else if( m == 1 && b < 0){
cout << "y = " << "x - " << -b << "\n";
}else if (m == 1 && b > 0 ){
cout << "y = " << "x + " << b << "\n" ;
}else if (m == -1 && b < 0 ){
cout << "y = " << "-x - " << -b << "\n";
}else if (m == -1 && b > 0 ){
cout << "y = " << "-x + " << b << "\n";
}else if( b < 0 ){
cout << "y = " << m << "x - " << -b << "\n";
}else{
cout << "y = " << m << "x + " << +b << "\n";
}
}
} | # 0139, 2024-11-02 12:00:11, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n ;
cin >> n ;
float m , b ;
string cmd ;
cin >> cmd ;
vector<float> x , y ;
for(int i = 0 ; i < n ; i++){
float xi , yi ;
cin >> xi >> yi ;
x.push_back(xi); y.push_back(yi);
}
float sum_xiyi = 0 ;
for( int i = 0 ; i < n ; i++ ){
sum_xiyi += x[i]*y[i] ;
}
float n_t_sum_xiyi = n * sum_xiyi ;
////////////////////////////////
float sum_xi = 0 ;
for( int i = 0 ; i < n ;i++){
sum_xi += x[i] ;
}
float sum_yi = 0 ;
for( int i = 0 ; i < n ; i++ ){
sum_yi += y[i] ;
}
float sum_x_t_sum_y = sum_xi * sum_yi ;
//////////////////////////////////
float sum_xsqr = 0 ;
for( int i = 0 ; i < n ;i++){
sum_xsqr += x[i]*x[i] ;
}
///dont forget * n
m = ( n_t_sum_xiyi - sum_x_t_sum_y )/ ((n*sum_xsqr ) - (sum_xi * sum_xi)) ;
b = (sum_yi - m* sum_xi ) / float(n) ;
if( cmd == "mb"){
cout << round(m*1e3)/1e3 << "\n" << round(b*1e3)/1e3 << "\n" ;
}else if (cmd == "func"){
m = round(m*1e3)/1e3 ;
b = round(b*1e3)/1e3 ;
if( m == 0 && b == 0 ){
cout << "y = 0 " << "\n";
}else if( m == 0 && b != 0 ){
cout << "y = " << b << "\n";
}else if( m == 1 && b == 0){
cout << "y = " << "x" << "\n";
}else if (m == -1 && b == 0 ){
cout << "y = " << "-x" << "\n" ;
}else if( m == 1 && b < 0){
cout << "y = " << "x - " << -b << "\n";
}else if (m == 1 && b > 0 ){
cout << "y = " << "x + " << b << "\n" ;
}else if (m == -1 && b < 0 ){
cout << "y = " << "-x - " << -b << "\n";
}else if (m == -1 && b > 0 ){
cout << "y = " << "-x + " << b << "\n";
}else if( b < 0 ){
cout << "y = " << m << "x - " << -b << "\n";
}else{
cout << "y = " << m << "x + " << +b << "\n";
}
}
} | # 0140, 2024-11-02 12:01:24, -----PPP-------P-------- (16%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n ;
cin >> n ;
float m , b ;
string cmd ;
cin >> cmd ;
vector<float> x , y ;
for(int i = 0 ; i < n ; i++){
float xi , yi ;
cin >> xi >> yi ;
x.push_back(xi); y.push_back(yi);
}
float sum_xiyi = 0 ;
for( int i = 0 ; i < n ; i++ ){
sum_xiyi += x[i]*y[i] ;
}
float n_t_sum_xiyi = n * sum_xiyi ;
////////////////////////////////
float sum_xi = 0 ;
for( int i = 0 ; i < n ;i++){
sum_xi += x[i] ;
}
float sum_yi = 0 ;
for( int i = 0 ; i < n ; i++ ){
sum_yi += y[i] ;
}
float sum_x_t_sum_y = sum_xi * sum_yi ;
//////////////////////////////////
float sum_xsqr = 0 ;
for( int i = 0 ; i < n ;i++){
sum_xsqr += x[i]*x[i] ;
}
///dont forget * n
m = ( n_t_sum_xiyi - sum_x_t_sum_y )/ ((n*sum_xsqr ) - (sum_xi * sum_xi)) ;
b = (sum_yi - m* sum_xi ) / float(n) ;
b = round(b*1e3) ;
if( cmd == "mb"){
cout << round(m*1e3)/1e3 << "\n" << round(b*1e3)/1e3 << "\n" ;
}else if (cmd == "func"){
m = round(m*1e3) ;
b = round(b*1e3) ;
if( m == 0 && b == 0 ){
cout << "y = 0 " << "\n";
}else if( m == 0 && b != 0 ){
cout << "y = " << b << "\n";
}else if( m == 1 && b == 0){
cout << "y = " << "x" << "\n";
}else if (m == -1 && b == 0 ){
cout << "y = " << "-x" << "\n" ;
}else if( m == 1 && b < 0){
cout << "y = " << "x - " << -b << "\n";
}else if (m == 1 && b > 0 ){
cout << "y = " << "x + " << b << "\n" ;
}else if (m == -1 && b < 0 ){
cout << "y = " << "-x - " << -b << "\n";
}else if (m == -1 && b > 0 ){
cout << "y = " << "-x + " << b << "\n";
}else if( b < 0 ){
cout << "y = " << m << "x - " << -b << "\n";
}else{
cout << "y = " << m << "x + " << +b << "\n";
}
}
} | # 0141, 2024-11-02 12:02:26, -----PPP-------P--PP---- (25%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n ;
cin >> n ;
float m , b ;
string cmd ;
cin >> cmd ;
vector<float> x , y ;
for(int i = 0 ; i < n ; i++){
float xi , yi ;
cin >> xi >> yi ;
x.push_back(xi); y.push_back(yi);
}
float sum_xiyi = 0 ;
for( int i = 0 ; i < n ; i++ ){
sum_xiyi += x[i]*y[i] ;
}
float n_t_sum_xiyi = n * sum_xiyi ;
////////////////////////////////
float sum_xi = 0 ;
for( int i = 0 ; i < n ;i++){
sum_xi += x[i] ;
}
float sum_yi = 0 ;
for( int i = 0 ; i < n ; i++ ){
sum_yi += y[i] ;
}
float sum_x_t_sum_y = sum_xi * sum_yi ;
//////////////////////////////////
float sum_xsqr = 0 ;
for( int i = 0 ; i < n ;i++){
sum_xsqr += x[i]*x[i] ;
}
///dont forget * n
m = ( n_t_sum_xiyi - sum_x_t_sum_y )/ ((n*sum_xsqr ) - (sum_xi * sum_xi)) ;
b = (sum_yi - m* sum_xi ) / float(n) ;
b = round(b*1e3) ;
if( cmd == "mb"){
cout << round(m*1e3)/1e3 << "\n" << round(b*1e3)/1e3 << "\n" ;
}else if (cmd == "func"){
m = round(m*1e3)/1e3 ;
b = round(b*1e3)/1e3 ;
if( m == 0 && b == 0 ){
cout << "y = 0 " << "\n";
}else if( m == 0 && b != 0 ){
cout << "y = " << b << "\n";
}else if( m == 1 && b == 0){
cout << "y = " << "x" << "\n";
}else if (m == -1 && b == 0 ){
cout << "y = " << "-x" << "\n" ;
}else if( m == 1 && b < 0){
cout << "y = " << "x - " << -b << "\n";
}else if (m == 1 && b > 0 ){
cout << "y = " << "x + " << b << "\n" ;
}else if (m == -1 && b < 0 ){
cout << "y = " << "-x - " << -b << "\n";
}else if (m == -1 && b > 0 ){
cout << "y = " << "-x + " << b << "\n";
}else if( b < 0 ){
cout << "y = " << m << "x - " << -b << "\n";
}else{
cout << "y = " << m << "x + " << +b << "\n";
}
}
} | # 0142, 2024-11-02 12:03:31, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n ;
cin >> n ;
float m , b ;
string cmd ;
cin >> cmd ;
vector<float> x , y ;
for(int i = 0 ; i < n ; i++){
float xi , yi ;
cin >> xi >> yi ;
x.push_back(xi); y.push_back(yi);
}
float sum_xiyi = 0 ;
for( int i = 0 ; i < n ; i++ ){
sum_xiyi += x[i]*y[i] ;
}
float n_t_sum_xiyi = n * sum_xiyi ;
////////////////////////////////
float sum_xi = 0 ;
for( int i = 0 ; i < n ;i++){
sum_xi += x[i] ;
}
float sum_yi = 0 ;
for( int i = 0 ; i < n ; i++ ){
sum_yi += y[i] ;
}
float sum_x_t_sum_y = sum_xi * sum_yi ;
//////////////////////////////////
float sum_xsqr = 0 ;
for( int i = 0 ; i < n ;i++){
sum_xsqr += x[i]*x[i] ;
}
///dont forget * n
m = ( n_t_sum_xiyi - sum_x_t_sum_y )/ ((n*sum_xsqr ) - (sum_xi * sum_xi)) ;
b = (sum_yi - m* sum_xi ) / float(n) ;
if( cmd == "mb"){
cout << round(m*1e3)/1e3 << "\n" << round(b*1e3)/1e3 << "\n" ;
}else if (cmd == "func"){
m = round(m*1e3)/1e3 ;
b = round(b*1e3)/1e3 ;
if( m == 0 && b == 0 ){
cout << "y = 0 " << "\n";
}else if( m == 0 && b != 0 ){
cout << "y = " << b << "\n";
}else if( m == 1 && b == 0){
cout << "y = " << "x" << "\n";
}else if (m == -1 && b == 0 ){
cout << "y = " << "-x" << "\n" ;
}else if( m == 1 && b < 0){
cout << "y = " << "x - " << -b << "\n";
}else if (m == 1 && b > 0 ){
cout << "y = " << "x + " << b << "\n" ;
}else if (m == -1 && b < 0 ){
cout << "y = " << "-x - " << -b << "\n";
}else if (m == -1 && b > 0 ){
cout << "y = " << "-x + " << b << "\n";
}else if( b < 0 ){
cout << "y = " << m << "x - " << -b << "\n";
}else{
cout << "y = " << m << "x + " << +b << "\n";
}
}
} | # 0143, 2024-11-02 12:04:24, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n ;
cin >> n ;
float m , b ;
string cmd ;
cin >> cmd ;
vector<float> x , y ;
for(int i = 0 ; i < n ; i++){
float xi , yi ;
cin >> xi >> yi ;
x.push_back(xi); y.push_back(yi);
}
float sum_xiyi = 0 ;
for( int i = 0 ; i < n ; i++ ){
sum_xiyi += x[i]*y[i] ;
}
float n_t_sum_xiyi = n * sum_xiyi ;
////////////////////////////////
float sum_xi = 0 ;
for( int i = 0 ; i < n ;i++){
sum_xi += x[i] ;
}
float sum_yi = 0 ;
for( int i = 0 ; i < n ; i++ ){
sum_yi += y[i] ;
}
float sum_x_t_sum_y = sum_xi * sum_yi ;
//////////////////////////////////
float sum_xsqr = 0 ;
for( int i = 0 ; i < n ;i++){
sum_xsqr += x[i]*x[i] ;
}
///dont forget * n
m = ( n_t_sum_xiyi - sum_x_t_sum_y )/ ((n*sum_xsqr ) - (sum_xi * sum_xi)) ;
b = (sum_yi - m* sum_xi ) / float(n) ;
if( cmd == "mb"){
cout << round(m*1e3)/1e3 << "\n" << round(b*1e3)/1e3 << "\n" ;
}else if (cmd == "func"){
m = round(m*1e3)/1e3 ;
b = round(b*1e3)/1e3 ;
if( m == 0 && b == 0 ){
cout << "y = 0 " << "\n";
}else if( m == 0 && b != 0 ){
cout << "y = " << b << "\n";
}else if( m == 1 && b == 0){
cout << "y = " << "x" << "\n";
}else if (m == -1 && b == 0 ){
cout << "y = " << "-x" << "\n" ;
}else if( m == 1 && b < 0){
cout << "y = " << "x - " << -b << "\n";
}else if (m == 1 && b > 0 ){
cout << "y = " << "x + " << b << "\n" ;
}else if (m == -1 && b < 0 ){
cout << "y = " << "-x - " << -b << "\n";
}else if (m == -1 && b > 0 ){
cout << "y = " << "-x + " << b << "\n";
}else if( b < 0 ){
cout << "y = " << m << "x - " << -b << "\n";
}else{
cout << "y = " << m << "x + " << +b << "\n";
}
}
} |
# 0144, 2024-11-02 09:43:52, -----PPPPP-------------- (20%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
string m;
cin>>m;
if(m=="mb"){
float a,b;
vector<int> x,y;
int i;
for(i=0;i<n;i++){
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
float s1=0,s2=0,s3=0,s4=0,ans1,ans2;
for(i=0;i<n;i++){
s1+=x[i]*y[i];
s2+=x[i];
s3+=y[i];
s4+=x[i]*x[i];
}
//cout<<s1<<" "<<s2<<" "<<s3<<" "<<s4<<endl;
ans1=((n*s1)-s2*s3)/((n*s4)-s2*s2);
ans2=(s3-(ans1*s2))/n;
cout<<round(ans1*1e3)/1e3<<endl<<round(ans2*1e3)/1e3;
}
} | # 0145, 2024-11-02 09:51:59, -----PPPPP-----P--PP---- (33%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
string x;
cin>>x;
float a,a1;
vector<int> x1,y;
int i;
for(i=0;i<n;i++){
cin>>a>>a1;
x1.push_back(a);
y.push_back(a1);
}
float s1=0,s2=0,s3=0,s4=0,m,b;
for(i=0;i<n;i++){
s1+=x1[i]*y[i];
s2+=x1[i];
s3+=y[i];
s4+=x1[i]*x1[i];
}
//cout<<s1<<" "<<s2<<" "<<s3<<" "<<s4<<endl;
m=((n*s1)-s2*s3)/((n*s4)-s2*s2);
b=(s3-(m*s2))/n;
if(x=="mb") cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
else{
cout<<"y = ";
if(m==0&&b==0) cout<<"0";
else if(m==1) cout<<"x";
else if(m==-1) cout<<"-x";
else cout<<m<<"x";
cout<<" ";
if(b>0) cout<<"+ "<<b;
else if(b<0) cout<<"- "<<b*-1;
}
} | # 0146, 2024-11-02 09:56:20, -----PPPPP-----P--PP-P-- (37%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
string x;
cin>>x;
float a,a1;
vector<int> x1,y;
int i;
float s1=0,s2=0,s3=0,s4=0,m,b;
for(i=0;i<n;i++){
cin>>a>>a1;
x1.push_back(a);
y.push_back(a1);
s1+=x1[i]*y[i];
s2+=x1[i];
s3+=y[i];
s4+=x1[i]*x1[i];
}
for(i=0;i<n;i++){
}
//cout<<s1<<" "<<s2<<" "<<s3<<" "<<s4<<endl;
m=((n*s1)-s2*s3)/((n*s4)-s2*s2);
b=(s3-(m*s2))/n;
if(x=="mb") cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
else{
cout<<"y = ";
if(m==0&&b==0) cout<<"0";
else if(m==1) cout<<"x ";
else if(m==-1) cout<<"-x ";
else if(m!=0) cout<<m<<"x ";
if(b>0) cout<<"+ "<<b;
else if(b<0&&m!=0) cout<<"- "<<b*-1;
else if(b<0) cout<<"-"<<b*-1;
}
} | # 0147, 2024-11-02 09:57:44, -----PPPPP-----P--PP-P-- (37%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
string x;
cin>>x;
float a,a1;
vector<int> x1,y;
int i;
float s1=0,s2=0,s3=0,s4=0,m,b;
for(i=0;i<n;i++){
cin>>a>>a1;
x1.push_back(a);
y.push_back(a1);
s1+=x1[i]*y[i];
s2+=x1[i];
s3+=y[i];
s4+=x1[i]*x1[i];
}
for(i=0;i<n;i++){
}
//cout<<s1<<" "<<s2<<" "<<s3<<" "<<s4<<endl;
m=((n*s1)-s2*s3)/((n*s4)-s2*s2);
b=(s3-(m*s2))/n;
if(x=="mb") cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
else{
cout<<"y = ";
if(m==0&&b==0) cout<<"0";
else if(m==1&&b!=0) cout<<"x ";
else if(m==-1&&b!=0) cout<<"-x ";
else if(m!=0&&b!=0) cout<<m<<"x ";
else if(m==1) cout<<"x";
else if(m==-1) cout<<"-x";
else if(m!=0) cout<<m<<"x";
if(b>0) cout<<"+ "<<b;
else if(b<0&&m!=0) cout<<"- "<<b*-1;
else if(b<0) cout<<"-"<<b*-1;
}
} | # 0148, 2024-11-02 10:00:33, ------------------------ (0%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
string x;
cin>>x;
float a,a1;
vector<float> x1,y;
int i;
float s1=0,s2=0,s3=0,s4=0,m,b;
for(i=0;i<n;i++){
cin>>a>>a1;
x1.push_back(a);
y.push_back(a1);
s1+=x1[i]*y[i];
s2+=x1[i];
s3+=y[i];
s4+=x1[i]*x1[i];
}
for(i=0;i<n;i++){
}
cout<<s1<<" "<<s2<<" "<<s3<<" "<<s4<<endl;
m=((n*s1)-s2*s3)/((n*s4)-s2*s2);
b=(s3-(m*s2))/n;
if(x=="mb") cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
else{
cout<<"y = ";
if(m==0&&b==0) cout<<"0";
else if(m==1&&b!=0) cout<<"x ";
else if(m==-1&&b!=0) cout<<"-x ";
else if(m!=0&&b!=0) cout<<m<<"x ";
else if(m==1) cout<<"x";
else if(m==-1) cout<<"-x";
else if(m!=0) cout<<m<<"x";
if(b>0) cout<<"+ "<<b;
else if(b<0&&m!=0) cout<<"- "<<b*-1;
else if(b<0) cout<<"-"<<b*-1;
}
} | # 0149, 2024-11-02 10:01:03, PPPPPPPPPP-----P--PP-P-- (58%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
string x;
cin>>x;
float a,a1;
vector<float> x1,y;
int i;
float s1=0,s2=0,s3=0,s4=0,m,b;
for(i=0;i<n;i++){
cin>>a>>a1;
x1.push_back(a);
y.push_back(a1);
s1+=x1[i]*y[i];
s2+=x1[i];
s3+=y[i];
s4+=x1[i]*x1[i];
}
for(i=0;i<n;i++){
}
//cout<<s1<<" "<<s2<<" "<<s3<<" "<<s4<<endl;
m=((n*s1)-s2*s3)/((n*s4)-s2*s2);
b=(s3-(m*s2))/n;
if(x=="mb") cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
else{
cout<<"y = ";
if(m==0&&b==0) cout<<"0";
else if(m==1&&b!=0) cout<<"x ";
else if(m==-1&&b!=0) cout<<"-x ";
else if(m!=0&&b!=0) cout<<m<<"x ";
else if(m==1) cout<<"x";
else if(m==-1) cout<<"-x";
else if(m!=0) cout<<m<<"x";
if(b>0) cout<<"+ "<<b;
else if(b<0&&m!=0) cout<<"- "<<b*-1;
else if(b<0) cout<<"-"<<b*-1;
}
} | # 0150, 2024-11-02 10:03:53, PPPPPPPPPPPPPPPP-PPPPPPP (95%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
string x;
cin>>x;
float a,a1;
vector<float> x1,y;
int i;
float s1=0,s2=0,s3=0,s4=0,m,b;
for(i=0;i<n;i++){
cin>>a>>a1;
x1.push_back(a);
y.push_back(a1);
s1+=x1[i]*y[i];
s2+=x1[i];
s3+=y[i];
s4+=x1[i]*x1[i];
}
for(i=0;i<n;i++){
}
//cout<<s1<<" "<<s2<<" "<<s3<<" "<<s4<<endl;
m=((n*s1)-s2*s3)/((n*s4)-s2*s2);
b=(s3-(m*s2))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(x=="mb") cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
else{
cout<<"y = ";
if(m==0&&b==0) cout<<"0";
else if(m==1&&b!=0) cout<<"x ";
else if(m==-1&&b!=0) cout<<"-x ";
else if(m!=0&&b!=0) cout<<m<<"x ";
else if(m==1) cout<<"x";
else if(m==-1) cout<<"-x";
else if(m!=0) cout<<m<<"x";
if(b>0) cout<<"+ "<<b;
else if(b<0&&m!=0) cout<<"- "<<b*-1;
else if(b<0) cout<<"-"<<b*-1;
}
} | # 0151, 2024-11-02 10:59:05, PPPPPPPPPPPPPPPP-PPPPPPP (95%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
string x;
cin>>x;
float a,a1;
vector<float> x1,y;
int i;
float s1=0,s2=0,s3=0,s4=0,m,b;
for(i=0;i<n;i++){
cin>>a>>a1;
x1.push_back(a);
y.push_back(a1);
s1+=x1[i]*y[i];
s2+=x1[i];
s3+=y[i];
s4+=x1[i]*x1[i];
}
for(i=0;i<n;i++){
}
//cout<<s1<<" "<<s2<<" "<<s3<<" "<<s4<<endl;
m=((n*s1)-s2*s3)/((n*s4)-s2*s2);
b=(s3-(m*s2))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(x=="mb") cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
else{
cout<<"y = ";
if(m==0&&b==0) cout<<"0";
/*else if(m==1&&b!=0) cout<<"x ";
else if(m==-1&&b!=0) cout<<"-x ";
else if(m!=0&&b!=0) cout<<m<<"x ";*/
else if(m==1) cout<<"x ";
else if(m==-1) cout<<"-x ";
else if(m!=0) cout<<m<<"x ";
if(b>0) cout<<"+ "<<b;
else if(b<0&&m!=0) cout<<"- "<<b*-1;
else if(b<0) cout<<"-"<<b*-1;
}
} | # 0152, 2024-11-02 11:01:08, PPPPPPPPPPPPPPPP-PPPPPPP (95%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
string x;
cin>>x;
float a,a1;
vector<float> x1,y;
int i;
float s1=0,s2=0,s3=0,s4=0,m,b;
for(i=0;i<n;i++){
cin>>a>>a1;
x1.push_back(a);
y.push_back(a1);
s1+=x1[i]*y[i];
s2+=x1[i];
s3+=y[i];
s4+=x1[i]*x1[i];
}
for(i=0;i<n;i++){
}
//cout<<s1<<" "<<s2<<" "<<s3<<" "<<s4<<endl;
m=((n*s1)-s2*s3)/((n*s4)-s2*s2);
b=(s3-(m*s2))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(x=="mb") cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
else{
cout<<"y = ";
if(m==0&&b==0) cout<<"0";
/*else if(m==1&&b!=0) cout<<"x ";
else if(m==-1&&b!=0) cout<<"-x ";
else if(m!=0&&b!=0) cout<<m<<"x ";*/
else if(m==1) cout<<"x ";
else if(m==-1) cout<<"-x ";
else if(m!=0) cout<<m<<"x ";
if(b>0) cout<<"+ "<<b;
else if(b<0&&m!=0) cout<<"- "<<b*-1;
else if(b<0) cout<<b;
}
} | # 0153, 2024-11-02 11:02:26, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
string x;
cin>>x;
float a,a1;
vector<float> x1,y;
int i;
float s1=0,s2=0,s3=0,s4=0,m,b;
for(i=0;i<n;i++){
cin>>a>>a1;
x1.push_back(a);
y.push_back(a1);
s1+=x1[i]*y[i];
s2+=x1[i];
s3+=y[i];
s4+=x1[i]*x1[i];
}
for(i=0;i<n;i++){
}
//cout<<s1<<" "<<s2<<" "<<s3<<" "<<s4<<endl;
m=((n*s1)-s2*s3)/((n*s4)-s2*s2);
b=(s3-(m*s2))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(x=="mb") cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
else{
cout<<"y = ";
if(m==0&&b==0) cout<<"0";
/*else if(m==1&&b!=0) cout<<"x ";
else if(m==-1&&b!=0) cout<<"-x ";
else if(m!=0&&b!=0) cout<<m<<"x ";*/
else if(m==1) cout<<"x ";
else if(m==-1) cout<<"-x ";
else if(m!=0) cout<<m<<"x ";
if(b>0&&m!=0) cout<<"+ "<<b;
else if(b<0&&m!=0) cout<<"- "<<b*-1;
else if(b<0) cout<<b;
else if(b>0) cout<<b;
}
} |
# 0154, 2024-11-02 13:36:27, -x---PPPPP-x---PPPPPPP-- (50%)
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
int n;
float sx=0,sy=0,sxy=0,sx2=0,m=0,b=0;
cin >> n >> s;
vector<float> x(n),y(n);
for(int i = 1 ; i <= n ; i++){
float c,d;
cin >> c >> d;
x[i] = c;
y[i] = d;
}
for(int i = 1 ; i <= n ;i++){
sx += x[i];
}
for(int i = 1 ; i <= n ;i++){
sy += y[i];
}
for(int i = 1 ; i <= n ;i++){
sxy += x[i] * y[i];
}
for(int i = 1 ; i <= n ;i++){
sx2 += x[i]*x[i];
}
m = ((n*sxy) - sx*sy)/(n*sx2 - (sx*sx));
m = round(m*1e3)/1e3;
b = (sy - (m*sx))/float(n);
b = round(b*1e3)/1e3;
if(s == "mb")cout << m << endl << b << endl;
if(s == "func"){
if(m == 0 && b == 0)cout << "y = 0";
else if(m == 1){
if(b == 0)cout << "y = x";
else cout << "y = x + " << b;
}
else if(m == -1){
if(b == 0)cout << "y = -x";
else cout << "y = -x + " << b;
}
else if(m == 0)cout << "y = " << b;
else if(b == 0)cout << "y = " << m << "x";
else cout << "y = " << m << "x + " << b;
}
} | # 0155, 2024-11-02 13:38:35, -x---PPPPP-x---PPPPPPPPP (58%)
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
int n;
float sx=0,sy=0,sxy=0,sx2=0,m=0,b=0;
cin >> n >> s;
vector<float> x(n),y(n);
for(int i = 1 ; i <= n ; i++){
float c,d;
cin >> c >> d;
x[i] = c;
y[i] = d;
}
for(int i = 1 ; i <= n ;i++){
sx += x[i];
}
for(int i = 1 ; i <= n ;i++){
sy += y[i];
}
for(int i = 1 ; i <= n ;i++){
sxy += x[i] * y[i];
}
for(int i = 1 ; i <= n ;i++){
sx2 += x[i]*x[i];
}
m = ((n*sxy) - sx*sy)/(n*sx2 - (sx*sx));
m = round(m*1e3)/1e3;
b = (sy - (m*sx))/float(n);
b = round(b*1e3)/1e3;
if(s == "mb")cout << m << endl << b << endl;
if(s == "func"){
if(m == 0 && b == 0)cout << "y = 0";
else if(m == 1){
if(b == 0)cout << "y = x";
else {
if(b>0)cout << "y = x + " << b;
if(b<0)cout << "y = x - " << abs(b);
}
}
else if(m == -1){
if(b == 0)cout << "y = -x";
else {
if(b>0)cout << "y = -x + " << b;
if(b<0)cout << "y = -x - " << abs(b);
}
}
else if(m == 0)cout << "y = " << b;//
else if(b == 0)cout << "y = " << m << "x";
else cout << "y = " << m << "x + " << b;
}
} | # 0156, 2024-11-02 13:40:35, -----PPPPP-----PPPPPPPPP (58%)
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
int n;
float sx=0,sy=0,sxy=0,sx2=0,m=0,b=0;
cin >> n >> s;
vector<float> x(n*2),y(n*2);
for(int i = 1 ; i <= n ; i++){
float c,d;
cin >> c >> d;
x[i] = c;
y[i] = d;
}
for(int i = 1 ; i <= n ;i++){
sx += x[i];
}
for(int i = 1 ; i <= n ;i++){
sy += y[i];
}
for(int i = 1 ; i <= n ;i++){
sxy += x[i] * y[i];
}
for(int i = 1 ; i <= n ;i++){
sx2 += x[i]*x[i];
}
m = ((n*sxy) - sx*sy)/(n*sx2 - (sx*sx));
m = round(m*1e3)/1e3;
b = (sy - (m*sx))/float(n);
b = round(b*1e3)/1e3;
if(s == "mb")cout << m << endl << b << endl;
if(s == "func"){
if(m == 0 && b == 0)cout << "y = 0";
else if(m == 1){
if(b == 0)cout << "y = x";
else {
if(b>0)cout << "y = x + " << b;
if(b<0)cout << "y = x - " << abs(b);
}
}
else if(m == -1){
if(b == 0)cout << "y = -x";
else {
if(b>0)cout << "y = -x + " << b;
if(b<0)cout << "y = -x - " << abs(b);
}
}
else if(m == 0)cout << "y = " << b;//
else if(b == 0)cout << "y = " << m << "x";
else cout << "y = " << m << "x + " << b;
}
} | # 0157, 2024-11-02 13:41:01, ---------------PPPPPPPPP (37%)
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
int n;
float sx=0,sy=0,sxy=0,sx2=0,m=0,b=0;
cin >> n >> s;
vector<float> x(n*2),y(n*2);
for(int i = 1 ; i <= n ; i++){
float c,d;
cin >> c >> d;
x[i] = c;
y[i] = d;
}
for(int i = 1 ; i <= n ;i++){
sx += x[i];
}
for(int i = 1 ; i <= n ;i++){
sy += y[i];
}
for(int i = 1 ; i <= n ;i++){
sxy += x[i] * y[i];
}
for(int i = 1 ; i <= n ;i++){
sx2 += x[i]*x[i];
}
m = ((n*sxy) - sx*sy)/(n*sx2 - (sx*sx));
m = round(m*1e3)/1e3;
b = (sy - (m*sx))/float(n);
b = round(b*1e3)/1e3;
//if(s == "mb")cout << m << endl << b << endl;
if(s == "func"){
if(m == 0 && b == 0)cout << "y = 0";
else if(m == 1){
if(b == 0)cout << "y = x";
else {
if(b>0)cout << "y = x + " << b;
if(b<0)cout << "y = x - " << abs(b);
}
}
else if(m == -1){
if(b == 0)cout << "y = -x";
else {
if(b>0)cout << "y = -x + " << b;
if(b<0)cout << "y = -x - " << abs(b);
}
}
else if(m == 0)cout << "y = " << b;//
else if(b == 0)cout << "y = " << m << "x";
else cout << "y = " << m << "x + " << b;
}
} | # 0158, 2024-11-02 13:41:15, -----PPPPP-----PPPPPPPPP (58%)
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
int n;
float sx=0,sy=0,sxy=0,sx2=0,m=0,b=0;
cin >> n >> s;
vector<float> x(n*2),y(n*2);
for(int i = 1 ; i <= n ; i++){
float c,d;
cin >> c >> d;
x[i] = c;
y[i] = d;
}
for(int i = 1 ; i <= n ;i++){
sx += x[i];
}
for(int i = 1 ; i <= n ;i++){
sy += y[i];
}
for(int i = 1 ; i <= n ;i++){
sxy += x[i] * y[i];
}
for(int i = 1 ; i <= n ;i++){
sx2 += x[i]*x[i];
}
m = ((n*sxy) - sx*sy)/(n*sx2 - (sx*sx));
m = round(m*1e3)/1e3;
b = (sy - (m*sx))/float(n);
b = round(b*1e3)/1e3;
if(s == "mb")cout << m << endl << b << endl;
if(s == "func"){
if(m == 0 && b == 0)cout << "y = 0";
else if(m == 1){
if(b == 0)cout << "y = x";
else {
if(b>0)cout << "y = x + " << b;
if(b<0)cout << "y = x - " << abs(b);
}
}
else if(m == -1){
if(b == 0)cout << "y = -x";
else {
if(b>0)cout << "y = -x + " << b;
if(b<0)cout << "y = -x - " << abs(b);
}
}
else if(m == 0)cout << "y = " << b;//
else if(b == 0)cout << "y = " << m << "x";
else cout << "y = " << m << "x + " << b;
}
} | # 0159, 2024-11-02 13:47:32, -----PPPPP-----PPPPPPPPP (58%)
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
int n;
float sx=0,sy=0,sxy=0,sx2=0,m=0,b=0;
cin >> n >> s;
vector<float> x(n*2),y(n*2);
for(int i = 1 ; i <= n ; i++){
float c,d;
cin >> c >> d;
x[i] = c;
y[i] = d;
}
for(int i = 1 ; i <= n ;i++){
sx += x[i];
}
for(int i = 1 ; i <= n ;i++){
sy += y[i];
}
for(int i = 1 ; i <= n ;i++){
sxy += x[i] * y[i];
}
for(int i = 1 ; i <= n ;i++){
sx2 += x[i]*x[i];
}
m = ((float(n)*sxy) - sx*sy)/(float(n)*sx2 - (sx*sx));
m = round(m*1e3)/1e3;
b = (sy - (m*sx))/float(n);
b = round(b*1e3)/1e3;
if(s == "mb")cout << m << endl << b << endl;
if(s == "func"){
if(m == 0 && b == 0)cout << "y = 0";
else if(m == 1){
if(b == 0)cout << "y = x";
else {
if(b>0)cout << "y = x + " << b;
if(b<0)cout << "y = x - " << abs(b);
}
}
else if(m == -1){
if(b == 0)cout << "y = -x";
else {
if(b>0)cout << "y = -x + " << b;
if(b<0)cout << "y = -x - " << abs(b);
}
}
else if(m == 0)cout << "y = " << b;//
else if(b == 0)cout << "y = " << m << "x";
else cout << "y = " << m << "x + " << b;
}
} | # 0160, 2024-11-02 13:48:36, -----PPPPP-----PPPPPPPPP (58%)
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
int n;
float sx=0,sy=0,sxy=0,sx2=0,m=0,b=0;
cin >> n >> s;
vector<float> x(n*2),y(n*2);
for(int i = 1 ; i <= n ; i++){
float c,d;
cin >> c >> d;
x[i] = c;
y[i] = d;
}
for(int i = 1 ; i <= n ;i++){
sx += x[i];
sy += y[i];
sxy += x[i] * y[i];
sx2 += x[i]*x[i];
}
m = ((n*sxy) - sx*sy)/(n*sx2 - (sx*sx));
m = round(m*1e3)/1e3;
b = (sy - (m*sx))/float(n);
b = round(b*1e3)/1e3;
if(s == "mb")cout << m << endl << b << endl;
if(s == "func"){
if(m == 0 && b == 0)cout << "y = 0";
else if(m == 1){
if(b == 0)cout << "y = x";
else {
if(b>0)cout << "y = x + " << b;
if(b<0)cout << "y = x - " << abs(b);
}
}
else if(m == -1){
if(b == 0)cout << "y = -x";
else {
if(b>0)cout << "y = -x + " << b;
if(b<0)cout << "y = -x - " << abs(b);
}
}
else if(m == 0)cout << "y = " << b;//
else if(b == 0)cout << "y = " << m << "x";
else cout << "y = " << m << "x + " << b;
}
} | # 0161, 2024-11-02 13:50:29, PPPPPPPPPPP-P--PPPPPPPPP (87%)
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
int n;
float sx=0,sy=0,sxy=0,sx2=0,m=0,b=0;
cin >> n >> s;
vector<float> x(n*2),y(n*2);
for(int i = 1 ; i <= n ; i++){
float c,d;
cin >> c >> d;
x[i] = c;
y[i] = d;
}
for(int i = 1 ; i <= n ;i++){
sx += x[i];
sy += y[i];
sxy += x[i] * y[i];
sx2 += x[i]*x[i];
}
m = ((n*sxy) - sx*sy)/(n*sx2 - (sx*sx));
b = (sy - (m*sx))/float(n);
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(s == "mb")cout << m << endl << b ;
if(s == "func"){
if(m == 0 && b == 0)cout << "y = 0";
else if(m == 1){
if(b == 0)cout << "y = x";
else {
if(b>0)cout << "y = x + " << b;
if(b<0)cout << "y = x - " << abs(b);
}
}
else if(m == -1){
if(b == 0)cout << "y = -x";
else {
if(b>0)cout << "y = -x + " << b;
if(b<0)cout << "y = -x - " << abs(b);
}
}
else if(m == 0)cout << "y = " << b;//
else if(b == 0)cout << "y = " << m << "x";
else cout << "y = " << m << "x + " << b;
}
} | # 0162, 2024-11-02 13:55:01, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
int n;
float sx=0,sy=0,sxy=0,sx2=0,m=0,b=0;
cin >> n >> s;
vector<float> x(n*2),y(n*2);
for(int i = 1 ; i <= n ; i++){
float c,d;
cin >> c >> d;
x[i] = c;
y[i] = d;
}
for(int i = 1 ; i <= n ;i++){
sx += x[i];
sy += y[i];
sxy += x[i] * y[i];
sx2 += x[i]*x[i];
}
m = ((n*sxy) - sx*sy)/(n*sx2 - (sx*sx));
b = (sy - (m*sx))/float(n);
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(s == "mb")cout << m << endl << b ;
if(s == "func"){
if(m == 0 && b == 0)cout << "y = 0";
else if(m == 1){
if(b == 0)cout << "y = x";
else {
if(b>0)cout << "y = x + " << b;
if(b<0)cout << "y = x - " << abs(b);
}
}
else if(m == -1){
if(b == 0)cout << "y = -x";
else {
if(b>0)cout << "y = -x + " << b;
if(b<0)cout << "y = -x - " << abs(b);
}
}
else if(m == 0)cout << "y = " << b;//
else if(b == 0)cout << "y = " << m << "x";
else {
if(b>0)cout << "y = " << m << "x + " << b;
if(b<0)cout << "y = " << m << "x - " << abs(b);
}
}
} |
# 0163, 2024-11-02 13:50:22, -----PPPPP-------------- (20%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n; cin>>n;
string s; cin>>s;
float x,y,m;
long sumX=0,sumY=0,sumXY=0, sumXsquare=0 , sumYsquare =0;
if(s=="mb"){
for(int i=0;i<n;i++)
{
cin>>x>>y;
sumX += x; sumY += y; sumXY += x*y;
sumXsquare += x*x; sumYsquare += y*y;
}
m= ((n*sumXY)-(sumX*sumY)) / (n*sumXsquare - sumX*sumX); // m
cout<<m;
cout << endl;
cout<< (sumY - m*sumX)/n; //b
cout<< endl;
}
else if(s=="func"){
;
}
} | # 0164, 2024-11-02 14:00:34, -----PPPPP-----P--PP-P-- (37%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n; cin>>n;
string s; cin>>s;
float x,y,m,b;
long sumX=0,sumY=0,sumXY=0, sumXsquare=0 , sumYsquare =0;
for(int i=0;i<n;i++)
{
cin>>x>>y;
sumX += x; sumY += y; sumXY += x*y;
sumXsquare += x*x; sumYsquare += y*y;
}
m = ((n*sumXY)-(sumX*sumY)) / (n*sumXsquare - sumX*sumX);
b = (sumY - m*sumX)/n;
m= round(m*1e3)/1e3;
b= round(b*1000 ) /1000 ;
if(s=="mb"){
cout << m << endl;
cout<<b<<endl;
}
else if(s=="func"){
cout<<"y = ";
if(m!=1 & m!=0 & m!= -1) cout<<m;
if(m==-1 ) cout<<"-";
if(m!= 0) cout << "x";
if(m!=0 & b!=0) cout<<" + ";
if(b!=0) cout << b;
else if(m==b & m==0) cout<<0<<endl;
}
} | # 0165, 2024-11-02 15:11:54, -----PPPPP-----P--PP---- (33%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n; cin>>n;
string s; cin>>s;
float x,y;
long double m,b;
long long int sumX=0,sumY=0,sumXY=0, sumXsquare=0 , sumYsquare =0;
for(int i=0;i<n;i++)
{
cin>>x>>y;
sumX += x; sumY += y; sumXY += x*y;
sumXsquare += x*x; sumYsquare += y*y;
}
m = ((n*sumXY)-(sumX*sumY)) / (n*sumXsquare - sumX*sumX);
b = (sumY - m*sumX)/n;
//m= round(m*1e3)/1e3;
//b= round(b*1000 ) /1000 ;
if(s=="mb"){
cout << m << endl;
cout<<b<<endl;
}
else if(s=="func"){
cout<<"y = ";
if(m!=1 & m!=0 & m!= -1) cout<<m;
if(m==-1 ) cout<<"-";
if(m!= 0) cout << "x";
if(m!=0 & b>0) cout<<" + ";
else if(m!=0 & b<0) cout<<" - ";
if(b>0) cout << b; else if(b<0) cout<<-b;
else if(m==b & m==0) cout<<0;
}
cout<<endl;
} | # 0166, 2024-11-02 15:14:07, -----PPPPP-----P--PP---- (33%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n; cin>>n;
string s; cin>>s;
float x,y;
long double m,b;
long long int sumX=0,sumY=0,sumXY=0, sumXsquare=0 , sumYsquare =0;
for(int i=0;i<n;i++)
{
cin>>x>>y;
sumX += x; sumY += y; sumXY += x*y;
sumXsquare += x*x; sumYsquare += y*y;
}
m = ((n*sumXY)-(sumX*sumY)) / (n*sumXsquare - sumX*sumX);
b = (sumY - m*sumX)/n;
//m= round(m*1e3)/1e3;
//b= round(b*1000 ) /1000 ;
if(s=="mb"){
cout << m << endl;
cout<<b<<endl;
}
else if(s=="func"){
cout<<"y = ";
if(m!=1 & m!=0 & m!= -1) cout<<m;
if(m==-1 ) cout<<"-";
if(m!= 0) cout << "x";
if(m!=0 & b>0) cout<<" + ";
else if(m!=0 & b<0) cout<<" - ";
if(b>0) cout << b; else if(b<0) cout<<-b;
if(m==b & m==0) cout<<0;
}
cout<<endl;
} | # 0167, 2024-11-02 15:21:09, -----PPPPP-----P--PP---- (33%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n; cin>>n;
string s; cin>>s;
float x,y;
long double m,b;
long double sumX=0,sumY=0,sumXY=0, sumXsquare=0 , sumYsquare =0;
for(int i=0;i<n;i++)
{
cin>>x>>y;
sumX += x; sumY += y; sumXY += x*y;
sumXsquare += x*x; sumYsquare += y*y;
}
m = ((n*sumXY)-(sumX*sumY)) / (n*sumXsquare - sumX*sumX);
b = (sumY - m*sumX)/n;
//m= round(m*1e3)/1e3;
//b= round(b*1000 ) /1000 ;
if(s=="mb"){
cout << m << endl;
cout<<b<<endl;
}
else if(s=="func"){
cout<<"y = ";
if(m!=1 & m!=0 & m!= -1) cout<<m;
if(m==-1 ) cout<<"-";
if(m!= 0) cout << "x";
if(m!=0 & b>0) cout<<" + ";
else if(m!=0 & b<0) cout<<" - ";
if(b>0) cout << b; else if(b<0) cout<<-b;
if(m==b & m==0) cout<<0;
}
cout<<endl;
} | # 0168, 2024-11-02 15:21:23, PPPPPPPPPPPPPPPPPPPPP-PP (95%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n; cin>>n;
string s; cin>>s;
float x,y;
long double m,b;
long double sumX=0,sumY=0,sumXY=0, sumXsquare=0 , sumYsquare =0;
for(int i=0;i<n;i++)
{
cin>>x>>y;
sumX += x; sumY += y; sumXY += x*y;
sumXsquare += x*x; sumYsquare += y*y;
}
m = ((n*sumXY)-(sumX*sumY)) / (n*sumXsquare - sumX*sumX);
b = (sumY - m*sumX)/n;
m= round(m*1e3)/1e3;
b= round(b*1000 ) /1000 ;
if(s=="mb"){
cout << m << endl;
cout<<b<<endl;
}
else if(s=="func"){
cout<<"y = ";
if(m!=1 & m!=0 & m!= -1) cout<<m;
if(m==-1 ) cout<<"-";
if(m!= 0) cout << "x";
if(m!=0 & b>0) cout<<" + ";
else if(m!=0 & b<0) cout<<" - ";
if(b>0) cout << b; else if(b<0) cout<<-b;
if(m==b & m==0) cout<<0;
}
cout<<endl;
} | # 0169, 2024-11-02 15:26:17, PPPPPPPPPPPPPPPP--PP---- (75%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n; cin>>n;
string s; cin>>s;
float x,y;
long double m,b;
long double sumX=0,sumY=0,sumXY=0, sumXsquare=0 , sumYsquare =0;
for(int i=0;i<n;i++)
{
cin>>x>>y;
sumX += x; sumY += y; sumXY += x*y;
sumXsquare += x*x; sumYsquare += y*y;
}
m = ((n*sumXY)-(sumX*sumY)) / (n*sumXsquare - sumX*sumX);
b = (sumY - m*sumX)/n;
// m= round(m*1e3)/1e3;
//b= round(b*1000 ) /1000 ;
if(s=="mb"){
cout << round(m*1e3)/1e3 << endl;
cout<< round(b*1e3)/1e3 <<endl;
}
else if(s=="func"){
cout<<"y = ";
if(m!=1 & m!=0 & m!= -1) cout<< round(m*1e3)/1e3 ;
if(m==-1 ) cout<<"-";
if(m!= 0) cout << "x";
if(m!=0 & b>0) cout<<" + ";
else if(m!=0 & b<0) cout<<" - ";
if(b>0) cout << round(b*1e3 ) /1e3; else if(b<0) cout<<-round(b*1e3 ) /1e3;
if(m==b & m==0) cout<<0;
}
cout<<endl;
} | # 0170, 2024-11-02 15:27:23, PPPPPPPPPPPPPPPPPPPPP-PP (95%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n; cin>>n;
string s; cin>>s;
float x,y;
long double m,b;
long double sumX=0,sumY=0,sumXY=0, sumXsquare=0 , sumYsquare =0;
for(int i=0;i<n;i++)
{
cin>>x>>y;
sumX += x; sumY += y; sumXY += x*y;
sumXsquare += x*x; sumYsquare += y*y;
}
m = ((n*sumXY)-(sumX*sumY)) / (n*sumXsquare - sumX*sumX);
b = (sumY - m*sumX)/n;
m= round(m*1e3)/1e3;
b= round(b*1e3 ) /1e3;
if(s=="mb"){
cout << round(m*1e3)/1e3 << endl;
cout<< round(b*1e3)/1e3 <<endl;
}
else if(s=="func"){
cout<<"y = ";
if(m!=1 & m!=0 & m!= -1) cout<< round(m*1e3)/1e3 ;
if(m==-1 ) cout<<"-";
if(m!= 0) cout << "x";
if(m!=0 & b>0) cout<<" + ";
else if(m!=0 & b<0) cout<<" - ";
if(b>0) cout << round(b*1e3 ) /1e3; else if(b<0) cout<<-round(b*1e3 ) /1e3;
if(m==b & m==0) cout<<0;
}
cout<<endl;
} | # 0171, 2024-11-02 15:29:40, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n; cin>>n;
string s; cin>>s;
float x,y;
long double m,b;
long double sumX=0,sumY=0,sumXY=0, sumXsquare=0 , sumYsquare =0;
for(int i=0;i<n;i++)
{
cin>>x>>y;
sumX += x; sumY += y; sumXY += x*y;
sumXsquare += x*x; sumYsquare += y*y;
}
m = ((n*sumXY)-(sumX*sumY)) / (n*sumXsquare - sumX*sumX);
b = (sumY - m*sumX)/n;
m= round(m*1e3)/1e3;
b= round(b*1e3 ) /1e3;
if(s=="mb"){
cout << round(m*1e3)/1e3 << endl;
cout<< round(b*1e3)/1e3 <<endl;
}
else if(s=="func"){
cout<<"y = ";
if(m!=1 & m!=0 & m!= -1) cout<< round(m*1e3)/1e3 ;
if(m==-1 ) cout<<"-";
if(m!= 0) cout << "x";
if(m!=0 & b>0) cout<<" + ";
else if(m!=0 & b<0) cout<<" - ";
if(b>0) cout << round(b*1e3 ) /1e3; else if(m!=0 & b<0) cout<<-round(b*1e3 ) /1e3;
if(m==b & m==0) cout<<0;
else if(m==0 & b<0) cout <<b;
}
cout<<endl;
} |
# 0172, 2024-11-02 13:35:42, PPPPPPPPPP-------------- (41%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main () {
int n;
string cmd;
vector<float> X,Y;
cin >> n >> cmd;
float x,y;
for (int i=0;i<n;i++) {
cin >> x >> y;
X.push_back(x);
Y.push_back(y);
}
float A=0.0,B=0.0,C=0.0,D=0.0;
for (int i=0;i<n;i++) {
A+=(X[i]*Y[i]);
B+=X[i];
C+=Y[i];
D+=(X[i]*X[i]);
}
A*=n;
D*=n;
float m=(A-(B*C))/(D-(B*B));
float b=(C-(B*m))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if (m==-0.000) m=0;
if (b==-0.000) b=0;
if (cmd=="mb") {
cout << m << endl;
cout << b << endl;
} else if (cmd=="func") {
string answer="y = ";
if (m==0&&b==0) answer+="0";
else {
if (m!=0) {
if (m==1) cout << "x";
else if (m==-1) cout << "-x";
else {
cout << m << "x";
}
}
if (b!=0) {
if (b>0) {
cout << " + " << b << endl;
}
else cout << " - " << (abs(b)) << endl;;
}
}
}
} | # 0173, 2024-11-02 13:37:20, PPPPPPPPPPPPPPPP-PPPP-PP (91%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main () {
int n;
string cmd;
vector<float> X,Y;
cin >> n >> cmd;
float x,y;
for (int i=0;i<n;i++) {
cin >> x >> y;
X.push_back(x);
Y.push_back(y);
}
float A=0.0,B=0.0,C=0.0,D=0.0;
for (int i=0;i<n;i++) {
A+=(X[i]*Y[i]);
B+=X[i];
C+=Y[i];
D+=(X[i]*X[i]);
}
A*=n;
D*=n;
float m=(A-(B*C))/(D-(B*B));
float b=(C-(B*m))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if (m==-0.000) m=0;
if (b==-0.000) b=0;
if (cmd=="mb") {
cout << m << endl;
cout << b << endl;
} else if (cmd=="func") {
cout << "y = ";
if (m==0&&b==0) cout << "0";
else {
if (m!=0) {
if (m==1) cout << "x";
else if (m==-1) cout << "-x";
else {
cout << m << "x";
}
}
if (b!=0) {
if (b>0) {
cout << " + " << b << endl;
}
else cout << " - " << (abs(b)) << endl;;
}
}
}
} | # 0174, 2024-11-02 13:38:52, Compilation error (0%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main () {
int n;
string cmd;
vector<float> X,Y;
cin >> n >> cmd;
float x,y;
for (int i=0;i<n;i++) {
cin >> x >> y;
X.push_back(x);
Y.push_back(y);
}
float A=0.0,B=0.0,C=0.0,D=0.0;
for (int i=0;i<n;i++) {
A+=(X[i]*Y[i]);
B+=X[i];
C+=Y[i];
D+=(X[i]*X[i]);
}
A*=n;
D*=n;
float m=(A-(B*C))/(D-(B*B));
float b=(C-(B*m))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if (m==-0.000) m=0;
if (b==-0.000) b=0;
if (cmd=="mb") {
cout << m << endl;
cout << b << endl;
} else if (cmd=="func") {
cout << "y = ";
if (m==0&&b==0) cout << "0";
else {
if (m!=0) {
if (m==1) cout << "x";
else if (m==-1) cout << "-x";
else {
cout << m << "x";
}
}
if (b!=0) {
if (b>0) {
cout << " + " << b;
}
else cout << " - " << (abs(b));
}
}
cout << endl;
} | # 0175, 2024-11-02 13:39:04, Compilation error (0%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main () {
int n;
string cmd;
vector<float> X,Y;
cin >> n >> cmd;
float x,y;
for (int i=0;i<n;i++) {
cin >> x >> y;
X.push_back(x);
Y.push_back(y);
}
float A=0.0,B=0.0,C=0.0,D=0.0;
for (int i=0;i<n;i++) {
A+=(X[i]*Y[i]);
B+=X[i];
C+=Y[i];
D+=(X[i]*X[i]);
}
A*=n;
D*=n;
float m=(A-(B*C))/(D-(B*B));
float b=(C-(B*m))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if (m==-0.000) m=0;
if (b==-0.000) b=0;
if (cmd=="mb") {
cout << m << endl;
cout << b << endl;
} else if (cmd=="func") {
cout << "y = ";
if (m==0&&b==0) cout << "0";
else {
if (m!=0) {
if (m==1) cout << "x";
else if (m==-1) cout << "-x";
else {
cout << m << "x";
}
}
if (b!=0) {
if (b>0) {
cout << " + " << b;
}
else cout << " - " << (abs(b));
}
}
cout << endl;
} | # 0176, 2024-11-02 13:40:02, PPPPPPPPPPPPPPPP-PPPP-PP (91%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main () {
int n;
string cmd;
vector<float> X,Y;
cin >> n >> cmd;
float x,y;
for (int i=0;i<n;i++) {
cin >> x >> y;
X.push_back(x);
Y.push_back(y);
}
float A=0.0,B=0.0,C=0.0,D=0.0;
for (int i=0;i<n;i++) {
A+=(X[i]*Y[i]);
B+=X[i];
C+=Y[i];
D+=(X[i]*X[i]);
}
A*=n;
D*=n;
float m=(A-(B*C))/(D-(B*B));
float b=(C-(B*m))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if (m==-0.000) m=0;
if (b==-0.000) b=0;
if (cmd=="mb") {
cout << m << endl;
cout << b << endl;
} else if (cmd=="func") {
cout << "y = ";
if (m==0&&b==0) cout << "0";
else {
if (m!=0) {
if (m==1) cout << "x";
else if (m==-1) cout << "-x";
else {
cout << m << "x";
}
}
if (b!=0) {
if (b>0) {
cout << " + " << b;
}
else cout << " - " << (abs(b));
}
}
cout << endl;
}
} | # 0177, 2024-11-02 13:42:50, PPPPPPPPPPPPPPPP-PPPPPPP (95%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main () {
int n;
string cmd;
vector<float> X,Y;
cin >> n >> cmd;
float x,y;
for (int i=0;i<n;i++) {
cin >> x >> y;
X.push_back(x);
Y.push_back(y);
}
float A=0.0,B=0.0,C=0.0,D=0.0;
for (int i=0;i<n;i++) {
A+=(X[i]*Y[i]);
B+=X[i];
C+=Y[i];
D+=(X[i]*X[i]);
}
A*=n;
D*=n;
float m=(A-(B*C))/(D-(B*B));
float b=(C-(B*m))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if (m==-0.000) m=0;
if (b==-0.000) b=0;
if (cmd=="mb") {
cout << m << endl;
cout << b << endl;
} else if (cmd=="func") {
cout << "y = ";
if (m==0&&b==0) cout << "0";
else {
if (m!=0) {
if (m==1) cout << "x";
else if (m==-1) cout << "-x";
else {
cout << m << "x";
}
}
if (b!=0) {
if (b>0) {
cout << " + " << b;
}
else {
if (m!=0) cout << " - " << (abs(b));
else cout << " -" << (abs(b));
}
}
}
cout << endl;
}
} | # 0178, 2024-11-02 14:14:35, PPPPPPPPPPPPPPPP-PPPPPPP (95%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main () {
int n;
string cmd;
vector<float> X,Y;
cin >> n >> cmd;
float x,y;
for (int i=0;i<n;i++) {
cin >> x >> y;
X.push_back(x);
Y.push_back(y);
}
float A=0.0,B=0.0,C=0.0,D=0.0;
for (int i=0;i<n;i++) {
A+=(X[i]*Y[i]);
B+=X[i];
C+=Y[i];
D+=(X[i]*X[i]);
}
A*=n;
D*=n;
float m=(A-(B*C))/(D-(B*B));
float b=(C-(B*m))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if (m==-0.000) m=0;
if (b==-0.000) b=0;
if (cmd=="mb") {
cout << m << endl;
cout << b << endl;
} else if (cmd=="func") {
cout << "y = ";
if (m==0&&b==0) cout << "0";
else {
if (m!=0) {
if (m==1) cout << "x";
else if (m==-1) cout << "-x";
else {
cout << m << "x";
}
}
if (b!=0) {
if (b>0) {
cout << " + " << b;
}
else {
if (m!=0) cout << " - " << (abs(b));
else cout << "-" << (abs(b));
}
}
}
cout << endl;
}
} | # 0179, 2024-11-02 14:18:44, Compilation error (0%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main () {
int n;
string cmd;
vector<float> X,Y;
cin >> n >> cmd;
float x,y;
for (int i=0;i<n;i++) {
cin >> x >> y;
X.push_back(x);
Y.push_back(y);
}
float A=0.0,B=0.0,C=0.0,D=0.0;
for (int i=0;i<n;i++) {
A+=(X[i]*Y[i]);
B+=X[i];
C+=Y[i];
D+=(X[i]*X[i]);
}
A*=n;
D*=n;
float m=(A-(B*C))/(D-(B*B));
float b=(C-(B*m))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if (m==-0.000) m=0;
if (b==-0.000) b=0;
if (cmd=="mb") {
cout << m << endl;
cout << b << endl;
} else if (cmd=="func") {
cout << "y = ";
if (m==0&&b==0) cout << "0";
else {
if (m!=0) {
if (m==1) cout << "x";
else if (m==-1) cout << "-x";
else {
cout << m << "x";
}
}
if (b!=0) {
if (b>0) {
if (m!=0) cout << " + " << (abs(b));
else cout << b;
}
else {
if (m!=0) cout << " - " << (abs(b));
else cout << b;
}
}
}
cout << endl;
}
}
} | # 0180, 2024-11-02 14:18:53, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main () {
int n;
string cmd;
vector<float> X,Y;
cin >> n >> cmd;
float x,y;
for (int i=0;i<n;i++) {
cin >> x >> y;
X.push_back(x);
Y.push_back(y);
}
float A=0.0,B=0.0,C=0.0,D=0.0;
for (int i=0;i<n;i++) {
A+=(X[i]*Y[i]);
B+=X[i];
C+=Y[i];
D+=(X[i]*X[i]);
}
A*=n;
D*=n;
float m=(A-(B*C))/(D-(B*B));
float b=(C-(B*m))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if (m==-0.000) m=0;
if (b==-0.000) b=0;
if (cmd=="mb") {
cout << m << endl;
cout << b << endl;
} else if (cmd=="func") {
cout << "y = ";
if (m==0&&b==0) cout << "0";
else {
if (m!=0) {
if (m==1) cout << "x";
else if (m==-1) cout << "-x";
else {
cout << m << "x";
}
}
if (b!=0) {
if (b>0) {
if (m!=0) cout << " + " << (abs(b));
else cout << b;
}
else {
if (m!=0) cout << " - " << (abs(b));
else cout << b;
}
}
}
cout << endl;
}
} |
# 0181, 2024-11-02 10:00:59, ------------------------ (0%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,x,y,c=0;
vector<int> vx1,vy1,vx2,vy2,vx3,vy3,vx4,vy4;
cin>>n;
for(int i=0;i<n;i++){
cin>>x>>y;
if(x!=0&&y!=0){
if(x>0&&y>0){
vx1.push_back(x);
vy1.push_back(y);
}if(x<0&&y>0){
vx2.push_back(x);
vy2.push_back(y);
}if(x<0&&y<0){
vx3.push_back(x);
vy3.push_back(y);
}if(x>0&&y<0){
vx4.push_back(x);
vy4.push_back(y);
}
}
}
if(vx1.size()!=0){
sort(vx1.begin(),vx1.end());
sort(vy1.begin(),vy1.end());
n=(*(vx1.end()-1)-*vx1.begin())*(*(vy1.end()-1)-*vy1.begin());
cout<<"Q1: ("<<*vx1.begin()<<", "<<*vy1.begin()<<") ("<<*(vx1.end()-1)<<", "<<*(vy1.end()-1)<<") "<<n<<endl;
}else c++;
if(vx2.size()!=0){
sort(vx2.begin(),vx2.end());
sort(vy2.begin(),vy2.end());
n=(*(vx2.end()-1)-*vx2.begin())*(*(vy2.end()-1)-*vy2.begin());
cout<<"Q2: ("<<*vx2.begin()<<", "<<*vy2.begin()<<") ("<<*(vx2.end()-1)<<", "<<*(vy2.end()-1)<<") "<<n<<endl;
}else c++;if(vx3.size()!=0){
sort(vx3.begin(),vx3.end());
sort(vy3.begin(),vy3.end());
n=(*(vx3.end()-1)-*vx3.begin())*(*(vy3.end()-1)-*vy3.begin());
cout<<"Q3: ("<<*vx3.begin()<<", "<<*vy3.begin()<<") ("<<*(vx3.end()-1)<<", "<<*(vy3.end()-1)<<") "<<n<<endl;
}else c++;if(vx4.size()!=0){
sort(vx4.begin(),vx4.end());
sort(vy4.begin(),vy4.end());
n=(*(vx4.end()-1)-*vx4.begin())*(*(vy4.end()-1)-*vy4.begin());
cout<<"Q4: ("<<*vx4.begin()<<", "<<*vy4.begin()<<") ("<<*(vx4.end()-1)<<", "<<*(vy4.end()-1)<<") "<<n<<endl;
}else c++;
if(c==4)cout<<"No point in any quadrant";
} | # 0182, 2024-11-02 10:56:09, PPPPPPPPPP-----P--PP-P-- (58%)
#include<bits/stdc++.h>
using namespace std;
float S(int n,vector<float> v){
float sum=0;
for(int i=0;i<n;i++)sum+=v[i];
return sum;
}
float Ss(int n,vector<float> v,vector<float> v2){
float sum=0;
for(int i=0;i<n;i++)sum+=v[i]*v2[i];
return sum;
}
float Sp(int n,vector<float> v){
float sum=0;
for(int i=0;i<n;i++)sum+=v[i]*v[i];
return sum;
}
int main(){
int n;
float N,x,y,m,b;
string s;
cin>>N>>s;
n=N;
vector<float> vx,vy;
for(int i=0;i<n;i++){
cin>>x>>y;
vx.push_back(x);vy.push_back(y);
}
m=((N*Ss(n,vx,vy))-(S(n,vx)*S(n,vy)))/((N*Sp(n,vx))-(S(n,vx)*S(n,vx)));
b=(S(n,vy)-(m*S(n,vx)))/N;
if(s=="mb")cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
else{
cout<<"y = ";
if(m==0||m==-0)cout<<round(b*1e3)/1e3;
else if(m==1){
cout <<"x ";
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0)cout<<"- "<<abs(round(b*1e3)/1e3);
}else if(m==-1){
cout <<"-x ";
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0)cout<<"- "<<abs(round(b*1e3)/1e3);
}else{
cout<<round(m*1e3)/1e3<<"-x ";
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0)cout<<"- "<<abs(round(b*1e3)/1e3);
}
}
} | # 0183, 2024-11-02 10:59:23, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
float S(int n,vector<float> v){
float sum=0;
for(int i=0;i<n;i++)sum+=v[i];
return sum;
}
float Ss(int n,vector<float> v,vector<float> v2){
float sum=0;
for(int i=0;i<n;i++)sum+=v[i]*v2[i];
return sum;
}
float Sp(int n,vector<float> v){
float sum=0;
for(int i=0;i<n;i++)sum+=v[i]*v[i];
return sum;
}
int main(){
int n;
float N,x,y,m,b;
string s;
cin>>N>>s;
n=N;
vector<float> vx,vy;
for(int i=0;i<n;i++){
cin>>x>>y;
vx.push_back(x);vy.push_back(y);
}
m=((N*Ss(n,vx,vy))-(S(n,vx)*S(n,vy)))/((N*Sp(n,vx))-(S(n,vx)*S(n,vx)));
b=(S(n,vy)-(m*S(n,vx)))/N;
if(s=="mb")cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
else{
cout<<"y = ";
if(m==0||m==-0)cout<<round(b*1e3)/1e3;
else if(m==1){
cout <<"x ";
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0)cout<<"- "<<abs(round(b*1e3)/1e3);
}else if(m==-1){
cout <<"-x ";
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0)cout<<"- "<<abs(round(b*1e3)/1e3);
}else{
cout<<round(m*1e3)/1e3<<"x ";
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0)cout<<"- "<<abs(round(b*1e3)/1e3);
}
}
} | # 0184, 2024-11-02 11:29:59, PPPPPPPPPPPPPPP---PP---- (70%)
#include<bits/stdc++.h>
using namespace std;
float S(int n,vector<float> v){
float sum=0;
for(int i=0;i<n;i++)sum+=v[i];
return sum;
}
float Ss(int n,vector<float> v,vector<float> v2){
float sum=0;
for(int i=0;i<n;i++)sum+=v[i]*v2[i];
return sum;
}
float Sp(int n,vector<float> v){
float sum=0;
for(int i=0;i<n;i++)sum+=v[i]*v[i];
return sum;
}
int main(){
int n;
float N,x,y,m,b;
string s,am;
cin>>N>>s;
n=N;
vector<float> vx,vy;
for(int i=0;i<n;i++){
cin>>x>>y;
vx.push_back(x);vy.push_back(y);
}
m=((N*Ss(n,vx,vy))-(S(n,vx)*S(n,vy)))/((N*Sp(n,vx))-(S(n,vx)*S(n,vx)));
b=(S(n,vy)-(m*S(n,vx)))/N;
am=to_string(round(m*1e3)/1e3);
if(s=="mb")cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
else{
cout<<"y = ";
if(m==0)cout<<round(b*1e3)/1e3;
if(am=="-0.000000")cout<<round(b*1e3)/1e3;
else if(m==1){
cout <<"x ";
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0)cout<<"- "<<abs(round(b*1e3)/1e3);
}else if(m==-1){
cout <<"-x ";
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0)cout<<"- "<<abs(round(b*1e3)/1e3);
}else{
cout<<round(m*1e3)/1e3<<"x ";
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0)cout<<"- "<<abs(round(b*1e3)/1e3);
}
}
} | # 0185, 2024-11-02 11:31:16, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
float S(int n,vector<float> v){
float sum=0;
for(int i=0;i<n;i++)sum+=v[i];
return sum;
}
float Ss(int n,vector<float> v,vector<float> v2){
float sum=0;
for(int i=0;i<n;i++)sum+=v[i]*v2[i];
return sum;
}
float Sp(int n,vector<float> v){
float sum=0;
for(int i=0;i<n;i++)sum+=v[i]*v[i];
return sum;
}
int main(){
int n;
float N,x,y,m,b;
string s,am;
cin>>N>>s;
n=N;
vector<float> vx,vy;
for(int i=0;i<n;i++){
cin>>x>>y;
vx.push_back(x);vy.push_back(y);
}
m=((N*Ss(n,vx,vy))-(S(n,vx)*S(n,vy)))/((N*Sp(n,vx))-(S(n,vx)*S(n,vx)));
b=(S(n,vy)-(m*S(n,vx)))/N;
am=to_string(round(m*1e3)/1e3);
if(s=="mb")cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
else{
cout<<"y = ";
if(m==0)cout<<round(b*1e3)/1e3;
else if(am=="-0.000000")cout<<round(b*1e3)/1e3;
else if(m==1){
cout <<"x ";
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0)cout<<"- "<<abs(round(b*1e3)/1e3);
}else if(m==-1){
cout <<"-x ";
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0)cout<<"- "<<abs(round(b*1e3)/1e3);
}else{
cout<<round(m*1e3)/1e3<<"x ";
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0)cout<<"- "<<abs(round(b*1e3)/1e3);
}
}
} | # 0186, 2024-11-02 12:05:48, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include<bits/stdc++.h>
using namespace std;
float S(int n,vector<float> v){
float sum=0;
for(int i=0;i<n;i++)sum+=v[i];
return sum;
}
float Ss(int n,vector<float> v,vector<float> v2){
float sum=0;
for(int i=0;i<n;i++)sum+=v[i]*v2[i];
return sum;
}
float Sp(int n,vector<float> v){
float sum=0;
for(int i=0;i<n;i++)sum+=v[i]*v[i];
return sum;
}
int main(){
int n;
float N,x,y,m,b;
string s,am;
cin>>N>>s;
n=N;
vector<float> vx,vy;
for(int i=0;i<n;i++){
cin>>x>>y;
vx.push_back(x);vy.push_back(y);
}
m=((N*Ss(n,vx,vy))-(S(n,vx)*S(n,vy)))/((N*Sp(n,vx))-(S(n,vx)*S(n,vx)));
b=(S(n,vy)-(m*S(n,vx)))/N;
am=to_string(round(m*1e3)/1e3);
if(s=="mb")cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
else{
cout<<"y = ";
if(m==0)cout<<round(b*1e3)/1e3;
else if(round(m*1e3)/1e3==0)cout<<round(b*1e3)/1e3;
else if(m==1){
cout <<"x ";
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0)cout<<"- "<<abs(round(b*1e3)/1e3);
}else if(m==-1){
cout <<"-x ";
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0)cout<<"- "<<abs(round(b*1e3)/1e3);
}else{
cout<<round(m*1e3)/1e3<<"x ";
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0)cout<<"- "<<abs(round(b*1e3)/1e3);
}
}
} | # 0187, 2024-11-02 12:06:23, PPPPPPPPPPPPPPPPPPPP-PP- (91%)
#include<bits/stdc++.h>
using namespace std;
float S(int n,vector<float> v){
float sum=0;
for(int i=0;i<n;i++)sum+=v[i];
return sum;
}
float Ss(int n,vector<float> v,vector<float> v2){
float sum=0;
for(int i=0;i<n;i++)sum+=v[i]*v2[i];
return sum;
}
float Sp(int n,vector<float> v){
float sum=0;
for(int i=0;i<n;i++)sum+=v[i]*v[i];
return sum;
}
int main(){
int n;
float N,x,y,m,b;
string s,am;
cin>>N>>s;
n=N;
vector<float> vx,vy;
for(int i=0;i<n;i++){
cin>>x>>y;
vx.push_back(x);vy.push_back(y);
}
m=((N*Ss(n,vx,vy))-(S(n,vx)*S(n,vy)))/((N*Sp(n,vx))-(S(n,vx)*S(n,vx)));
b=(S(n,vy)-(m*S(n,vx)))/N;
am=to_string(round(m*1e3)/1e3);
if(s=="mb")cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
else{
cout<<"y = ";
if(m==0)cout<<round(b*1e3)/1e3;
else if(round(m*1e3)/1e3==0)cout<<round(b*1e3)/1e3;
else if(round(m*1e3)/1e3==1){
cout <<"x ";
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0)cout<<"- "<<abs(round(b*1e3)/1e3);
}else if(m==-1){
cout <<"-x ";
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0)cout<<"- "<<abs(round(b*1e3)/1e3);
}else{
cout<<round(m*1e3)/1e3<<"x ";
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0)cout<<"- "<<abs(round(b*1e3)/1e3);
}
}
} | # 0188, 2024-11-02 12:07:05, Compilation error (0%)
#include<bits/stdc++.h>
using namespace std;
float S(int n,vector<float> v){
float sum=0;
for(int i=0;i<n;i++)sum+=v[i];
return sum;
}
float Ss(int n,vector<float> v,vector<float> v2){
float sum=0;
for(int i=0;i<n;i++)sum+=v[i]*v2[i];
return sum;
}
float Sp(int n,vector<float> v){
float sum=0;
for(int i=0;i<n;i++)sum+=v[i]*v[i];
return sum;
}
int main(){
int n;
float N,x,y,m,b;
string s,am;
cin>>N>>s;
n=N;
vector<float> vx,vy;
for(int i=0;i<n;i++){
cin>>x>>y;
vx.push_back(x);vy.push_back(y);
}
m=((N*Ss(n,vx,vy))-(S(n,vx)*S(n,vy)))/((N*Sp(n,vx))-(S(n,vx)*S(n,vx)));
b=(S(n,vy)-(m*S(n,vx)))/N;
am=to_string(round(m*1e3)/1e3);
if(s=="mb")cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
else{
cout<<"y = ";
if(m==0)cout<<round(b*1e3)/1e3;
else if(round(m*1e3)/1e3==0)cout<<round(b*1e3)/1e3;
else if(round(m*1e3)/1e3==1){
cout <<"x ";
if(round(b*1e3)/1e3>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(round(b*1e3)/1e3<0)cout<<"- "<<abs(round(b*1e3)/1e3);
}else if(round(m*1e3)/1e3==-1){
cout <<"-x ";
if(round(b*1e3)/1e3>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0)cout<<"- "<<abs(round(b*1e3)/1e3);
}else{
cout<<round(m*1e3)/1e3<<"x ";
if(bround(b*1e3)/1e30)cout<<"+ "<<round(b*1e3)/1e3;
else if(round(b*1e3)/1e3<0)cout<<"- "<<abs(round(b*1e3)/1e3);
}
}
} | # 0189, 2024-11-02 12:07:54, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<bits/stdc++.h>
using namespace std;
float S(int n,vector<float> v){
float sum=0;
for(int i=0;i<n;i++)sum+=v[i];
return sum;
}
float Ss(int n,vector<float> v,vector<float> v2){
float sum=0;
for(int i=0;i<n;i++)sum+=v[i]*v2[i];
return sum;
}
float Sp(int n,vector<float> v){
float sum=0;
for(int i=0;i<n;i++)sum+=v[i]*v[i];
return sum;
}
int main(){
int n;
float N,x,y,m,b;
string s,am;
cin>>N>>s;
n=N;
vector<float> vx,vy;
for(int i=0;i<n;i++){
cin>>x>>y;
vx.push_back(x);vy.push_back(y);
}
m=((N*Ss(n,vx,vy))-(S(n,vx)*S(n,vy)))/((N*Sp(n,vx))-(S(n,vx)*S(n,vx)));
b=(S(n,vy)-(m*S(n,vx)))/N;
am=to_string(round(m*1e3)/1e3);
if(s=="mb")cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
else{
cout<<"y = ";
if(round(m*1e3)/1e3==0)cout<<round(b*1e3)/1e3;
else if(round(m*1e3)/1e3==1){
cout <<"x ";
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0)cout<<"- "<<abs(round(b*1e3)/1e3);
}else if(round(m*1e3)/1e3==-1){
cout <<"-x ";
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0)cout<<"- "<<abs(round(b*1e3)/1e3);
}else{
cout<<round(m*1e3)/1e3<<"x ";
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0)cout<<"- "<<abs(round(b*1e3)/1e3);
}
}
} |
# 0190, 2024-11-02 09:42:24, -----PPPPP-------------- (20%)
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#include <cmath>
using namespace std;
int main(){
float n;
string ss;
float x,y;
cin>>n>>ss;
float m=0,b=0;
float xy=0,xi=0,yi=0,powx=0;
vector<pair<float,float>> asd;
for(int i=1;i<=n;i++){
cin>>x>>y;
xy+=x*y;
xi+=x;
yi+=y;
powx+=pow(x,2);
asd.push_back(make_pair(x,y));
}
m=((n*xy)-(xi*yi))/((n*powx)-(pow(xi,2)));
b=(yi-(m*xi))/n;
if(ss=="mb"){
cout<<m<<endl<<b;
}
return 0;
} | # 0191, 2024-11-02 09:44:13, PPPPPPPPPP-------------- (41%)
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#include <cmath>
using namespace std;
int main(){
float n;
string ss;
float x,y;
cin>>n>>ss;
float m=0,b=0;
float xy=0,xi=0,yi=0,powx=0;
vector<pair<float,float>> asd;
for(int i=1;i<=n;i++){
cin>>x>>y;
xy+=x*y;
xi+=x;
yi+=y;
powx+=pow(x,2);
asd.push_back(make_pair(x,y));
}
m=((n*xy)-(xi*yi))/((n*powx)-(pow(xi,2)));
b=(yi-(m*xi))/n;
if(ss=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
return 0;
} | # 0192, 2024-11-02 09:51:06, PPPPPPPPPP-----P--PP-PP- (62%)
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#include <cmath>
using namespace std;
int main(){
float n;
string ss;
float x,y;
cin>>n>>ss;
float m=0,b=0;
float xy=0,xi=0,yi=0,powx=0;
vector<pair<float,float>> asd;
for(int i=1;i<=n;i++){
cin>>x>>y;
xy+=x*y;
xi+=x;
yi+=y;
powx+=pow(x,2);
asd.push_back(make_pair(x,y));
}
m=((n*xy)-(xi*yi))/((n*powx)-(pow(xi,2)));
b=(yi-(m*xi))/n;
if(ss=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else if(ss=="func"){
if(m==0&&b==0){
cout<<"y = 0";
}else if(m==0){
cout<<"y = "<<round(b*1e3)/1e3;
}else if(m==1){
cout<<"y = x";
if(b>0){
cout<<" + "<<round(b*1e3)/1e3;
}else if(b<0){
b= -b;
cout<<" - "<<round(b*1e3)/1e3;
}
}else if(m==-1){
cout<<"y = -x";
if(b>0){
cout<<" + "<<round(b*1e3)/1e3;
}else if(b<0){
b= -b;
cout<<" - "<<round(b*1e3)/1e3;
}
}
}
return 0;
} | # 0193, 2024-11-02 09:52:15, PPPPPPPPPP-----P--PP-PP- (62%)
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#include <cmath>
using namespace std;
int main(){
float n;
string ss;
float x,y;
cin>>n>>ss;
float m=0,b=0;
float xy=0,xi=0,yi=0,powx=0;
vector<pair<float,float>> asd;
for(int i=1;i<=n;i++){
cin>>x>>y;
xy+=x*y;
xi+=x;
yi+=y;
powx+=pow(x,2);
asd.push_back(make_pair(x,y));
}
m=((n*xy)-(xi*yi))/((n*powx)-(pow(xi,2)));
b=(yi-(m*xi))/n;
if(ss=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else if(ss=="func"){
if(m==0&&b==0){
cout<<"y = 0";
}else if(m==0){
cout<<"y = "<<round(b*1e3)/1e3;
}else if(m==1){
cout<<"y = x";
if(b>0){
cout<<" + "<<round(b*1e3)/1e3;
}else if(b<0){
b= -b;
cout<<" - "<<round(b*1e3)/1e3;
}
}else if(m==-1){
cout<<"y = -x";
if(b>0){
cout<<" + "<<round(b*1e3)/1e3;
}else if(b<0){
b= -b;
cout<<" - "<<round(b*1e3)/1e3;
}
}else{
cout<<"y = ";
cout<<round(m*1e3)/1e3<<"x";
cout<<"y = -x";
if(b>0){
cout<<" + "<<round(b*1e3)/1e3;
}else if(b<0){
b= -b;
cout<<" - "<<round(b*1e3)/1e3;
}
}
}
return 0;
} | # 0194, 2024-11-02 09:53:49, PPPPPPPPPPPPPPPP--PP-PP- (83%)
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#include <cmath>
using namespace std;
int main(){
float n;
string ss;
float x,y;
cin>>n>>ss;
float m=0,b=0;
float xy=0,xi=0,yi=0,powx=0;
vector<pair<float,float>> asd;
for(int i=1;i<=n;i++){
cin>>x>>y;
xy+=x*y;
xi+=x;
yi+=y;
powx+=pow(x,2);
asd.push_back(make_pair(x,y));
}
m=((n*xy)-(xi*yi))/((n*powx)-(pow(xi,2)));
b=(yi-(m*xi))/n;
if(ss=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else if(ss=="func"){
if(m==0&&b==0){
cout<<"y = 0";
}else if(m==0){
cout<<"y = "<<round(b*1e3)/1e3;
}else if(m==1){
cout<<"y = x";
if(b>0){
cout<<" + "<<round(b*1e3)/1e3;
}else if(b<0){
b= abs(b);
cout<<" - "<<round(b*1e3)/1e3;
}
}else if(m==-1){
cout<<"y = -x";
if(b>0){
cout<<" + "<<round(b*1e3)/1e3;
}else if(b<0){
b= abs(b);
cout<<" - "<<round(b*1e3)/1e3;
}
}else{
cout<<"y = ";
cout<<round(m*1e3)/1e3<<"x";
if(b>0){
cout<<" + "<<round(b*1e3)/1e3;
}else if(b<0){
b= -b;
cout<<" - "<<round(b*1e3)/1e3;
}
}
}
return 0;
} | # 0195, 2024-11-02 09:54:20, PPPPPPPPPPPPPPPP--PP-PP- (83%)
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#include <cmath>
using namespace std;
int main(){
float n;
string ss;
float x,y;
cin>>n>>ss;
float m=0,b=0;
float xy=0,xi=0,yi=0,powx=0;
vector<pair<float,float>> asd;
for(int i=1;i<=n;i++){
cin>>x>>y;
xy+=x*y;
xi+=x;
yi+=y;
powx+=pow(x,2);
asd.push_back(make_pair(x,y));
}
m=((n*xy)-(xi*yi))/((n*powx)-(pow(xi,2)));
b=(yi-(m*xi))/n;
if(ss=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else if(ss=="func"){
if(m==0&&b==0){
cout<<"y = 0";
}else if(m==0){
cout<<"y = "<<round(b*1e3)/1e3;
}else if(m==1){
cout<<"y = x";
if(b>0){
cout<<" + "<<round(b*1e3)/1e3;
}else if(b<0){
b= abs(b);
cout<<" - "<<round(b*1e3)/1e3;
}
}else if(m==-1){
cout<<"y = -x";
if(b>0){
cout<<" + "<<round(b*1e3)/1e3;
}else if(b<0){
b= abs(b);
cout<<" - "<<round(b*1e3)/1e3;
}
}else{
cout<<"y = ";
cout<<round(m*1e3)/1e3<<"x";
if(b>0){
cout<<" + "<<round(b*1e3)/1e3;
}else if(b<0){
b= abs(b);
cout<<" - "<<round(b*1e3)/1e3;
}
}
}
return 0;
} | # 0196, 2024-11-02 09:58:18, PPPPPPPPPPPPPPPP--PP-PP- (83%)
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#include <cmath>
using namespace std;
int main(){
float n;
string ss;
float x,y;
cin>>n>>ss;
float m=0,b=0;
float xy=0,xi=0,yi=0,powx=0;
for(int i=1;i<=n;i++){
cin>>x>>y;
xy+=x*y;
xi+=x;
yi+=y;
powx+=pow(x,2);
}
m=((n*xy)-(xi*yi))/((n*powx)-(pow(xi,2)));
b=(yi-(m*xi))/n;
if(ss=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else if(ss=="func"){
if(m==0&&b==0){
cout<<"y = 0";
}else if(m==0){
cout<<"y = "<<round(b*1e3)/1e3;
}else if(m==1){
cout<<"y = x";
if(b>0){
cout<<" + "<<round(b*1e3)/1e3;
}else if(b<0){
b= abs(b);
cout<<" - "<<round(b*1e3)/1e3;
}
}else if(m==-1){
cout<<"y = -x";
if(b>0){
cout<<" + "<<round(b*1e3)/1e3;
}else if(b<0){
b= abs(b);
cout<<" - "<<round(b*1e3)/1e3;
}
}else{
cout<<"y = ";
cout<<round(m*1e3)/1e3<<"x";
if(b>0){
cout<<" + "<<round(b*1e3)/1e3;
}else if(b<0){
b= abs(b);
cout<<" - "<<round(b*1e3)/1e3;
}
}
}
return 0;
} | # 0197, 2024-11-02 10:38:21, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#include <cmath>
using namespace std;
int main(){
float n;
string ss;
float x,y;
cin>>n>>ss;
float m=0,b=0;
float xy=0,xi=0,yi=0,powx=0;
for(int i=1;i<=n;i++){
cin>>x>>y;
xy+=x*y;
xi+=x;
yi+=y;
powx+=pow(x,2);
}
m=((n*xy)-(xi*yi))/((n*powx)-(pow(xi,2)));
b=(yi-(m*xi))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(ss=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else if(ss=="func"){
if(m==0&&b==0){
cout<<"y = 0";
}else if(m==0){
cout<<"y = "<<round(b*1e3)/1e3;
}else if(m==1){
cout<<"y = x";
if(b>0){
cout<<" + "<<round(b*1e3)/1e3;
}else if(b<0){
b= abs(b);
cout<<" - "<<round(b*1e3)/1e3;
}
}else if(m==-1){
cout<<"y = -x";
if(b>0){
cout<<" + "<<round(b*1e3)/1e3;
}else if(b<0){
b= abs(b);
cout<<" - "<<round(b*1e3)/1e3;
}
}else{
cout<<"y = ";
cout<<round(m*1e3)/1e3<<"x";
if(b>0){
cout<<" + "<<round(b*1e3)/1e3;
}else if(b<0){
b= abs(b);
cout<<" - "<<round(b*1e3)/1e3;
}
}
}
return 0;
} |
# 0198, 2024-11-02 11:26:49, PPPPPPPPPPPPPPP--P--P-PP (79%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int n; cin >> n;
string cmd; cin >> cmd;
float x[n+1],y[n+1];
for(int i=1;i<=n;i++) cin >> x[i] >> y[i];
float m;
vector<float> arr_m(5,0);
for(int i=1;i<=n;i++) arr_m[0] += x[i]*y[i];
arr_m[0] *= n;
for(int i=1;i<=n;i++) arr_m[1] += x[i];
for(int i=1;i<=n;i++) arr_m[2] += y[i];
for(int i=1;i<=n;i++) arr_m[3] += x[i]*x[i];
arr_m[3] *= n;
arr_m[4] = arr_m[1] * arr_m[1];
m = (arr_m[0] - (arr_m[1]*arr_m[2])) / (arr_m[3]-arr_m[4]);
float b;
vector<float> arr_b(2,0);
for(int i=1;i<=n;i++) arr_b[0] += y[i];
for(int i=1;i<=n;i++) arr_b[1] += x[i];
arr_b[1] *= m;
b = (arr_b[0] - arr_b[1]) / n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(cmd == "mb"){
cout << m << "\n" << b;
}else{
cout << "y = ";
if(m == 0 && y == 0) cout << 0;
if(m == -1) cout << "-x ";
else if(m == 1) cout << "x ";
else cout << m << "x ";
if(b > 0) cout << "+ ";
else cout << "- ";
cout << abs(b);
}
return 0;
} | # 0199, 2024-11-02 11:28:12, PPPPPPPPPPPPPPP--PPPP-PP (87%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int n; cin >> n;
string cmd; cin >> cmd;
float x[n+1],y[n+1];
for(int i=1;i<=n;i++) cin >> x[i] >> y[i];
float m;
vector<float> arr_m(5,0);
for(int i=1;i<=n;i++) arr_m[0] += x[i]*y[i];
arr_m[0] *= n;
for(int i=1;i<=n;i++) arr_m[1] += x[i];
for(int i=1;i<=n;i++) arr_m[2] += y[i];
for(int i=1;i<=n;i++) arr_m[3] += x[i]*x[i];
arr_m[3] *= n;
arr_m[4] = arr_m[1] * arr_m[1];
m = (arr_m[0] - (arr_m[1]*arr_m[2])) / (arr_m[3]-arr_m[4]);
float b;
vector<float> arr_b(2,0);
for(int i=1;i<=n;i++) arr_b[0] += y[i];
for(int i=1;i<=n;i++) arr_b[1] += x[i];
arr_b[1] *= m;
b = (arr_b[0] - arr_b[1]) / n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(cmd == "mb"){
cout << m << "\n" << b;
}else{
cout << "y = ";
if(m == 0 && y == 0) cout << 0;
if(m == -1) cout << "-x ";
else if(m == 1) cout << "x ";
else cout << m << "x ";
if(b != 0){
if(b > 0) cout << "+ ";
else cout << "- ";
cout << abs(b);
}
}
return 0;
} | # 0200, 2024-11-02 11:30:27, PPPPPPPPPPPPPPP--PPPPPPP (91%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int n; cin >> n;
string cmd; cin >> cmd;
float x[n+1],y[n+1];
for(int i=1;i<=n;i++) cin >> x[i] >> y[i];
float m;
vector<float> arr_m(5,0);
for(int i=1;i<=n;i++) arr_m[0] += x[i]*y[i];
arr_m[0] *= n;
for(int i=1;i<=n;i++) arr_m[1] += x[i];
for(int i=1;i<=n;i++) arr_m[2] += y[i];
for(int i=1;i<=n;i++) arr_m[3] += x[i]*x[i];
arr_m[3] *= n;
arr_m[4] = arr_m[1] * arr_m[1];
m = (arr_m[0] - (arr_m[1]*arr_m[2])) / (arr_m[3]-arr_m[4]);
float b;
vector<float> arr_b(2,0);
for(int i=1;i<=n;i++) arr_b[0] += y[i];
for(int i=1;i<=n;i++) arr_b[1] += x[i];
arr_b[1] *= m;
b = (arr_b[0] - arr_b[1]) / n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(cmd == "mb"){
cout << m << "\n" << b;
}else{
cout << "y = ";
if(m == 0 && y == 0) cout << 0;
if(m != 0){
if(m == -1) cout << "-x ";
else if(m == 1) cout << "x ";
else cout << m << "x ";
}
if(b != 0){
if(b > 0) cout << "+ ";
else{
cout << "-";
if(m != 0) cout << " ";
}
cout << abs(b);
}
}
return 0;
} | # 0201, 2024-11-02 11:31:12, PPPPPPPPPPPPPPPP-PPPPPPP (95%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int n; cin >> n;
string cmd; cin >> cmd;
float x[n+1],y[n+1];
for(int i=1;i<=n;i++) cin >> x[i] >> y[i];
float m;
vector<float> arr_m(5,0);
for(int i=1;i<=n;i++) arr_m[0] += x[i]*y[i];
arr_m[0] *= n;
for(int i=1;i<=n;i++) arr_m[1] += x[i];
for(int i=1;i<=n;i++) arr_m[2] += y[i];
for(int i=1;i<=n;i++) arr_m[3] += x[i]*x[i];
arr_m[3] *= n;
arr_m[4] = arr_m[1] * arr_m[1];
m = (arr_m[0] - (arr_m[1]*arr_m[2])) / (arr_m[3]-arr_m[4]);
float b;
vector<float> arr_b(2,0);
for(int i=1;i<=n;i++) arr_b[0] += y[i];
for(int i=1;i<=n;i++) arr_b[1] += x[i];
arr_b[1] *= m;
b = (arr_b[0] - arr_b[1]) / n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(cmd == "mb"){
cout << m << "\n" << b;
}else{
cout << "y = ";
if(m == 0 && b == 0) cout << 0;
if(m != 0){
if(m == -1) cout << "-x ";
else if(m == 1) cout << "x ";
else cout << m << "x ";
}
if(b != 0){
if(b > 0) cout << "+ ";
else{
cout << "-";
if(m != 0) cout << " ";
}
cout << abs(b);
}
}
return 0;
} | # 0202, 2024-11-02 11:34:45, PPPPPPPPPPPPPPPP-PPPPPPP (95%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int n; cin >> n;
string cmd; cin >> cmd;
float x[n+1],y[n+1];
for(int i=1;i<=n;i++) cin >> x[i] >> y[i];
float m;
vector<float> arr_m(5,0);
for(int i=1;i<=n;i++) arr_m[0] += x[i]*y[i];
arr_m[0] *= n;
for(int i=1;i<=n;i++) arr_m[1] += x[i];
for(int i=1;i<=n;i++) arr_m[2] += y[i];
for(int i=1;i<=n;i++) arr_m[3] += x[i]*x[i];
arr_m[3] *= n;
arr_m[4] = arr_m[1] * arr_m[1];
m = (arr_m[0] - (arr_m[1]*arr_m[2])) / (arr_m[3]-arr_m[4]);
float b;
vector<float> arr_b(2,0);
for(int i=1;i<=n;i++) arr_b[0] += y[i];
for(int i=1;i<=n;i++) arr_b[1] += x[i];
arr_b[1] *= m;
b = (arr_b[0] - arr_b[1]) / n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(cmd == "mb"){
cout << m << "\n" << b;
}else{
cout << "y = ";
if(m == 0 && b == 0) cout << 0;
if(m != 0){
if(m == -1) cout << "-x ";
else if(m == 1) cout << "x ";
else cout << m << "x ";
}
if(b != 0){
if(b > 0) cout << "+ ";
else{
cout << "-";
if(m != 0) cout << " ";
}
cout << abs(b);
}
}
return 0;
} | # 0203, 2024-11-02 11:43:43, PPPPPPPPPPPPPPPP-PPPPPPP (95%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int n; cin >> n;
string cmd; cin >> cmd;
float x[n+1],y[n+1];
for(int i=1;i<=n;i++) cin >> x[i] >> y[i];
float m;
vector<float> arr_m(5,0);
for(int i=1;i<=n;i++) arr_m[0] += x[i]*y[i];
for(int i=1;i<=n;i++) arr_m[1] += x[i];
for(int i=1;i<=n;i++) arr_m[2] += y[i];
for(int i=1;i<=n;i++) arr_m[3] += x[i]*x[i];
arr_m[4] = arr_m[1] * arr_m[1];
m = ((n*arr_m[0]) - (arr_m[1]*arr_m[2])) / ((n*arr_m[3])-arr_m[4]);
float b;
vector<float> arr_b(2,0);
for(int i=1;i<=n;i++) arr_b[0] += y[i];
for(int i=1;i<=n;i++) arr_b[1] += x[i];
b = (arr_b[0] - (m*arr_b[1])) / float(n);
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(cmd == "mb"){
cout << m << "\n" << b;
}else{
cout << "y = ";
if(m == 0 && b == 0) cout << 0;
if(m != 0){
if(m == -1) cout << "-x ";
else if(m == 1) cout << "x ";
else cout << m << "x ";
}
if(b != 0){
if(b > 0) cout << "+ ";
else{
cout << "-";
if(m != 0) cout << " ";
}
cout << abs(b);
}
}
return 0;
} | # 0204, 2024-11-02 11:45:43, PPPPPPPPPPPPPPPP-PPPPPPP (95%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int n; cin >> n;
string cmd; cin >> cmd;
float x[n+1],y[n+1];
for(int i=1;i<=n;i++) cin >> x[i] >> y[i];
float m;
vector<float> arr_m(5,0);
for(int i=1;i<=n;i++) arr_m[0] += x[i]*y[i];
for(int i=1;i<=n;i++) arr_m[1] += x[i];
for(int i=1;i<=n;i++) arr_m[2] += y[i];
for(int i=1;i<=n;i++) arr_m[3] += x[i]*x[i];
arr_m[4] = arr_m[1] * arr_m[1];
m = ((n*arr_m[0]) - (arr_m[1]*arr_m[2])) / ((n*arr_m[3])-arr_m[4]);
float b;
vector<float> arr_b(2,0);
for(int i=1;i<=n;i++) arr_b[0] += y[i];
for(int i=1;i<=n;i++) arr_b[1] += x[i];
b = (arr_b[0] - (m*arr_b[1])) / n;
int tmp_m = m,tmp_b = b;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(cmd == "mb"){
cout << m << "\n" << b;
}else{
cout << "y = ";
if(tmp_m == 0 && tmp_b == 0) cout << 0;
if(m != 0){
if(m == -1) cout << "-x ";
else if(m == 1) cout << "x ";
else cout << m << "x ";
}
if(b != 0){
if(b > 0) cout << "+ ";
else{
cout << "-";
if(m != 0) cout << " ";
}
cout << abs(b);
}
}
return 0;
} | # 0205, 2024-11-02 11:49:35, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int n; cin >> n;
string cmd; cin >> cmd;
float x[n+1],y[n+1];
for(int i=1;i<=n;i++) cin >> x[i] >> y[i];
float m;
vector<float> arr_m(5,0);
for(int i=1;i<=n;i++) arr_m[0] += x[i]*y[i];
for(int i=1;i<=n;i++) arr_m[1] += x[i];
for(int i=1;i<=n;i++) arr_m[2] += y[i];
for(int i=1;i<=n;i++) arr_m[3] += x[i]*x[i];
arr_m[4] = arr_m[1] * arr_m[1];
m = ((n*arr_m[0]) - (arr_m[1]*arr_m[2])) / ((n*arr_m[3])-arr_m[4]);
float b;
vector<float> arr_b(2,0);
for(int i=1;i<=n;i++) arr_b[0] += y[i];
for(int i=1;i<=n;i++) arr_b[1] += x[i];
b = (arr_b[0] - (m*arr_b[1])) / n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(cmd == "mb"){
cout << m << "\n" << b;
}else{
cout << "y = ";
if(m == 0 && b == 0) cout << 0;
if(m != 0){
if(m == -1) cout << "-x ";
else if(m == 1) cout << "x ";
else cout << m << "x ";
}
if(b != 0){
if(b > 0){
if(m != 0) cout << "+ ";
}
else{
cout << "-";
if(m != 0) cout << " ";
}
cout << abs(b);
}
}
return 0;
}
/*
3 func
1.0 3.0
2.0 3.0
4.4 3.0
*/ |
# 0206, 2024-11-02 09:45:44, PPPPPPPPPP-P-PPP---P-P-- (66%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string cmd;
cin >> cmd;
float X, Y;
vector<float> x, y;
for(int i = 0; i < n; i++)
{
cin >> X;
cin >> Y;
x.push_back(X);
y.push_back(Y);
}
float totalX = 0, totalY = 0, totalX2 = 0, totalXY = 0;
for(float i : x)
{
totalX += i;
totalX2 += i*i;
}
for(float i : y)
{
totalY += i;
}
for(int i = 0 ; i < n; i++)
{
totalXY += x[i]*y[i];
}
float m = ((totalXY * n)- (totalX*totalY))/((totalX2 * n)- (totalX*totalX));
float b = (totalY - (m * totalX))/ n;
if(cmd == "mb")
{
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if(cmd == "func")
{
if(m == 0 && b == 0)
{
cout << "y = 0";
}
else if(m == 0 && b != 0)
{
cout << "y = " << round(b*1e3)/1e3;
}
else if(m == -1 && b < 0)
{
cout << "y = " << "-x - " << -(round(b*1e3)/1e3);
}
else if(m == -1 && b > 0)
{
cout << "y = " << "-x - " << round(b*1e3)/1e3;
}
else if(m == -1 && b == 0)
{
cout << "y = -x";
}
else if(b == 0)
{
cout <<"y = " << round(m*1e3)/1e3 << "x";
}
else if(b < 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x" << " - " << -(round(b*1e3)/1e3) ;
}
else
{
cout << "y = " << m << "x" << " + " << round(b*1e3)/1e3;
}
}
//cout << totalX2 << " " << totalY;
return 0;
} | # 0207, 2024-11-02 09:48:30, PPPPPPPPPP-P-PPP---P-P-- (66%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string cmd;
cin >> cmd;
float X, Y;
vector<float> x, y;
for(int i = 0; i < n; i++)
{
cin >> X;
cin >> Y;
x.push_back(X);
y.push_back(Y);
}
float totalX = 0, totalY = 0, totalX2 = 0, totalXY = 0;
for(float i : x)
{
totalX += i;
totalX2 += i*i;
}
for(float i : y)
{
totalY += i;
}
for(int i = 0 ; i < n; i++)
{
totalXY += x[i]*y[i];
}
float m = ((totalXY * n)- (totalX*totalY))/((totalX2 * n)- (totalX*totalX));
float b = (totalY - (m * totalX))/ n;
if(cmd == "mb")
{
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if(cmd == "func")
{
if(m == 0 && b == 0)
{
cout << "y = 0";
}
else if(m == 0 && b != 0)
{
cout << "y = " << round(b*1e3)/1e3;
}
else if(m == -1 && b < 0)
{
cout << "y = " << "-x - " << -(round(b*1e3)/1e3);
}
else if(m == -1 && b > 0)
{
cout << "y = " << "-x - " << round(b*1e3)/1e3;
}
else if(m == -1 && b == 0)
{
cout << "y = -x";
}
else if(b == 0)
{
cout <<"y = " << round(m*1e3)/1e3 << "x";
}
else if(b < 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x" << " - " << -(round(b*1e3)/1e3) ;
}
else if (m == 1)
{
if(b > 0) cout << "y = " << "x" << " + " << round(b*1e3)/1e3;
if(b < 0) cout << "y = " << "x" << " - " << round(b*1e3)/1e3;
}
else
{
cout << "y = " << m << "x" << " + " << round(b*1e3)/1e3;
}
}
//cout << totalX2 << " " << totalY;
return 0;
} | # 0208, 2024-11-02 09:50:49, PPPPPPPPPP-P-PPP--PP-P-- (70%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string cmd;
cin >> cmd;
float X, Y;
vector<float> x, y;
for(int i = 0; i < n; i++)
{
cin >> X;
cin >> Y;
x.push_back(X);
y.push_back(Y);
}
float totalX = 0, totalY = 0, totalX2 = 0, totalXY = 0;
for(float i : x)
{
totalX += i;
totalX2 += i*i;
}
for(float i : y)
{
totalY += i;
}
for(int i = 0 ; i < n; i++)
{
totalXY += x[i]*y[i];
}
float m = ((totalXY * n)- (totalX*totalY))/((totalX2 * n)- (totalX*totalX));
float b = (totalY - (m * totalX))/ n;
if(cmd == "mb")
{
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if(cmd == "func")
{
if(m == 0 && b == 0)
{
cout << "y = 0";
}
else if(m == 0 && b != 0)
{
cout << "y = " << round(b*1e3)/1e3;
}
else if(m == -1 && b < 0)
{
cout << "y = " << "-x - " << -(round(b*1e3)/1e3);
}
else if(m == -1 && b > 0)
{
cout << "y = " << "-x - " << round(b*1e3)/1e3;
}
else if(b == 0)
{
if(m == 1)cout <<"y = " << "x";
else if(m == -1)cout <<"y = "<< "-x";
else cout <<"y = " << round(m*1e3)/1e3 << "x";
}
else if(b < 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x" << " - " << -(round(b*1e3)/1e3) ;
}
else if (m == 1)
{
if(b > 0) cout << "y = " << "x" << " + " << round(b*1e3)/1e3;
if(b < 0) cout << "y = " << "x" << " - " << round(b*1e3)/1e3;
}
else
{
cout << "y = " << m << "x" << " + " << round(b*1e3)/1e3;
}
}
//cout << totalX2 << " " << totalY;
return 0;
} | # 0209, 2024-11-02 09:53:49, -----P----PPPPPPPPPP-P-P (54%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string cmd;
cin >> cmd;
float X, Y;
vector<float> x, y;
for(int i = 0; i < n; i++)
{
cin >> X;
cin >> Y;
x.push_back(X);
y.push_back(Y);
}
float totalX = 0, totalY = 0, totalX2 = 0, totalXY = 0;
for(float i : x)
{
totalX += i;
totalX2 += i*i;
}
for(float i : y)
{
totalY += i;
}
for(int i = 0 ; i < n; i++)
{
totalXY += x[i]*y[i];
}
float m = ((totalXY * n)- (totalX*totalY))/((totalX2 * n)- (totalX*totalX));
float b = (totalY - (m * totalX))/ n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(cmd == "mb")
{
cout << m << endl;
cout << m << endl;
}
else if(cmd == "func")
{
if(m == 0 && b == 0)
{
cout << "y = 0";
}
else if(m == 0 && b != 0)
{
cout << "y = " << b;
}
else if(m == -1 && b < 0)
{
cout << "y = " << "-x - " << -(b);
}
else if(m == -1 && b > 0)
{
cout << "y = " << "-x - " << b;
}
else if(b == 0)
{
if(m == 1)cout <<"y = " << "x";
else if(m == -1)cout <<"y = "<< "-x";
else cout <<"y = " << m << "x";
}
else if(b < 0)
{
cout << "y = " << m << "x" << " - " << -(b) ;
}
else if (m == 1)
{
if(b > 0) cout << "y = " << "x" << " + " << b;
if(b < 0) cout << "y = " << "x" << " - " << b;
}
else
{
cout << "y = " << m << "x" << " + " << b;
}
}
//cout << totalX2 << " " << totalY;
return 0;
} | # 0210, 2024-11-02 09:54:09, PPPPPPPPPPPPPPPPPPPP-P-P (91%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string cmd;
cin >> cmd;
float X, Y;
vector<float> x, y;
for(int i = 0; i < n; i++)
{
cin >> X;
cin >> Y;
x.push_back(X);
y.push_back(Y);
}
float totalX = 0, totalY = 0, totalX2 = 0, totalXY = 0;
for(float i : x)
{
totalX += i;
totalX2 += i*i;
}
for(float i : y)
{
totalY += i;
}
for(int i = 0 ; i < n; i++)
{
totalXY += x[i]*y[i];
}
float m = ((totalXY * n)- (totalX*totalY))/((totalX2 * n)- (totalX*totalX));
float b = (totalY - (m * totalX))/ n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(cmd == "mb")
{
cout << m << endl;
cout << b << endl;
}
else if(cmd == "func")
{
if(m == 0 && b == 0)
{
cout << "y = 0";
}
else if(m == 0 && b != 0)
{
cout << "y = " << b;
}
else if(m == -1 && b < 0)
{
cout << "y = " << "-x - " << -(b);
}
else if(m == -1 && b > 0)
{
cout << "y = " << "-x - " << b;
}
else if(b == 0)
{
if(m == 1)cout <<"y = " << "x";
else if(m == -1)cout <<"y = "<< "-x";
else cout <<"y = " << m << "x";
}
else if(b < 0)
{
cout << "y = " << m << "x" << " - " << -(b) ;
}
else if (m == 1)
{
if(b > 0) cout << "y = " << "x" << " + " << b;
if(b < 0) cout << "y = " << "x" << " - " << b;
}
else
{
cout << "y = " << m << "x" << " + " << b;
}
}
//cout << totalX2 << " " << totalY;
return 0;
} | # 0211, 2024-11-02 09:56:34, PPPPPPPPPPPPPPPPPPPPPP-P (95%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string cmd;
cin >> cmd;
float X, Y;
vector<float> x, y;
for(int i = 0; i < n; i++)
{
cin >> X;
cin >> Y;
x.push_back(X);
y.push_back(Y);
}
float totalX = 0, totalY = 0, totalX2 = 0, totalXY = 0;
for(float i : x)
{
totalX += i;
totalX2 += i*i;
}
for(float i : y)
{
totalY += i;
}
for(int i = 0 ; i < n; i++)
{
totalXY += x[i]*y[i];
}
float m = ((totalXY * n)- (totalX*totalY))/((totalX2 * n)- (totalX*totalX));
float b = (totalY - (m * totalX))/ n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(cmd == "mb")
{
cout << m << endl;
cout << b << endl;
}
else if(cmd == "func")
{
if(m == 0 && b == 0)
{
cout << "y = 0";
}
else if(m == 0 && b != 0)
{
cout << "y = " << b;
}
else if(m == -1 && b < 0)
{
cout << "y = " << "-x - " << -(b);
}
else if(m == -1 && b > 0)
{
cout << "y = " << "-x + " << b;
}
else if(b == 0)
{
if(m == 1)cout <<"y = " << "x";
else if(m == -1)cout <<"y = "<< "-x";
else cout <<"y = " << m << "x";
}
else if(b < 0)
{
cout << "y = " << m << "x" << " - " << -(b) ;
}
else if (m == 1)
{
if(b > 0) cout << "y = " << "x" << " + " << b;
if(b < 0) cout << "y = " << "x" << " - " << b;
}
else
{
cout << "y = " << m << "x" << " + " << b;
}
}
//cout << totalX2 << " " << totalY;
return 0;
} | # 0212, 2024-11-02 09:58:07, PPPPPPPPPPPPPPPPPPPPPP-P (95%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string cmd;
cin >> cmd;
float X, Y;
vector<float> x, y;
for(int i = 0; i < n; i++)
{
cin >> X;
cin >> Y;
x.push_back(X);
y.push_back(Y);
}
float totalX = 0, totalY = 0, totalX2 = 0, totalXY = 0;
for(float i : x)
{
totalX += i;
totalX2 += i*i;
}
for(float i : y)
{
totalY += i;
}
for(int i = 0 ; i < n; i++)
{
totalXY += x[i]*y[i];
}
float m = ((totalXY * n)- (totalX*totalY))/((totalX2 * n)- (totalX*totalX));
float b = (totalY - (m * totalX))/ n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(cmd == "mb")
{
cout << m << endl;
cout << b << endl;
}
else if(cmd == "func")
{
if(m == 0 && b == 0)
{
cout << "y = 0";
}
else if(m == 0 && b != 0)
{
cout << "y = " << b;
}
else if(m == -1 && b < 0)
{
cout << "y = " << "-x - " << -(b);
}
else if(m == -1 && b > 0)
{
cout << "y = " << "-x + " << b;
}
else if(b == 0)
{
if(m == 1)cout <<"y = " << "x";
else if(m == -1)cout <<"y = "<< "-x";
else cout <<"y = " << m << "x";
}
else if (m == 1)
{
if(b > 0) cout << "y = " << "x" << " + " << b;
if(b < 0) cout << "y = " << "x" << " - " << b;
}
else if(b < 0)
{
cout << "y = " << m << "x" << " - " << -(b) ;
}
else
{
cout << "y = " << m << "x" << " + " << b;
}
}
//cout << totalX2 << " " << totalY;
return 0;
} | # 0213, 2024-11-02 11:58:43, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string cmd;
cin >> cmd;
float X, Y;
vector<float> x, y;
for(int i = 0; i < n; i++)
{
cin >> X;
cin >> Y;
x.push_back(X);
y.push_back(Y);
}
float totalX = 0, totalY = 0, totalX2 = 0, totalXY = 0;
for(float i : x)
{
totalX += i;
totalX2 += i*i;
}
for(float i : y)
{
totalY += i;
}
for(int i = 0 ; i < n; i++)
{
totalXY += x[i]*y[i];
}
float m = ((totalXY * n)- (totalX*totalY))/((totalX2 * n)- (totalX*totalX));
float b = (totalY - (m * totalX))/ n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(cmd == "mb")
{
cout << m << endl;
cout << b << endl;
}
else if(cmd == "func")
{
if(m == 0 && b == 0)
{
cout << "y = 0";
}
else if(m == 0 && b != 0)
{
cout << "y = " << b;
}
else if(m == -1 && b < 0)
{
cout << "y = " << "-x - " << -(b);
}
else if(m == -1 && b > 0)
{
cout << "y = " << "-x + " << b;
}
else if(b == 0)
{
if(m == 1)cout <<"y = " << "x";
else if(m == -1)cout <<"y = "<< "-x";
else cout <<"y = " << m << "x";
}
else if (m == 1)
{
if(b > 0) cout << "y = " << "x" << " + " << b;
if(b < 0) cout << "y = " << "x" << " - " << (-b);
}
else if(b < 0)
{
cout << "y = " << m << "x" << " - " << -(b) ;
}
else
{
cout << "y = " << m << "x" << " + " << b;
}
}
//cout << totalX2 << " " << totalY;
return 0;
} |
# 0214, 2024-11-02 09:45:01, PPPPPPPPPPP-P--PPPPPPP-- (79%)
#include <bits/stdc++.h>
using namespace std;
int main(){
vector<pair<float,float>> v;
float x,y,m,b;
string s;
int n;
cin>>n>>s;
for(int i=0;i<n;i++){
cin>>x>>y;
v.push_back(make_pair(x,y));
}
float t1=0,t2=0,t3=0,t4=0;
for(int i=0;i<n;i++){
t1+=v[i].first*v[i].second;
t2+=v[i].first;
t3+=v[i].second;
t4+=v[i].first*v[i].first;
}
m=((n*t1)-(t2*t3))/((n*t4)-(t2*t2));
b=(t3-(m*t2))/n;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if(s=="mb"){
cout<<m<<endl<<b;
}else{
if(!m)cout<<"y = "<<b;
else if(m==1 && !b)cout<<"y = x";
else if(m==-1 && !b)cout<<"y = -x";
else if(m==1)cout<<"y = "<<"x + "<<b;
else if(m==-1)cout<<"y = "<<"-x + "<<b;
else if(!b)cout<<"y = "<<m<<"x";
else cout<<"y = "<<m<<"x + "<<b;
}
} | # 0215, 2024-11-02 09:50:12, PPPPPPPPPPPPPPPPPPPPP-PP (95%)
#include <bits/stdc++.h>
using namespace std;
int main(){
vector<pair<float,float>> v;
float x,y,m,b;
string s;
int n;
cin>>n>>s;
for(int i=0;i<n;i++){
cin>>x>>y;
v.push_back(make_pair(x,y));
}
float t1=0,t2=0,t3=0,t4=0;
for(int i=0;i<n;i++){
t1+=v[i].first*v[i].second;
t2+=v[i].first;
t3+=v[i].second;
t4+=v[i].first*v[i].first;
}
m=((n*t1)-(t2*t3))/((n*t4)-(t2*t2));
b=(t3-(m*t2))/n;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if(s=="mb"){
cout<<m<<endl<<b;
}else{
if(!m){
if(b<0)cout<<"y = - "<<abs(b);
else cout<<"y = "<<b;
}
else if(m==1 && !b)cout<<"y = x";
else if(m==-1 && !b)cout<<"y = -x";
else if(m==1){
if(b<0)cout<<"y = "<<"x - "<<abs(b);
else cout<<"y = "<<"x + "<<b;
}
else if(m==-1){
if(b<0)cout<<"y = "<<"-x - "<<abs(b);
else cout<<"y = "<<"-x + "<<b;
}
else if(!b)cout<<"y = "<<m<<"x";
else{
if(b<0)cout<<"y = "<<m<<"x - "<<abs(b);
else cout<<"y = "<<m<<"x + "<<b;
}
}
} | # 0216, 2024-11-02 09:51:06, PPPPPPPPPPPPPPPPPPPPP-PP (95%)
#include <bits/stdc++.h>
using namespace std;
int main(){
vector<pair<float,float>> v;
float x,y,m,b;
string s;
int n;
cin>>n>>s;
for(int i=0;i<n;i++){
cin>>x>>y;
v.push_back(make_pair(x,y));
}
float t1=0,t2=0,t3=0,t4=0;
for(int i=0;i<n;i++){
t1+=v[i].first*v[i].second;
t2+=v[i].first;
t3+=v[i].second;
t4+=v[i].first*v[i].first;
}
m=((n*t1)-(t2*t3))/((n*t4)-(t2*t2));
b=(t3-(m*t2))/n;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if(s=="mb"){
cout<<m<<endl<<b;
}else{
if(!m){
if(b<0)cout<<"y = - "<<abs(b);
else cout<<"y = "<<b;
}
else if(m==1 && !b)cout<<"y = x";
else if(m==-1 && !b)cout<<"y = -x";
else if(m==1){
if(b<0)cout<<"y = "<<"x - "<<abs(b);
else cout<<"y = "<<"x + "<<b;
}
else if(m==-1){
if(b<0)cout<<"y = "<<"-x - "<<abs(b);
else cout<<"y = "<<"-x + "<<b;
}
else if(!b)cout<<"y = "<<m<<"x";
else{
if(b<0)cout<<"y = "<<m<<"x - "<<abs(b);
else cout<<"y = "<<m<<"x + "<<b;
}
}
} | # 0217, 2024-11-02 09:51:30, PPPPPPPPPPPPPPPPPPPPP-PP (95%)
#include <bits/stdc++.h>
using namespace std;
int main(){
vector<pair<float,float>> v;
float x,y,m,b;
string s;
int n;
cin>>n>>s;
for(int i=0;i<n;i++){
cin>>x>>y;
v.push_back(make_pair(x,y));
}
float t1=0,t2=0,t3=0,t4=0;
for(int i=0;i<n;i++){
t1+=v[i].first*v[i].second;
t2+=v[i].first;
t3+=v[i].second;
t4+=v[i].first*v[i].first;
}
m=((n*t1)-(t2*t3))/((n*t4)-(t2*t2));
b=(t3-(m*t2))/n;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if(s=="mb"){
cout<<m<<endl<<b;
}else{
if(!m){
if(b<0)cout<<"y = - "<<abs(b);
else cout<<"y = "<<b;
}
else if(m==1 && !b)cout<<"y = x";
else if(m==-1 && !b)cout<<"y = -x";
else if(m==1){
if(b<0)cout<<"y = "<<"x - "<<abs(b);
else cout<<"y = "<<"x + "<<b;
}
else if(m==-1){
if(b<0)cout<<"y = "<<"-x - "<<abs(b);
else cout<<"y = "<<"-x + "<<b;
}
else if(!b)cout<<"y = "<<m<<"x";
else{
if(b<0)cout<<"y = "<<m<<"x - "<<abs(b);
else cout<<"y = "<<m<<"x + "<<b;
}
}
} | # 0218, 2024-11-02 09:52:04, PPPPPPPPPPPPPPPPPPPPP-PP (95%)
#include <bits/stdc++.h>
using namespace std;
int main(){
vector<pair<float,float>> v;
float x,y,m,b;
string s;
int n;
cin>>n>>s;
for(int i=0;i<n;i++){
cin>>x>>y;
v.push_back(make_pair(x,y));
}
float t1=0,t2=0,t3=0,t4=0;
for(int i=0;i<n;i++){
t1+=v[i].first*v[i].second;
t2+=v[i].first;
t3+=v[i].second;
t4+=v[i].first*v[i].first;
}
m=((n*t1)-(t2*t3))/((n*t4)-(t2*t2));
b=(t3-(m*t2))/n;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if(s=="mb"){
cout<<m<<endl<<b;
}else{
if(!m){
if(b<0)cout<<"y = - "<<abs(b);
else cout<<"y = "<<b;
}
else if(m==1 && !b)cout<<"y = x";
else if(m==-1 && !b)cout<<"y = -x";
else if(m==1){
if(b<0)cout<<"y = "<<"x - "<<abs(b);
else cout<<"y = "<<"x + "<<b;
}
else if(m==-1){
if(b<0)cout<<"y = "<<"-x - "<<abs(b);
else cout<<"y = "<<"-x + "<<b;
}
else if(!b)cout<<"y = "<<m<<"x";
else{
if(b<0)cout<<"y = "<<m<<"x - "<<abs(b);
else cout<<"y = "<<m<<"x + "<<b;
}
}
} | # 0219, 2024-11-02 09:52:20, PPPPPPPPPPPPPPPPPPPPP-PP (95%)
#include <bits/stdc++.h>
using namespace std;
int main(){
vector<pair<float,float>> v;
float x,y,m,b;
string s;
int n;
cin>>n>>s;
for(int i=0;i<n;i++){
cin>>x>>y;
v.push_back(make_pair(x,y));
}
float t1=0,t2=0,t3=0,t4=0;
for(int i=0;i<n;i++){
t1+=v[i].first*v[i].second;
t2+=v[i].first;
t3+=v[i].second;
t4+=v[i].first*v[i].first;
}
m=((n*t1)-(t2*t3))/((n*t4)-(t2*t2));
b=(t3-(m*t2))/n;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if(s=="mb"){
cout<<m<<endl<<b;
}else{
if(!m){
if(b<0)cout<<"y = - "<<abs(b);
else cout<<"y = "<<b;
}
else if(m==1 && !b)cout<<"y = x";
else if(m==-1 && !b)cout<<"y = -x";
else if(m==1){
if(b<0)cout<<"y = "<<"x - "<<abs(b);
else cout<<"y = "<<"x + "<<b;
}
else if(m==-1){
if(b<0)cout<<"y = "<<"-x - "<<abs(b);
else cout<<"y = "<<"-x + "<<b;
}
else if(!b)cout<<"y = "<<m<<"x";
else{
if(b<0)cout<<"y = "<<m<<"x - "<<abs(b);
else cout<<"y = "<<m<<"x + "<<b;
}
}
} | # 0220, 2024-11-02 09:52:41, PPPPPPPPPPPPPPPPPPPPP-PP (95%)
#include <bits/stdc++.h>
using namespace std;
int main(){
vector<pair<float,float>> v;
float x,y,m,b;
string s;
int n;
cin>>n>>s;
for(int i=0;i<n;i++){
cin>>x>>y;
v.push_back(make_pair(x,y));
}
float t1=0,t2=0,t3=0,t4=0;
for(int i=0;i<n;i++){
t1+=v[i].first*v[i].second;
t2+=v[i].first;
t3+=v[i].second;
t4+=v[i].first*v[i].first;
}
m=((n*t1)-(t2*t3))/((n*t4)-(t2*t2));
b=(t3-(m*t2))/n;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if(s=="mb"){
cout<<m<<endl<<b;
}else{
if(!m){
if(b<0)cout<<"y =- "<<abs(b);
else cout<<"y = "<<b;
}
else if(m==1 && !b)cout<<"y = x";
else if(m==-1 && !b)cout<<"y = -x";
else if(m==1){
if(b<0)cout<<"y = "<<"x - "<<abs(b);
else cout<<"y = "<<"x + "<<b;
}
else if(m==-1){
if(b<0)cout<<"y = "<<"-x - "<<abs(b);
else cout<<"y = "<<"-x + "<<b;
}
else if(!b)cout<<"y = "<<m<<"x";
else{
if(b<0)cout<<"y = "<<m<<"x - "<<abs(b);
else cout<<"y = "<<m<<"x + "<<b;
}
}
} | # 0221, 2024-11-02 09:53:27, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
int main(){
vector<pair<float,float>> v;
float x,y,m,b;
string s;
int n;
cin>>n>>s;
for(int i=0;i<n;i++){
cin>>x>>y;
v.push_back(make_pair(x,y));
}
float t1=0,t2=0,t3=0,t4=0;
for(int i=0;i<n;i++){
t1+=v[i].first*v[i].second;
t2+=v[i].first;
t3+=v[i].second;
t4+=v[i].first*v[i].first;
}
m=((n*t1)-(t2*t3))/((n*t4)-(t2*t2));
b=(t3-(m*t2))/n;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if(s=="mb"){
cout<<m<<endl<<b;
}else{
if(!m)cout<<"y = "<<b;
else if(m==1 && !b)cout<<"y = x";
else if(m==-1 && !b)cout<<"y = -x";
else if(m==1){
if(b<0)cout<<"y = "<<"x - "<<abs(b);
else cout<<"y = "<<"x + "<<b;
}
else if(m==-1){
if(b<0)cout<<"y = "<<"-x - "<<abs(b);
else cout<<"y = "<<"-x + "<<b;
}
else if(!b)cout<<"y = "<<m<<"x";
else{
if(b<0)cout<<"y = "<<m<<"x - "<<abs(b);
else cout<<"y = "<<m<<"x + "<<b;
}
}
} |
# 0222, 2024-11-02 13:00:22, -----PPPPP-------------- (20%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string s;
cin >> n >> s;
vector<float> x,y;
float a,b, m, z;
for(int i=0;i<n;i++){
cin >> a >> z;
x.push_back(a);
y.push_back(z);
}
float m1=0,m2=0,m3=0,m4=0,m5=0, b1=0,b2=0;
for(int i=0;i<n;i++){
m1 = m1 + (x[i]*y[i]);
m2 = m2 + x[i];
m3 = m3 + y[i];
m4 = m4 + (x[i]*x[i]);
b1+=y[i];
b2+=x[i];
}
m1*=n;
m4 *= n;
m5 = m2*m2;
m = (m1 - (m2*m3))/(m4-m5);
b = (b1 - (m*b2))/n;
if(s=="mb"){
cout << m << endl;
cout << b;
}
} | # 0223, 2024-11-02 13:03:25, -----PPPPP-------------- (20%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string s;
cin >> n >> s;
vector<float> x,y;
float a,b, m, z;
for(int i=0;i<n;i++){
cin >> a >> z;
x.push_back(a);
y.push_back(z);
}
float m1=0,m2=0,m3=0,m4=0,m5=0, b1=0,b2=0;
for(int i=0;i<n;i++){
m1 = m1 + (x[i]*y[i]);
m2 = m2 + x[i];
m3 = m3 + y[i];
m4 = m4 + (x[i]*x[i]);
b1+=y[i];
b2+=x[i];
}
m1*=n;
m4 *= n;
m5 = m2*m2;
m = (m1 - (m2*m3))/(m4-m5);
b = (b1 - (m*b2))/n;
if(s=="mb"){
cout << m << endl;
cout << b;
}else{
cout << "y = " << m <<"x";
if(b>=0) cout << " + ";
if(b<0) cout << " - ";
cout << abs(b);
}
} | # 0224, 2024-11-02 13:05:14, PPPPPPPPPPPPPPP--------- (62%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string s;
cin >> n >> s;
vector<float> x,y;
float a,b, m, z;
for(int i=0;i<n;i++){
cin >> a >> z;
x.push_back(a);
y.push_back(z);
}
float m1=0,m2=0,m3=0,m4=0,m5=0, b1=0,b2=0;
for(int i=0;i<n;i++){
m1 = m1 + (x[i]*y[i]);
m2 = m2 + x[i];
m3 = m3 + y[i];
m4 = m4 + (x[i]*x[i]);
b1+=y[i];
b2+=x[i];
}
m1*=n;
m4 *= n;
m5 = m2*m2;
m = (m1 - (m2*m3))/(m4-m5);
b = (b1 - (m*b2))/n;
b = round(b*1e3)/1e3;
m = round(m*1e3)/1e3;
if(s=="mb"){
cout << m << endl;
cout << b;
}else{
cout << "y = " << m <<"x";
if(b>=0) cout << " + ";
if(b<0) cout << " - ";
cout << abs(b);
}
} | # 0225, 2024-11-02 13:13:10, PPPPPPPPPP-------------- (41%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string s;
cin >> n >> s;
vector<float> x,y;
float a,b, m, z;
for(int i=0;i<n;i++){
cin >> a >> z;
x.push_back(a);
y.push_back(z);
}
float m1=0,m2=0,m3=0,m4=0,m5=0, b1=0,b2=0;
for(int i=0;i<n;i++){
m1 = m1 + (x[i]*y[i]);
m2 = m2 + x[i];
m3 = m3 + y[i];
m4 = m4 + (x[i]*x[i]);
b1+=y[i];
b2+=x[i];
}
m1*=n;
m4 *= n;
m5 = m2*m2;
m = (m1 - (m2*m3))/(m4-m5);
b = (b1 - (m*b2))/n;
b = round(b*1e3)/1e3;
m = round(m*1e3)/1e3;
if(s=="mb"){
cout << m << endl;
cout << b;
}else{
cout << m << ' ' << b;
if(m!=0){
cout << "y = ";
if(m!=1) cout << m;
cout << "x";
if(b>0) cout << " + " << abs(b);;
if(b<0) cout << " - " << abs(b);;
}
else cout << "y = 0";
}
} | # 0226, 2024-11-02 13:13:47, PPPPPPPPPPPPPPPP-PP---P- (79%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string s;
cin >> n >> s;
vector<float> x,y;
float a,b, m, z;
for(int i=0;i<n;i++){
cin >> a >> z;
x.push_back(a);
y.push_back(z);
}
float m1=0,m2=0,m3=0,m4=0,m5=0, b1=0,b2=0;
for(int i=0;i<n;i++){
m1 = m1 + (x[i]*y[i]);
m2 = m2 + x[i];
m3 = m3 + y[i];
m4 = m4 + (x[i]*x[i]);
b1+=y[i];
b2+=x[i];
}
m1*=n;
m4 *= n;
m5 = m2*m2;
m = (m1 - (m2*m3))/(m4-m5);
b = (b1 - (m*b2))/n;
b = round(b*1e3)/1e3;
m = round(m*1e3)/1e3;
if(s=="mb"){
cout << m << endl;
cout << b;
}else{
if(m!=0){
cout << "y = ";
if(m!=1) cout << m;
cout << "x";
if(b>0) cout << " + " << abs(b);;
if(b<0) cout << " - " << abs(b);;
}
else cout << "y = 0";
}
} | # 0227, 2024-11-02 13:16:03, PPPPPPPPPP-------------- (41%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string s;
cin >> n >> s;
vector<float> x,y;
float a,b, m, z;
for(int i=0;i<n;i++){
cin >> a >> z;
x.push_back(a);
y.push_back(z);
}
float m1=0,m2=0,m3=0,m4=0,m5=0, b1=0,b2=0;
for(int i=0;i<n;i++){
m1 = m1 + (x[i]*y[i]);
m2 = m2 + x[i];
m3 = m3 + y[i];
m4 = m4 + (x[i]*x[i]);
b1+=y[i];
b2+=x[i];
}
m1*=n;
m4 *= n;
m5 = m2*m2;
m = (m1 - (m2*m3))/(m4-m5);
b = (b1 - (m*b2))/n;
b = round(b*1e3)/1e3;
m = round(m*1e3)/1e3;
if(s=="mb"){
cout << m << endl;
cout << b;
}else{
cout << m << ' ' << b << endl;
if(m!=0){
cout << "y = ";
if(m!=1) cout << m;
cout << "x";
if(b>0) cout << " + " << abs(b);;
if(b<0) cout << " - " << abs(b);;
}
else if(m==0&&b==0)cout << "y = 0";
else if(m==0&&b!=0) cout << "y = " << b;
}
} | # 0228, 2024-11-02 13:16:15, PPPPPPPPPPPPPPPPPPP--PP- (87%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string s;
cin >> n >> s;
vector<float> x,y;
float a,b, m, z;
for(int i=0;i<n;i++){
cin >> a >> z;
x.push_back(a);
y.push_back(z);
}
float m1=0,m2=0,m3=0,m4=0,m5=0, b1=0,b2=0;
for(int i=0;i<n;i++){
m1 = m1 + (x[i]*y[i]);
m2 = m2 + x[i];
m3 = m3 + y[i];
m4 = m4 + (x[i]*x[i]);
b1+=y[i];
b2+=x[i];
}
m1*=n;
m4 *= n;
m5 = m2*m2;
m = (m1 - (m2*m3))/(m4-m5);
b = (b1 - (m*b2))/n;
b = round(b*1e3)/1e3;
m = round(m*1e3)/1e3;
if(s=="mb"){
cout << m << endl;
cout << b;
}else{
//cout << m << ' ' << b << endl;
if(m!=0){
cout << "y = ";
if(m!=1) cout << m;
cout << "x";
if(b>0) cout << " + " << abs(b);;
if(b<0) cout << " - " << abs(b);;
}
else if(m==0&&b==0)cout << "y = 0";
else if(m==0&&b!=0) cout << "y = " << b;
}
} | # 0229, 2024-11-02 13:18:03, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string s;
cin >> n >> s;
vector<float> x,y;
float a,b, m, z;
for(int i=0;i<n;i++){
cin >> a >> z;
x.push_back(a);
y.push_back(z);
}
float m1=0,m2=0,m3=0,m4=0,m5=0, b1=0,b2=0;
for(int i=0;i<n;i++){
m1 = m1 + (x[i]*y[i]);
m2 = m2 + x[i];
m3 = m3 + y[i];
m4 = m4 + (x[i]*x[i]);
b1+=y[i];
b2+=x[i];
}
m1*=n;
m4 *= n;
m5 = m2*m2;
m = (m1 - (m2*m3))/(m4-m5);
b = (b1 - (m*b2))/n;
b = round(b*1e3)/1e3;
m = round(m*1e3)/1e3;
if(s=="mb"){
cout << m << endl;
cout << b;
}else{
//cout << m << ' ' << b << endl;
if(m!=0){
cout << "y = ";
if(m!=1 && m!=-1) cout << m;
if(m==-1)cout << "-";
cout << "x";
if(b>0) cout << " + " << abs(b);;
if(b<0) cout << " - " << abs(b);;
}
else if(m==0&&b==0)cout << "y = 0";
else if(m==0&&b!=0) cout << "y = " << b;
}
} |
# 0230, 2024-11-02 14:02:12, ------------------------ (0%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; string comm;
cin >> n >> comm;
vector<pair<float,float>> data;
float x,y;
for (int i=0; i<n; i++) {
cin >> x >> y;
data.push_back(make_pair(x,y));
}
//res 1 m
float res1 = 0;
for (int i=0; i<n; i++) {
res1 += data[i].first*data[i].second;
}
res1 *= n;
//res 2,3 m
float res2,res3 = 0;
for (int i=0; i<n; i++) {
res2 += data[i].first;
res3 += data[i].second;
}
//res 4
float res4 = 0;
for (int i=0; i<n; i++) {
res4 += pow(data[i].first,2);
}
res4 *= n;
//res5
float res5 = 0;
for (int i=0; i<n; i++) {
res5 += data[i].first;
}
res5 *= res5;
float m = (res1-(res2*res3))/(res4-res5);
float b = (res3-(m*res2))/n;
if (comm == "mb") {
cout << round(m*1e3)/1e3;
cout << round(b*1e3)/1e3;
}
} | # 0231, 2024-11-02 14:02:38, PPPPPPPPPP-------------- (41%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; string comm;
cin >> n >> comm;
vector<pair<float,float>> data;
float x,y;
for (int i=0; i<n; i++) {
cin >> x >> y;
data.push_back(make_pair(x,y));
}
//res 1 m
float res1 = 0;
for (int i=0; i<n; i++) {
res1 += data[i].first*data[i].second;
}
res1 *= n;
//res 2,3 m
float res2,res3 = 0;
for (int i=0; i<n; i++) {
res2 += data[i].first;
res3 += data[i].second;
}
//res 4
float res4 = 0;
for (int i=0; i<n; i++) {
res4 += pow(data[i].first,2);
}
res4 *= n;
//res5
float res5 = 0;
for (int i=0; i<n; i++) {
res5 += data[i].first;
}
res5 *= res5;
float m = (res1-(res2*res3))/(res4-res5);
float b = (res3-(m*res2))/n;
if (comm == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
}
} | # 0232, 2024-11-02 14:04:30, PP-P-PPPPP-------------- (33%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; string comm;
cin >> n >> comm;
vector<pair<float,float>> data;
float x,y;
for (int i=0; i<n; i++) {
cin >> x >> y;
data.push_back(make_pair(x,y));
}
//res 1 m
float res1 = 0;
for (int i=0; i<n; i++) {
res1 += data[i].first*data[i].second;
}
res1 *= n;
//res 2,3 m
float res2,res3 = 0;
for (int i=0; i<n; i++) {
res2 += data[i].first;
res3 += data[i].second;
}
//res 4
float res4 = 0;
for (int i=0; i<n; i++) {
res4 += pow(data[i].first,2);
}
res4 *= n;
//res5
float res5 = 0;
for (int i=0; i<n; i++) {
res5 += data[i].first;
}
res5 *= res5;
float m = (res1-(res2*res3))/(res4-res5);
float b = (res3-(m*res2))/n;
if (comm == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
} else {
cout << "y = " << m << "x " << b;
}
} | # 0233, 2024-11-02 14:09:43, PPPPPPPPPP-----P-------- (45%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; string comm;
cin >> n >> comm;
vector<pair<float,float>> data;
float x,y;
for (int i=0; i<n; i++) {
cin >> x >> y;
data.push_back(make_pair(x,y));
}
//res 1 m
float res1 = 0;
for (int i=0; i<n; i++) {
res1 += data[i].first*data[i].second;
}
res1 *= n;
//res 2,3 m
float res2,res3 = 0;
for (int i=0; i<n; i++) {
res2 += data[i].first;
res3 += data[i].second;
}
//res 4
float res4 = 0;
for (int i=0; i<n; i++) {
res4 += pow(data[i].first,2);
}
res4 *= n;
//res5
float res5 = 0;
for (int i=0; i<n; i++) {
res5 += data[i].first;
}
res5 *= res5;
float m = (res1-(res2*res3))/(res4-res5);
float b = (res3-(m*res2))/n;
if (comm == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
} else {
if (m==0) {
cout << "y = 0";
} else
cout << "y = " << m << "x";
if (b>0) {
cout << " + " << b;
} else if (b<0) {
cout << " - " << -b;
}
}
} | # 0234, 2024-11-02 14:25:00, ----PPPPP------P--P----- (29%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; string comm;
cin >> n >> comm;
vector<pair<float,float>> data;
float x,y;
for (int i=0; i<n; i++) {
cin >> x >> y;
data.push_back(make_pair(x,y));
}
//res 1 m
float res1 = 0;
for (int i=0; i<n; i++) {
res1 += data[i].first*data[i].second;
}
res1 *= n;
//res 2,3 m
float res2,res3 = 0;
for (int i=0; i<n; i++) {
res2 += data[i].first;
res3 += data[i].second;
}
//res 4
float res4 = 0;
for (int i=0; i<n; i++) {
res4 += pow(data[i].first,2);
}
res4 *= n;
//res5
float res5 = 0;
for (int i=0; i<n; i++) {
res5 += data[i].first;
}
res5 *= res5;
float m = (res1-(res2*res3))/(res4-res5);
float b = (res3-(m*res2))/n;
if (comm == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
} else {
if (m==0) {
if (b==0) cout << "y = 0";
else {
cout << "y = " << b;
}
} else if (m==1) {
if (b==0) cout << "y = x";
else {
if (b>0) cout << "y = x + " << b;
else cout << "y = x - " << -b;
}
} else {
cout << "ok";
}
}
} | # 0235, 2024-11-02 14:34:40, PP-P-P--P------P-------- (25%)
#include <bits/stdc++.h>
using namespace std;
int main() {
float n; string comm;
cin >> n >> comm;
vector<pair<float,float>> data;
float x,y;
for (int i=0; i<n; i++) {
cin >> x >> y;
data.push_back(make_pair(x,y));
}
//res 1 m
float res1 = 0;
for (int i=0; i<n; i++) {
res1 += data[i].first*data[i].second;
}
res1 *= n;
//res 2,3 m
float res2,res3 = 0;
for (int i=0; i<n; i++) {
res2 += data[i].first;
res3 += data[i].second;
}
//res 4
float res4 = 0;
for (int i=0; i<n; i++) {
res4 += pow(data[i].first,2);
}
res4 *= n;
//res5
float res5 = 0;
for (int i=0; i<n; i++) {
res5 += data[i].first;
}
res5 *= res5;
float m = (res1-(res2*res3))/(res4-res5);
float b = (res3-(m*res2))/n;
if (comm == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
} else {
if (m==0) {
cout << "y = 0";
} else
cout << "y = " << m << "x";
if (b>0) {
cout << " + " << b;
} else if (b<0) {
cout << " - " << -b;
}
}
} | # 0236, 2024-11-02 14:34:56, PPPPPPPPPP-----P-------- (45%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; string comm;
cin >> n >> comm;
vector<pair<float,float>> data;
float x,y;
for (int i=0; i<n; i++) {
cin >> x >> y;
data.push_back(make_pair(x,y));
}
//res 1 m
float res1 = 0;
for (int i=0; i<n; i++) {
res1 += data[i].first*data[i].second;
}
res1 *= n;
//res 2,3 m
float res2,res3 = 0;
for (int i=0; i<n; i++) {
res2 += data[i].first;
res3 += data[i].second;
}
//res 4
float res4 = 0;
for (int i=0; i<n; i++) {
res4 += pow(data[i].first,2);
}
res4 *= n;
//res5
float res5 = 0;
for (int i=0; i<n; i++) {
res5 += data[i].first;
}
res5 *= res5;
float m = (res1-(res2*res3))/(res4-res5);
float b = (res3-(m*res2))/n;
if (comm == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
} else {
if (m==0) {
cout << "y = 0";
} else
cout << "y = " << m << "x";
if (b>0) {
cout << " + " << b;
} else if (b<0) {
cout << " - " << -b;
}
}
} | # 0237, 2024-11-02 14:52:46, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
int main() {
float n; string comm;
cin >> n >> comm;
vector<pair<float,float>> data;
float x,y;
for (int i=0; i<n; i++) {
cin >> x >> y;
data.push_back(make_pair(x,y));
}
//res 1 m
float res1 = 0;
for (int i=0; i<n; i++) {
res1 += data[i].first*data[i].second;
}
res1 *= n;
//res 2,3 m
float res2,res3 = 0;
for (int i=0; i<n; i++) {
res2 += data[i].first;
res3 += data[i].second;
}
//res 4
float res4 = 0;
for (int i=0; i<n; i++) {
res4 += pow(data[i].first,2);
}
res4 *= n;
//res5
float res5 = 0;
for (int i=0; i<n; i++) {
res5 += data[i].first;
}
res5 *= res5;
float M = (res1-(res2*res3))/(res4-res5);
float B = (res3-(M*res2))/n;
float m = round(M*1e3)/1e3;
float b = round(B*1e3)/1e3;
if (m==-0) m=0;
if (comm == "mb") {
cout << m << endl;
cout << b;
} else {
if (m==0) {
cout << "y = ";
if (b==0) {
cout << 0;
} else {
cout << b;
}
} else if (m==1) {
cout << "y = x ";
if (b>0) {
cout << "+ " << b;
} else if (b<0) {
cout << "- " << -b;
}
} else if (m==-1) {
cout << "y = -x ";
if (b>0) {
cout << "+ " << b;
} else if (b<0) {
cout << "- " << -b;
}
} else {
cout << "y = " << m << "x ";
if (b>0) {
cout << "+ " << b;
} else if (b<0) {
cout << "- " << -b;
}
}
}
} |
# 0238, 2024-11-02 09:21:19, -----PPPPP-------------- (20%)
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin>>N;
string use;
cin>>use;
vector<float> x;
vector<float> y;
if (use == "mb") {
float a,b;
float sumx = 0, sumy = 0, sumxy = 0, sumxpow = 0;
for (int i =0 ; i < N ; i++) {
cin>>a>>b;
sumx+=a;
sumy+=b;
sumxy+= a*b;
sumxpow+= pow(a,2);
}
float m = (N*sumxy) - (sumx*sumy);
m = m / (N*sumxpow - pow(sumx,2));
float B = (sumy - (m*sumx)) / N;
cout << m << "\n"<< B << endl;
}
else if (use == "func") {
}
} | # 0239, 2024-11-02 09:23:02, PPPPPPPPPP-------------- (41%)
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin>>N;
string use;
cin>>use;
vector<float> x;
vector<float> y;
if (use == "mb") {
float a,b;
float sumx = 0, sumy = 0, sumxy = 0, sumxpow = 0;
for (int i =0 ; i < N ; i++) {
cin>>a>>b;
sumx+=a;
sumy+=b;
sumxy+= a*b;
sumxpow+= pow(a,2);
}
float m = (N*sumxy) - (sumx*sumy);
m = m / (N*sumxpow - pow(sumx,2));
float B = (sumy - (m*sumx)) / N;
cout << round(m * 1e3)/1e3 << "\n"<< round(B * 1e3)/1e3 << endl;
}
else if (use == "func") {
}
} | # 0240, 2024-11-02 09:28:21, PPPPPPPPPPP-P----------- (50%)
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin>>N;
string use;
cin>>use;
vector<float> x;
vector<float> y;
float a,b;
float sumx = 0, sumy = 0, sumxy = 0, sumxpow = 0;
for (int i =0 ; i < N ; i++) {
cin>>a>>b;
sumx+=a;
sumy+=b;
sumxy+= a*b;
sumxpow+= pow(a,2);
}
float m = (N*sumxy) - (sumx*sumy);
m = m / (N*sumxpow - pow(sumx,2));
float B = (sumy - (m*sumx)) / N;
if (use == "mb") {
cout << round(m * 1e3)/1e3 << "\n"<< round(B * 1e3)/1e3 << endl;
}
else if (use =="func") {
cout << "y = ";
if (m == -1) {
cout << "-x ";
}
else if (m == 1) {
}
else {
cout << round(m * 1e3)/1e3 <<"x ";
}
if (B < 0) {
cout<< "- " << round(B * 1e3)/1e3;
}
else {
cout << "+ " << round(B * 1e3)/1e3;
}
cout<<"\n";
}
} | # 0241, 2024-11-02 09:29:40, PPPPPPPPPPPPPPP--------- (62%)
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin>>N;
string use;
cin>>use;
vector<float> x;
vector<float> y;
float a,b;
float sumx = 0, sumy = 0, sumxy = 0, sumxpow = 0;
for (int i =0 ; i < N ; i++) {
cin>>a>>b;
sumx+=a;
sumy+=b;
sumxy+= a*b;
sumxpow+= pow(a,2);
}
float m = (N*sumxy) - (sumx*sumy);
m = m / (N*sumxpow - pow(sumx,2));
float B = (sumy - (m*sumx)) / N;
if (use == "mb") {
cout << round(m * 1e3)/1e3 << "\n"<< round(B * 1e3)/1e3 << endl;
}
else if (use =="func") {
cout << "y = ";
if (m == -1) {
cout << "-x ";
}
else if (m == 1) {
}
else {
cout << round(m * 1e3)/1e3 <<"x ";
}
if (B < 0) {
cout<< "- " << abs(round(B * 1e3)/1e3);
}
else {
cout << "+ " << round(B * 1e3)/1e3;
}
cout<<"\n";
}
} | # 0242, 2024-11-02 09:32:09, Compilation error (0%)
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin>>N;
string use;
cin>>use;
vector<float> x;
vector<float> y;
float a,b;
float sumx = 0, sumy = 0, sumxy = 0, sumxpow = 0;
for (int i =0 ; i < N ; i++) {
cin>>a>>b;
sumx+=a;
sumy+=b;
sumxy+= a*b;
sumxpow+= pow(a,2);
}
float m = (N*sumxy) - (sumx*sumy);
m = m / (N*sumxpow - pow(sumx,2));
float B = (sumy - (m*sumx)) / N;
if (use == "mb") {
cout << round(m3 func
1.0 0.0
2.0 0.0
9.4 0.0e3)/1e3 << "\n"<< round(B * 1e3)/1e3 << endl;
}
else if (use =="func") {
cout << "y = ";
if (m == -1) {
cout << "-x ";
}
else if (m == 1) {
}
else if (m == 0 ) {
}
else {
cout << round(m * 1e3)/1e3 <<"x ";
}
if (B < 0) {
cout<< "- " << abs(round(B * 1e3)/1e3);
}
else if (B == 0) {
}
else {
cout << "+ " << round(B * 1e3)/1e3;
}
cout<<"\n";
}
} | # 0243, 2024-11-02 09:34:28, PPPPPPPPPPPPPPP----P---- (66%)
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin>>N;
string use;
cin>>use;
vector<float> x;
vector<float> y;
float a,b;
float sumx = 0, sumy = 0, sumxy = 0, sumxpow = 0;
for (int i =0 ; i < N ; i++) {
cin>>a>>b;
sumx+=a;
sumy+=b;
sumxy+= a*b;
sumxpow+= pow(a,2);
}
float m = (N*sumxy) - (sumx*sumy);
m = m / (N*sumxpow - pow(sumx,2));
float B = (sumy - (m*sumx)) / N;
if (use == "mb") {
cout << round(m * 1e3)/1e3 << "\n"<< round(B * 1e3)/1e3 << endl;
}
else if (use =="func") {
cout << "y = ";
if (m == -1) {
cout << "-x ";
}
else if (m == 1) {
}
else if (m == 0 ) {
}
else {
cout << round(m * 1e3)/1e3 <<"x ";
}
if (m == 0) {
}
else {
if (B < 0) {
cout << "- ";
}
else if (B > 0) {
cout << "+ ";
}
}
if (B < 0) {
cout<< abs(round(B * 1e3)/1e3);
}
else if (B == 0) {
}
else {
cout << round(B * 1e3)/1e3;
}
cout<<"\n";
}
} | # 0244, 2024-11-02 09:35:23, PPPPPPPPPPPPPPPP---P---- (70%)
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin>>N;
string use;
cin>>use;
vector<float> x;
vector<float> y;
float a,b;
float sumx = 0, sumy = 0, sumxy = 0, sumxpow = 0;
for (int i =0 ; i < N ; i++) {
cin>>a>>b;
sumx+=a;
sumy+=b;
sumxy+= a*b;
sumxpow+= pow(a,2);
}
float m = (N*sumxy) - (sumx*sumy);
m = m / (N*sumxpow - pow(sumx,2));
float B = (sumy - (m*sumx)) / N;
if (use == "mb") {
cout << round(m * 1e3)/1e3 << "\n"<< round(B * 1e3)/1e3 << endl;
}
else if (use =="func") {
cout << "y = ";
if (m == -1) {
cout << "-x ";
}
else if (m == 1) {
}
else if (m == 0 ) {
}
else {
cout << round(m * 1e3)/1e3 <<"x ";
}
if (m == 0) {
}
else {
if (B < 0) {
cout << "- ";
}
else if (B > 0) {
cout << "+ ";
}
}
if (B < 0) {
cout<< abs(round(B * 1e3)/1e3);
}
else if (B == 0) {
}
else {
cout << round(B * 1e3)/1e3;
}
if (m ==0 && B==0) {
cout<<"0";
}
cout<<"\n";
}
} | # 0245, 2024-11-02 09:42:08, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin>>N;
string use;
cin>>use;
vector<float> x;
vector<float> y;
float a,b;
float sumx = 0, sumy = 0, sumxy = 0, sumxpow = 0;
for (int i =0 ; i < N ; i++) {
cin>>a>>b;
sumx+=a;
sumy+=b;
sumxy+= a*b;
sumxpow+= pow(a,2);
}
float m = (N*sumxy) - (sumx*sumy);
m = m / (N*sumxpow - pow(sumx,2));
float B = (sumy - (m*sumx)) / N;
if (use == "mb") {
cout << round(m * 1e3)/1e3 << "\n"<< round(B * 1e3)/1e3 << endl;
}
else if (use =="func") {
cout << "y = ";
B = round(B * 1e3)/1e3;
if (round(m * 1e3)/1e3 == 0 && B ==0) {
cout << "0";
}
else if (B == 0) {
if (round(m * 1e3)/1e3 == 1) {
cout <<"x";
}
else if (round(m * 1e3)/1e3 == -1) {
cout << "-x";
}
else {
cout << round(m * 1e3)/1e3 <<"x";
}
}
else if (round(m * 1e3)/1e3 == 0) {
cout <<B;
}
else {
if (round(m * 1e3)/1e3 == 1) {
cout <<"x";
}
else if (round(m * 1e3)/1e3 == -1) {
cout << "-x";
}
else {
cout << round(m * 1e3)/1e3 <<"x";
}
cout << " ";
if (B > 0) {
cout << "+ " << B;
}
else if (B < 0) {
cout << "- " << abs(B);
}
}
cout<<"\n";
}
} |
# 0246, 2024-11-02 09:33:29, -----PPPPP-----P-PPPP--- (41%)
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
int n;
string func;
cin >> n >> func;
double xi, yi;
vector<vector<double>> data;
for(int i = 0; i < n; i++){
cin >> xi >> yi;
data.push_back({xi, yi});
}
double m = 0;
double b = 0;
if(func == "mb"){
double d = 0;
double e = 0;
double f = 0;
double g = 0;
double h = 0;
for(int i = 0 ; i < n; i++){
d += data[i][0] * data[i][1];
}
d = d * n;
for(int i = 0; i < n; i++){
e += data[i][0];
}
for(int i = 0; i < n; i++){
f += data[i][1];
}
for(int i = 0; i < n; i++){
g += data[i][0] * data[i][0];
}
g = g * n;
h = e * e;
m = (d - (e * f)) / (g - h);
b = (f - (m * e)) / n;
round(m * 1e3) / 1e3;
round(b * 1e3) / 1e3;
cout << m << endl << b;
}else if(func == "func"){
double d = 0;
double e = 0;
double f = 0;
double g = 0;
double h = 0;
for(int i = 0 ; i < n; i++){
d += data[i][0] * data[i][1];
}
d = d * n;
for(int i = 0; i < n; i++){
e += data[i][0];
}
for(int i = 0; i < n; i++){
f += data[i][1];
}
for(int i = 0; i < n; i++){
g += data[i][0] * data[i][0];
}
g = g * n;
h = e * e;
m = (d - (e * f)) / (g - h);
b = (f - (m * e)) / n;
round(m * 1e3) / 1e3;
round(b* 1e3) / 1e3;
if(m == -1){
cout << "y = -x";
if(b != 0){
cout << " + " << b;
}
}else if(m == 1){
cout << "y = x";
if(b != 0){
cout << " + " << b;
}
}else{
cout << "y = " << m;
if(b != 0){
cout << " + " << b;
}
}
}
} | # 0247, 2024-11-02 09:34:25, PPPPPPPPPP-----P-PPPP--- (62%)
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
int n;
string func;
cin >> n >> func;
double xi, yi;
vector<vector<double>> data;
for(int i = 0; i < n; i++){
cin >> xi >> yi;
data.push_back({xi, yi});
}
double m = 0;
double b = 0;
if(func == "mb"){
double d = 0;
double e = 0;
double f = 0;
double g = 0;
double h = 0;
for(int i = 0 ; i < n; i++){
d += data[i][0] * data[i][1];
}
d = d * n;
for(int i = 0; i < n; i++){
e += data[i][0];
}
for(int i = 0; i < n; i++){
f += data[i][1];
}
for(int i = 0; i < n; i++){
g += data[i][0] * data[i][0];
}
g = g * n;
h = e * e;
m = (d - (e * f)) / (g - h);
b = (f - (m * e)) / n;
m = round(m * 1e3) / 1e3;
b = round(b * 1e3) / 1e3;
cout << m << endl << b;
}else if(func == "func"){
double d = 0;
double e = 0;
double f = 0;
double g = 0;
double h = 0;
for(int i = 0 ; i < n; i++){
d += data[i][0] * data[i][1];
}
d = d * n;
for(int i = 0; i < n; i++){
e += data[i][0];
}
for(int i = 0; i < n; i++){
f += data[i][1];
}
for(int i = 0; i < n; i++){
g += data[i][0] * data[i][0];
}
g = g * n;
h = e * e;
m = (d - (e * f)) / (g - h);
b = (f - (m * e)) / n;
m = round(m * 1e3) / 1e3;
b = round(b* 1e3) / 1e3;
if(m == -1){
cout << "y = -x";
if(b != 0){
cout << " + " << b;
}
}else if(m == 1){
cout << "y = x";
if(b != 0){
cout << " + " << b;
}
}else{
cout << "y = " << m;
if(b != 0){
cout << " + " << b;
}
}
}
} | # 0248, 2024-11-02 09:38:39, PPPPPPPPPP-----P-PPP--PP (66%)
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
int n;
string func;
cin >> n >> func;
double xi, yi;
vector<vector<double>> data;
for(int i = 0; i < n; i++){
cin >> xi >> yi;
data.push_back({xi, yi});
}
double m = 0;
double b = 0;
if(func == "mb"){
double d = 0;
double e = 0;
double f = 0;
double g = 0;
double h = 0;
for(int i = 0 ; i < n; i++){
d += data[i][0] * data[i][1];
}
d = d * n;
for(int i = 0; i < n; i++){
e += data[i][0];
}
for(int i = 0; i < n; i++){
f += data[i][1];
}
for(int i = 0; i < n; i++){
g += data[i][0] * data[i][0];
}
g = g * n;
h = e * e;
m = (d - (e * f)) / (g - h);
b = (f - (m * e)) / n;
m = round(m * 1e3) / 1e3;
b = round(b * 1e3) / 1e3;
cout << m << endl << b;
}else if(func == "func"){
double d = 0;
double e = 0;
double f = 0;
double g = 0;
double h = 0;
for(int i = 0 ; i < n; i++){
d += data[i][0] * data[i][1];
}
d = d * n;
for(int i = 0; i < n; i++){
e += data[i][0];
}
for(int i = 0; i < n; i++){
f += data[i][1];
}
for(int i = 0; i < n; i++){
g += data[i][0] * data[i][0];
}
g = g * n;
h = e * e;
m = (d - (e * f)) / (g - h);
b = (f - (m * e)) / n;
m = round(m * 1e3) / 1e3;
b = round(b* 1e3) / 1e3;
if(m == -1){
cout << "y = -x";
if(b > 0){
cout << " - " << b;
}else if(b < 0){
cout << " - " << b * -1;
}
}else if(m == 1){
cout << "y = x";
if(b > 0){
cout << " + " << b;
}else if(b < 0){
cout << " - " << b * -1;
}
}else{
cout << "y = " << m;
if(b > 0){
cout << " + " << b;
}else if(b < 0){
cout << " - " << b * -1;
}
}
}
} | # 0249, 2024-11-02 09:40:41, PPPPPPPPPP-----P-PPPP-PP (70%)
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
int n;
string func;
cin >> n >> func;
double xi, yi;
vector<vector<double>> data;
for(int i = 0; i < n; i++){
cin >> xi >> yi;
data.push_back({xi, yi});
}
double m = 0;
double b = 0;
if(func == "mb"){
double d = 0;
double e = 0;
double f = 0;
double g = 0;
double h = 0;
for(int i = 0 ; i < n; i++){
d += data[i][0] * data[i][1];
}
d = d * n;
for(int i = 0; i < n; i++){
e += data[i][0];
}
for(int i = 0; i < n; i++){
f += data[i][1];
}
for(int i = 0; i < n; i++){
g += data[i][0] * data[i][0];
}
g = g * n;
h = e * e;
m = (d - (e * f)) / (g - h);
b = (f - (m * e)) / n;
m = round(m * 1e3) / 1e3;
b = round(b * 1e3) / 1e3;
cout << m << endl << b;
}else if(func == "func"){
double d = 0;
double e = 0;
double f = 0;
double g = 0;
double h = 0;
for(int i = 0 ; i < n; i++){
d += data[i][0] * data[i][1];
}
d = d * n;
for(int i = 0; i < n; i++){
e += data[i][0];
}
for(int i = 0; i < n; i++){
f += data[i][1];
}
for(int i = 0; i < n; i++){
g += data[i][0] * data[i][0];
}
g = g * n;
h = e * e;
m = (d - (e * f)) / (g - h);
b = (f - (m * e)) / n;
m = round(m * 1e3) / 1e3;
b = round(b* 1e3) / 1e3;
if(m == -1){
cout << "y = -x";
if(b > 0){
cout << " + " << b;
}else if(b < 0){
cout << " - " << b * -1;
}
}else if(m == 1){
cout << "y = x";
if(b > 0){
cout << " + " << b;
}else if(b < 0){
cout << " - " << b * -1;
}
}else{
cout << "y = " << m;
if(b > 0){
cout << " + " << b;
}else if(b < 0){
cout << " - " << b * -1;
}
}
}
} | # 0250, 2024-11-02 09:45:28, PPPPPPPPPP-----PPPPPPPPP (79%)
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
int n;
string func;
cin >> n >> func;
double xi, yi;
vector<vector<double>> data;
for(int i = 0; i < n; i++){
cin >> xi >> yi;
data.push_back({xi, yi});
}
double m = 0;
double b = 0;
if(func == "mb"){
double d = 0;
double e = 0;
double f = 0;
double g = 0;
double h = 0;
for(int i = 0 ; i < n; i++){
d += data[i][0] * data[i][1];
}
d = d * n;
for(int i = 0; i < n; i++){
e += data[i][0];
}
for(int i = 0; i < n; i++){
f += data[i][1];
}
for(int i = 0; i < n; i++){
g += data[i][0] * data[i][0];
}
g = g * n;
h = e * e;
m = (d - (e * f)) / (g - h);
b = (f - (m * e)) / n;
m = round(m * 1e3) / 1e3;
b = round(b * 1e3) / 1e3;
cout << m << endl << b;
}else if(func == "func"){
double d = 0;
double e = 0;
double f = 0;
double g = 0;
double h = 0;
for(int i = 0 ; i < n; i++){
d += data[i][0] * data[i][1];
}
d = d * n;
for(int i = 0; i < n; i++){
e += data[i][0];
}
for(int i = 0; i < n; i++){
f += data[i][1];
}
for(int i = 0; i < n; i++){
g += data[i][0] * data[i][0];
}
g = g * n;
h = e * e;
m = (d - (e * f)) / (g - h);
b = (f - (m * e)) / n;
m = round(m * 1e3) / 1e3;
b = round(b* 1e3) / 1e3;
if(m == -1){
cout << "y = -x";
if(b > 0){
cout << " + " << b;
}else if(b < 0){
cout << " - " << b * -1;
}
}else if(m == 1){
cout << "y = x";
if(b > 0){
cout << " + " << b;
}else if(b < 0){
cout << " - " << b * -1;
}
}else if(m == 0 && b != 0){
cout << "y = ";
if(b > 0){
cout << b;
}else if(b < 0){
cout << "-" << b * -1;
}
}else{
cout << "y = " << m;
if(b > 0){
cout << " + " << b;
}else if(b < 0){
cout << " - " << b * -1;
}
}
}
} | # 0251, 2024-11-02 09:48:46, PPPPPPPPPPPPPPP-PPPPPPPP (95%)
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
int n;
string func;
cin >> n >> func;
double xi, yi;
vector<vector<double>> data;
for(int i = 0; i < n; i++){
cin >> xi >> yi;
data.push_back({xi, yi});
}
double m = 0;
double b = 0;
if(func == "mb"){
double d = 0;
double e = 0;
double f = 0;
double g = 0;
double h = 0;
for(int i = 0 ; i < n; i++){
d += data[i][0] * data[i][1];
}
d = d * n;
for(int i = 0; i < n; i++){
e += data[i][0];
}
for(int i = 0; i < n; i++){
f += data[i][1];
}
for(int i = 0; i < n; i++){
g += data[i][0] * data[i][0];
}
g = g * n;
h = e * e;
m = (d - (e * f)) / (g - h);
b = (f - (m * e)) / n;
m = round(m * 1e3) / 1e3;
b = round(b * 1e3) / 1e3;
cout << m << endl << b;
}else if(func == "func"){
double d = 0;
double e = 0;
double f = 0;
double g = 0;
double h = 0;
for(int i = 0 ; i < n; i++){
d += data[i][0] * data[i][1];
}
d = d * n;
for(int i = 0; i < n; i++){
e += data[i][0];
}
for(int i = 0; i < n; i++){
f += data[i][1];
}
for(int i = 0; i < n; i++){
g += data[i][0] * data[i][0];
}
g = g * n;
h = e * e;
m = (d - (e * f)) / (g - h);
b = (f - (m * e)) / n;
m = round(m * 1e3) / 1e3;
b = round(b* 1e3) / 1e3;
if(m == -1){
cout << "y = -x";
if(b > 0){
cout << " + " << b;
}else if(b < 0){
cout << " - " << b * -1;
}
}else if(m == 1){
cout << "y = x";
if(b > 0){
cout << " + " << b;
}else if(b < 0){
cout << " - " << b * -1;
}
}else if(m == 0 && b != 0){
cout << "y = ";
if(b > 0){
cout << b;
}else if(b < 0){
cout << "-" << b * -1;
}
}else{
cout << "y = " << m << "x";
if(b > 0){
cout << " + " << b;
}else if(b < 0){
cout << " - " << b * -1;
}
}
}
} | # 0252, 2024-11-02 09:50:02, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
int n;
string func;
cin >> n >> func;
double xi, yi;
vector<vector<double>> data;
for(int i = 0; i < n; i++){
cin >> xi >> yi;
data.push_back({xi, yi});
}
double m = 0;
double b = 0;
if(func == "mb"){
double d = 0;
double e = 0;
double f = 0;
double g = 0;
double h = 0;
for(int i = 0 ; i < n; i++){
d += data[i][0] * data[i][1];
}
d = d * n;
for(int i = 0; i < n; i++){
e += data[i][0];
}
for(int i = 0; i < n; i++){
f += data[i][1];
}
for(int i = 0; i < n; i++){
g += data[i][0] * data[i][0];
}
g = g * n;
h = e * e;
m = (d - (e * f)) / (g - h);
b = (f - (m * e)) / n;
m = round(m * 1e3) / 1e3;
b = round(b * 1e3) / 1e3;
cout << m << endl << b;
}else if(func == "func"){
double d = 0;
double e = 0;
double f = 0;
double g = 0;
double h = 0;
for(int i = 0 ; i < n; i++){
d += data[i][0] * data[i][1];
}
d = d * n;
for(int i = 0; i < n; i++){
e += data[i][0];
}
for(int i = 0; i < n; i++){
f += data[i][1];
}
for(int i = 0; i < n; i++){
g += data[i][0] * data[i][0];
}
g = g * n;
h = e * e;
m = (d - (e * f)) / (g - h);
b = (f - (m * e)) / n;
m = round(m * 1e3) / 1e3;
b = round(b* 1e3) / 1e3;
if(m == -1){
cout << "y = -x";
if(b > 0){
cout << " + " << b;
}else if(b < 0){
cout << " - " << b * -1;
}
}else if(m == 1){
cout << "y = x";
if(b > 0){
cout << " + " << b;
}else if(b < 0){
cout << " - " << b * -1;
}
}else if(m == 0 && b != 0){
cout << "y = ";
if(b > 0){
cout << b;
}else if(b < 0){
cout << "-" << b * -1;
}
}else if(m == 0 && b == 0){
cout << "y = 0";
}else{
cout << "y = " << m << "x";
if(b > 0){
cout << " + " << b;
}else if(b < 0){
cout << " - " << b * -1;
}
}
}
} |
# 0253, 2024-11-02 13:08:45, ----------PPPPPP-------- (25%)
#include<bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t;
string fun;
float m,b,input1,input2;
cin>>t>>fun;
vector<float> x,y;
int N = t;
while (t--)
{
cin>>input1>>input2;
x.push_back(input1);
y.push_back(input2);
}
float sum1 = 0;
float sum2 = 0;
float sum3 = 0;
float sum4 = 0;
float sumy1 = 0;
float sumy2 = 0;
for(int i = 0 ; i < N ; i++) {
sum1 += x[i]*y[i];
sum2 += x[i];
sum3 += y[i];
sum4 += x[i]*x[i];
}
m = ((N*sum1) - (sum2*sum3))/((N*sum4)-(sum2*sum2));
for(int i = 0 ; i < N ; i++) {
sumy1 += y[i];
sumy2 += x[i];
}
b = (sumy1-(m*sumy2))/N;
if(fun == "mb") cout<<round(m * 1e3)/1e3<<round(b * 1e3)/1e3;
else cout<<"y = ";
if(b==0&&m==0) {cout<<0;
return 0;}
if(m==-1) cout<<"-x";
else if(m == 1) cout<<"x";
else if(m==0) cout<<"";
else cout<<round(m * 1e3)/1e3<<'x';
if(b < 0) cout<<" - "<<abs(round(b * 1e3)/1e3);
else cout<<" + "<<round(b * 1e3)/1e3;
return 0;
} | # 0254, 2024-11-02 13:09:09, ----------PPPPPP-------- (25%)
#include<bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t;
string fun;
float m,b,input1,input2;
cin>>t>>fun;
vector<float> x,y;
int N = t;
while (t--)
{
cin>>input1>>input2;
x.push_back(input1);
y.push_back(input2);
}
float sum1 = 0;
float sum2 = 0;
float sum3 = 0;
float sum4 = 0;
float sumy1 = 0;
float sumy2 = 0;
for(int i = 0 ; i < N ; i++) {
sum1 += x[i]*y[i];
sum2 += x[i];
sum3 += y[i];
sum4 += x[i]*x[i];
}
m = ((N*sum1) - (sum2*sum3))/((N*sum4)-(sum2*sum2));
for(int i = 0 ; i < N ; i++) {
sumy1 += y[i];
sumy2 += x[i];
}
b = (sumy1-(m*sumy2))/N;
if(fun == "mb") cout<<round(m * 1e3)/1e3<<round(b * 1e3)/1e3;
else {cout<<"y = ";
if(b==0&&m==0) {cout<<0;
return 0;}
if(m==-1) cout<<"-x";
else if(m == 1) cout<<"x";
else if(m==0) cout<<"";
else cout<<round(m * 1e3)/1e3<<'x';
if(b < 0) cout<<" - "<<abs(round(b * 1e3)/1e3);
else cout<<" + "<<round(b * 1e3)/1e3;
}
return 0;
} | # 0255, 2024-11-02 13:09:39, PPPPPPPPPPPPPPPP-------- (66%)
#include<bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t;
string fun;
float m,b,input1,input2;
cin>>t>>fun;
vector<float> x,y;
int N = t;
while (t--)
{
cin>>input1>>input2;
x.push_back(input1);
y.push_back(input2);
}
float sum1 = 0;
float sum2 = 0;
float sum3 = 0;
float sum4 = 0;
float sumy1 = 0;
float sumy2 = 0;
for(int i = 0 ; i < N ; i++) {
sum1 += x[i]*y[i];
sum2 += x[i];
sum3 += y[i];
sum4 += x[i]*x[i];
}
m = ((N*sum1) - (sum2*sum3))/((N*sum4)-(sum2*sum2));
for(int i = 0 ; i < N ; i++) {
sumy1 += y[i];
sumy2 += x[i];
}
b = (sumy1-(m*sumy2))/N;
if(fun == "mb") cout<<round(m * 1e3)/1e3<<'\n'<<round(b * 1e3)/1e3;
else {cout<<"y = ";
if(b==0&&m==0) {cout<<0;
return 0;}
if(m==-1) cout<<"-x";
else if(m == 1) cout<<"x";
else if(m==0) cout<<"";
else cout<<round(m * 1e3)/1e3<<'x';
if(b < 0) cout<<" - "<<abs(round(b * 1e3)/1e3);
else cout<<" + "<<round(b * 1e3)/1e3;
}
return 0;
} | # 0256, 2024-11-02 13:18:31, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t;
string fun;
float m,b,input1,input2;
cin>>t>>fun;
vector<float> x,y;
int N = t;
while (t--)
{
cin>>input1>>input2;
x.push_back(input1);
y.push_back(input2);
}
float sum1 = 0;
float sum2 = 0;
float sum3 = 0;
float sum4 = 0;
float sumy1 = 0;
float sumy2 = 0;
for(int i = 0 ; i < N ; i++) {
sum1 += x[i]*y[i];
sum2 += x[i];
sum3 += y[i];
sum4 += x[i]*x[i];
}
m = ((N*sum1) - (sum2*sum3))/((N*sum4)-(sum2*sum2));
for(int i = 0 ; i < N ; i++) {
sumy1 += y[i];
sumy2 += x[i];
}
b = (sumy1-(m*sumy2))/N;
if(fun == "mb") cout<<round(m * 1e3)/1e3<<'\n'<<round(b * 1e3)/1e3;
else {
if(m == 0 && b == 0) {
cout<<"y = 0";
return 0;
}
if(m == 0 && b!=0) {
cout<<"y = "<< round(b * 1e3)/1e3;
return 0;
}
if( m != 0 && b == 0) {
if(m == 1) {
cout<<"y = "<<"x";
return 0;
}
else if (m == -1) {
cout<<"y = "<<"-x";
return 0;
}
cout<<"y = "<<round(m * 1e3)/1e3;
return 0;
}
if(m == 0 && b != 0) {
cout<<"y = ";
cout<<round(b * 1e3)/1e3;
return 0;
}
cout<<"y = ";
if(m==-1) cout<<"-x ";
else if (m == 1) cout<<"x ";
else {
cout<<round(m * 1e3)/1e3<<"x ";}
if(b < 0) {cout<<"- ";
cout<<-1*round(b * 1e3)/1e3;
}
if(b>0) {
cout<<"+ ";
cout<<round(b * 1e3)/1e3;
}
}
return 0;
} | # 0257, 2024-11-02 13:20:53, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t;
string fun;
float m,b,input1,input2;
cin>>t>>fun;
vector<float> x,y;
int N = t;
while (t--)
{
cin>>input1>>input2;
x.push_back(input1);
y.push_back(input2);
}
float sum1 = 0;
float sum2 = 0;
float sum3 = 0;
float sum4 = 0;
float sumy1 = 0;
float sumy2 = 0;
for(int i = 0 ; i < N ; i++) {
sum1 += x[i]*y[i];
sum2 += x[i];
sum3 += y[i];
sum4 += x[i]*x[i];
}
m = ((N*sum1) - (sum2*sum3))/((N*sum4)-(sum2*sum2));
for(int i = 0 ; i < N ; i++) {
sumy1 += y[i];
sumy2 += x[i];
}
b = (sumy1-(m*sumy2))/N;
if(fun == "mb") cout<<round(m * 1e3)/1e3<<'\n'<<round(b * 1e3)/1e3;
else {
if(m == 0 && b == 0) {
cout<<"y = 0";
return 0;
}
if(m == 0 && b!=0) {
cout<<"y = "<< round(b * 1e3)/1e3;
return 0;
}
if( m != 0 && b == 0) {
if(m == 1) {
cout<<"y = "<<"x";
return 0;
}
else if (m == -1) {
cout<<"y = "<<"-x";
return 0;
}
cout<<"y = "<<round(m * 1e3)/1e3;
return 0;
}
if(m == 0 && b != 0) {
cout<<"y = ";
cout<<round(b * 1e3)/1e3;
return 0;
}
cout<<"y = ";
if(m==-1) cout<<"-x ";
else if (m == 1) cout<<"x ";
else {
cout<<round(m * 1e3)/1e3<<"x ";}
if(b < 0) {cout<<"- ";
cout<<-1*round(b * 1e3)/1e3;
}
if(b>0) {
cout<<"+ ";
cout<<round(b * 1e3)/1e3;
}
}
return 0;
} | # 0258, 2024-11-02 13:23:06, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t;
string fun;
float m,b,input1,input2;
cin>>t>>fun;
vector<float> x,y;
int N = t;
while (t--)
{
cin>>input1>>input2;
x.push_back(input1);
y.push_back(input2);
}
float sum1 = 0;
float sum2 = 0;
float sum3 = 0;
float sum4 = 0;
float sumy1 = 0;
float sumy2 = 0;
for(int i = 0 ; i < N ; i++) {
sum1 += x[i]*y[i];
sum2 += x[i];
sum3 += y[i];
sum4 += x[i]*x[i];
}
m = ((N*sum1) - (sum2*sum3))/((N*sum4)-(sum2*sum2));
for(int i = 0 ; i < N ; i++) {
sumy1 += y[i];
sumy2 += x[i];
}
b = (sumy1-(m*sumy2))/N;
if(fun == "mb") cout<<round(m * 1e3)/1e3<<'\n'<<round(b * 1e3)/1e3;
else {
if(abs(m) == 0 && abs(b) == 0) {
cout<<"y = 0";
return 0;
}
if(abs(m) == 0 && b!=0) {
cout<<"y = "<< round(b * 1e3)/1e3;
return 0;
}
if( abs(m) != 0 && abs(b) == 0) {
if(m == 1) {
cout<<"y = "<<"x";
return 0;
}
else if (m == -1) {
cout<<"y = "<<"-x";
return 0;
}
cout<<"y = "<<round(m * 1e3)/1e3;
return 0;
}
if(abs(m) == 0 && abs(b) != 0) {
cout<<"y = ";
cout<<round(b * 1e3)/1e3;
return 0;
}
cout<<"y = ";
if(m==-1) cout<<"-x ";
else if (m == 1) cout<<"x ";
else {
cout<<round(m * 1e3)/1e3<<"x ";}
if(b < 0) {cout<<"- ";
cout<<-1*round(b * 1e3)/1e3;
}
if(b>0) {
cout<<"+ ";
cout<<round(b * 1e3)/1e3;
}
}
return 0;
} | # 0259, 2024-11-02 13:26:03, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t;
string fun;
float m,b,input1,input2;
cin>>t>>fun;
vector<float> x,y;
int N = t;
while (t--)
{
cin>>input1>>input2;
x.push_back(input1);
y.push_back(input2);
}
float sum1 = 0;
float sum2 = 0;
float sum3 = 0;
float sum4 = 0;
float sumy1 = 0;
float sumy2 = 0;
for(int i = 0 ; i < N ; i++) {
sum1 += x[i]*y[i];
sum2 += x[i];
sum3 += y[i];
sum4 += x[i]*x[i];
}
m = ((N*sum1) - (sum2*sum3))/((N*sum4)-(sum2*sum2));
for(int i = 0 ; i < N ; i++) {
sumy1 += y[i];
sumy2 += x[i];
}
b = (sumy1-(m*sumy2))/N;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if(fun == "mb") cout<<round(m * 1e3)/1e3<<'\n'<<round(b * 1e3)/1e3;
else {
if(abs(m) == 0 && abs(b) == 0 ) {
cout<<"y = 0";
return 0;
}
if(abs(m) == 0 && b!=0 || m == -0 && b!=0) {
cout<<"y = "<< round(b * 1e3)/1e3;
return 0;
}
if( abs(m) != 0 && abs(b) == 0) {
if(m == 1) {
cout<<"y = "<<"x";
return 0;
}
else if (m == -1) {
cout<<"y = "<<"-x";
return 0;
}
cout<<"y = "<<round(m * 1e3)/1e3;
return 0;
}
if(abs(m) == 0 && abs(b) != 0) {
cout<<"y = ";
cout<<round(b * 1e3)/1e3;
return 0;
}
cout<<"y = ";
if(m==-1) cout<<"-x ";
else if (m == 1) cout<<"x ";
else {
cout<<round(m * 1e3)/1e3<<"x ";}
if(b < 0) {cout<<"- ";
cout<<-1*round(b * 1e3)/1e3;
}
if(b>0) {
cout<<"+ ";
cout<<round(b * 1e3)/1e3;
}
}
return 0;
} |
# 0260, 2024-11-02 13:24:32, ------------------------ (0%)
#include <bits/stdc++.h>
using namespace std;
int main(){
float n;
float x,y,m,b;
string s;
float sumxy = 0;
float sumx = 0;
float sumy = 0;
float sumxsq = 0;
cin >> n >> s;
for(int i = 0; i < n; i++){
cin >> x >> y;
sumxy += x*y;
sumx += x;
sumy += y;
sumxsq += x*x;
}
cout << "sumx = " << sumx << endl;
cout << "sumxy = " << sumxy<< endl;
cout << "sumy = " << sumy << endl;
cout << "sumxsq = " << sumxsq << endl;
m = (n*(sumxy) - sumx*sumy)/((n*sumxsq)-(sumx*sumx));
b = (sumy-(m*sumx))/n;
cout << m;
if(s == "mb"){
cout << "m =" << round(m*1e3)/1e3 << endl;
cout << "b = " << round(b*1e3)/1e3 << endl;
}
else if (s == "func"){
cout << "y = ";
if(round(m*1e3)/1e3 == 1){
cout << "x";
}
else if(round(m*1e3)/1e3 == -1){
cout << "-x";
}
else if(round(m*1e3)/1e3 == 0){
cout << "0";
}
if(round(b*1e3)/1e3 > 0){
cout << " + " << round(b*1e3)/1e3;
}
else if(round(b*1e3)/1e3 < 0){
cout << " - " << round(b*1e3)/1e3;
}
}
} | # 0261, 2024-11-02 13:25:10, ------------------------ (0%)
#include <bits/stdc++.h>
using namespace std;
int main(){
float n;
float x,y,m,b;
string s;
float sumxy = 0;
float sumx = 0;
float sumy = 0;
float sumxsq = 0;
cin >> n >> s;
for(int i = 0; i < n; i++){
cin >> x >> y;
sumxy += x*y;
sumx += x;
sumy += y;
sumxsq += x*x;
}
m = (n*(sumxy) - sumx*sumy)/((n*sumxsq)-(sumx*sumx));
b = (sumy-(m*sumx))/n;
cout << m;
if(s == "mb"){
cout << "m =" << round(m*1e3)/1e3 << endl;
cout << "b = " << round(b*1e3)/1e3 << endl;
}
else if (s == "func"){
cout << "y = ";
if(round(m*1e3)/1e3 == 1){
cout << "x";
}
else if(round(m*1e3)/1e3 == -1){
cout << "-x";
}
else if(round(m*1e3)/1e3 == 0){
cout << "0";
}
if(round(b*1e3)/1e3 > 0){
cout << " + " << round(b*1e3)/1e3;
}
else if(round(b*1e3)/1e3 < 0){
cout << " - " << round(b*1e3)/1e3;
}
}
} | # 0262, 2024-11-02 13:25:38, ---------------P-PPPP--- (20%)
#include <bits/stdc++.h>
using namespace std;
int main(){
float n;
float x,y,m,b;
string s;
float sumxy = 0;
float sumx = 0;
float sumy = 0;
float sumxsq = 0;
cin >> n >> s;
for(int i = 0; i < n; i++){
cin >> x >> y;
sumxy += x*y;
sumx += x;
sumy += y;
sumxsq += x*x;
}
m = (n*(sumxy) - sumx*sumy)/((n*sumxsq)-(sumx*sumx));
b = (sumy-(m*sumx))/n;
if(s == "mb"){
cout << "m =" << round(m*1e3)/1e3 << endl;
cout << "b = " << round(b*1e3)/1e3 << endl;
}
else if (s == "func"){
cout << "y = ";
if(round(m*1e3)/1e3 == 1){
cout << "x";
}
else if(round(m*1e3)/1e3 == -1){
cout << "-x";
}
else if(round(m*1e3)/1e3 == 0){
cout << "0";
}
if(round(b*1e3)/1e3 > 0){
cout << " + " << round(b*1e3)/1e3;
}
else if(round(b*1e3)/1e3 < 0){
cout << " - " << round(b*1e3)/1e3;
}
}
} | # 0263, 2024-11-02 13:27:50, ----------PPPPPP-PPPP-PP (50%)
#include <bits/stdc++.h>
using namespace std;
int main(){
float n;
float x,y,m,b;
string s;
float sumxy = 0;
float sumx = 0;
float sumy = 0;
float sumxsq = 0;
cin >> n >> s;
for(int i = 0; i < n; i++){
cin >> x >> y;
sumxy += x*y;
sumx += x;
sumy += y;
sumxsq += x*x;
}
m = (n*(sumxy) - sumx*sumy)/((n*sumxsq)-(sumx*sumx));
b = (sumy-(m*sumx))/n;
if(s == "mb"){
cout << "m =" << round(m*1e3)/1e3 << endl;
cout << "b = " << round(b*1e3)/1e3 << endl;
}
else if (s == "func"){
cout << "y = ";
if(round(m*1e3)/1e3 == 1){
cout << "x";
}
else if(round(m*1e3)/1e3 == -1){
cout << "-x";
}
else if(round(m*1e3)/1e3 == 0){
cout << "0";
}
else{
cout << round(m*1e3)/1e3 << "x";
}
if(round(b*1e3)/1e3 > 0){
cout << " + " << round(b*1e3)/1e3;
}
else if(round(b*1e3)/1e3 < 0){
cout << " - " << abs(round(b*1e3))/1e3;
}
}
} | # 0264, 2024-11-02 13:28:46, PPPPPPPPPPPPPPPP-PPPP-PP (91%)
#include <bits/stdc++.h>
using namespace std;
int main(){
float n;
float x,y,m,b;
string s;
float sumxy = 0;
float sumx = 0;
float sumy = 0;
float sumxsq = 0;
cin >> n >> s;
for(int i = 0; i < n; i++){
cin >> x >> y;
sumxy += x*y;
sumx += x;
sumy += y;
sumxsq += x*x;
}
m = (n*(sumxy) - sumx*sumy)/((n*sumxsq)-(sumx*sumx));
b = (sumy-(m*sumx))/n;
if(s == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if (s == "func"){
cout << "y = ";
if(round(m*1e3)/1e3 == 1){
cout << "x";
}
else if(round(m*1e3)/1e3 == -1){
cout << "-x";
}
else if(round(m*1e3)/1e3 == 0){
cout << "0";
}
else{
cout << round(m*1e3)/1e3 << "x";
}
if(round(b*1e3)/1e3 > 0){
cout << " + " << round(b*1e3)/1e3;
}
else if(round(b*1e3)/1e3 < 0){
cout << " - " << abs(round(b*1e3))/1e3;
}
}
} | # 0265, 2024-11-02 15:05:31, PPPPPPPPPPPPPPP--PPPP-PP (87%)
#include <bits/stdc++.h>
using namespace std;
int main(){
float n;
float x,y,m,b;
string s;
float sumxy = 0;
float sumx = 0;
float sumy = 0;
float sumxsq = 0;
cin >> n >> s;
for(int i = 0; i < n; i++){
cin >> x >> y;
sumxy += x*y;
sumx += x;
sumy += y;
sumxsq += x*x;
}
m = (n*(sumxy) - sumx*sumy)/((n*sumxsq)-(sumx*sumx));
b = (sumy-(m*sumx))/n;
if(s == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if (s == "func"){
cout << "y = ";
if(round(m*1e3)/1e3 == 1){
cout << "x";
}
else if(round(m*1e3)/1e3 == -1){
cout << "-x";
}
else if(round(m*1e3)/1e3 == 0){
if(round(b*1e3)/1e3 != 0){
cout <<"";
}
else {
cout << "0";
}
}
else{
cout << round(m*1e3)/1e3 << "x";
}
if(round(b*1e3)/1e3 > 0){
cout << " + " << round(b*1e3)/1e3;
}
else if(round(b*1e3)/1e3 < 0){
cout << " - " << abs(round(b*1e3))/1e3;
}
else if(round(m*1e3)/1e3 == 0){
cout << round(b*1e3)/1e3;
}
}
} | # 0266, 2024-11-02 15:08:08, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
int main(){
float n;
float x,y,m,b;
string s;
float sumxy = 0;
float sumx = 0;
float sumy = 0;
float sumxsq = 0;
cin >> n >> s;
for(int i = 0; i < n; i++){
cin >> x >> y;
sumxy += x*y;
sumx += x;
sumy += y;
sumxsq += x*x;
}
m = (n*(sumxy) - sumx*sumy)/((n*sumxsq)-(sumx*sumx));
b = (sumy-(m*sumx))/n;
if(s == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if (s == "func"){
cout << "y = ";
if(round(m*1e3)/1e3 == 1){
cout << "x";
}
else if(round(m*1e3)/1e3 == -1){
cout << "-x";
}
else if(round(m*1e3)/1e3 == 0){
if(round(b*1e3)/1e3 != 0){
cout <<round(b*1e3)/1e3 ;
}
else {
cout << "0";
}
}
else{
cout << round(m*1e3)/1e3 << "x";
}
if(round(b*1e3)/1e3 > 0 && round(m*1e3)/1e3 != 0){
cout << " + " << round(b*1e3)/1e3;
}
else if(round(b*1e3)/1e3 < 0 && round(m*1e3)/1e3 != 0){
cout << " - " << abs(round(b*1e3))/1e3;
}
}
} |
# 0267, 2024-11-02 09:48:26, PPPPPPPPPPP-P--P--P----- (58%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
string s;
cin >> n >> s;
float sumX, sumY, sumXY, sumX2;
sumX = sumY = sumXY = sumX2 = 0;
float x, y;
for(int i = 0; i < n ; i++){
cin >> x >> y;
sumX += x;
sumY += y;
sumXY += (x * y);
sumX2 += (x * x);
}
float m, b;
m = (n * sumXY - sumX * sumY) / (n * sumX2 - sumX * sumX);\
b = (sumY - m * sumX) / n;
if(s == "mb") cout << round(m * 1e3)/1e3 << endl << round(b * 1e3)/1e3;
if(s == "mb") return 0;
cout << "y = ";
if(m == 0.0 && b == 0.0) cout << 0;
else{
if(m != 1.0 && m != -1.0) cout << round(m * 1e3)/1e3 << "x";
else cout << "x";
if(b != 0.0) cout << " + " << round(b * 1e3)/1e3;
}
return 0;
} | # 0268, 2024-11-02 09:48:37, PPPPPPPPPPP-P--P--P----- (58%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
string s;
cin >> n >> s;
float sumX, sumY, sumXY, sumX2;
sumX = sumY = sumXY = sumX2 = 0;
float x, y;
for(int i = 0; i < n ; i++){
cin >> x >> y;
sumX += x;
sumY += y;
sumXY += (x * y);
sumX2 += (x * x);
}
float m, b;
m = (n * sumXY - sumX * sumY) / (n * sumX2 - sumX * sumX);\
b = (sumY - m * sumX) / n;
if(s == "mb") cout << round(m * 1e3)/1e3 << endl << round(b * 1e3)/1e3;
if(s == "mb") return 0;
cout << "y = ";
if(m == 0.0 && b == 0.0) cout << 0;
else{
if(m != 1.0 && m != -1.0) cout << round(m * 1e3)/1e3 << "x";
else cout << "x";
if(b != 0.0) cout << " + " << round(b * 1e3)/1e3;
}
return 0;
} | # 0269, 2024-11-02 09:57:21, PPPPPPPPPPP-P--PP----P-- (62%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
string s;
cin >> n >> s;
float sumX, sumY, sumXY, sumX2;
sumX = sumY = sumXY = sumX2 = 0;
float x, y;
for(int i = 0; i < n ; i++){
cin >> x >> y;
sumX += x;
sumY += y;
sumXY += (x * y);
sumX2 += (x * x);
}
float m, b;
m = (n * sumXY - sumX * sumY) / (n * sumX2 - sumX * sumX);\
b = (sumY - m * sumX) / n;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if(s == "mb") cout << round(m * 1e3)/1e3 << endl << round(b * 1e3)/1e3;
if(s == "mb") return 0;
cout << "y = ";
if(m == 0.0 && b == 0.0) cout << 0;
else{
bool have = false;
if(m != 1.0 && m != -1.0 && (m > 0 || m < 0)) {
cout << round(m * 1e3)/1e3 << "x";
have = true;
}
else if(m != 0.0) {
cout << x;
have = true;
}
if(b != 0.0 && have) cout << " + " << round(b * 1e3)/1e3;
else cout << round(b * 1e3)/1e3;
}
return 0;
} | # 0270, 2024-11-02 09:59:37, PPPPPPPPPPPPPPPPP----P-- (75%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
string s;
cin >> n >> s;
float sumX, sumY, sumXY, sumX2;
sumX = sumY = sumXY = sumX2 = 0;
float x, y;
for(int i = 0; i < n ; i++){
cin >> x >> y;
sumX += x;
sumY += y;
sumXY += (x * y);
sumX2 += (x * x);
}
float m, b;
m = (n * sumXY - sumX * sumY) / (n * sumX2 - sumX * sumX);\
b = (sumY - m * sumX) / n;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if(s == "mb") cout << round(m * 1e3)/1e3 << endl << round(b * 1e3)/1e3;
if(s == "mb") return 0;
cout << "y = ";
if(m == 0.0 && b == 0.0) cout << 0;
else{
bool have = false;
if(m != 1.0 && m != -1.0 && (m > 0 || m < 0)) {
cout << round(m * 1e3)/1e3 << "x";
have = true;
}
else if(m != 0.0) {
cout << x;
have = true;
}
if(b > 0 && have) cout << " + " << round(b * 1e3)/1e3;
else if(b < 0 && have) cout << " - " << -1 * round(b * 1e3)/1e3;
else cout << round(b * 1e3)/1e3;
}
return 0;
} | # 0271, 2024-11-02 10:01:17, PPPPPPPPPPPPPPPPPP---PP- (83%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
string s;
cin >> n >> s;
float sumX, sumY, sumXY, sumX2;
sumX = sumY = sumXY = sumX2 = 0;
float x, y;
for(int i = 0; i < n ; i++){
cin >> x >> y;
sumX += x;
sumY += y;
sumXY += (x * y);
sumX2 += (x * x);
}
float m, b;
m = (n * sumXY - sumX * sumY) / (n * sumX2 - sumX * sumX);\
b = (sumY - m * sumX) / n;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if(s == "mb") cout << round(m * 1e3)/1e3 << endl << round(b * 1e3)/1e3;
if(s == "mb") return 0;
cout << "y = ";
if(m == 0.0 && b == 0.0) cout << 0;
else{
bool have = false;
if(m != 1.0 && m != -1.0 && (m > 0 || m < 0)) {
cout << round(m * 1e3)/1e3 << "x";
have = true;
}
else if(m != 0.0) {
cout << "x";
have = true;
}
if(b > 0 && have) cout << " + " << round(b * 1e3)/1e3;
else if(b < 0 && have) cout << " - " << -1 * round(b * 1e3)/1e3;
else cout << round(b * 1e3)/1e3;
}
return 0;
} | # 0272, 2024-11-02 10:02:39, PPPPPPPPPPPPPPPPPP--PPPP (91%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
string s;
cin >> n >> s;
float sumX, sumY, sumXY, sumX2;
sumX = sumY = sumXY = sumX2 = 0;
float x, y;
for(int i = 0; i < n ; i++){
cin >> x >> y;
sumX += x;
sumY += y;
sumXY += (x * y);
sumX2 += (x * x);
}
float m, b;
m = (n * sumXY - sumX * sumY) / (n * sumX2 - sumX * sumX);\
b = (sumY - m * sumX) / n;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if(s == "mb") cout << round(m * 1e3)/1e3 << endl << round(b * 1e3)/1e3;
if(s == "mb") return 0;
cout << "y = ";
if(m == 0.0 && b == 0.0) cout << 0;
else{
bool have = false;
if(m != 1.0 && m != -1.0 && (m > 0 || m < 0)) {
cout << round(m * 1e3)/1e3 << "x";
have = true;
}
else if(m != 0.0) {
if(m < 0) cout <<"-";
cout << "x";
have = true;
}
if(b > 0 && have) cout << " + " << round(b * 1e3)/1e3;
else if(b < 0 && have) cout << " - " << -1 * round(b * 1e3)/1e3;
else cout << round(b * 1e3)/1e3;
}
return 0;
} | # 0273, 2024-11-02 10:04:18, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
string s;
cin >> n >> s;
float sumX, sumY, sumXY, sumX2;
sumX = sumY = sumXY = sumX2 = 0;
float x, y;
for(int i = 0; i < n ; i++){
cin >> x >> y;
sumX += x;
sumY += y;
sumXY += (x * y);
sumX2 += (x * x);
}
float m, b;
m = (n * sumXY - sumX * sumY) / (n * sumX2 - sumX * sumX);\
b = (sumY - m * sumX) / n;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if(s == "mb") cout << round(m * 1e3)/1e3 << endl << round(b * 1e3)/1e3;
if(s == "mb") return 0;
cout << "y = ";
if(m == 0.0 && b == 0.0) cout << 0;
else{
bool have = false;
if(m != 1.0 && m != -1.0 && (m > 0 || m < 0)) {
cout << round(m * 1e3)/1e3 << "x";
have = true;
}
else if(m != 0.0) {
if(m < 0) cout <<"-";
cout << "x";
have = true;
}
if(b > 0 && have) cout << " + " << round(b * 1e3)/1e3;
else if(b < 0 && have) cout << " - " << -1 * round(b * 1e3)/1e3;
else if(b != 0.0) cout << round(b * 1e3)/1e3;
}
return 0;
} |
# 0274, 2024-11-02 09:57:14, PPPPPPPPPP-------------- (41%)
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
int main(){
int n;
string cmd;
cin >> n >> cmd;
vector<pair<float, float>> v1;
for(int i = 0; i < n; i++){
pair<float, float> tP;
cin >> tP.first >> tP.second;
v1.push_back(tP);
}
//v1[i].first
//v1[i].second
float m;
float m1 = 0;
float m2 = 0;
float m3 = 0;
float m4 = 0;
float m5 = 0;
float b;
float b1 = 0;
float b2 = 0;
for(int i = 0; i < n; i++){
m1 += v1[i].first * v1[i].second;
m2 += v1[i].first;
m3 += v1[i].second;
m4 += v1[i].first * v1[i].first;
m5 = m2;
b1 = m3;
b2 = m2;
}
// cout << m1 << " " << m2 << " " << m3 << " " << m4 << " " << m5 << endl;
// cout << (n*m1) << endl;
// cout << (m2*m3) << endl;
// cout << (n*m4) << endl;
// cout << (m5*m5) << endl;
float down = (n*m4) - (m5*m5);
m = ((n*m1) - (m2*m3))/down;
b = (b1 - (m*b2)) / n;
// for(auto a : v1){
// cout << a.first << " " << a.second << endl;
// }
if(cmd == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if(cmd == "func"){
}
return 0;
} | # 0275, 2024-11-02 10:07:20, PPPPPPPPPP-------PPP---- (54%)
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
int main(){
int n;
string cmd;
cin >> n >> cmd;
vector<pair<float, float>> v1;
for(int i = 0; i < n; i++){
pair<float, float> tP;
cin >> tP.first >> tP.second;
v1.push_back(tP);
}
//v1[i].first
//v1[i].second
float m;
float m1 = 0;
float m2 = 0;
float m3 = 0;
float m4 = 0;
float m5 = 0;
float b;
float b1 = 0;
float b2 = 0;
for(int i = 0; i < n; i++){
m1 += v1[i].first * v1[i].second;
m2 += v1[i].first;
m3 += v1[i].second;
m4 += v1[i].first * v1[i].first;
m5 = m2;
b1 = m3;
b2 = m2;
}
// cout << m1 << " " << m2 << " " << m3 << " " << m4 << " " << m5 << endl;
// cout << (n*m1) << endl;
// cout << (m2*m3) << endl;
// cout << (n*m4) << endl;
// cout << (m5*m5) << endl;
float down = (n*m4) - (m5*m5);
m = ((n*m1) - (m2*m3))/down;
b = (b1 - (m*b2)) / n;
// for(auto a : v1){
// cout << a.first << " " << a.second << endl;
// }
if(cmd == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if(cmd == "func"){
cout << "y = ";
if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 != 0){
cout << "x + " << b;
}
else if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 == 0){
cout << "x";
}
else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 != 0){
cout << "-x + " << b;
}
else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 == 0){
cout << "-x";
}
else if(round(m*1e3)/1e3 == 0 && round(b*1e3)/1e3 != 0){
cout << m;
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 == 0){
cout << b;
}
else{
cout << m << "x + " << b ;
}
cout << endl;
}
return 0;
} | # 0276, 2024-11-02 10:12:04, PPPPPPPPPPP-P--PPPPPPP-- (79%)
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
int main(){
int n;
string cmd;
cin >> n >> cmd;
vector<pair<float, float>> v1;
for(int i = 0; i < n; i++){
pair<float, float> tP;
cin >> tP.first >> tP.second;
v1.push_back(tP);
}
//v1[i].first
//v1[i].second
float m;
float m1 = 0;
float m2 = 0;
float m3 = 0;
float m4 = 0;
float m5 = 0;
float b;
float b1 = 0;
float b2 = 0;
for(int i = 0; i < n; i++){
m1 += v1[i].first * v1[i].second;
m2 += v1[i].first;
m3 += v1[i].second;
m4 += v1[i].first * v1[i].first;
m5 = m2;
b1 = m3;
b2 = m2;
}
// cout << m1 << " " << m2 << " " << m3 << " " << m4 << " " << m5 << endl;
// cout << (n*m1) << endl;
// cout << (m2*m3) << endl;
// cout << (n*m4) << endl;
// cout << (m5*m5) << endl;
float down = (n*m4) - (m5*m5);
m = ((n*m1) - (m2*m3))/down;
b = (b1 - (m*b2)) / n;
// for(auto a : v1){
// cout << a.first << " " << a.second << endl;
// }
if(cmd == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if(cmd == "func"){
cout << "y = ";
if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 != 0){
cout << "x + " << round(b*1e3)/1e3;
}
else if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 == 0){
cout << "x";
}
else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 != 0){
cout << "-x + " << round(b*1e3)/1e3;
}
else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 == 0){
cout << "-x";
}
else if(round(m*1e3)/1e3 == 0 && round(b*1e3)/1e3 != 0){
cout << round(b*1e3)/1e3;
}
else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 == 0){
cout << round(m*1e3)/1e3;
}
else if(round(m*1e3)/1e3 == 0 && round(b*1e3)/1e3 == 0){
cout << 0;
}
else{
cout << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3; ;
}
cout << endl;
}
return 0;
} | # 0277, 2024-11-02 10:23:31, PPPPPPPPPPP-P--P-PPPP--- (70%)
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
int main(){
int n;
string cmd;
cin >> n >> cmd;
vector<pair<float, float>> v1;
for(int i = 0; i < n; i++){
pair<float, float> tP;
cin >> tP.first >> tP.second;
v1.push_back(tP);
}
//v1[i].first
//v1[i].second
float m;
float m1 = 0;
float m2 = 0;
float m3 = 0;
float m4 = 0;
float m5 = 0;
float b;
float b1 = 0;
float b2 = 0;
for(int i = 0; i < n; i++){
m1 += v1[i].first * v1[i].second;
m2 += v1[i].first;
m3 += v1[i].second;
m4 += v1[i].first * v1[i].first;
m5 = m2;
b1 = m3;
b2 = m2;
}
// cout << m1 << " " << m2 << " " << m3 << " " << m4 << " " << m5 << endl;
// cout << (n*m1) << endl;
// cout << (m2*m3) << endl;
// cout << (n*m4) << endl;
// cout << (m5*m5) << endl;
float down = (n*m4) - (m5*m5);
m = ((n*m1) - (m2*m3))/down;
b = (b1 - (m*b2)) / n;
if(cmd == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if(cmd == "func"){
cout << "y = ";
// if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 != 0){
// cout << "x + " << round(b*1e3)/1e3;
// }
// else if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 == 0){
// cout << "x";
// }
// else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 != 0){
// cout << "-x + " << round(b*1e3)/1e3;
// }
// else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 == 0){
// cout << "-x";
// }
// else if(round(m*1e3)/1e3 == 0 && round(b*1e3)/1e3 != 0){
// cout << round(b*1e3)/1e3;
// }
// else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 == 0){
// cout << round(m*1e3)/1e3;
// }
// else if(round(m*1e3)/1e3 == 0 && round(b*1e3)/1e3 == 0){
// cout << 0;
// }
// else{
// cout << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3; ;
// }
if(round(m*1e3)/1e3 == 1){
cout << "x";
}
else if(round(m*1e3)/1e3 == -1){
cout << "-x";
}
else if(round(m*1e3)/1e3 == 0){
cout << "0";
}
else{
cout << round(m*1e3)/1e3 << "x";
}
if(round(b*1e3)/1e3 == 0){
//if(round(m*1e3)/1e3 == 0);
}
else{
cout << " + " << round(b*1e3)/1e3;
}
cout << endl;
}
return 0;
} | # 0278, 2024-11-02 10:25:46, PPPPPPPPPPP-P--PPPPPPP-- (79%)
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
int main(){
int n;
string cmd;
cin >> n >> cmd;
vector<pair<float, float>> v1;
for(int i = 0; i < n; i++){
pair<float, float> tP;
cin >> tP.first >> tP.second;
v1.push_back(tP);
}
//v1[i].first
//v1[i].second
float m;
float m1 = 0;
float m2 = 0;
float m3 = 0;
float m4 = 0;
float m5 = 0;
float b;
float b1 = 0;
float b2 = 0;
for(int i = 0; i < n; i++){
m1 += v1[i].first * v1[i].second;
m2 += v1[i].first;
m3 += v1[i].second;
m4 += v1[i].first * v1[i].first;
m5 = m2;
b1 = m3;
b2 = m2;
}
// cout << m1 << " " << m2 << " " << m3 << " " << m4 << " " << m5 << endl;
// cout << (n*m1) << endl;
// cout << (m2*m3) << endl;
// cout << (n*m4) << endl;
// cout << (m5*m5) << endl;
float down = (n*m4) - (m5*m5);
m = ((n*m1) - (m2*m3))/down;
b = (b1 - (m*b2)) / n;
if(cmd == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if(cmd == "func"){
cout << "y = ";
// if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 != 0){
// cout << "x + " << round(b*1e3)/1e3;
// }
// else if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 == 0){
// cout << "x";
// }
// else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 != 0){
// cout << "-x + " << round(b*1e3)/1e3;
// }
// else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 == 0){
// cout << "-x";
// }
// else if(round(m*1e3)/1e3 == 0 && round(b*1e3)/1e3 != 0){
// cout << round(b*1e3)/1e3;
// }
// else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 == 0){
// cout << round(m*1e3)/1e3;
// }
// else if(round(m*1e3)/1e3 == 0 && round(b*1e3)/1e3 == 0){
// cout << 0;
// }
// else{
// cout << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3; ;
// }
if(round(m*1e3)/1e3 == 1){
cout << "x";
}
else if(round(m*1e3)/1e3 == -1){
cout << "-x";
}
else if(round(m*1e3)/1e3 == 0 && round(b*1e3)/1e3 != 0){
}
else if(round(m*1e3)/1e3 == 0){
cout << "0";
}
else{
cout << round(m*1e3)/1e3 << "x";
}
if(round(b*1e3)/1e3 == 0){
//if(round(m*1e3)/1e3 == 0);
}
else if(round(m*1e3)/1e3 == 0 && round(b*1e3)/1e3 != 0){
cout << round(b*1e3)/1e3 << endl;
}
else{
cout << " + " << round(b*1e3)/1e3;
}
cout << endl;
}
return 0;
} | # 0279, 2024-11-02 10:27:18, PPPPPPPPPPP-P--PPPPPPP-- (79%)
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
int main(){
int n;
string cmd;
cin >> n >> cmd;
vector<pair<float, float>> v1;
for(int i = 0; i < n; i++){
pair<float, float> tP;
cin >> tP.first >> tP.second;
v1.push_back(tP);
}
//v1[i].first
//v1[i].second
float m;
float m1 = 0;
float m2 = 0;
float m3 = 0;
float m4 = 0;
float m5 = 0;
float b;
float b1 = 0;
float b2 = 0;
for(int i = 0; i < n; i++){
m1 += v1[i].first * v1[i].second;
m2 += v1[i].first;
m3 += v1[i].second;
m4 += v1[i].first * v1[i].first;
m5 = m2;
b1 = m3;
b2 = m2;
}
// cout << m1 << " " << m2 << " " << m3 << " " << m4 << " " << m5 << endl;
// cout << (n*m1) << endl;
// cout << (m2*m3) << endl;
// cout << (n*m4) << endl;
// cout << (m5*m5) << endl;
float down = (n*m4) - (m5*m5);
m = ((n*m1) - (m2*m3))/down;
b = (b1 - (m*b2)) / n;
if(cmd == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if(cmd == "func"){
cout << "y = ";
// if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 != 0){
// cout << "x + " << round(b*1e3)/1e3;
// }
// else if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 == 0){
// cout << "x";
// }
// else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 != 0){
// cout << "-x + " << round(b*1e3)/1e3;
// }
// else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 == 0){
// cout << "-x";
// }
// else if(round(m*1e3)/1e3 == 0 && round(b*1e3)/1e3 != 0){
// cout << round(b*1e3)/1e3;
// }
// else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 == 0){
// cout << round(m*1e3)/1e3;
// }
// else if(round(m*1e3)/1e3 == 0 && round(b*1e3)/1e3 == 0){
// cout << 0;
// }
// else{
// cout << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3; ;
// }
if(round(m*1e3)/1e3 == 1){
cout << "x";
}
else if(round(m*1e3)/1e3 == -1){
cout << "-x";
}
else if(round(m*1e3)/1e3 == 0 && round(b*1e3)/1e3 != 0){
}
else if(round(m*1e3)/1e3 == 0){
cout << "0";
}
else{
cout << round(m*1e3)/1e3 << "x";
}
if(round(b*1e3)/1e3 == 0){
//if(round(m*1e3)/1e3 == 0);
}
else if(round(m*1e3)/1e3 == 0 && round(b*1e3)/1e3 != 0){
cout << round(b*1e3)/1e3 << endl;
}
else if(round(b*1e3)/1e3 < 0){
cout << " - " << round(b*1e3)/1e3;
}
else{
cout << " + " << round(b*1e3)/1e3;
}
cout << endl;
}
return 0;
} | # 0280, 2024-11-02 10:28:01, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
int main(){
int n;
string cmd;
cin >> n >> cmd;
vector<pair<float, float>> v1;
for(int i = 0; i < n; i++){
pair<float, float> tP;
cin >> tP.first >> tP.second;
v1.push_back(tP);
}
//v1[i].first
//v1[i].second
float m;
float m1 = 0;
float m2 = 0;
float m3 = 0;
float m4 = 0;
float m5 = 0;
float b;
float b1 = 0;
float b2 = 0;
for(int i = 0; i < n; i++){
m1 += v1[i].first * v1[i].second;
m2 += v1[i].first;
m3 += v1[i].second;
m4 += v1[i].first * v1[i].first;
m5 = m2;
b1 = m3;
b2 = m2;
}
// cout << m1 << " " << m2 << " " << m3 << " " << m4 << " " << m5 << endl;
// cout << (n*m1) << endl;
// cout << (m2*m3) << endl;
// cout << (n*m4) << endl;
// cout << (m5*m5) << endl;
float down = (n*m4) - (m5*m5);
m = ((n*m1) - (m2*m3))/down;
b = (b1 - (m*b2)) / n;
if(cmd == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if(cmd == "func"){
cout << "y = ";
// if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 != 0){
// cout << "x + " << round(b*1e3)/1e3;
// }
// else if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 == 0){
// cout << "x";
// }
// else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 != 0){
// cout << "-x + " << round(b*1e3)/1e3;
// }
// else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 == 0){
// cout << "-x";
// }
// else if(round(m*1e3)/1e3 == 0 && round(b*1e3)/1e3 != 0){
// cout << round(b*1e3)/1e3;
// }
// else if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 == 0){
// cout << round(m*1e3)/1e3;
// }
// else if(round(m*1e3)/1e3 == 0 && round(b*1e3)/1e3 == 0){
// cout << 0;
// }
// else{
// cout << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3; ;
// }
if(round(m*1e3)/1e3 == 1){
cout << "x";
}
else if(round(m*1e3)/1e3 == -1){
cout << "-x";
}
else if(round(m*1e3)/1e3 == 0 && round(b*1e3)/1e3 != 0){
}
else if(round(m*1e3)/1e3 == 0){
cout << "0";
}
else{
cout << round(m*1e3)/1e3 << "x";
}
if(round(b*1e3)/1e3 == 0){
//if(round(m*1e3)/1e3 == 0);
}
else if(round(m*1e3)/1e3 == 0 && round(b*1e3)/1e3 != 0){
cout << round(b*1e3)/1e3 << endl;
}
else if(round(b*1e3)/1e3 < 0){
cout << " - " << abs(round(b*1e3)/1e3);
}
else{
cout << " + " << round(b*1e3)/1e3;
}
cout << endl;
}
return 0;
} |
# 0281, 2024-11-02 09:44:12, -----PPPPP-------------- (20%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string fuc;
cin >> n >> fuc;
float m = 0,b=0;
double X=0,Y=0,X2=0,XY=0;
vector<float> x(n),y(n);
for (int i = 0;i<n;i++) {
cin >> x[i] >> y[i];
XY += x[i] * y[i];
X += x[i];
Y += y[i];
X2 += x[i] * x[i];
}
m = (n*XY - X*Y) / (n*X2 - X * X);
b = (Y - m * X)/n;
if (fuc == "mb") {
cout << m << '\n' << b;
}else {
cout << "y = " << m <<"x ";
if (b > 0) cout << "+ " << b;
if (b < 0) cout << "- " << b;
}
} | # 0282, 2024-11-02 09:47:34, -----PPPPP-----P-----P-- (29%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string fuc;
cin >> n >> fuc;
float m = 0,b=0;
float X=0,Y=0,X2=0,XY=0;
vector<float> x(n),y(n);
for (int i = 0;i<n;i++) {
cin >> x[i] >> y[i];
XY += x[i] * y[i];
X += x[i];
Y += y[i];
X2 += x[i] * x[i];
}
m = (n*XY - X*Y) / (n*X2 - X * X);
b = (Y - m * X)/n;
if (fuc == "mb") {
cout << m << '\n' << b;
}else {
cout << "y = ";
if (m != 0) {
cout<< m <<"x ";
if (b > 0) cout << "+ " << b;
if (b < 0) cout << "- " << b;
}
else {
cout << b;
}
}
} | # 0283, 2024-11-02 10:00:17, PPPPPPPPPPP-P--PP----P-- (62%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string fuc;
cin >> n >> fuc;
float m = 0,b=0;
float X=0,Y=0,X2=0,XY=0;
vector<float> x(n),y(n);
for (int i = 0;i<n;i++) {
cin >> x[i] >> y[i];
XY += x[i] * y[i];
X += x[i];
Y += y[i];
X2 += x[i] * x[i];
}
m = (n*XY - X*Y) / (n*X2 - X * X);
b = (Y - m * X)/n;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if (fuc == "mb") {
cout << m << '\n' << b;
}else {
cout << "y = ";
if (m != 0) {
cout<< m <<"x ";
if (b > 0) cout << "+ " << b;
if (b < 0) cout << "- " << b;
}
else {
cout << b;
}
}
} | # 0284, 2024-11-02 10:42:52, PPPPPPPPPPP-P--PP----P-- (62%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string fuc;
cin >> n >> fuc;
float m = 0,b=0;
float X=0,Y=0,X2=0,XY=0;
vector<float> x(n),y(n);
for (int i = 0;i<n;i++) {
cin >> x[i] >> y[i];
XY += x[i] * y[i];
X += x[i];
Y += y[i];
X2 += x[i] * x[i];
}
m = (n*XY - X*Y) / (n*X2 - X * X);
b = (Y - m * X)/n;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if (fuc == "mb") {
cout << m << '\n' << b;
}else {
cout << "y = ";
if (m != 0) {
cout<< m <<"x ";
if (b > 0) cout << "+ " << b;
if (b < 0) cout << "- " << b;
}
else {
cout << b;
}
}
} | # 0285, 2024-11-02 10:44:14, PPPPPPPPPPPPPPPPP----P-- (75%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string fuc;
cin >> n >> fuc;
float m = 0,b=0;
float X=0,Y=0,X2=0,XY=0;
vector<float> x(n),y(n);
for (int i = 0;i<n;i++) {
cin >> x[i] >> y[i];
XY += x[i] * y[i];
X += x[i];
Y += y[i];
X2 += x[i] * x[i];
}
m = (n*XY - X*Y) / (n*X2 - X * X);
b = (Y - m * X)/n;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if (fuc == "mb") {
cout << m << '\n' << b;
}else {
cout << "y = ";
if (m != 0) {
cout<< m <<"x ";
if (b > 0) cout << "+ " << b;
if (b < 0) cout << "- " << abs(b);
}
else {
cout << b;
}
}
} | # 0286, 2024-11-02 11:45:56, PPPPPPPPPPPPPPPPPPP--PP- (87%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string fuc;
cin >> n >> fuc;
float m = 0,b=0;
float X=0,Y=0,X2=0,XY=0;
vector<float> x(n),y(n);
for (int i = 0;i<n;i++) {
cin >> x[i] >> y[i];
XY += x[i] * y[i];
X += x[i];
Y += y[i];
X2 += x[i] * x[i];
}
m = (n*XY - X*Y) / (n*X2 - X * X);
b = (Y - m * X)/n;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if (fuc == "mb") {
cout << m << '\n' << b;
}else {
cout << "y = ";
if (m != 0) {
if (m != 1)cout<< m <<"x ";
else cout <<"x ";
if (b > 0) cout << "+ " << b;
if (b < 0) cout << "- " << abs(b);
}
else {
cout << b;
}
}
} | # 0287, 2024-11-02 11:47:01, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string fuc;
cin >> n >> fuc;
float m = 0,b=0;
float X=0,Y=0,X2=0,XY=0;
vector<float> x(n),y(n);
for (int i = 0;i<n;i++) {
cin >> x[i] >> y[i];
XY += x[i] * y[i];
X += x[i];
Y += y[i];
X2 += x[i] * x[i];
}
m = (n*XY - X*Y) / (n*X2 - X * X);
b = (Y - m * X)/n;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if (fuc == "mb") {
cout << m << '\n' << b;
}else {
cout << "y = ";
if (m != 0) {
if (m == 1)cout <<"x ";
else if(m==-1)cout <<"-x ";
else cout<< m <<"x ";
if (b > 0) cout << "+ " << b;
if (b < 0) cout << "- " << abs(b);
}
else {
cout << b;
}
}
} |
# 0288, 2024-11-02 10:48:22, PPPPPPPPPPP-P--PP-PP-P-- (70%)
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int n;
float sum_x=0, sum_y=0, sum_xny=0, sum_powx=0;
string word;
cin>>n>>word;
float x[n],y[n];
for(int i=0;i<n;i++){
cin>>x[i]>>y[i];
}
// sum pow x
for(int z=0;z<n;z++){
sum_powx+=pow(x[z],2);
}
//sum x
for(int i=0;i<n;i++){
sum_x+=x[i];
}
//sum y
for(int j=0;j<n;j++){
sum_y+=y[j];
}
//sum x n y
for(int k=0;k<n;k++){
sum_xny+=(x[k]*y[k]);
}
//calculate m
float M = ((n*sum_xny)-((sum_x)*(sum_y)))/(n*(sum_powx)-(pow(sum_x,2)));
//calculate b
float B = ((sum_y) - (M*sum_x))/n;
float m = round(M*1e3)/1e3;
float b = round(B*1e3)/1e3;
if(word=="mb"){
cout<<m<<endl;
cout<<b<<endl;
}
else if(word=="func"){
if(m==0 && b==0){
cout<<"y = 0";
}
else if(b==0){
if(m==1){
cout<<"y = "<<"x";
}
else if(m==-1){
cout<<"y = "<<"-x";
}
else {
cout<<"y = "<<m<<"x";
}
}
else if(m==0){
cout<<"y = "<<b;
}
else{
cout<<"y = "<<m<<"x + "<<b;
}
}
} | # 0289, 2024-11-02 10:50:22, PPPPPPPPPP-----P--PP---- (54%)
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int n;
float sum_x=0, sum_y=0, sum_xny=0, sum_powx=0;
string word;
cin>>n>>word;
float x[n],y[n];
for(int i=0;i<n;i++){
cin>>x[i]>>y[i];
}
// sum pow x
for(int z=0;z<n;z++){
sum_powx+=pow(x[z],2);
}
//sum x
for(int i=0;i<n;i++){
sum_x+=x[i];
}
//sum y
for(int j=0;j<n;j++){
sum_y+=y[j];
}
//sum x n y
for(int k=0;k<n;k++){
sum_xny+=(x[k]*y[k]);
}
//calculate m
float M = ((n*sum_xny)-((sum_x)*(sum_y)))/(n*(sum_powx)-(pow(sum_x,2)));
//calculate b
float B = ((sum_y) - (M*sum_x))/n;
float m = round(M*1e3)/1e3;
float b = round(B*1e3)/1e3;
if(word=="mb"){
cout<<m<<endl;
cout<<b<<endl;
}
else if(word=="func"){
if(m==0 && b==0){
cout<<"y = 0";
}
else if(b==0){
if(m==1){
cout<<"y = "<<"x";
}
else if(m==-1){
cout<<"y = "<<"-x";
}
else {
cout<<"y = "<<m<<"x";
}
}
else if(b!=0){
if(m==1){
cout<<"y = "<<"x +"<<b;
}
else if(m==-1){
cout<<"y = "<<"-x +"<<b;
}
else {
cout<<"y = "<<m<<"x +"<<b;
}
}
else if(m==0){
cout<<"y = "<<b;
}
else{
cout<<"y = "<<m<<"x + "<<b;
}
}
} | # 0290, 2024-11-02 10:50:47, PPPPPPPPPPP-P--PP-PP-P-- (70%)
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int n;
float sum_x=0, sum_y=0, sum_xny=0, sum_powx=0;
string word;
cin>>n>>word;
float x[n],y[n];
for(int i=0;i<n;i++){
cin>>x[i]>>y[i];
}
// sum pow x
for(int z=0;z<n;z++){
sum_powx+=pow(x[z],2);
}
//sum x
for(int i=0;i<n;i++){
sum_x+=x[i];
}
//sum y
for(int j=0;j<n;j++){
sum_y+=y[j];
}
//sum x n y
for(int k=0;k<n;k++){
sum_xny+=(x[k]*y[k]);
}
//calculate m
float M = ((n*sum_xny)-((sum_x)*(sum_y)))/(n*(sum_powx)-(pow(sum_x,2)));
//calculate b
float B = ((sum_y) - (M*sum_x))/n;
float m = round(M*1e3)/1e3;
float b = round(B*1e3)/1e3;
if(word=="mb"){
cout<<m<<endl;
cout<<b<<endl;
}
else if(word=="func"){
if(m==0 && b==0){
cout<<"y = 0";
}
else if(b==0){
if(m==1){
cout<<"y = "<<"x";
}
else if(m==-1){
cout<<"y = "<<"-x";
}
else {
cout<<"y = "<<m<<"x";
}
}
else if(m==0){
cout<<"y = "<<b;
}
else{
cout<<"y = "<<m<<"x + "<<b;
}
}
} | # 0291, 2024-11-02 10:55:08, PPPPPPPPPPPPPPPP-PPPP-PP (91%)
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int n;
float sum_x=0, sum_y=0, sum_xny=0, sum_powx=0;
string word;
cin>>n>>word;
float x[n],y[n];
for(int i=0;i<n;i++){
cin>>x[i]>>y[i];
}
// sum pow x
for(int z=0;z<n;z++){
sum_powx+=pow(x[z],2);
}
//sum x
for(int i=0;i<n;i++){
sum_x+=x[i];
}
//sum y
for(int j=0;j<n;j++){
sum_y+=y[j];
}
//sum x n y
for(int k=0;k<n;k++){
sum_xny+=(x[k]*y[k]);
}
//calculate m
float M = ((n*sum_xny)-((sum_x)*(sum_y)))/(n*(sum_powx)-(pow(sum_x,2)));
//calculate b
float B = ((sum_y) - (M*sum_x))/n;
float m = round(M*1e3)/1e3;
float b = round(B*1e3)/1e3;
if(word=="mb"){
cout<<m<<endl;
cout<<b<<endl;
}
else if(word=="func"){
if(m==0 && b==0){
cout<<"y = 0";
}
else if(b==0){
if(m==1){
cout<<"y = "<<"x";
}
else if(m==-1){
cout<<"y = "<<"-x";
}
else {
cout<<"y = "<<m<<"x";
}
}
else if(b<0){
if(m==1){
cout<<"y = "<<"x - "<<(b*-1);
}
else if(m==-1){
cout<<"y = "<<"-x - "<<(b*-1);
}
else {
cout<<"y = "<<m<<"x - "<<(b*-1);
}
}
else if(b>0){
if(m==1){
cout<<"y = "<<"x + "<<b;
}
else if(m==-1){
cout<<"y = "<<"-x + "<<b;
}
else {
cout<<"y = "<<m<<"x + "<<b;
}
}
else if(m==0){
cout<<"y = "<<b;
}
else{
cout<<"y = "<<m<<"x + "<<b;
}
}
} | # 0292, 2024-11-02 10:58:36, PPPPPPPPPPPPPPPP-PPPPPPP (95%)
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int n;
float sum_x=0, sum_y=0, sum_xny=0, sum_powx=0;
string word;
cin>>n>>word;
float x[n],y[n];
for(int i=0;i<n;i++){
cin>>x[i]>>y[i];
}
// sum pow x
for(int z=0;z<n;z++){
sum_powx+=pow(x[z],2);
}
//sum x
for(int i=0;i<n;i++){
sum_x+=x[i];
}
//sum y
for(int j=0;j<n;j++){
sum_y+=y[j];
}
//sum x n y
for(int k=0;k<n;k++){
sum_xny+=(x[k]*y[k]);
}
//calculate m
float M = ((n*sum_xny)-((sum_x)*(sum_y)))/(n*(sum_powx)-(pow(sum_x,2)));
//calculate b
float B = ((sum_y) - (M*sum_x))/n;
float m = round(M*1e3)/1e3;
float b = round(B*1e3)/1e3;
if(word=="mb"){
cout<<m<<endl;
cout<<b<<endl;
}
else if(word=="func"){
if(m==0 && b==0){
cout<<"y = 0";
}
else if(b==0){
if(m==1){
cout<<"y = "<<"x";
}
else if(m==-1){
cout<<"y = "<<"-x";
}
else {
cout<<"y = "<<m<<"x";
}
}
else if(b<0){
if(m==1){
cout<<"y = "<<"x - "<<(b*-1);
}
else if(m==-1){
cout<<"y = "<<"-x - "<<(b*-1);
}
else if(m==0){
cout<<"y = "<<b;
}
else {
cout<<"y = "<<m<<"x - "<<(b*-1);
}
}
else if(b>0){
if(m==1){
cout<<"y = "<<"x + "<<b;
}
else if(m==-1){
cout<<"y = "<<"-x + "<<b;
}
else {
cout<<"y = "<<m<<"x + "<<b;
}
}
else if(m==0){
cout<<"y = "<<b;
}
else{
cout<<"y = "<<m<<"x + "<<b;
}
}
} | # 0293, 2024-11-02 10:59:27, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int n;
float sum_x=0, sum_y=0, sum_xny=0, sum_powx=0;
string word;
cin>>n>>word;
float x[n],y[n];
for(int i=0;i<n;i++){
cin>>x[i]>>y[i];
}
// sum pow x
for(int z=0;z<n;z++){
sum_powx+=pow(x[z],2);
}
//sum x
for(int i=0;i<n;i++){
sum_x+=x[i];
}
//sum y
for(int j=0;j<n;j++){
sum_y+=y[j];
}
//sum x n y
for(int k=0;k<n;k++){
sum_xny+=(x[k]*y[k]);
}
//calculate m
float M = ((n*sum_xny)-((sum_x)*(sum_y)))/(n*(sum_powx)-(pow(sum_x,2)));
//calculate b
float B = ((sum_y) - (M*sum_x))/n;
float m = round(M*1e3)/1e3;
float b = round(B*1e3)/1e3;
if(word=="mb"){
cout<<m<<endl;
cout<<b<<endl;
}
else if(word=="func"){
if(m==0 && b==0){
cout<<"y = 0";
}
else if(b==0){
if(m==1){
cout<<"y = "<<"x";
}
else if(m==-1){
cout<<"y = "<<"-x";
}
else {
cout<<"y = "<<m<<"x";
}
}
else if(b<0){
if(m==1){
cout<<"y = "<<"x - "<<(b*-1);
}
else if(m==-1){
cout<<"y = "<<"-x - "<<(b*-1);
}
else if(m==0){
cout<<"y = "<<b;
}
else {
cout<<"y = "<<m<<"x - "<<(b*-1);
}
}
else if(b>0){
if(m==1){
cout<<"y = "<<"x + "<<b;
}
else if(m==-1){
cout<<"y = "<<"-x + "<<b;
}
else if(m==0){
cout<<"y = "<<b;
}
else {
cout<<"y = "<<m<<"x + "<<b;
}
}
else if(m==0){
cout<<"y = "<<b;
}
else{
cout<<"y = "<<m<<"x + "<<b;
}
}
} |
# 0294, 2024-11-02 13:33:43, PPPPPPPPPPPPPPPP---P-P-- (75%)
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
float sum_xy = 0;
float sum_x = 0;
float sum_y = 0;
float sum_x2 = 0;
vector<float> data_x;
vector<float> data_y;
float m , b;
float x,y ;
int N;
string type;
cin >> N >> type;
for(int i = 0 ; i < N ; i++){
cin >> x >> y;
data_x.push_back(x);
data_y.push_back(y);
}
for(int i = 0 ; i <= N-1; ++i ){
sum_xy += data_x[i]*data_y[i];
}
for(int i = 0 ; i <= N-1; ++i ){
sum_x += data_x[i];
}
for(int i = 0 ; i <= N-1; ++i ){
sum_y += data_y[i];
}
for(int i = 0 ; i <= N-1; ++i ){
sum_x2 += data_x[i]*data_x[i];
}
m = ((N*sum_xy)-(sum_x * sum_y)) / ((N * sum_x2) - (sum_x*sum_x));
b = (sum_y - m*sum_x) / N ;
if( type == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
}
else if(type == "func"){
if (m == 0 && b == 0){
cout << "y = 0" << endl;
}
if( m == 0 && b != 0){
cout << "y = " <<round(b*1e3)/1e3 << endl;
}
if( (m == 1 || m == -1) && b > 0){
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}
if( (m == 1 || m == -1) && b < 0){
cout << "y = -x - " << -round(b*1e3)/1e3 << endl;
}
if( (m == 1 || m == -1) && b == 0){
cout << "y = -x" << endl;
}
if( (m > 1 || m < -1) && b == 0){
cout << "y = " << round(m*1e3)/1e3<<"x" << endl;
}
if( (m > 1 || m < -1) && b > 0){
cout << "y = " << round(m*1e3)/1e3 <<"x + "<< round(b*1e3)/1e3<< endl;
}
if( (m > 1 || m < -1) && b < 0){
cout << "y = " << round(m*1e3)/1e3 <<"x - "<< -round(b*1e3)/1e3<< endl;
}
}
} | # 0295, 2024-11-02 13:37:49, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
float sum_xy = 0;
float sum_x = 0;
float sum_y = 0;
float sum_x2 = 0;
vector<float> data_x;
vector<float> data_y;
float m , b;
float x,y ;
int N;
string type;
cin >> N >> type;
for(int i = 0 ; i < N ; i++){
cin >> x >> y;
data_x.push_back(x);
data_y.push_back(y);
}
for(int i = 0 ; i <= N-1; ++i ){
sum_xy += data_x[i]*data_y[i];
}
for(int i = 0 ; i <= N-1; ++i ){
sum_x += data_x[i];
}
for(int i = 0 ; i <= N-1; ++i ){
sum_y += data_y[i];
}
for(int i = 0 ; i <= N-1; ++i ){
sum_x2 += data_x[i]*data_x[i];
}
m = ((N*sum_xy)-(sum_x * sum_y)) / ((N * sum_x2) - (sum_x*sum_x));
b = (sum_y - m*sum_x) / N ;
if( type == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
}
else if(type == "func"){
if (m == 0 && b == 0){
cout << "y = 0" << endl;
}
if( m == 0 && b != 0){
cout << "y = " <<round(b*1e3)/1e3 << endl;
}
if( (m == 1 ) && b > 0){
cout << "y = x + " << round(b*1e3)/1e3 << endl;
}
if( (m == 1 ) && b < 0){
cout << "y = x - " << -round(b*1e3)/1e3 << endl;
}
if( (m == 1 ) && b == 0){
cout << "y = x" << endl;
}
if( ( m == -1) && b > 0){
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}
if( (m == -1) && b < 0){
cout << "y = -x - " << -round(b*1e3)/1e3 << endl;
}
if( ( m == -1) && b == 0){
cout << "y = -x" << endl;
}
if( (m > 1 || m < -1) && b == 0){
cout << "y = " << round(m*1e3)/1e3<<"x" << endl;
}
if( (m > 1 || m < -1) && b > 0){
cout << "y = " << round(m*1e3)/1e3 <<"x + "<< round(b*1e3)/1e3<< endl;
}
if( (m > 1 || m < -1) && b < 0){
cout << "y = " << round(m*1e3)/1e3 <<"x - "<< -round(b*1e3)/1e3<< endl;
}
}
} | # 0296, 2024-11-02 15:15:46, PPPPPPPPPPPPPPPP--PP---- (75%)
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
float sum_xy = 0;
float sum_x = 0;
float sum_y = 0;
float sum_x2 = 0;
vector<float> data_x;
vector<float> data_y;
float m , b;
float x,y ;
int N;
string type;
cin >> N >> type;
for(int i = 0 ; i < N ; i++){
cin >> x >> y;
data_x.push_back(x);
data_y.push_back(y);
}
for(int i = 0 ; i <= N-1; ++i ){
sum_xy += data_x[i]*data_y[i];
}
for(int i = 0 ; i <= N-1; ++i ){
sum_x += data_x[i];
}
for(int i = 0 ; i <= N-1; ++i ){
sum_y += data_y[i];
}
for(int i = 0 ; i <= N-1; ++i ){
sum_x2 += data_x[i]*data_x[i];
}
m = ((N*sum_xy)-(sum_x * sum_y)) / ((N * sum_x2) - (sum_x*sum_x));
b = (sum_y - m*sum_x) / N ;
if( type == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
}
else if(type == "func"){
if (round(m*1e3)/1e3 == 0 && b == round(b*1e3)/1e3){
cout << "y = 0" << endl;
}
if( round(m*1e3)/1e3 == 0 && b != 0){
cout << "y = " <<round(b*1e3)/1e3 << endl;
}
if( (m == 1 ) && b > 0){
cout << "y = x + " << round(b*1e3)/1e3 << endl;
}
if( (m == 1 ) && b < 0){
cout << "y = x - " << -round(b*1e3)/1e3 << endl;
}
if( (m == 1 ) && b == 0){
cout << "y = x" << endl;
}
if( ( m == -1) && b > 0){
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}
if( (m == -1) && b < 0){
cout << "y = -x - " << -round(b*1e3)/1e3 << endl;
}
if( ( m == -1) && b == 0){
cout << "y = -x" << endl;
}
if( (m > 1 || m < -1) && b == 0){
cout << "y = " << round(m*1e3)/1e3<<"x" << endl;
}
if( (m > 1 || m < -1) && b > 0){
cout << "y = " << round(m*1e3)/1e3 <<"x + "<< round(b*1e3)/1e3<< endl;
}
if( (m > 1 || m < -1) && b < 0){
cout << "y = " << round(m*1e3)/1e3 <<"x - "<< -round(b*1e3)/1e3<< endl;
}
}
} | # 0297, 2024-11-02 15:16:57, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
float sum_xy = 0;
float sum_x = 0;
float sum_y = 0;
float sum_x2 = 0;
vector<float> data_x;
vector<float> data_y;
float m , b;
float x,y ;
int N;
string type;
cin >> N >> type;
for(int i = 0 ; i < N ; i++){
cin >> x >> y;
data_x.push_back(x);
data_y.push_back(y);
}
for(int i = 0 ; i <= N-1; ++i ){
sum_xy += data_x[i]*data_y[i];
}
for(int i = 0 ; i <= N-1; ++i ){
sum_x += data_x[i];
}
for(int i = 0 ; i <= N-1; ++i ){
sum_y += data_y[i];
}
for(int i = 0 ; i <= N-1; ++i ){
sum_x2 += data_x[i]*data_x[i];
}
m = ((N*sum_xy)-(sum_x * sum_y)) / ((N * sum_x2) - (sum_x*sum_x));
b = (sum_y - m*sum_x) / N ;
if( type == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
}
else if(type == "func"){
if ( round(m*1e3)/1e3 == 0 && round(b*1e3)/1e3 == 0){
cout << "y = 0" << endl;
}
if( round(m*1e3)/1e3 == 0 && round(b*1e3)/1e3 != 0){
cout << "y = " <<round(b*1e3)/1e3 << endl;
}
if( (m == 1 ) && b > 0){
cout << "y = x + " << round(b*1e3)/1e3 << endl;
}
if( (m == 1 ) && b < 0){
cout << "y = x - " << -round(b*1e3)/1e3 << endl;
}
if( (m == 1 ) && b == 0){
cout << "y = x" << endl;
}
if( ( m == -1) && b > 0){
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}
if( (m == -1) && b < 0){
cout << "y = -x - " << -round(b*1e3)/1e3 << endl;
}
if( ( m == -1) && b == 0){
cout << "y = -x" << endl;
}
if( (m > 1 || m < -1) && b == 0){
cout << "y = " << round(m*1e3)/1e3<<"x" << endl;
}
if( (m > 1 || m < -1) && b > 0){
cout << "y = " << round(m*1e3)/1e3 <<"x + "<< round(b*1e3)/1e3<< endl;
}
if( (m > 1 || m < -1) && b < 0){
cout << "y = " << round(m*1e3)/1e3 <<"x - "<< -round(b*1e3)/1e3<< endl;
}
}
} | # 0298, 2024-11-02 15:17:48, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
float sum_xy = 0;
float sum_x = 0;
float sum_y = 0;
float sum_x2 = 0;
vector<float> data_x;
vector<float> data_y;
float m , b;
float x,y ;
int N;
string type;
cin >> N >> type;
for(int i = 0 ; i < N ; i++){
cin >> x >> y;
data_x.push_back(x);
data_y.push_back(y);
}
for(int i = 0 ; i <= N-1; ++i ){
sum_xy += data_x[i]*data_y[i];
}
for(int i = 0 ; i <= N-1; ++i ){
sum_x += data_x[i];
}
for(int i = 0 ; i <= N-1; ++i ){
sum_y += data_y[i];
}
for(int i = 0 ; i <= N-1; ++i ){
sum_x2 += data_x[i]*data_x[i];
}
m = ((N*sum_xy)-(sum_x * sum_y)) / ((N * sum_x2) - (sum_x*sum_x));
b = (sum_y - m*sum_x) / N ;
if( type == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
}
else if(type == "func"){
if ( round(m*1e3)/1e3 == 0 && round(b*1e3)/1e3 == 0){
cout << "y = 0" << endl;
}
if( round(m*1e3)/1e3 == 0 && round(b*1e3)/1e3 != 0){
cout << "y = " <<round(b*1e3)/1e3 << endl;
}
if( (m == 1 ) && b > 0){
cout << "y = x + " << round(b*1e3)/1e3 << endl;
}
if( (m == 1 ) && b < 0){
cout << "y = x - " << -round(b*1e3)/1e3 << endl;
}
if( (m == 1 ) && round(b*1e3)/1e3 == 0){
cout << "y = x" << endl;
}
if( ( m == -1) && b > 0){
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}
if( (m == -1) && b < 0){
cout << "y = -x - " << -round(b*1e3)/1e3 << endl;
}
if( ( m == -1) && round(b*1e3)/1e3 == 0){
cout << "y = -x" << endl;
}
if( (m > 1 || m < -1) && round(b*1e3)/1e3 == 0){
cout << "y = " << round(m*1e3)/1e3<<"x" << endl;
}
if( (m > 1 || m < -1) && b > 0){
cout << "y = " << round(m*1e3)/1e3 <<"x + "<< round(b*1e3)/1e3<< endl;
}
if( (m > 1 || m < -1) && b < 0){
cout << "y = " << round(m*1e3)/1e3 <<"x - "<< -round(b*1e3)/1e3<< endl;
}
}
} | # 0299, 2024-11-02 15:20:01, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
float sum_xy = 0;
float sum_x = 0;
float sum_y = 0;
float sum_x2 = 0;
vector<float> data_x;
vector<float> data_y;
float m , b;
float x,y ;
int N;
string type;
cin >> N >> type;
for(int i = 0 ; i < N ; i++){
cin >> x >> y;
data_x.push_back(x);
data_y.push_back(y);
}
for(int i = 0 ; i <= N-1; ++i ){
sum_xy += data_x[i]*data_y[i];
}
for(int i = 0 ; i <= N-1; ++i ){
sum_x += data_x[i];
}
for(int i = 0 ; i <= N-1; ++i ){
sum_y += data_y[i];
}
for(int i = 0 ; i <= N-1; ++i ){
sum_x2 += data_x[i]*data_x[i];
}
m = ((N*sum_xy)-(sum_x * sum_y)) / ((N * sum_x2) - (sum_x*sum_x));
b = (sum_y - m*sum_x) / N ;
if( type == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
}
else if(type == "func"){
if ( round(m*1e3)/1e3 == 0 && round(b*1e3)/1e3 == 0){
cout << "y = 0" << endl;
}
if( round(m*1e3)/1e3 == 0 && round(b*1e3)/1e3 != 0){
cout << "y = " <<round(b*1e3)/1e3 << endl;
}
if( (round(m*1e3)/1e3 == 1 ) && round(b*1e3)/1e3 > 0){
cout << "y = x + " << round(b*1e3)/1e3 << endl;
}
if( (round(m*1e3)/1e3 == 1 ) && round(b*1e3)/1e3 < 0){
cout << "y = x - " << -round(b*1e3)/1e3 << endl;
}
if( (round(m*1e3)/1e3 == 1 ) && round(b*1e3)/1e3 == 0){
cout << "y = x" << endl;
}
if( ( round(m*1e3)/1e3 == -1) && round(b*1e3)/1e3 > 0){
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}
if( (round(m*1e3)/1e3 == -1) && round(b*1e3)/1e3 < 0){
cout << "y = -x - " << -round(b*1e3)/1e3 << endl;
}
if( ( round(m*1e3)/1e3 == -1) && round(b*1e3)/1e3 == 0){
cout << "y = -x" << endl;
}
if( (round(m*1e3)/1e3 > 1 || round(m*1e3)/1e3 < -1) && round(b*1e3)/1e3 == 0){
cout << "y = " << round(m*1e3)/1e3<<"x" << endl;
}
if( (round(m*1e3)/1e3 > 1 || round(m*1e3)/1e3 < -1) && round(b*1e3)/1e3 > 0){
cout << "y = " << round(m*1e3)/1e3 <<"x + "<< round(b*1e3)/1e3<< endl;
}
if( (round(m*1e3)/1e3 > 1 || round(m*1e3)/1e3 < -1) && round(b*1e3)/1e3 < 0){
cout << "y = " << round(m*1e3)/1e3 <<"x - "<< -round(b*1e3)/1e3<< endl;
}
}
} |
# 0300, 2024-11-02 09:57:21, ----P-PP---------------- (12%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string type;
cin >> type;
vector<pair<float, float>> data;
for (int i = 0; i < n; i++)
{
float x, y;
cin >> x >> y;
data.push_back({x, y});
}
float m, b;
if (type == "mb")
{
float m1;
for (int i = 1; i <= n; i++)
{
m1 += (data[i - 1].first * data[i - 1].second);
}
m1 *= n;
float m2;
for (int i = 1; i <= n; i++)
{
m2 += data[i - 1].first;
}
float m3;
for (int i = 1; i <= n; i++)
{
m3 += data[i - 1].second;
}
float m4;
for (int i = 1; i <= n; i++)
{
m4 += (data[i - 1].first * data[i - 1].first);
}
m4 *= n;
float m5;
for (int i = 1; i <= n; i++)
{
m5 += data[i - 1].first;
}
m5 = m5 * m5;
m = ((m1) - (m2 * m3)) / ((m4) - (m5));
float b1;
for (int i = 1; i <= n; i++)
{
b1 += data[i - 1].second;
}
float b2;
for (int i = 1; i <= n; i++)
{
b2 += data[i - 1].first;
}
b2 *= m;
b = (b1 - b2) / n;
cout << round(m * 1e3) / 1e3 << endl
<< round(b * 1e3) / 1e3;
}
else
{
}
} | # 0301, 2024-11-02 10:05:54, ------------------------ (0%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string type;
cin >> type;
vector<pair<float, float>> data;
for (int i = 0; i < n; i++)
{
float x, y;
cin >> x >> y;
data.push_back({x, y});
}
float m, b;
float m1;
for (int i = 1; i <= n; i++)
{
m1 += (data[i - 1].first * data[i - 1].second);
}
m1 *= n;
float m2;
for (int i = 1; i <= n; i++)
{
m2 += data[i - 1].first;
}
float m3;
for (int i = 1; i <= n; i++)
{
m3 += data[i - 1].second;
}
float m4;
for (int i = 1; i <= n; i++)
{
m4 += (data[i - 1].first * data[i - 1].first);
}
m4 *= n;
float m5;
for (int i = 1; i <= n; i++)
{
m5 += data[i - 1].first;
}
m5 = m5 * m5;
m = ((m1) - (m2 * m3)) / ((m4) - (m5));
float b1;
for (int i = 1; i <= n; i++)
{
b1 += data[i - 1].second;
}
float b2;
for (int i = 1; i <= n; i++)
{
b2 += data[i - 1].first;
}
b2 *= m;
b = (b1 - b2) / n;
float mt = round(m * 1e3) / 1e3;
float bt = round(b * 1e3) / 1e3;
cout << mt << endl
<< bt;
m = mt;
b = bt;
if (type == "mb")
{
cout << m << endl;
cout << b;
}
else if (type == "func")
{
cout << "y = ";
if (b == 0 && m != 0)
{
cout << m << "x";
}
else if (m == 0 && b != 0)
{
cout << b;
}
else if (m != 0 && b != 0)
{
cout << m << "x + " << b;
}
}
} | # 0302, 2024-11-02 10:08:44, PPPPPPPPPPP-P---P----P-- (58%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string type;
cin >> type;
vector<pair<float, float>> data;
for (int i = 0; i < n; i++)
{
float x, y;
cin >> x >> y;
data.push_back({x, y});
}
float m = 0.0, b = 0.0;
float m1 = 0.0;
for (int i = 1; i <= n; i++)
{
m1 += (data[i - 1].first * data[i - 1].second);
}
m1 *= n;
float m2 = 0.0;
for (int i = 1; i <= n; i++)
{
m2 += data[i - 1].first;
}
float m3 = 0.0;
for (int i = 1; i <= n; i++)
{
m3 += data[i - 1].second;
}
float m4 = 0.0;
for (int i = 1; i <= n; i++)
{
m4 += (data[i - 1].first * data[i - 1].first);
}
m4 *= n;
float m5 = 0.0;
for (int i = 1; i <= n; i++)
{
m5 += data[i - 1].first;
}
m5 = m5 * m5;
m = ((m1) - (m2 * m3)) / ((m4) - (m5));
float b1 = 0.0;
for (int i = 1; i <= n; i++)
{
b1 += data[i - 1].second;
}
float b2 = 0.0;
for (int i = 1; i <= n; i++)
{
b2 += data[i - 1].first;
}
b2 *= m;
b = (b1 - b2) / n;
float mt = round(m * 1e3) / 1e3;
float bt = round(b * 1e3) / 1e3;
if (type == "mb")
{
cout << mt << endl;
cout << bt;
}
else if (type == "func")
{
cout << "y = ";
if (bt == 0 && mt != 0)
{
cout << mt << "x";
}
else if (mt == 0 && bt != 0)
{
cout << bt;
}
else if (mt != 0 && bt != 0)
{
cout << mt << "x + " << bt;
}
}
} | # 0303, 2024-11-02 10:14:49, PPPPPPPPPPP-P--PP-PP-P-- (70%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string type;
cin >> type;
vector<pair<float, float>> data;
for (int i = 0; i < n; i++)
{
float x, y;
cin >> x >> y;
data.push_back({x, y});
}
float m = 0.0, b = 0.0;
float m1 = 0.0;
for (int i = 1; i <= n; i++)
{
m1 += (data[i - 1].first * data[i - 1].second);
}
m1 *= n;
float m2 = 0.0;
for (int i = 1; i <= n; i++)
{
m2 += data[i - 1].first;
}
float m3 = 0.0;
for (int i = 1; i <= n; i++)
{
m3 += data[i - 1].second;
}
float m4 = 0.0;
for (int i = 1; i <= n; i++)
{
m4 += (data[i - 1].first * data[i - 1].first);
}
m4 *= n;
float m5 = 0.0;
for (int i = 1; i <= n; i++)
{
m5 += data[i - 1].first;
}
m5 = m5 * m5;
m = ((m1) - (m2 * m3)) / ((m4) - (m5));
float b1 = 0.0;
for (int i = 1; i <= n; i++)
{
b1 += data[i - 1].second;
}
float b2 = 0.0;
for (int i = 1; i <= n; i++)
{
b2 += data[i - 1].first;
}
b2 *= m;
b = (b1 - b2) / n;
float mt = round(m * 1e3) / 1e3;
float bt = round(b * 1e3) / 1e3;
if (type == "mb")
{
cout << mt << endl;
cout << bt;
}
else if (type == "func")
{
cout << "y = ";
if (bt == 0 && mt != 0)
{
if (mt == -1)
{
cout << "-x";
}
else if (mt == 1)
{
cout << "x";
}
else
{
cout << mt << "x";
}
}
else if (mt == 0 && bt != 0)
{
cout << bt;
}
else if (mt != 0 && bt != 0)
{
cout << mt << "x + " << bt;
}
else if (mt == 0 && bt == 0)
{
cout << "0";
}
}
} | # 0304, 2024-11-02 10:17:56, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string type;
cin >> type;
vector<pair<float, float>> data;
for (int i = 0; i < n; i++)
{
float x, y;
cin >> x >> y;
data.push_back({x, y});
}
float m = 0.0, b = 0.0;
float m1 = 0.0;
for (int i = 1; i <= n; i++)
{
m1 += (data[i - 1].first * data[i - 1].second);
}
m1 *= n;
float m2 = 0.0;
for (int i = 1; i <= n; i++)
{
m2 += data[i - 1].first;
}
float m3 = 0.0;
for (int i = 1; i <= n; i++)
{
m3 += data[i - 1].second;
}
float m4 = 0.0;
for (int i = 1; i <= n; i++)
{
m4 += (data[i - 1].first * data[i - 1].first);
}
m4 *= n;
float m5 = 0.0;
for (int i = 1; i <= n; i++)
{
m5 += data[i - 1].first;
}
m5 = m5 * m5;
m = ((m1) - (m2 * m3)) / ((m4) - (m5));
float b1 = 0.0;
for (int i = 1; i <= n; i++)
{
b1 += data[i - 1].second;
}
float b2 = 0.0;
for (int i = 1; i <= n; i++)
{
b2 += data[i - 1].first;
}
b2 *= m;
b = (b1 - b2) / n;
float mt = round(m * 1e3) / 1e3;
float bt = round(b * 1e3) / 1e3;
if (type == "mb")
{
cout << mt << endl;
cout << bt;
}
else if (type == "func")
{
cout << "y = ";
if (bt == 0 && mt != 0)
{
if (mt == -1)
{
cout << "-x";
}
else if (mt == 1)
{
cout << "x";
}
else
{
cout << mt << "x";
}
}
else if (mt == 0 && bt != 0)
{
cout << bt;
}
else if (mt != 0 && bt != 0)
{
if (bt > 0)
{
cout << mt << "x + " << bt;
}
else if (bt < 0)
{
cout << mt << "x - " << -bt;
}
}
else if (mt == 0 && bt == 0)
{
cout << "0";
}
}
} | # 0305, 2024-11-02 10:22:54, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string type;
cin >> type;
vector<pair<float, float>> data;
for (int i = 0; i < n; i++)
{
float x, y;
cin >> x >> y;
data.push_back({x, y});
}
float m = 0.0, b = 0.0;
float m1 = 0.0;
for (int i = 1; i <= n; i++)
{
m1 += (data[i - 1].first * data[i - 1].second);
}
m1 *= n;
float m2 = 0.0;
for (int i = 1; i <= n; i++)
{
m2 += data[i - 1].first;
}
float m3 = 0.0;
for (int i = 1; i <= n; i++)
{
m3 += data[i - 1].second;
}
float m4 = 0.0;
for (int i = 1; i <= n; i++)
{
m4 += (data[i - 1].first * data[i - 1].first);
}
m4 *= n;
float m5 = 0.0;
for (int i = 1; i <= n; i++)
{
m5 += data[i - 1].first;
}
m5 = m5 * m5;
m = ((m1) - (m2 * m3)) / ((m4) - (m5));
float b1 = 0.0;
for (int i = 1; i <= n; i++)
{
b1 += data[i - 1].second;
}
float b2 = 0.0;
for (int i = 1; i <= n; i++)
{
b2 += data[i - 1].first;
}
b2 *= m;
b = (b1 - b2) / n;
float mt = round(m * 1e3) / 1e3;
float bt = round(b * 1e3) / 1e3;
if (type == "mb")
{
cout << mt << endl;
cout << bt;
}
else if (type == "func")
{
cout << "y = ";
if (bt == 0 && mt != 0)
{
if (mt == -1)
{
cout << "-x";
}
else if (mt == 1)
{
cout << "x";
}
else
{
cout << mt << "x";
}
}
else if (mt == 0 && bt != 0)
{
cout << bt;
}
else if (mt != 0 && bt != 0)
{
if (mt == -1 && bt > 0)
{
cout << "-"
<< "x + " << bt;
}
else if (mt == -1 && bt < 0)
{
cout << "-"
<< "x - " << -bt;
}
else if (mt == 1 && bt > 0)
{
cout << "x + " << bt;
}
else if (mt == 1 && bt < 0)
{
cout << "x - " << -bt;
}
else if (bt > 0)
{
cout << mt << "x + " << bt;
}
else if (bt < 0)
{
cout << mt << "x - " << -bt;
}
}
else if (mt == 0 && bt == 0)
{
cout << "0";
}
}
} |
# 0306, 2024-11-02 13:24:10, PPPPP-PPPP-------------- (37%)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
float mm(vector<float> xi, vector<float> yi ,float N){
// cout << "check2" << '\n';
float a=0,b=0,c=0,d =0;
// a
for(int i=0;i<N;i++){
a += ((xi[i]) * (yi[i]));
}
a = N*a;
// cout << N << '\n';
// cout << a << '\n';
// b
float l,r;
for(int i=0;i<N;i++){
l += xi[i];
}
for(int i=0;i<N;i++){
r += yi[i];
}
b = l * r;
// c
for(int i=0;i<N;i++){
c += ((xi[i]) * (xi[i]));
}
c = N*c;
// d
for(int i=0;i<N;i++){
d += (xi[i]);
}
d = d*d;
float ans = (a-b) / (c-d);
return ans;
}
float bb(vector<float> xi, vector<float> yi , float N , float m){
float a = 0,b=0;
for(int i=0;i<N;i++){
a += yi[i];
}
for(int i=0;i<N;i++){
b += xi[i];
}
b = b*m;
return (a-b)/N;
}
int main(){
int n; string cmd;
cin >> n >> cmd;
int N = n;
float x,y;
vector<float> xi,yi;
while(n--){
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// cout << "N is " << N << '\n';
float m = mm(xi,yi,N);
// cout << "m is " << m << '\n';
float b = bb(xi,yi,N,m);
// cout << "b is " << b << '\n';
if(cmd == "mb"){
cout << round(m*1e3)/1e3 << '\n' << round(b*1e3)/1e3;
}
else{
cout << "y = " << m << "x ";
if(b != 0){
if(b < 0){
cout << "- " << -b;
}
else{
cout << "+ " << b;
}
}
}
} | # 0307, 2024-11-02 14:09:00, -----PPPPP-------PPPP-PP (45%)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
float mm(vector<float> xi, vector<float> yi ,float N){
// cout << "check2" << '\n';
float a=0,b=0,c=0,d =0;
// a
for(int i=0;i<N;i++){
a += ((xi[i]) * (yi[i]));
}
a *= N;
// cout << N << '\n';
// cout << a << '\n';
// b
float l = 0,r=0;
for(int i=0;i<N;i++){
l += xi[i];
}
for(int i=0;i<N;i++){
r += yi[i];
}
b = l * r;
// c
for(int i=0;i<N;i++){
c += ((xi[i]) * (xi[i]));
}
c *= N;
// d
for(int i=0;i<N;i++){
d += (xi[i]);
}
float d2 = d*d;
float ans = (a-b) / (c-d2);
return round(ans*1e3)/1e3;
}
float bb(vector<float> xi, vector<float> yi , float N , float m){
float a = 0,b=0;
for(int i=0;i<N;i++){
a += yi[i];
}
for(int i=0;i<N;i++){
b += xi[i];
}
b = b*m;
return round(((a-b)/N)*1e3)/1e3;
}
int main(){
int n; string cmd;
cin >> n >> cmd;
int N = n;
float x,y;
vector<float> xi,yi;
while(n--){
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// cout << "N is " << N << '\n';
float m = mm(xi,yi,N);
// cout << "m is " << round(m*1e3)/1e3 << '\n';
float b = bb(xi,yi,N,m);
// cout << "b is " << round(b*1e3)/1e3 << '\n';
if(cmd == "mb"){
cout << round(m*1e3)/1e3 << '\n' << round(b*1e3)/1e3;
}
else{
cout << "y = ";
if(round(m*1e3)/1e3 != 1){
if(round(m*1e3)/1e3 == -1){
cout << "-";
}
else{
cout << round(m*1e3)/1e3;
}
}
cout << "x ";
if(b != 0){
if(b < 0){
cout << "- " << -round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
}
} | # 0308, 2024-11-02 14:17:21, -----PPPPP-----PP-PP-P-- (41%)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
float mm(vector<float> xi, vector<float> yi ,float N){
// cout << "check2" << '\n';
float a=0,b=0,c=0,d =0;
// a
for(int i=0;i<N;i++){
a += ((xi[i]) * (yi[i]));
}
a *= N;
// cout << N << '\n';
// cout << a << '\n';
// b
float l = 0,r=0;
for(int i=0;i<N;i++){
l += xi[i];
}
for(int i=0;i<N;i++){
r += yi[i];
}
b = l * r;
// c
for(int i=0;i<N;i++){
c += ((xi[i]) * (xi[i]));
}
c *= N;
// d
for(int i=0;i<N;i++){
d += (xi[i]);
}
float d2 = d*d;
float ans = (a-b) / (c-d2);
return round(ans*1e3)/1e3;
}
float bb(vector<float> xi, vector<float> yi , float N , float m){
float a = 0,b=0;
for(int i=0;i<N;i++){
a += yi[i];
}
for(int i=0;i<N;i++){
b += xi[i];
}
b = b*m;
return round(((a-b)/N)*1e3)/1e3;
}
int main(){
int n; string cmd;
cin >> n >> cmd;
int N = n;
float x,y;
vector<float> xi,yi;
while(n--){
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// cout << "N is " << N << '\n';
float m = mm(xi,yi,N);
// cout << "m is " << round(m*1e3)/1e3 << '\n';
float b = bb(xi,yi,N,m);
// cout << "b is " << round(b*1e3)/1e3 << '\n';
if(round(m*1e3)/1e3 == -0){
m = 0;
}
if(round(b*1e3)/1e3 == -0){
b = 0;
}
if(cmd == "mb"){
cout << round(m*1e3)/1e3 << '\n' << round(b*1e3)/1e3;
}
else{
bool noX = true;
if(round(m*1e3)/1e3 != 0){
noX = false;
}
cout << "y = ";
bool loneB = true;;
if(round(m*1e3)/1e3 != 1){
if(round(m*1e3)/1e3 == -1){
cout << "-";
}
else{
if(!(noX && round(b*1e3)/1e3 != 0)){
cout << round(m*1e3)/1e3;
loneB = true;
}
}
}
if(round(m*1e3)/1e3 != 0){
cout << "x";
}
if(b != 0){
if(loneB){
cout << round(b*1e3)/1e3;
}
else{
if(b < 0){
cout << " - " << -round(b*1e3)/1e3;
}
else{
cout << " + " << round(b*1e3)/1e3;
}
}
}
}
} | # 0309, 2024-11-02 14:27:51, -----PPPPP-----PPPPPPPPP (58%)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
float mm(vector<float> xi, vector<float> yi ,float N){
// cout << "check2" << '\n';
float a=0,b=0,c=0,d =0;
// a
for(int i=0;i<N;i++){
a += ((xi[i]) * (yi[i]));
}
a *= N;
// cout << N << '\n';
// cout << a << '\n';
// b
float l = 0,r=0;
for(int i=0;i<N;i++){
l += xi[i];
}
for(int i=0;i<N;i++){
r += yi[i];
}
b = l * r;
// c
for(int i=0;i<N;i++){
c += ((xi[i]) * (xi[i]));
}
c *= N;
// d
for(int i=0;i<N;i++){
d += (xi[i]);
}
float d2 = d*d;
float ans = (a-b) / (c-d2);
return round(ans*1e3)/1e3;
}
float bb(vector<float> xi, vector<float> yi , float N , float m){
float a = 0,b=0;
for(int i=0;i<N;i++){
a += yi[i];
}
for(int i=0;i<N;i++){
b += xi[i];
}
b = b*m;
return ((a-b)/N);
}
int main(){
int n; string cmd;
cin >> n >> cmd;
int N = n;
float x,y;
vector<float> xi,yi;
while(n--){
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// cout << "N is " << N << '\n';
float m = mm(xi,yi,N);
// cout << "m is " << round(m*1e3)/1e3 << '\n';
float b = bb(xi,yi,N,m);
// cout << "b is " << b << '\n';
// cout << "b is " << round(b*1e3)/1e3 << '\n';
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
// cout << "b is " << b << '\n';
if(round(m*1e3)/1e3 == -0){
m = 0;
}
if(round(b*1e3)/1e3 == -0){
b = 0;
}
if(cmd == "mb"){
cout << round(m*1e3)/1e3 << '\n' << round(b*1e3)/1e3;
}
else{
if(round(b*1e3)/1e3 == 0){
if(m == 0){
cout << "y = 0";
}
else{
cout << "y = ";
if(m != -1 && m != 1){
cout << m << "x";
}
else if( m == 1){
cout << "x";
}
else if(m == -1){
cout << "-x";
}
}
}
else{
cout << "y = ";
if(m != 0){
if(m != -1 && m != 1){
cout << m << "x";
}
else if( m == 1){
cout << "x";
}
else if(m == -1){
cout << "-x";
}
if(b > 0){
cout << " + " << b;
}
else{
cout << " - " << -b;
}
}
else{
cout << b;
}
}
}
} | # 0310, 2024-11-02 14:33:52, PPPPPPPPPP-----PP-PP-P-- (62%)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
float mm(vector<float> xi, vector<float> yi ,float N){
// cout << "check2" << '\n';
float a=0,b=0,c=0,d =0;
// a
for(int i=0;i<N;i++){
a += ((xi[i]) * (yi[i]));
}
a *= N;
// cout << N << '\n';
// cout << a << '\n';
// b
float l = 0,r=0;
for(int i=0;i<N;i++){
l += xi[i];
}
for(int i=0;i<N;i++){
r += yi[i];
}
b = l * r;
// c
for(int i=0;i<N;i++){
c += ((xi[i]) * (xi[i]));
}
c *= N;
// d
for(int i=0;i<N;i++){
d += (xi[i]);
}
float d2 = d*d;
float ans = (a-b) / (c-d2);
return ans;
}
float bb(vector<float> xi, vector<float> yi , float N , float m){
float a = 0,b=0;
for(int i=0;i<N;i++){
a += yi[i];
}
for(int i=0;i<N;i++){
b += xi[i];
}
b = b*m;
float ans = (a-b)/N;
return ans;
}
int main(){
int n; string cmd;
cin >> n >> cmd;
int N = n;
float x=0,y=0;
vector<float> xi,yi;
while(n--){
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// cout << "N is " << N << '\n';
float m = mm(xi,yi,N);
float b = bb(xi,yi,N,m);
// cout << "b is " << b << '\n';
// cout << "b is " << round(b*1e3)/1e3 << '\n';
b = round(b*1e3)/1e3;
// cout << "b is " << b << '\n';
if(round(m*1e3)/1e3 == -0){
m = 0;
}
if(round(b*1e3)/1e3 == -0){
b = 0;
}
if(cmd == "mb"){
cout << round(m*1e3)/1e3 << '\n' << round(b*1e3)/1e3;
}
else{
if(round(b*1e3)/1e3 == 0){
if(m == 0){
cout << "y = 0";
}
else{
cout << "y = ";
if(m != -1 && m != 1){
cout << m << "x";
}
else if( m == 1){
cout << "x";
}
else if(m == -1){
cout << "-x";
}
}
}
else{
cout << "y = ";
if(m != 0){
if(m != -1 && m != 1){
cout << m << "x";
}
else if( m == 1){
cout << "x";
}
else if(m == -1){
cout << "-x";
}
if(b > 0){
cout << " + " << b;
}
else{
cout << " - " << -b;
}
}
else{
cout << b;
}
}
}
} | # 0311, 2024-11-02 14:38:17, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
float mm(vector<float> xi, vector<float> yi ,float N){
// cout << "check2" << '\n';
float a=0,b=0,c=0,d =0;
// a
for(int i=0;i<N;i++){
a += ((xi[i]) * (yi[i]));
}
a *= N;
// cout << N << '\n';
// cout << a << '\n';
// b
float l = 0,r=0;
for(int i=0;i<N;i++){
l += xi[i];
}
for(int i=0;i<N;i++){
r += yi[i];
}
b = l * r;
// c
for(int i=0;i<N;i++){
c += ((xi[i]) * (xi[i]));
}
c *= N;
// d
for(int i=0;i<N;i++){
d += (xi[i]);
}
float d2 = d*d;
float ans = (a-b) / (c-d2);
return ans;
}
float bb(vector<float> xi, vector<float> yi , float N , float m){
float a = 0,b=0;
for(int i=0;i<N;i++){
a += yi[i];
}
for(int i=0;i<N;i++){
b += xi[i];
}
b = b*m;
float ans = (a-b)/N;
return ans;
}
int main(){
int n; string cmd;
cin >> n >> cmd;
int N = n;
float x=0,y=0;
vector<float> xi,yi;
while(n--){
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// cout << "N is " << N << '\n';
float m = mm(xi,yi,N);
float b = bb(xi,yi,N,m);
// cout << "b is " << b << '\n';
// cout << "b is " << round(b*1e3)/1e3 << '\n';
b = round(b*1e3)/1e3;
m = round(m*1e3)/1e3;
// cout << "b is " << b << '\n';
if(round(m*1e3)/1e3 == -0){
m = 0;
}
if(round(b*1e3)/1e3 == -0){
b = 0;
}
if(cmd == "mb"){
cout << round(m*1e3)/1e3 << '\n' << round(b*1e3)/1e3;
}
else{
if(round(b*1e3)/1e3 == 0){
if(m == 0){
cout << "y = 0";
}
else{
cout << "y = ";
if(m != -1 && m != 1){
cout << m << "x";
}
else if( m == 1){
cout << "x";
}
else if(m == -1){
cout << "-x";
}
}
}
else{
cout << "y = ";
if(m != 0){
if(m != -1 && m != 1){
cout << m << "x";
}
else if( m == 1){
cout << "x";
}
else if(m == -1){
cout << "-x";
}
if(b > 0){
cout << " + " << b;
}
else{
cout << " - " << -b;
}
}
else{
cout << b;
}
}
}
} |
# 0312, 2024-11-02 13:30:45, PPPPPPPPPPPPPPP-----P--P (70%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;
string cmd;
float x, y ,
sum_x = 0, sum_y = 0,
sum_xy = 0, sum_xx = 0,
m, b;
cin >> N >> cmd;
for(int i = 0; i < N; i++){
cin >> x >> y;
sum_x += x;
sum_y += y;
sum_xy += x*y;
sum_xx += x*x;
}
m = ((N * sum_xy) - (sum_x * sum_y)) / ((N * sum_xx) - (sum_x*sum_x));
b = (sum_y - (m*sum_x))/N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(cmd == "mb"){
cout << m << endl << b << endl;
}else if(cmd == "func"){
cout << "y = ";
if(m == -1)cout << "-";
else cout << m;
cout << "x ";
if(b < 0) cout << "- " << -1*b;
else cout << "+ " << b;
cout << endl;
}
} | # 0313, 2024-11-02 13:35:40, PPPPPPPPPPPPPPPPP--PPP-P (87%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;
string cmd;
float x, y ,
sum_x = 0, sum_y = 0,
sum_xy = 0, sum_xx = 0,
m, b;
cin >> N >> cmd;
for(int i = 0; i < N; i++){
cin >> x >> y;
sum_x += x;
sum_y += y;
sum_xy += x*y;
sum_xx += x*x;
}
m = ((N * sum_xy) - (sum_x * sum_y)) / ((N * sum_xx) - (sum_x*sum_x));
b = (sum_y - (m*sum_x))/N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(cmd == "mb"){
cout << m << endl << b << endl;
}else if(cmd == "func"){
cout << "y = ";
if(m != 0){
if(m == -1)cout << "-x ";
else cout << m << "x ";
if(b < 0) cout << "- " << -1*b;
else if(b > 0) cout << "+ " << b;
}else cout << b;
cout << endl;
}
} | # 0314, 2024-11-02 13:40:22, PPPPPPPPPPPPPPPP---P-P-- (75%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;
string cmd;
float x, y ,
sum_x = 0, sum_y = 0,
sum_xy = 0, sum_xx = 0,
m, b;
cin >> N >> cmd;
for(int i = 0; i < N; i++){
cin >> x >> y;
sum_x += x;
sum_y += y;
sum_xy += x*y;
sum_xx += x*x;
}
m = ((N * sum_xy) - (sum_x * sum_y)) / ((N * sum_xx) - (sum_x*sum_x));
b = (sum_y - (m*sum_x))/N;
if(cmd == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
}else if(cmd == "func"){
cout << "y = ";
if(m != 0){
if(m == -1)cout << "-x ";
else cout << round(m*1e3)/1e3 << "x ";
if(b < 0) cout << "- " << -1*round(b*1e3)/1e3;
else if(b > 0) cout << "+ " << round(b*1e3)/1e3;
}else cout << round(b*1e3)/1e3;
cout << endl;
}
} | # 0315, 2024-11-02 13:40:40, PPPPPPPPPPPPPPPPP--PPP-P (87%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;
string cmd;
float x, y ,
sum_x = 0, sum_y = 0,
sum_xy = 0, sum_xx = 0,
m, b;
cin >> N >> cmd;
for(int i = 0; i < N; i++){
cin >> x >> y;
sum_x += x;
sum_y += y;
sum_xy += x*y;
sum_xx += x*x;
}
m = ((N * sum_xy) - (sum_x * sum_y)) / ((N * sum_xx) - (sum_x*sum_x));
b = (sum_y - (m*sum_x))/N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(cmd == "mb"){
cout << m << endl << b << endl;
}else if(cmd == "func"){
cout << "y = ";
if(m != 0){
if(m == -1)cout << "-x ";
else cout << m << "x ";
if(b < 0) cout << "- " << -1*b;
else if(b > 0) cout << "+ " << b;
}else cout << b;
cout << endl;
}
} | # 0316, 2024-11-02 13:42:41, PPPPPPPPPPPPPPPPP--PPP-P (87%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;
string cmd;
float x, y ,
sum_x = 0, sum_y = 0,
sum_xy = 0, sum_xx = 0,
m, b;
cin >> N >> cmd;
for(int i = 0; i < N; i++){
cin >> x >> y;
sum_x += x;
sum_y += y;
sum_xy += x*y;
sum_xx += x*x;
}
m = ((N * sum_xy) - (sum_x * sum_y)) / ((N * sum_xx) - (sum_x*sum_x));
b = (sum_y - (m*sum_x))/N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(cmd == "mb"){
cout << m << endl << b << endl;
}else if(cmd == "func"){
cout << "y = ";
if(m != 0){
if(m == -1)cout << "-x ";
else cout << m << "x ";
if(b < 0) cout << "- " << -1*b;
else if(b > 0) cout << "+ " << b;
}else{
if(b < 0) cout << "-" << -1*b;
else cout << b;
}
cout << endl;
}
} | # 0317, 2024-11-02 13:47:45, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;
string cmd;
float x, y ,
sum_x = 0, sum_y = 0,
sum_xy = 0, sum_xx = 0,
m, b;
cin >> N >> cmd;
for(int i = 0; i < N; i++){
cin >> x >> y;
sum_x += x;
sum_y += y;
sum_xy += x*y;
sum_xx += x*x;
}
m = ((N * sum_xy) - (sum_x * sum_y)) / ((N * sum_xx) - (sum_x*sum_x));
b = (sum_y - (m*sum_x))/N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(cmd == "mb"){
cout << m << endl << b << endl;
}else if(cmd == "func"){
cout << "y = ";
if(m != 0){
if(m == -1)cout << "-x ";
else if(m == 1) cout << "x ";
else cout << m << "x ";
if(b < 0) cout << "- " << -1*b;
else if(b > 0) cout << "+ " << b;
}else{
if(b < 0) cout << "-" << -1*b;
else cout << b;
}
cout << endl;
}
} |
# 0318, 2024-11-02 09:38:46, PPPPPPPPPPP-P--P---P-P-- (62%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
string a; cin>>a;
vector<float>x,y;
for(int i=0;i<n;i++){
float xx,yy; cin>>xx>>yy;
x.push_back(xx);
y.push_back(yy);
}
float f=0,xs=0,ys=0,xp=0;
for(int i=0;i<x.size();i++){
f += x[i]*y[i];
xs +=x[i];
ys+= y[i];
xp += x[i]*x[i];
}
//cout<<f<<" "<<xs<<" "<<ys<<" "<<xp;
float m= (n*f-(xs*ys))/(n*xp-xs*xs);
float b = (ys-m*xs)/n;
if(a=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
else{cout<<"y = ";
if(m==0){cout<<b; return 0;}
else if(m==-1)cout<<"-x ";
else cout<<round(m*1e3)/1e3<<"x ";
if(b==0)return 0;
if(b<0)cout<<round(b*1e3)/1e3;
else cout<< "+ "<<round(b*1e3)/1e3;
}
} | # 0319, 2024-11-02 09:40:13, PPPPPPPPPPPPPPPP---P-P-- (75%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
string a; cin>>a;
vector<float>x,y;
for(int i=0;i<n;i++){
float xx,yy; cin>>xx>>yy;
x.push_back(xx);
y.push_back(yy);
}
float f=0,xs=0,ys=0,xp=0;
for(int i=0;i<x.size();i++){
f += x[i]*y[i];
xs +=x[i];
ys+= y[i];
xp += x[i]*x[i];
}
//cout<<f<<" "<<xs<<" "<<ys<<" "<<xp;
float m= (n*f-(xs*ys))/(n*xp-xs*xs);
float b = (ys-m*xs)/n;
if(a=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
else{cout<<"y = ";
if(m==0){cout<<b; return 0;}
else if(m==-1)cout<<"-x ";
else cout<<round(m*1e3)/1e3<<"x ";
if(b==0)return 0;
if(b<0)cout<<"- "<<abs(round(b*1e3)/1e3);
else cout<< "+ "<<round(b*1e3)/1e3;
}
} | # 0320, 2024-11-02 09:43:02, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
string a; cin>>a;
vector<float>x,y;
for(int i=0;i<n;i++){
float xx,yy; cin>>xx>>yy;
x.push_back(xx);
y.push_back(yy);
}
float f=0,xs=0,ys=0,xp=0;
for(int i=0;i<x.size();i++){
f += x[i]*y[i];
xs +=x[i];
ys+= y[i];
xp += x[i]*x[i];
}
//cout<<f<<" "<<xs<<" "<<ys<<" "<<xp;
float m= (n*f-(xs*ys))/(n*xp-xs*xs);
float b = (ys-m*xs)/n;
if(a=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
else{cout<<"y = ";
if(m==0){cout<<b; return 0;}
else if(m==1)cout<<"x ";
else if(m==-1)cout<<"-x ";
else cout<<round(m*1e3)/1e3<<"x ";
if(b==0)return 0;
if(b<0)cout<<"- "<<abs(round(b*1e3)/1e3);
else cout<< "+ "<<round(b*1e3)/1e3;
}
} | # 0321, 2024-11-02 11:59:45, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
string a; cin>>a;
vector<float>x,y;
for(int i=0;i<n;i++){
float xx,yy; cin>>xx>>yy;
x.push_back(xx);
y.push_back(yy);
}
float f=0,xs=0,ys=0,xp=0;
for(int i=0;i<x.size();i++){
f += x[i]*y[i];
xs +=x[i];
ys+= y[i];
xp += x[i]*x[i];
}
//cout<<f<<" "<<xs<<" "<<ys<<" "<<xp;
float m= (n*f-(xs*ys))/(n*xp-xs*xs);
float b = (ys-m*xs)/n;
if(a=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
else{cout<<"y = ";
if(round(m*1e3)/1e3==0){cout<<b; return 0;}
else if(m==1)cout<<"x ";
else if(m==-1)cout<<"-x ";
else cout<<round(m*1e3)/1e3<<"x ";
if(b==0)return 0;
if(b<0)cout<<"- "<<abs(round(b*1e3)/1e3);
else cout<< "+ "<<round(b*1e3)/1e3;
}
} | # 0322, 2024-11-02 12:00:12, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
string a; cin>>a;
vector<float>x,y;
for(int i=0;i<n;i++){
float xx,yy; cin>>xx>>yy;
x.push_back(xx);
y.push_back(yy);
}
float f=0,xs=0,ys=0,xp=0;
for(int i=0;i<x.size();i++){
f += x[i]*y[i];
xs +=x[i];
ys+= y[i];
xp += x[i]*x[i];
}
//cout<<f<<" "<<xs<<" "<<ys<<" "<<xp;
float m= (n*f-(xs*ys))/(n*xp-xs*xs);
float b = (ys-m*xs)/n;
if(a=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
else{cout<<"y = ";
if(round(m*1e3)/1e3==0){cout<<b; return 0;}
else if(m==1)cout<<"x ";
else if(m==-1)cout<<"-x ";
else cout<<round(m*1e3)/1e3<<"x ";
if(round(b*1e3)/1e3==0)return 0;
if(b<0)cout<<"- "<<abs(round(b*1e3)/1e3);
else cout<< "+ "<<round(b*1e3)/1e3;
}
} | # 0323, 2024-11-02 12:01:25, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
string a; cin>>a;
vector<float>x,y;
for(int i=0;i<n;i++){
float xx,yy; cin>>xx>>yy;
x.push_back(xx);
y.push_back(yy);
}
float f=0,xs=0,ys=0,xp=0;
for(int i=0;i<x.size();i++){
f += x[i]*y[i];
xs +=x[i];
ys+= y[i];
xp += x[i]*x[i];
}
//cout<<f<<" "<<xs<<" "<<ys<<" "<<xp;
float m= (n*f-(xs*ys))/(n*xp-xs*xs);
float b = (ys-m*xs)/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(a=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
else{cout<<"y = ";
if(round(m*1e3)/1e3==0){cout<<b; return 0;}
else if(m==1)cout<<"x ";
else if(m==-1)cout<<"-x ";
else cout<<round(m*1e3)/1e3<<"x ";
if(b==0)return 0;
if(b<0)cout<<"- "<<abs(round(b*1e3)/1e3);
else cout<< "+ "<<round(b*1e3)/1e3;
}
} |
# 0324, 2024-11-02 09:48:32, PPPPPPPPPPP-P--P-PPP---- (66%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string t;
float a,b,xxy=0,x=0,y=0,xx=0,m;
cin >> n >> t;
for(int i=0;i<n;i++)
{
cin >> a >> b;
xxy += a*b;
x += a;
y += b;
xx += a*a;
}
m = (n*xxy - (x*y))/(n*xx-x*x);
b = (y - m*x)/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(t == "mb")
{
cout << m;
cout << endl;
cout << b;
}
else
{
if(m==0 && b==0)
cout<< "y = 0";
else if(m==1 && b==0)
cout<< "y = x";
else if(m==-1 && b==0)
cout<< "y = -x";
else if(m==1 && b>0)
cout<< "y = x + "<<b;
else if(m==1 && b<0)
cout<< "y = x - "<<b;
else if(m==-1 && b>0)
cout<< "y = x + "<<b;
else if(m==-1 && b<0)
cout<< "y = -x - "<<b;
else if(b==0)
cout<< "y = " << m << "x";
else if(b>1)
cout<< "y = " << m << "x + " <<b;
else
cout<< "y = " << m << "x - " <<b;
}
} | # 0325, 2024-11-02 09:52:40, PPPPPPPPPPPPPPP--PPP-PPP (87%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string t;
float a,b,xxy=0,x=0,y=0,xx=0,m;
cin >> n >> t;
for(int i=0;i<n;i++)
{
cin >> a >> b;
xxy += a*b;
x += a;
y += b;
xx += a*a;
}
m = (n*xxy - (x*y))/(n*xx-x*x);
b = (y - m*x)/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(t == "mb")
{
cout << m;
cout << endl;
cout << b;
}
else
{
if(m==0 && b==0)
cout<< "y = 0";
if(m==0 && b>0)
cout<< "y = " << b;
if(m==0 && b<0)
cout<< "y = " << b;
else if(m==1 && b==0)
cout<< "y = x";
else if(m==-1 && b==0)
cout<< "y = -x";
else if(m==1 && b>0)
cout<< "y = x + "<<b;
else if(m==1 && b<0)
cout<< "y = x - "<< -1*b;
else if(m==-1 && b>0)
cout<< "y = x + "<<b;
else if(m==-1 && b<0)
cout<< "y = -x - "<< -1*b;
else if(b==0)
cout<< "y = " << m << "x";
else if(b>1)
cout<< "y = " << m << "x + " <<b;
else
cout<< "y = " << m << "x - " << -1*b;
}
} | # 0326, 2024-11-02 09:55:32, PPPPPPPPPPPPPPP--PPPPPPP (91%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string t;
float a,b,xxy=0,x=0,y=0,xx=0,m;
cin >> n >> t;
for(int i=0;i<n;i++)
{
cin >> a >> b;
xxy += a*b;
x += a;
y += b;
xx += a*a;
}
m = (n*xxy - (x*y))/(n*xx-x*x);
b = (y - m*x)/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(t == "mb")
{
cout << m;
cout << endl;
cout << b;
}
else
{
if(m==0 && b==0)
cout<< "y = 0";
if(m==0 && b>0)
cout<< "y = " << b;
if(m==0 && b<0)
cout<< "y = " << b;
else if(m==1 && b==0)
cout<< "y = x";
else if(m==-1 && b==0)
cout<< "y = -x";
else if(m==1 && b>0)
cout<< "y = x + "<<b;
else if(m==1 && b<0)
cout<< "y = x - "<< -1*b;
else if(m==-1 && b>0)
cout<< "y = -x + "<<b;
else if(m==-1 && b<0)
cout<< "y = -x - "<< -1*b;
else if(b==0)
cout<< "y = " << m << "x";
else if(b>1)
cout<< "y = " << m << "x + " <<b;
else
cout<< "y = " << m << "x - " << -1*b;
}
} | # 0327, 2024-11-02 11:04:28, PPPPPPPPPPPPPPPPPP--PPPP (91%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string t;
float a,b,xxy=0,x=0,y=0,xx=0,m;
cin >> n >> t;
for(int i=0;i<n;i++)
{
cin >> a >> b;
xxy += a*b;
x += a;
y += b;
xx += a*a;
}
m = (n*xxy - (x*y))/(n*xx-x*x);
b = (y - m*x)/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(t == "mb")
{
cout << m;
cout << endl;
cout << b;
}
else
{
if(m==0 && b==0)
cout<< "y = 0";
else if(m==0 && b>0)
cout<< "y = " << b;
else if(m>0 && b==0)
cout<< "y = "<< m << "x";
else if(m<0 && b==0)
cout<< "y = "<< m << "x";
else if(m==0 && b<0)
cout<< "y = " << b;
else if(m==1 && b==0)
cout<< "y = x";
else if(m==-1 && b==0)
cout<< "y = -x";
else if(m==1 && b>0)
cout<< "y = x + "<<b;
else if(m==1 && b<0)
cout<< "y = x - "<< -1*b;
else if(m==-1 && b>0)
cout<< "y = -x + "<<b;
else if(m==-1 && b<0)
cout<< "y = -x - "<< -1*b;
else if(b==0)
cout<< "y = " << m << "x";
else if(b>1)
cout<< "y = " << m << "x + " <<b;
else
cout<< "y = " << m << "x - " << -1*b;
}
} | # 0328, 2024-11-02 12:06:07, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string t;
float a,b,xxy=0,x=0,y=0,xx=0,m;
cin >> n >> t;
for(int i=0;i<n;i++)
{
cin >> a >> b;
xxy += a*b;
x += a;
y += b;
xx += a*a;
}
m = (n*xxy - (x*y))/(n*xx-x*x);
b = (y - m*x)/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(t == "mb")
{
cout << m;
cout << endl;
cout << b;
}
else
{
if(m==0 && b==0)
cout<< "y = 0";
else if(m==0 && b>0)
cout<< "y = " << b;
else if(m==0 && b<0)
cout<< "y = " << b;
else if(m==1 && b==0)
cout<< "y = x";
else if(m==-1 && b==0)
cout<< "y = -x";
else if(m==1 && b>0)
cout<< "y = x + "<<b;
else if(m==1 && b<0)
cout<< "y = x - "<< -1*b;
else if(m==-1 && b>0)
cout<< "y = -x + "<<b;
else if(m==-1 && b<0)
cout<< "y = -x - "<< -1*b;
else if(b==0)
cout<< "y = " << m << "x";
else if(b>1)
cout<< "y = " << m << "x + " <<b;
else
cout<< "y = " << m << "x - " << -1*b;
}
} |
# 0329, 2024-11-02 10:09:38, PPPPPPPPPP-----P--PP-P-- (58%)
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);cin.tie(0);
string s;
int n;
cin>>n>>s;
float a1,a2;
vector<pair<float,float>> v;
for(int i=0;i<n;i++){
cin>>a1>>a2;
v.push_back(make_pair(a1,a2));
}
float m=0,m1=0,m2=0,m3=0,m4=0,m5=0;
for(int i=0; i<=n; i++){
m1 += (v[i].first)*(v[i].second);
m2 += v[i].first;
m3 += v[i].second;
m4 += (v[i].first)*(v[i].first);
m5 += v[i].first;
}
m = ((n*m1)-(m2*m3))/((n*m4)-(m5*m5));
float b=0;
b = ((m3)-(m*m2))/(n);
if(s == "mb"){
// cout<<m<<'\n'<<m1<<'\n'<<m2<<'\n'<<m3<<'\n'<<m4<<'\n'<<m5<<'\n'<<n<<'\n'<<b;
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
}
else if(s == "func"){
if(m==0 && b==0){
cout<<"y = 0";
}
else if(m==0) {
cout<<"y = "<<b;
}
else if(b==0) {
if(m==1){
cout<<"y = x";
}
else if(m==-1){
cout<<"y = -x";
}
else {
cout<<"y = "<<m<<"x";
}
}
else if(b >0) {
if(m==1){
cout<<"y = x + "<<b;
}
else if(m==-1){
cout<<"y = -x + "<<b;
}
else {
cout<<"y = "<<m<<"x +"<<b;
}
}
else if(b<0){
if(m==1){
cout<<"y = x - "<<abs(b);
}
else if(m==-1){
cout<<"y = -x - "<<abs(b);
}
else {
cout<<"y = "<<m<<"x -"<<abs(b);
}
}
}
} | # 0330, 2024-11-02 10:12:09, PPPPPPPPPP-----P--PP-P-- (58%)
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);cin.tie(0);
string s;
int n;
cin>>n>>s;
float a1,a2;
vector<pair<float,float>> v;
for(int i=0;i<n;i++){
cin>>a1>>a2;
v.push_back(make_pair(a1,a2));
}
float m=0,m1=0,m2=0,m3=0,m4=0,m5=0;
for(int i=0; i<=n; i++){
m1 += (v[i].first)*(v[i].second);
m2 += v[i].first;
m3 += v[i].second;
m4 += (v[i].first)*(v[i].first);
m5 += v[i].first;
}
m = ((n*m1)-(m2*m3))/((n*m4)-(m5*m5));
float b=0;
b = ((m3)-(m*m2))/(n);
if(s == "mb"){
// cout<<m<<'\n'<<m1<<'\n'<<m2<<'\n'<<m3<<'\n'<<m4<<'\n'<<m5<<'\n'<<n<<'\n'<<b;
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
}
else if(s == "func"){
if(m==0 && b==0){
cout<<"y = 0";
}
else if(m==0) {
cout<<"y = "<<round(b*1e3)/1e3;
}
else if(b==0) {
if(m==1){
cout<<"y = x";
}
else if(m==-1){
cout<<"y = -x";
}
else {
cout<<"y = "<<round(m*1e3)/1e3<<"x";
}
}
else if(b >0) {
if(m==1){
cout<<"y = x + "<<round(b*1e3)/1e3;
}
else if(m==-1){
cout<<"y = -x + "<<round(b*1e3)/1e3;
}
else {
cout<<"y = "<<round(m*1e3)/1e3<<"x +"<<round(b*1e3)/1e3;
}
}
else if(b<0){
if(m==1){
cout<<"y = x - "<<abs(round(b*1e3)/1e3);
}
else if(m==-1){
cout<<"y = -x - "<<abs(round(b*1e3)/1e3);
}
else {
cout<<"y = "<<round(m*1e3)/1e3<<"x -"<<abs(round(b*1e3)/1e3);
}
}
}
} | # 0331, 2024-11-02 10:12:20, PPPPPPPPPP-----P--PP-P-- (58%)
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);cin.tie(0);
string s;
int n;
cin>>n>>s;
float a1,a2;
vector<pair<float,float>> v;
for(int i=0;i<n;i++){
cin>>a1>>a2;
v.push_back(make_pair(a1,a2));
}
float m=0,m1=0,m2=0,m3=0,m4=0,m5=0;
for(int i=0; i<=n; i++){
m1 += (v[i].first)*(v[i].second);
m2 += v[i].first;
m3 += v[i].second;
m4 += (v[i].first)*(v[i].first);
m5 += v[i].first;
}
m = ((n*m1)-(m2*m3))/((n*m4)-(m5*m5));
float b=0;
b = ((m3)-(m*m2))/(n);
if(s == "mb"){
// cout<<m<<'\n'<<m1<<'\n'<<m2<<'\n'<<m3<<'\n'<<m4<<'\n'<<m5<<'\n'<<n<<'\n'<<b;
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
}
else if(s == "func"){
if(m==0 && b==0){
cout<<"y = 0";
}
else if(m==0) {
cout<<"y = "<<round(b*1e3)/1e3;
}
else if(b==0) {
if(m==1){
cout<<"y = x";
}
else if(m==-1){
cout<<"y = -x";
}
else {
cout<<"y = "<<round(m*1e3)/1e3<<"x";
}
}
else if(b >0) {
if(m==1){
cout<<"y = x + "<<round(b*1e3)/1e3;
}
else if(m==-1){
cout<<"y = -x + "<<round(b*1e3)/1e3;
}
else {
cout<<"y = "<<round(m*1e3)/1e3<<"x +"<<round(b*1e3)/1e3;
}
}
else if(b<0){
if(m==1){
cout<<"y = x - "<<abs(round(b*1e3)/1e3);
}
else if(m==-1){
cout<<"y = -x - "<<abs(round(b*1e3)/1e3);
}
else {
cout<<"y = "<<round(m*1e3)/1e3<<"x -"<<abs(round(b*1e3)/1e3);
}
}
}
} | # 0332, 2024-11-02 10:13:02, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);cin.tie(0);
string s;
int n;
cin>>n>>s;
float a1,a2;
vector<pair<float,float>> v;
for(int i=0;i<n;i++){
cin>>a1>>a2;
v.push_back(make_pair(a1,a2));
}
float m=0,m1=0,m2=0,m3=0,m4=0,m5=0;
for(int i=0; i<=n; i++){
m1 += (v[i].first)*(v[i].second);
m2 += v[i].first;
m3 += v[i].second;
m4 += (v[i].first)*(v[i].first);
m5 += v[i].first;
}
m = ((n*m1)-(m2*m3))/((n*m4)-(m5*m5));
float b=0;
b = ((m3)-(m*m2))/(n);
if(s == "mb"){
// cout<<m<<'\n'<<m1<<'\n'<<m2<<'\n'<<m3<<'\n'<<m4<<'\n'<<m5<<'\n'<<n<<'\n'<<b;
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
}
else if(s == "func"){
if(m==0 && b==0){
cout<<"y = 0";
}
else if(m==0) {
cout<<"y = "<<round(b*1e3)/1e3;
}
else if(b==0) {
if(m==1){
cout<<"y = x";
}
else if(m==-1){
cout<<"y = -x";
}
else {
cout<<"y = "<<round(m*1e3)/1e3<<"x";
}
}
else if(b >0) {
if(m==1){
cout<<"y = x + "<<round(b*1e3)/1e3;
}
else if(m==-1){
cout<<"y = -x + "<<round(b*1e3)/1e3;
}
else {
cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
}
else if(b<0){
if(m==1){
cout<<"y = x - "<<abs(round(b*1e3)/1e3);
}
else if(m==-1){
cout<<"y = -x - "<<abs(round(b*1e3)/1e3);
}
else {
cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);
}
}
}
} | # 0333, 2024-11-02 10:24:04, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);cin.tie(0);
string s;
int n;
cin>>n>>s;
float a1,a2;
vector<pair<float,float>> v;
for(int i=0;i<n;i++){
cin>>a1>>a2;
v.push_back(make_pair(a1,a2));
}
float m=0,m1=0,m2=0,m3=0,m4=0,m5=0;
for(int i=0; i<=n; i++){
m1 += (v[i].first)*(v[i].second);
m2 += v[i].first;
m3 += v[i].second;
m4 += (v[i].first)*(v[i].first);
m5 += v[i].first;
}
m = ((n*m1)-(m2*m3))/((n*m4)-(m5*m5));
float b=0;
b = ((m3)-(m*m2))/(n);
if(s == "mb"){
// cout<<m<<'\n'<<m1<<'\n'<<m2<<'\n'<<m3<<'\n'<<m4<<'\n'<<m5<<'\n'<<n<<'\n'<<b;
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
}
else if(s == "func"){
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(m==0 && b==0){
cout<<"y = 0";
}
else if(m==0) {
cout<<"y = "<<round(b*1e3)/1e3;
}
else if(b==0 || b==-0) {
if(m==1){
cout<<"y = x";
}
else if(m==-1){
cout<<"y = -x";
}
else if(m==0 || m==-0){
cout<<"y = 0";
}
else {
cout<<"y = "<<round(m*1e3)/1e3<<"x";
}
}
else if(b >0) {
if(m==1){
cout<<"y = x + "<<round(b*1e3)/1e3;
}
else if(m==-1){
cout<<"y = -x + "<<round(b*1e3)/1e3;
}
else if(m==0 || m==-0){
cout<<"y = "<<round(b*1e3)/1e3;
}
else {
cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
}
else if(b<0){
if(m==1){
cout<<"y = x - "<<abs(round(b*1e3)/1e3);
}
else if(m==-1){
cout<<"y = -x - "<<abs(round(b*1e3)/1e3);
}
else if(m==0 || m==-0){
cout<<"y = -"<<abs(round(b*1e3)/1e3);
}
else {
cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);
}
}
}
} |
# 0334, 2024-11-02 09:53:01, PPPPPPPPPPPPPPP--PPPP-PP (87%)
#include<iostream>
#include<bits/stdc++.h>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
int main(){
int N;
string req;
cin>>N>>req;
float in1,in2;
//cout<<N<<endl;
vector<pair<float,float>> point;
for(int i=0;i<N;i++){
cin>>in1>>in2;
point.push_back({in1,in2});
}
float Sigma_x=0;
float Sigma_x2=0;
float Sigma_y=0;
float Sigma_xy=0;
for(int i=0;i<N;i++){
//cout<<point[i].first<<" "<<point[i].second;
Sigma_x+=point[i].first;
Sigma_y+=point[i].second;
Sigma_xy+=point[i].first*point[i].second;
Sigma_x2+=point[i].first*point[i].first;
}
float m=((N*Sigma_xy)-(Sigma_x*Sigma_y))/((N*Sigma_x2)-(Sigma_x*Sigma_x));
float b=(Sigma_y-(m*Sigma_x))/N;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(req=="mb"){
cout<<m<<endl<<b;
}else if(req=="func"){
cout<<"y = ";
if(m!=0){
if(m==-1){cout<<"-";}
else if(m!=1){cout<<m;}
cout<<"x";
}
if(b!=0){
string sign="+";
if(b<0){sign="-";}
cout<<" "<<sign<<" "<<abs(b);
}
}
} | # 0335, 2024-11-02 09:57:51, PPPPPPPPPPPPPPP--PPPPPPP (91%)
#include<iostream>
#include<bits/stdc++.h>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
int main(){
int N;
string req;
cin>>N>>req;
float in1,in2;
//cout<<N<<endl;
vector<pair<float,float>> point;
for(int i=0;i<N;i++){
cin>>in1>>in2;
point.push_back({in1,in2});
}
float Sigma_x=0;
float Sigma_x2=0;
float Sigma_y=0;
float Sigma_xy=0;
for(int i=0;i<N;i++){
//cout<<point[i].first<<" "<<point[i].second;
Sigma_x+=point[i].first;
Sigma_y+=point[i].second;
Sigma_xy+=point[i].first*point[i].second;
Sigma_x2+=point[i].first*point[i].first;
}
float m=((N*Sigma_xy)-(Sigma_x*Sigma_y))/((N*Sigma_x2)-(Sigma_x*Sigma_x));
float b=(Sigma_y-(m*Sigma_x))/N;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(req=="mb"){
cout<<m<<endl<<b;
}else if(req=="func"){
string space=" ";
cout<<"y = ";
if(m!=0){
if(m==-1){cout<<"-";}
else if(m!=1){cout<<m;}
cout<<"x";
}
if(b!=0){
string sign="+";
if(m==0){space="";}
if(b<0){sign="-";}
cout<<space<<sign<<space<<abs(b);
}
}
} | # 0336, 2024-11-02 10:27:46, PPPPPPPPPPPPPPPP-PPPPPPP (95%)
#include<iostream>
#include<bits/stdc++.h>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
int main(){
int N;
string req;
cin>>N>>req;
float in1,in2;
//cout<<N<<endl;
vector<pair<float,float>> point;
for(int i=0;i<N;i++){
cin>>in1>>in2;
point.push_back({in1,in2});
}
float Sigma_x=0;
float Sigma_x2=0;
float Sigma_y=0;
float Sigma_xy=0;
for(int i=0;i<N;i++){
//cout<<point[i].first<<" "<<point[i].second;
Sigma_x+=point[i].first;
Sigma_y+=point[i].second;
Sigma_xy+=point[i].first*point[i].second;
Sigma_x2+=point[i].first*point[i].first;
}
float m=((N*Sigma_xy)-(Sigma_x*Sigma_y))/((N*Sigma_x2)-(Sigma_x*Sigma_x));
float b=(Sigma_y-(m*Sigma_x))/N;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(req=="mb"){
cout<<m<<endl<<b;
}else if(req=="func"){
string space=" ";
cout<<"y = ";
if(m!=0){
if(m==-1){cout<<"-";}
else if(m!=1){cout<<m;}
cout<<"x";
}
if(b!=0){
string sign="+";
if(m==0){space="";}
if(b<0){sign="-";}
cout<<space<<sign<<space<<abs(b);
}
if(m==0&&b==0){cout<<0;}
}
} | # 0337, 2024-11-02 10:30:48, PPPPPPPPPP-P-PPPP-PP-PPP (83%)
#include<iostream>
#include<bits/stdc++.h>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
int main(){
int N;
string req;
cin>>N>>req;
float in1,in2;
//cout<<N<<endl;
vector<pair<float,float>> point;
for(int i=0;i<N;i++){
cin>>in1>>in2;
point.push_back({in1,in2});
}
float Sigma_x=0;
float Sigma_x2=0;
float Sigma_y=0;
float Sigma_xy=0;
for(int i=0;i<N;i++){
//cout<<point[i].first<<" "<<point[i].second;
Sigma_x+=point[i].first;
Sigma_y+=point[i].second;
Sigma_xy+=point[i].first*point[i].second;
Sigma_x2+=point[i].first*point[i].first;
}
float m=((N*Sigma_xy)-(Sigma_x*Sigma_y))/((N*Sigma_x2)-(Sigma_x*Sigma_x));
float b=(Sigma_y-(m*Sigma_x))/N;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(req=="mb"){
cout<<m<<endl<<b;
}else if(req=="func"){
string space=" ";
cout<<"y = ";
if(m!=0){
if(m==-1){cout<<"-";}
else if(m!=1){cout<<m;}
cout<<"x";
}
if(b!=0){
string sign="+";
if(m==0){space="";}
if(b<0){sign="-";}
if(m==0;b>0){sign="";}
cout<<space<<sign<<space<<abs(b);
}
if(m==0&&b==0){cout<<0;}
}
} | # 0338, 2024-11-02 10:32:18, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<iostream>
#include<bits/stdc++.h>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
int main(){
int N;
string req;
cin>>N>>req;
float in1,in2;
//cout<<N<<endl;
vector<pair<float,float>> point;
for(int i=0;i<N;i++){
cin>>in1>>in2;
point.push_back({in1,in2});
}
float Sigma_x=0;
float Sigma_x2=0;
float Sigma_y=0;
float Sigma_xy=0;
for(int i=0;i<N;i++){
//cout<<point[i].first<<" "<<point[i].second;
Sigma_x+=point[i].first;
Sigma_y+=point[i].second;
Sigma_xy+=point[i].first*point[i].second;
Sigma_x2+=point[i].first*point[i].first;
}
float m=((N*Sigma_xy)-(Sigma_x*Sigma_y))/((N*Sigma_x2)-(Sigma_x*Sigma_x));
float b=(Sigma_y-(m*Sigma_x))/N;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(req=="mb"){
cout<<m<<endl<<b;
}else if(req=="func"){
string space=" ";
cout<<"y = ";
if(m!=0){
if(m==-1){cout<<"-";}
else if(m!=1){cout<<m;}
cout<<"x";
}
if(b!=0){
string sign="+";
if(m==0){space="";}
if(b<0){sign="-";}
if(m==0&&b>0){sign="";}
cout<<space<<sign<<space<<abs(b);
}
if(m==0&&b==0){cout<<0;}
}
} |
# 0339, 2024-11-02 14:03:53, PPPPPPPPPPPPPPPP-PPPPP-- (87%)
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
int main(){
vector<pair<double,double>> point;
int n;
double b,m,x,y,tm1=0,tm2x=0,tm2y=0,bm1=0,bm2=0;
double bt1=0,bt2=0;
string opr;
cin >> n >> opr;
for(int i=0;i<n;i++){
cin >> x >> y;
point.push_back(make_pair(x,y));
}
for(auto x:point){
tm1+=(x.first*x.second);
}
tm1*=n;
for(auto x:point){
tm2x+=x.first;
}
for(auto x:point){
tm2y+=x.second;
}
for(auto x:point){
bm1+=pow(x.first,2);
}
bm1*=n;
for(auto x:point){
bm2+=(x.first);
}
bm2=pow(bm2,2);
m=(tm1-(tm2x*tm2y))/(bm1-bm2);
for(auto x:point){
bt1+=x.second;
}
for(auto x:point){
bt2+=x.first;
}
bt2*=m;
b=(bt1-bt2)/n;
if(opr=="mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
}
else if(opr=="func"){
if(m==0){
if(b==0){
cout << "y = 0" << endl;
}
else{
cout << "y = " << b << endl;
}
}
else if(m==1){
if(b==0){
cout << "y = x" << endl;
}
else if(b<0){
cout << "y = x - " << -1*b << endl;
}
else{
cout << "y = x + " << b << endl;
}
}
else if(m==-1){
if(b==0){
cout << "y = -x" << endl;
}
else if(b<0){
cout << "y = -x - " << -1*b << endl;
}
else{
cout << "y = -x + " << b << endl;
}
}
else{
if(b<0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << -1*round(b*1e3)/1e3 << endl;
}
else{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3 << endl;
}
}
}
return 0;
} | # 0340, 2024-11-02 14:11:40, PPPPPPPPPPPPPPPP-PPPPP-- (87%)
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
int main(){
vector<pair<double,double>> point;
int n;
double b,m,x,y,tm1=0,tm2x=0,tm2y=0,bm1=0,bm2=0;
double bt1=0,bt2=0;
string opr;
cin >> n >> opr;
for(int i=0;i<n;i++){
cin >> x >> y;
point.push_back(make_pair(x,y));
}
for(auto x:point){
tm1+=(x.first*x.second);
}
tm1*=n;
for(auto x:point){
tm2x+=x.first;
}
for(auto x:point){
tm2y+=x.second;
}
for(auto x:point){
bm1+=pow(x.first,2);
}
bm1*=n;
for(auto x:point){
bm2+=(x.first);
}
bm2=pow(bm2,2);
m=(tm1-(tm2x*tm2y))/(bm1-bm2);
for(auto x:point){
bt1+=x.second;
}
for(auto x:point){
bt2+=x.first;
}
bt2*=m;
b=(bt1-bt2)/n;
if(opr=="mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
}
else if(opr=="func"){
if(m==0){
if(b==0){
cout << "y = 0" << endl;
}
else{
cout << "y = " << b << endl;
}
}
else if(m==1){
if(b==0){
cout << "y = x" << endl;
}
else if(b<0){
cout << "y = x - " << -1*round(b*1e3)/1e3 << endl;
}
else{
cout << "y = x + " << round(b*1e3)/1e3 << endl;
}
}
else if(m==-1){
if(b==0){
cout << "y = -x" << endl;
}
else if(b<0){
cout << "y = -x - " << -1*round(b*1e3)/1e3 << endl;
}
else{
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}
}
else{
if(b<0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << -1*round(b*1e3)/1e3 << endl;
}
else{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3 << endl;
}
}
}
return 0;
} | # 0341, 2024-11-02 14:12:57, PPPPPPPPPPPPPPPP-PPPPP-- (87%)
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
int main(){
vector<pair<double,double>> point;
int n;
double b,m,x,y,tm1=0,tm2x=0,tm2y=0,bm1=0,bm2=0;
double bt1=0,bt2=0;
string opr;
cin >> n >> opr;
for(int i=0;i<n;i++){
cin >> x >> y;
point.push_back(make_pair(x,y));
}
for(auto x:point){
tm1+=(x.first*x.second);
}
tm1*=n;
for(auto x:point){
tm2x+=x.first;
}
for(auto x:point){
tm2y+=x.second;
}
for(auto x:point){
bm1+=pow(x.first,2);
}
bm1*=n;
for(auto x:point){
bm2+=(x.first);
}
bm2=pow(bm2,2);
m=(tm1-(tm2x*tm2y))/(bm1-bm2);
for(auto x:point){
bt1+=x.second;
}
for(auto x:point){
bt2+=x.first;
}
bt2*=m;
b=(bt1-bt2)/n;
if(opr=="mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
}
else if(opr=="func"){
if(m==0){
if(b==0){
cout << "y = 0" << endl;
}
else{
cout << "y = " << b << endl;
}
}
else if(m==1){
if(b==0){
cout << "y = x" << endl;
}
else if(b<0){
cout << "y = x - " << -1*round(b*1e3)/1e3 << endl;
}
else{
cout << "y = x + " << round(b*1e3)/1e3 << endl;
}
}
else if(m==-1){
if(b==0){
cout << "y = -x" << endl;
}
else if(b<0){
cout << "y = -x - " << -1*round(b*1e3)/1e3 << endl;
}
else{
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}
}
else{
if(b<0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << -1*round(b*1e3)/1e3 << endl;
}
else if(b==0){
cout << "y = " << round(m*1e3)/1e3 << "x" << endl;
}
else{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3 << endl;
}
}
}
return 0;
} | # 0342, 2024-11-02 14:13:42, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
int main(){
vector<pair<float,float>> point;
int n;
float b,m,x,y,tm1=0,tm2x=0,tm2y=0,bm1=0,bm2=0;
float bt1=0,bt2=0;
string opr;
cin >> n >> opr;
for(int i=0;i<n;i++){
cin >> x >> y;
point.push_back(make_pair(x,y));
}
for(auto x:point){
tm1+=(x.first*x.second);
}
tm1*=n;
for(auto x:point){
tm2x+=x.first;
}
for(auto x:point){
tm2y+=x.second;
}
for(auto x:point){
bm1+=pow(x.first,2);
}
bm1*=n;
for(auto x:point){
bm2+=(x.first);
}
bm2=pow(bm2,2);
m=(tm1-(tm2x*tm2y))/(bm1-bm2);
for(auto x:point){
bt1+=x.second;
}
for(auto x:point){
bt2+=x.first;
}
bt2*=m;
b=(bt1-bt2)/n;
if(opr=="mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
}
else if(opr=="func"){
if(m==0){
if(b==0){
cout << "y = 0" << endl;
}
else{
cout << "y = " << b << endl;
}
}
else if(m==1){
if(b==0){
cout << "y = x" << endl;
}
else if(b<0){
cout << "y = x - " << -1*round(b*1e3)/1e3 << endl;
}
else{
cout << "y = x + " << round(b*1e3)/1e3 << endl;
}
}
else if(m==-1){
if(b==0){
cout << "y = -x" << endl;
}
else if(b<0){
cout << "y = -x - " << -1*round(b*1e3)/1e3 << endl;
}
else{
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}
}
else{
if(b<0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << -1*round(b*1e3)/1e3 << endl;
}
else if(b==0){
cout << "y = " << round(m*1e3)/1e3 << "x" << endl;
}
else{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3 << endl;
}
}
}
return 0;
} | # 0343, 2024-11-02 14:31:37, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
int main(){
vector<pair<float,float>> point;
int n;
float b,m,x,y,tm1=0,tm2x=0,tm2y=0,bm1=0,bm2=0;
float bt1=0,bt2=0;
string opr;
cin >> n >> opr;
for(int i=0;i<n;i++){
cin >> x >> y;
point.push_back(make_pair(x,y));
}
for(auto x:point){
tm1+=(x.first*x.second);
}
tm1*=n;
for(auto x:point){
tm2x+=x.first;
}
for(auto x:point){
tm2y+=x.second;
}
for(auto x:point){
bm1+=pow(x.first,2);
}
bm1*=n;
for(auto x:point){
bm2+=(x.first);
}
bm2=pow(bm2,2);
m=(tm1-(tm2x*tm2y))/(bm1-bm2);
for(auto x:point){
bt1+=x.second;
}
for(auto x:point){
bt2+=x.first;
}
bt2*=m;
b=(bt1-bt2)/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(opr=="mb"){
cout << m << endl << b << endl;
}
else if(opr=="func"){
if(m==0){
if(b==0){
cout << "y = 0" << endl;
}
else{
cout << "y = " << b << endl;
}
}
else if(m==1){
if(b==0){
cout << "y = x" << endl;
}
else if(b<0){
cout << "y = x - " << -1*b << endl;
}
else{
cout << "y = x + " << b << endl;
}
}
else if(m==-1){
if(b==0){
cout << "y = -x" << endl;
}
else if(b<0){
cout << "y = -x - " << -1*b << endl;
}
else{
cout << "y = -x + " << b << endl;
}
}
else{
if(b<0){
cout << "y = " << m << "x - " << -1*b << endl;
}
else if(b==0){
cout << "y = " << m << "x" << endl;
}
else{
cout << "y = " << m << "x + " << b << endl;
}
}
}
return 0;
} |
# 0344, 2024-11-02 10:54:19, PPPPPPPPPP-----P-------- (45%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
string command; cin >> command;
vector<pair<float, float>> data;
float inputX, inputY;
for (int i=0; i < n; i++) {
cin >> inputX >> inputY;
data.push_back({inputX, inputY});
}
// find mb
// m = nA - BC / nD - B^2
// b = C - mB / n
// A
float A=0, B=0, C=0, D=0;
for (auto a: data) {
A += a.first*a.second; // x*y
B += a.first; // x
C += a.second; // y
D += a.first*a.first; // x^2
}
float m = (n*A-B*C)/(n*D-B*B);
float b = (C- m*B)/n;
if (command == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else {
char bsign = '+';
if (b < 0) {
b *= -1;
bsign = '-';
}
if (m == 0 ) {
cout << "y = ";
}
else if (m == 1) {
cout << "y = x ";
}
else if (m == -1) {
cout << "y = -x ";
}
else {
cout << "y = " << m << "x ";
}
if (m == 0 && b < 0) {
cout << "-" << b;
}
else if (m == 0 && b == 0) {
cout << "0";
}
else {
cout << bsign << " " << b;
}
cout << endl;
}
} | # 0345, 2024-11-02 10:56:42, PPPPPPPPPP-----P--PP---- (54%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
string command; cin >> command;
vector<pair<float, float>> data;
float inputX, inputY;
for (int i=0; i < n; i++) {
cin >> inputX >> inputY;
data.push_back({inputX, inputY});
}
// find mb
// m = nA - BC / nD - B^2
// b = C - mB / n
// A
float A=0, B=0, C=0, D=0;
for (auto a: data) {
A += a.first*a.second; // x*y
B += a.first; // x
C += a.second; // y
D += a.first*a.first; // x^2
}
float m = (n*A-B*C)/(n*D-B*B);
float b = (C- m*B)/n;
if (command == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else {
char bsign = '+';
if (b < 0) {
b *= -1;
bsign = '-';
}
if (m == 0 ) {
cout << "y = ";
}
else if (m == 1) {
cout << "y = x ";
}
else if (m == -1) {
cout << "y = -x ";
}
else {
cout << "y = " << m << "x ";
}
if (m == 0 && b < 0) {
cout << "-" << b;
}
else if (m == 0 && b == 0) {
cout << "0";
}
else if (b == 0) {
b;
}
else {
cout << bsign << " " << b;
}
cout << endl;
}
} | # 0346, 2024-11-02 11:00:59, PPPPPPPPPPPPPPPP-PPPP-PP (91%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
string command; cin >> command;
vector<pair<float, float>> data;
float inputX, inputY;
for (int i=0; i < n; i++) {
cin >> inputX >> inputY;
data.push_back({inputX, inputY});
}
// find mb
// m = nA - BC / nD - B^2
// b = C - mB / n
// A
float A=0, B=0, C=0, D=0;
for (auto a: data) {
A += a.first*a.second; // x*y
B += a.first; // x
C += a.second; // y
D += a.first*a.first; // x^2
}
float m = (n*A-B*C)/(n*D-B*B);
float b = (C- m*B)/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (command == "mb") {
cout << m << endl;
cout << b << endl;
}
else {
char bsign = '+';
if (b < 0) {
b *= -1;
bsign = '-';
}
if (m == 0 ) {
cout << "y = ";
}
else if (m == 1) {
cout << "y = x ";
}
else if (m == -1) {
cout << "y = -x ";
}
else {
cout << "y = " << m << "x ";
}
if (m == 0 && b < 0) {
cout << "-" << b;
}
else if (m == 0 && b == 0) {
cout << "0";
}
else if (b == 0) {
string v;
}
else {
cout << bsign << " " << b;
}
cout << endl;
}
} | # 0347, 2024-11-02 11:06:14, PPPPPPPPPP-----P--PP-P-- (58%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
string command; cin >> command;
vector<pair<float, float>> data;
float inputX, inputY;
for (int i=0; i < n; i++) {
cin >> inputX >> inputY;
data.push_back({inputX, inputY});
}
// find mb
// m = nA - BC / nD - B^2
// b = C - mB / n
// A
float A=0, B=0, C=0, D=0;
for (auto a: data) {
A += a.first*a.second; // x*y
B += a.first; // x
C += a.second; // y
D += a.first*a.first; // x^2
}
float m = (n*A-B*C)/(n*D-B*B);
float b = (C- m*B)/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (command == "mb") {
cout << m << endl;
cout << b << endl;
}
else {
char bsign = '+';
int bout = b;
if (b < 0) {
bout *= -1;
bsign = '-';
}
if (m == 0 ) {
if (b < 0) {
cout << "y = -" << bout;
}
else if (b == 0) {
cout << "y = 0";
}
else if (b > 0) {
cout << "y = " << bout;
}
return 0;
}
else if (m == 1) {
cout << "y = x ";
}
else if (m == -1) {
cout << "y = -x ";
}
else {
cout << "y = " << m << "x ";
}
if (b!= 0) cout << bsign << " " << bout;
}
} | # 0348, 2024-11-02 11:07:11, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
string command; cin >> command;
vector<pair<float, float>> data;
float inputX, inputY;
for (int i=0; i < n; i++) {
cin >> inputX >> inputY;
data.push_back({inputX, inputY});
}
// find mb
// m = nA - BC / nD - B^2
// b = C - mB / n
// A
float A=0, B=0, C=0, D=0;
for (auto a: data) {
A += a.first*a.second; // x*y
B += a.first; // x
C += a.second; // y
D += a.first*a.first; // x^2
}
float m = (n*A-B*C)/(n*D-B*B);
float b = (C- m*B)/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (command == "mb") {
cout << m << endl;
cout << b << endl;
}
else {
char bsign = '+';
float bout = b;
if (b < 0) {
bout *= -1;
bsign = '-';
}
if (m == 0 ) {
if (b < 0) {
cout << "y = -" << bout;
}
else if (b == 0) {
cout << "y = 0";
}
else if (b > 0) {
cout << "y = " << bout;
}
return 0;
}
else if (m == 1) {
cout << "y = x ";
}
else if (m == -1) {
cout << "y = -x ";
}
else {
cout << "y = " << m << "x ";
}
if (b!= 0) cout << bsign << " " << bout;
}
} |
# 0349, 2024-11-02 10:31:33, ----------PPPPP--P--P-PP (37%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
vector<pair<float,float>>point;
float m(int N,vector<pair<float,float>>point){
float sigma=0,sigmax=0,sigmay=0,sigmax2=0;
for(int i=0;i<N;i++)
sigma+=(point[i].first)*(point[i].second);
for(int i=0;i<N;i++)
sigmax+=(point[i].first);
for(int i=0;i<N;i++)
sigmay+=(point[i].second);
for(int i=0;i<N;i++)
sigmax2+=((point[i].first*point[i].first));
sigmax2*=N;
float result=((N*sigma)-(sigmax*sigmay))/(sigmax2-(sigmax*sigmax));
return result;
}
float b(int N,vector<pair<float,float>>point){
float sigmay=0,msigx=0;
for(int i=0;i<N;i++)
sigmay+=(point[i].second);
for(int i=0;i<N;i++)
msigx+=(point[i].first);
float from=m(N,point);
msigx*=from;
return (sigmay-msigx)/N;
}
int main(){
int N;
cin>>N;
string ch;cin>>ch;
vector<pair<float,float>>point;
for(int i=0;i<N;i++){
float c,d;
cin>>c>>d;
point.push_back(make_pair(c,d));
}
float slope=round(m(N,point) *1e3)/1e3;
float ys=round(b(N,point) *1e3)/1e3;
if(ch=="mb")
cout <<slope<<endl<<ys<<endl;
else if(ch=="func")
cout <<"y = ";
if(slope==-1)
cout <<"-";
else if(slope==1)
cout <<"";
else
cout <<slope;
cout<<"x ";
if(ys>=0)
cout <<"+ "<<ys;
else if(ys==0)
cout <<"";
else
cout <<"- "<<-(ys);
} | # 0350, 2024-11-02 10:34:05, PPPPPPPPPPPPPPP--P--P-PP (79%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
vector<pair<float,float>>point;
float m(int N,vector<pair<float,float>>point){
float sigma=0,sigmax=0,sigmay=0,sigmax2=0;
for(int i=0;i<N;i++)
sigma+=(point[i].first)*(point[i].second);
for(int i=0;i<N;i++)
sigmax+=(point[i].first);
for(int i=0;i<N;i++)
sigmay+=(point[i].second);
for(int i=0;i<N;i++)
sigmax2+=((point[i].first*point[i].first));
sigmax2*=N;
float result=((N*sigma)-(sigmax*sigmay))/(sigmax2-(sigmax*sigmax));
return result;
}
float b(int N,vector<pair<float,float>>point){
float sigmay=0,msigx=0;
for(int i=0;i<N;i++)
sigmay+=(point[i].second);
for(int i=0;i<N;i++)
msigx+=(point[i].first);
float from=m(N,point);
msigx*=from;
return (sigmay-msigx)/N;
}
int main(){
int N;
cin>>N;
string ch;cin>>ch;
vector<pair<float,float>>point;
for(int i=0;i<N;i++){
float c,d;
cin>>c>>d;
point.push_back(make_pair(c,d));
}
float slope=round(m(N,point) *1e3)/1e3;
float ys=round(b(N,point) *1e3)/1e3;
if(ch=="mb")
cout <<slope<<endl<<ys<<endl;
else if(ch=="func"){
cout <<"y = ";
if(slope==-1)
cout <<"-";
else if(slope==1)
cout <<"";
else
cout <<slope;
cout<<"x ";
if(ys>=0)
cout <<"+ "<<ys;
else if(ys==0)
cout <<"";
else
cout <<"- "<<-(ys);
}
} | # 0351, 2024-11-02 10:37:15, PPPPPPPPPPPPPPPP-P--P-PP (83%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
vector<pair<float,float>>point;
float m(int N,vector<pair<float,float>>point){
float sigma=0,sigmax=0,sigmay=0,sigmax2=0;
for(int i=0;i<N;i++)
sigma+=(point[i].first)*(point[i].second);
for(int i=0;i<N;i++)
sigmax+=(point[i].first);
for(int i=0;i<N;i++)
sigmay+=(point[i].second);
for(int i=0;i<N;i++)
sigmax2+=((point[i].first*point[i].first));
sigmax2*=N;
float result=((N*sigma)-(sigmax*sigmay))/(sigmax2-(sigmax*sigmax));
return result;
}
float b(int N,vector<pair<float,float>>point){
float sigmay=0,msigx=0;
for(int i=0;i<N;i++)
sigmay+=(point[i].second);
for(int i=0;i<N;i++)
msigx+=(point[i].first);
float from=m(N,point);
msigx*=from;
return (sigmay-msigx)/N;
}
int main(){
int N;
cin>>N;
string ch;cin>>ch;
vector<pair<float,float>>point;
for(int i=0;i<N;i++){
float c,d;
cin>>c>>d;
point.push_back(make_pair(c,d));
}
float slope=round(m(N,point) *1e3)/1e3;
float ys=round(b(N,point) *1e3)/1e3;
if(ch=="mb")
cout <<slope<<endl<<ys<<endl;
else if(ch=="func"){
if(slope!=0){
cout <<"y = ";
if(slope==-1)
cout <<"-";
else if(slope==1)
cout <<"";
else
cout <<slope;
cout<<"x ";
if(ys>=0)
cout <<"+ "<<ys;
else if(ys==0)
cout <<"";
else
cout <<"- "<<-(ys);
}
else{
cout <<"y = 0";
}
}
} | # 0352, 2024-11-02 10:38:54, PPPPPPPPPPPPPPPPPP--PPPP (91%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
vector<pair<float,float>>point;
float m(int N,vector<pair<float,float>>point){
float sigma=0,sigmax=0,sigmay=0,sigmax2=0;
for(int i=0;i<N;i++)
sigma+=(point[i].first)*(point[i].second);
for(int i=0;i<N;i++)
sigmax+=(point[i].first);
for(int i=0;i<N;i++)
sigmay+=(point[i].second);
for(int i=0;i<N;i++)
sigmax2+=((point[i].first*point[i].first));
sigmax2*=N;
float result=((N*sigma)-(sigmax*sigmay))/(sigmax2-(sigmax*sigmax));
return result;
}
float b(int N,vector<pair<float,float>>point){
float sigmay=0,msigx=0;
for(int i=0;i<N;i++)
sigmay+=(point[i].second);
for(int i=0;i<N;i++)
msigx+=(point[i].first);
float from=m(N,point);
msigx*=from;
return (sigmay-msigx)/N;
}
int main(){
int N;
cin>>N;
string ch;cin>>ch;
vector<pair<float,float>>point;
for(int i=0;i<N;i++){
float c,d;
cin>>c>>d;
point.push_back(make_pair(c,d));
}
float slope=round(m(N,point) *1e3)/1e3;
float ys=round(b(N,point) *1e3)/1e3;
if(ch=="mb")
cout <<slope<<endl<<ys<<endl;
else if(ch=="func"){
if(slope!=0){
cout <<"y = ";
if(slope==-1)
cout <<"-";
else if(slope==1)
cout <<"";
else
cout <<slope;
cout<<"x ";
if(ys>=0)
cout <<"+ "<<ys;
else if(ys==0)
cout <<"";
else
cout <<"- "<<-(ys);
}
else{
if(ys==0)
cout <<"y = 0";
else
cout <<"y = "<<ys;
}
}
} | # 0353, 2024-11-02 10:40:20, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
vector<pair<float,float>>point;
float m(int N,vector<pair<float,float>>point){
float sigma=0,sigmax=0,sigmay=0,sigmax2=0;
for(int i=0;i<N;i++)
sigma+=(point[i].first)*(point[i].second);
for(int i=0;i<N;i++)
sigmax+=(point[i].first);
for(int i=0;i<N;i++)
sigmay+=(point[i].second);
for(int i=0;i<N;i++)
sigmax2+=((point[i].first*point[i].first));
sigmax2*=N;
float result=((N*sigma)-(sigmax*sigmay))/(sigmax2-(sigmax*sigmax));
return result;
}
float b(int N,vector<pair<float,float>>point){
float sigmay=0,msigx=0;
for(int i=0;i<N;i++)
sigmay+=(point[i].second);
for(int i=0;i<N;i++)
msigx+=(point[i].first);
float from=m(N,point);
msigx*=from;
return (sigmay-msigx)/N;
}
int main(){
int N;
cin>>N;
string ch;cin>>ch;
vector<pair<float,float>>point;
for(int i=0;i<N;i++){
float c,d;
cin>>c>>d;
point.push_back(make_pair(c,d));
}
float slope=round(m(N,point) *1e3)/1e3;
float ys=round(b(N,point) *1e3)/1e3;
if(ch=="mb")
cout <<slope<<endl<<ys<<endl;
else if(ch=="func"){
if(slope!=0){
cout <<"y = ";
if(slope==-1)
cout <<"-";
else if(slope==1)
cout <<"";
else
cout <<slope;
cout<<"x ";
if(ys>0)
cout <<"+ "<<ys;
else if(ys==0)
cout <<"";
else
cout <<"- "<<-(ys);
}
else{
if(ys==0)
cout <<"y = 0";
else
cout <<"y = "<<ys;
}
}
} |
# 0354, 2024-11-02 13:46:49, ----------PPPPP--PPPP-PP (45%)
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>
using namespace std;
int main(){
int n;cin>>n;
string call;
cin>>call;
vector<pair<float,float>> info;
float in1,in2;
for(int i=0;i<n;i++){
cin>>in1>>in2;
info.push_back({in1,in2});
}
float m,b;
float one=0,two=0,three=0,four=0;
for(int i=0;i<n;i++){
one+=info[i].first*info[i].second;
two+=info[i].first;
three+=info[i].second;
four+=pow(info[i].first,2);
}
one*=n;
m=(one-(two*three))/(four*n-pow(two,2));
b=(three-m*two)/n;
m= round(m*1e3)/1e3;
b= round(b*1e3)/1e3;
if(call=="mb") cout<<m<<' '<<b;
//cout<<"y = "<<m<<"x + "<<b;
else {
cout<<"y = ";
if(m==-1) cout<<"-";
else if(m!=1) cout<<m;
cout<<'x';
if(b>0){
cout<<" + "<<b;
}
else if(b<0) cout<<" - "<<abs(b);
}
} | # 0355, 2024-11-02 13:48:00, PPPPPPPPPPPPPPP--PPPP-PP (87%)
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>
using namespace std;
int main(){
int n;cin>>n;
string call;
cin>>call;
vector<pair<float,float>> info;
float in1,in2;
for(int i=0;i<n;i++){
cin>>in1>>in2;
info.push_back({in1,in2});
}
float m,b;
float one=0,two=0,three=0,four=0;
for(int i=0;i<n;i++){
one+=info[i].first*info[i].second;
two+=info[i].first;
three+=info[i].second;
four+=pow(info[i].first,2);
}
one*=n;
m=(one-(two*three))/(four*n-pow(two,2));
b=(three-m*two)/n;
m= round(m*1e3)/1e3;
b= round(b*1e3)/1e3;
if(call=="mb") cout<<m<<endl<<b;
//cout<<"y = "<<m<<"x + "<<b;
else {
cout<<"y = ";
if(m==-1) cout<<"-";
else if(m!=1) cout<<m;
cout<<'x';
if(b>0){
cout<<" + "<<b;
}
else if(b<0) cout<<" - "<<abs(b);
}
} | # 0356, 2024-11-02 13:49:42, PPPPPPPPPPPPPPPP-PPPP-PP (91%)
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>
using namespace std;
int main(){
int n;cin>>n;
string call;
cin>>call;
vector<pair<float,float>> info;
float in1,in2;
for(int i=0;i<n;i++){
cin>>in1>>in2;
info.push_back({in1,in2});
}
float m,b;
float one=0,two=0,three=0,four=0;
for(int i=0;i<n;i++){
one+=info[i].first*info[i].second;
two+=info[i].first;
three+=info[i].second;
four+=pow(info[i].first,2);
}
one*=n;
m=(one-(two*three))/(four*n-pow(two,2));
b=(three-m*two)/n;
m= round(m*1e3)/1e3;
b= round(b*1e3)/1e3;
if(call=="mb") cout<<m<<endl<<b;
else {
cout<<"y = ";
if(m==-1) cout<<"-";
else if(m!=1) cout<<m;
if(m!=0)cout<<'x';
if(b>0){
cout<<" + "<<b;
}
else if(b<0) cout<<" - "<<abs(b);
}
} | # 0357, 2024-11-02 13:51:09, PPPPPPPPPPPPPPP--PPPP-PP (87%)
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>
using namespace std;
int main(){
int n;cin>>n;
string call;
cin>>call;
vector<pair<float,float>> info;
float in1,in2;
for(int i=0;i<n;i++){
cin>>in1>>in2;
info.push_back({in1,in2});
}
float m,b;
float one=0,two=0,three=0,four=0;
for(int i=0;i<n;i++){
one+=info[i].first*info[i].second;
two+=info[i].first;
three+=info[i].second;
four+=pow(info[i].first,2);
}
one*=n;
m=(one-(two*three))/(four*n-pow(two,2));
b=(three-m*two)/n;
m= round(m*1e3)/1e3;
b= round(b*1e3)/1e3;
if(call=="mb") cout<<m<<endl<<b;
else {
cout<<"y = ";
if(m==-1&&m!=0) cout<<"-";
else if(m!=1&&m!=0) cout<<m;
if(m!=0)cout<<'x';
if(b>0){
cout<<" + "<<b;
}
else if(b<0) cout<<" - "<<abs(b);
}
} | # 0358, 2024-11-02 14:06:14, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>
using namespace std;
int main(){
int n;cin>>n;
string call;
cin>>call;
vector<pair<float,float>> info;
float in1,in2;
for(int i=0;i<n;i++){
cin>>in1>>in2;
info.push_back({in1,in2});
}
float m,b;
float one=0,two=0,three=0,four=0;
for(int i=0;i<n;i++){
one+=info[i].first*info[i].second;
two+=info[i].first;
three+=info[i].second;
four+=pow(info[i].first,2);
}
one*=n;
m=(one-(two*three))/(four*n-pow(two,2));
b=(three-m*two)/n;
m= round(m*1e3)/1e3;
b= round(b*1e3)/1e3;
if(call=="mb") cout<<m<<endl<<b;
else {
if(m==0&&b!=0){
cout<<"y = "<<b;
return 0;
}
cout<<"y = ";
if(m==-1) cout<<"-";
else if(m!=1) cout<<m;
if(m!=0)cout<<'x';
if(b>0){
cout<<" + "<<b;
}
else if(b<0) cout<<" - "<<abs(b);
}
} |
# 0359, 2024-11-02 09:58:59, PPPPPPPPPP-------------- (41%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n ;
string type;
cin >> n >> type;
float x[n];
float y[n];
for (int i = 0 ; i < n ; ++i){
cin >> x[i] >> y[i];
}
if (type == "mb"){
float first = 0;
for (int i = 0 ; i < n ; ++i){
first += x[i] * y[i];
}
first *= n; // valid
//cout << "first = " << first << endl;
float second1 = 0 , second2 = 0;
for (int i = 0 ; i < n ; ++i){
second1 += x[i];
second2 += y[i];
}
float second = second1 * second2;
//cout << "second = " << second << endl;
float second3 = 0;
for (int i = 0 ; i < n ; ++i){
second3 += x[i] * x[i];
}
float third = n * second3;
float forth = second1 * second1;
//cout << "div = " << third - forth << endl;
float m = (first - second) / (third - forth);
cout << round(m*1e3) / 1e3 << endl;
float first22 = second2;
float second22 = m * second1;
float b = (first22 - second22) / n;
cout << round(b*1e3) / 1e3;
}
else if (type == "func"){
}
} | # 0360, 2024-11-02 10:11:18, PPPPPPPPPPPPPPP--------- (62%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n ;
string type;
cin >> n >> type;
float x[n];
float y[n];
float m , b;
for (int i = 0 ; i < n ; ++i){
cin >> x[i] >> y[i];
}
float first = 0;
for (int i = 0 ; i < n ; ++i){
first += x[i] * y[i];
}
first *= n; // valid
//cout << "first = " << first << endl;
float second1 = 0 , second2 = 0;
for (int i = 0 ; i < n ; ++i){
second1 += x[i];
second2 += y[i];
}
float second = second1 * second2;
//cout << "second = " << second << endl;
float second3 = 0;
for (int i = 0 ; i < n ; ++i){
second3 += x[i] * x[i];
}
float third = n * second3;
float forth = second1 * second1;
//cout << "div = " << third - forth << endl;
m = (first - second) / (third - forth);
//cout << round(m*1e3) / 1e3 << endl;
float first22 = second2;
float second22 = m * second1;
b = (first22 - second22) / n;
//cout << round(b*1e3) / 1e3;
if (type == "mb"){
cout << round(m*1e3) / 1e3 << endl;
cout << round(b*1e3) / 1e3 << endl;
}
else if (type == "func"){
if (round(m*1e3) / 1e3 != 1 || round(m*1e3) / 1e3 != -1){
cout << "y = " << round(m*1e3) / 1e3 << "x ";
}
else {
if (m < 0){
cout << "y = -x ";
}
else {
cout << "y = x ";
}
}// first done
if (b != 0){
if (b > 0){
cout << "+ " << abs(round(b*1e3) / 1e3);
}
else {
cout << "- " << abs(round(b*1e3) / 1e3);
}
}
}
} | # 0361, 2024-11-02 10:13:38, PPPPPPPPPPPPPPP--PPPP-PP (87%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n ;
string type;
cin >> n >> type;
float x[n];
float y[n];
float m , b;
for (int i = 0 ; i < n ; ++i){
cin >> x[i] >> y[i];
}
float first = 0;
for (int i = 0 ; i < n ; ++i){
first += x[i] * y[i];
}
first *= n; // valid
//cout << "first = " << first << endl;
float second1 = 0 , second2 = 0;
for (int i = 0 ; i < n ; ++i){
second1 += x[i];
second2 += y[i];
}
float second = second1 * second2;
//cout << "second = " << second << endl;
float second3 = 0;
for (int i = 0 ; i < n ; ++i){
second3 += x[i] * x[i];
}
float third = n * second3;
float forth = second1 * second1;
//cout << "div = " << third - forth << endl;
m = (first - second) / (third - forth);
//cout << round(m*1e3) / 1e3 << endl;
float first22 = second2;
float second22 = m * second1;
b = (first22 - second22) / n;
//cout << round(b*1e3) / 1e3;
if (type == "mb"){
cout << round(m*1e3) / 1e3 << endl;
cout << round(b*1e3) / 1e3 << endl;
}
else if (type == "func"){
if (round(m*1e3) / 1e3 != 1 && round(m*1e3) / 1e3 != -1){
cout << "y = " << round(m*1e3) / 1e3 << "x ";
}
else {
if (round(m*1e3) / 1e3 == -1){
cout << "y = -x ";
}
else {
cout << "y = x ";
}
}// first done
if (b != 0){
if (b > 0){
cout << "+ " << abs(round(b*1e3) / 1e3);
}
else {
cout << "- " << abs(round(b*1e3) / 1e3);
}
}
}
} | # 0362, 2024-11-02 10:18:26, PPPPPPPPPPPPPPP-PPPPPPPP (95%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n ;
string type;
cin >> n >> type;
float x[n];
float y[n];
float m , b;
for (int i = 0 ; i < n ; ++i){
cin >> x[i] >> y[i];
}
float first = 0;
for (int i = 0 ; i < n ; ++i){
first += x[i] * y[i];
}
first *= n; // valid
//cout << "first = " << first << endl;
float second1 = 0 , second2 = 0;
for (int i = 0 ; i < n ; ++i){
second1 += x[i];
second2 += y[i];
}
float second = second1 * second2;
//cout << "second = " << second << endl;
float second3 = 0;
for (int i = 0 ; i < n ; ++i){
second3 += x[i] * x[i];
}
float third = n * second3;
float forth = second1 * second1;
//cout << "div = " << third - forth << endl;
m = (first - second) / (third - forth);
//cout << round(m*1e3) / 1e3 << endl;
float first22 = second2;
float second22 = m * second1;
b = (first22 - second22) / n;
//cout << round(b*1e3) / 1e3;
if (type == "mb"){
cout << round(m*1e3) / 1e3 << endl;
cout << round(b*1e3) / 1e3 << endl;
}
else if (type == "func"){
if (round(m*1e3) / 1e3 != 1 && round(m*1e3) / 1e3 != -1 && round(m*1e3) / 1e3 != 0){
cout << "y = " << round(m*1e3) / 1e3 << "x ";
}
else {
if (round(m*1e3) / 1e3 == -1){
cout << "y = -x ";
}
else if (round(m*1e3) / 1e3 == 1){
cout << "y = x ";
}
else {
cout << "y = ";
}
}// first done
if (b != 0 && round(m*1e3) / 1e3 != 0){
if (b > 0){
cout << "+ " << abs(round(b*1e3) / 1e3);
}
else {
cout << "- " << abs(round(b*1e3) / 1e3);
}
}
else if (b != 0 && round(m*1e3) / 1e3 == 0){
cout << round(b*1e3) / 1e3;
}
}
} | # 0363, 2024-11-02 10:19:57, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n ;
string type;
cin >> n >> type;
float x[n];
float y[n];
float m , b;
for (int i = 0 ; i < n ; ++i){
cin >> x[i] >> y[i];
}
float first = 0;
for (int i = 0 ; i < n ; ++i){
first += x[i] * y[i];
}
first *= n; // valid
//cout << "first = " << first << endl;
float second1 = 0 , second2 = 0;
for (int i = 0 ; i < n ; ++i){
second1 += x[i];
second2 += y[i];
}
float second = second1 * second2;
//cout << "second = " << second << endl;
float second3 = 0;
for (int i = 0 ; i < n ; ++i){
second3 += x[i] * x[i];
}
float third = n * second3;
float forth = second1 * second1;
//cout << "div = " << third - forth << endl;
m = (first - second) / (third - forth);
//cout << round(m*1e3) / 1e3 << endl;
float first22 = second2;
float second22 = m * second1;
b = (first22 - second22) / n;
//cout << round(b*1e3) / 1e3;
if (type == "mb"){
cout << round(m*1e3) / 1e3 << endl;
cout << round(b*1e3) / 1e3 << endl;
}
else if (type == "func"){
if (round(m*1e3) / 1e3 != 1 && round(m*1e3) / 1e3 != -1 && round(m*1e3) / 1e3 != 0){
cout << "y = " << round(m*1e3) / 1e3 << "x ";
}
else {
if (round(m*1e3) / 1e3 == -1){
cout << "y = -x ";
}
else if (round(m*1e3) / 1e3 == 1){
cout << "y = x ";
}
else {
cout << "y = ";
}
}// first done
if (b != 0 && round(m*1e3) / 1e3 != 0){
if (b > 0){
cout << "+ " << abs(round(b*1e3) / 1e3);
}
else {
cout << "- " << abs(round(b*1e3) / 1e3);
}
}
else if (b != 0 && round(m*1e3) / 1e3 == 0){
cout << round(b*1e3) / 1e3;
}
else if (b == 0 && round(m*1e3) / 1e3 == 0){
cout << "0";
}
}
} |
# 0364, 2024-11-02 09:51:27, PPPPPPPPPPPPPPPP-PPPP-PP (91%)
#include <cmath>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main()
{
int n;
float m = 0, b = 0;
string inputType;
cin >> n >> inputType;
pair<float, float> inputXY;
vector<pair<float, float>> inputs;
for (int i = 0; i < n; i++)
{
cin >> inputXY.first >> inputXY.second;
inputs.push_back(inputXY);
}
// calculate M, B
float mUpperLeft = 0, mLowerLeft = 0, mLowerRight = 0;
pair<float, float> mUpperRight(0, 0);
float bUpperLeft = 0, bUpperRight = 0;
for (auto XY : inputs)
{
mUpperLeft += XY.first * XY.second;
mUpperRight.first += XY.first;
mUpperRight.second += XY.second;
mLowerLeft += pow(XY.first, 2);
mLowerRight += XY.first;
bUpperLeft += XY.second;
bUpperRight += XY.first;
}
mUpperLeft *= n;
float mUpperRightCombined = mUpperRight.first * mUpperRight.second;
float mUpper = mUpperLeft - mUpperRightCombined;
mLowerLeft *= n;
mLowerRight = pow(mLowerRight, 2);
float mLower = mLowerLeft - mLowerRight;
m = mUpper / mLower;
bUpperRight *= m;
float bUpper = bUpperLeft - bUpperRight;
b = bUpper / n;
m = round(m*1e3) / 1e3;
b = round(b*1e3) / 1e3;
if (inputType == "mb")
{
cout << m << endl << b << endl;
}
else if (inputType == "func")
{
cout << "y = ";
if (m == 0 && b == 0) {
cout << 0 << endl;
return 0;
}
else if (m == -1) cout << "-x";
else if (m == 1) cout << "x";
else if (m != 0){
cout << m;
cout << "x";
}
if (b > 0)
{
cout << " + ";
cout << b;
}
else if (b < 0)
{
cout << " - ";
cout << -b;
}
cout << endl;
}
return 0;
} | # 0365, 2024-11-02 09:53:22, PPPPPPPPPPPPPPPP-PPPP-PP (91%)
#include <cmath>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main()
{
float n;
float m = 0, b = 0;
string inputType;
cin >> n >> inputType;
pair<float, float> inputXY;
vector<pair<float, float>> inputs;
for (int i = 0; i < n; i++)
{
cin >> inputXY.first >> inputXY.second;
inputs.push_back(inputXY);
}
// calculate M, B
float mUpperLeft = 0, mLowerLeft = 0, mLowerRight = 0;
pair<float, float> mUpperRight(0, 0);
float bUpperLeft = 0, bUpperRight = 0;
for (auto XY : inputs)
{
mUpperLeft += XY.first * XY.second;
mUpperRight.first += XY.first;
mUpperRight.second += XY.second;
mLowerLeft += pow(XY.first, 2);
mLowerRight += XY.first;
bUpperLeft += XY.second;
bUpperRight += XY.first;
}
mUpperLeft *= n;
float mUpperRightCombined = mUpperRight.first * mUpperRight.second;
float mUpper = mUpperLeft - mUpperRightCombined;
mLowerLeft *= n;
mLowerRight = pow(mLowerRight, 2);
float mLower = mLowerLeft - mLowerRight;
m = mUpper / mLower;
bUpperRight *= m;
float bUpper = bUpperLeft - bUpperRight;
b = bUpper / n;
m = round(m*1e3) / 1e3;
b = round(b*1e3) / 1e3;
if (inputType == "mb")
{
cout << m << endl << b << endl;
}
else if (inputType == "func")
{
cout << "y = ";
if (m == 0 && b == 0) {
cout << 0 << endl;
return 0;
}
else if (m == -1) cout << "-x";
else if (m == 1) cout << "x";
else if (m != 0){
cout << m;
cout << "x";
}
if (b > 0)
{
cout << " + ";
cout << b;
}
else if (b < 0)
{
cout << " - ";
cout << -b;
}
cout << endl;
}
return 0;
} | # 0366, 2024-11-02 11:25:25, PPPPPPPPPPPPPPPP-PPPP-PP (91%)
#include <cmath>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main()
{
float n;
float m = 0, b = 0;
string inputType;
cin >> n >> inputType;
pair<float, float> inputXY;
vector<pair<float, float>> inputs;
for (int i = 0; i < n; i++)
{
cin >> inputXY.first >> inputXY.second;
inputs.push_back(inputXY);
}
// calculate M, B
float mUpperLeft = 0, mLowerLeft = 0, mLowerRight = 0;
pair<float, float> mUpperRight(0, 0);
float bUpperLeft = 0, bUpperRight = 0;
for (auto XY : inputs)
{
mUpperLeft += XY.first * XY.second;
mUpperRight.first += XY.first;
mUpperRight.second += XY.second;
mLowerLeft += powf(XY.first, 2);
mLowerRight += XY.first;
bUpperLeft += XY.second;
bUpperRight += XY.first;
}
mUpperLeft *= n;
float mUpperRightCombined = mUpperRight.first * mUpperRight.second;
float mUpper = mUpperLeft - mUpperRightCombined;
mLowerLeft *= n;
mLowerRight = powf(mLowerRight, 2);
float mLower = mLowerLeft - mLowerRight;
m = mUpper / mLower;
bUpperRight *= m;
float bUpper = bUpperLeft - bUpperRight;
b = bUpper / n;
m = round(m*1e3) / 1e3;
b = round(b*1e3) / 1e3;
if (inputType == "mb")
{
cout << m << endl << b << endl;
}
else if (inputType == "func")
{
cout << "y = ";
if (m == 0 && b == 0) {
cout << 0 << endl;
return 0;
}
else if (m == -1) cout << "-x";
else if (m == 1) cout << "x";
else if (m != 0){
cout << m;
cout << "x";
}
if (b > 0)
{
cout << " + ";
cout << b;
}
else if (b < 0)
{
cout << " - ";
cout << -b;
}
cout << endl;
}
return 0;
} | # 0367, 2024-11-02 11:30:11, -----PPPPP-----P-PPPP-PP (50%)
#include <cmath>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main()
{
float n;
float m = 0, b = 0;
string inputType;
cin >> n >> inputType;
pair<float, float> inputXY;
vector<pair<float, float>> inputs;
for (int i = 0; i < n; i++)
{
cin >> inputXY.first >> inputXY.second;
inputs.push_back(inputXY);
}
// calculate M, B
float mUpperLeft = 0, mLowerLeft = 0, mLowerRight = 0;
pair<float, float> mUpperRight(0, 0);
float bUpperLeft = 0, bUpperRight = 0;
for (auto XY : inputs)
{
mUpperLeft += XY.first * XY.second;
mUpperRight.first += XY.first;
mUpperRight.second += XY.second;
mLowerLeft += powf(XY.first, 2);
mLowerRight += XY.first;
bUpperLeft += XY.second;
bUpperRight += XY.first;
}
mUpperLeft *= n;
float mUpperRightCombined = mUpperRight.first * mUpperRight.second;
float mUpper = mUpperLeft - mUpperRightCombined;
mLowerLeft *= n;
mLowerRight = powf(mLowerRight, 2);
float mLower = mLowerLeft - mLowerRight;
m = mUpper / mLower;
m = round(m*1e3) / 1e3;
bUpperRight *= m;
float bUpper = bUpperLeft - bUpperRight;
b = bUpper / n;
b = round(b*1e3) / 1e3;
if (inputType == "mb")
{
cout << m << endl << b << endl;
}
else if (inputType == "func")
{
cout << "y = ";
if (m == 0 && b == 0) {
cout << 0 << endl;
return 0;
}
else if (m == -1) cout << "-x";
else if (m == 1) cout << "x";
else if (m != 0){
cout << m;
cout << "x";
}
if (b > 0)
{
cout << " + ";
cout << b;
}
else if (b < 0)
{
cout << " - ";
cout << -b;
}
cout << endl;
}
return 0;
} | # 0368, 2024-11-02 11:37:22, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <cmath>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main()
{
float n = 0;
float m = 0, b = 0;
string inputType;
cin >> n >> inputType;
pair<float, float> inputXY;
vector<pair<float, float>> inputs;
for (int i = 0; i < n; i++)
{
cin >> inputXY.first >> inputXY.second;
inputs.push_back(inputXY);
}
// calculate M, B
float mUpperLeft = 0, mLowerLeft = 0, mLowerRight = 0;
pair<float, float> mUpperRight(0, 0);
float bUpperLeft = 0, bUpperRight = 0;
for (auto XY : inputs)
{
mUpperLeft += XY.first * XY.second;
mUpperRight.first += XY.first;
mUpperRight.second += XY.second;
mLowerLeft += powf(XY.first, 2);
mLowerRight += XY.first;
bUpperLeft += XY.second;
bUpperRight += XY.first;
}
mUpperLeft *= n;
float mUpperRightCombined = mUpperRight.first * mUpperRight.second;
float mUpper = mUpperLeft - mUpperRightCombined;
mLowerLeft *= n;
mLowerRight = powf(mLowerRight, 2);
float mLower = mLowerLeft - mLowerRight;
m = mUpper / mLower;
bUpperRight *= m;
float bUpper = bUpperLeft - bUpperRight;
b = bUpper / n;
m = round(m*1e3) / 1e3;
b = round(b*1e3) / 1e3;
if (inputType == "mb")
{
cout << m << endl << b << endl;
}
else if (inputType == "func")
{
cout << "y = ";
if (m == 0 && b == 0) {
cout << 0 << endl;
return 0;
}
else if (m == -1) cout << "-x";
else if (m == 1) cout << "x";
else if (m != 0){
cout << m;
cout << "x";
}
if (b > 0)
{
if (m != 0) cout << " + ";
cout << b;
}
else if (b < 0)
{
if (m != 0)
{
cout << " - ";
cout << -b;
}
else cout << b;
}
cout << endl;
}
return 0;
} |
# 0369, 2024-11-02 09:55:29, PPPPPPPPPPPPPPP--PPPP-PP (87%)
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
float m ,b;
int N; string command;
cin >> N >> command;
float X[N+1], Y[N+1];
for(int i = 0 ; i < N ; i++)
{
/* code */
cin >> X[i] >> Y[i];
}
float m1 = 0, m2x = 0, m2y = 0, m3 = 0, m4 = 0;
float b1 = 0, b2 = 0;
for(int i = 0 ; i < N; i++){
// calulate m
m1 += X[i] * Y[i];
m2x += X[i];
m2y += Y[i];
m3 += X[i] * X[i];
m4 += X[i];
}
m = ((N * m1 )- (m2x * m2y)) / ((N * m3 )- (m4 * m4));
for(int i = 0 ; i < N; i++){
// calculate b
b1 += Y[i];
b2 += X[i];
}
b = (b1 - (m * b2)) / N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(command == "mb"){
cout << m << endl << b;
}
if(command == "func"){
cout << "y = ";
// m case
if(m == 0){
}else if(m == 1){
cout << "x";
}else if(m == -1){
cout << "-x";
}else if(m < -1){
cout << m << "x";
}else if(m > 1){
cout << m << "x";
}
// b case
if(b == 0){
}else if(b > 0){
cout << " + " << b;
}else if(b < 0){
cout << " - " << abs(b);
}
}
return 0;
} | # 0370, 2024-11-02 09:57:10, PPPPPPPPPPPPPPPP-P--P-PP (83%)
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
float m ,b;
int N; string command;
cin >> N >> command;
float X[N+1], Y[N+1];
for(int i = 0 ; i < N ; i++)
{
/* code */
cin >> X[i] >> Y[i];
}
float m1 = 0, m2x = 0, m2y = 0, m3 = 0, m4 = 0;
float b1 = 0, b2 = 0;
for(int i = 0 ; i < N; i++){
// calulate m
m1 += X[i] * Y[i];
m2x += X[i];
m2y += Y[i];
m3 += X[i] * X[i];
m4 += X[i];
}
m = ((N * m1 )- (m2x * m2y)) / ((N * m3 )- (m4 * m4));
for(int i = 0 ; i < N; i++){
// calculate b
b1 += Y[i];
b2 += X[i];
}
b = (b1 - (m * b2)) / N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(command == "mb"){
cout << m << endl << b;
}
if(command == "func"){
cout << "y = ";
// m case
if(m == 0){
}else if(m == 1){
cout << "x";
}else if(m == -1){
cout << "-x";
}else if(m < -1){
cout << m << "x";
}else if(m > 1){
cout << m << "x";
}
// b case
if(b == 0){
cout << 0;
}else if(b > 0){
cout << " + " << b;
}else if(b < 0){
cout << " - " << abs(b);
}
}
return 0;
} | # 0371, 2024-11-02 09:59:06, PPPPPPPPPPPPPPPP-PPPP-PP (91%)
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
float m ,b;
int N; string command;
cin >> N >> command;
float X[N+1], Y[N+1];
for(int i = 0 ; i < N ; i++)
{
/* code */
cin >> X[i] >> Y[i];
}
float m1 = 0, m2x = 0, m2y = 0, m3 = 0, m4 = 0;
float b1 = 0, b2 = 0;
for(int i = 0 ; i < N; i++){
// calulate m
m1 += X[i] * Y[i];
m2x += X[i];
m2y += Y[i];
m3 += X[i] * X[i];
m4 += X[i];
}
m = ((N * m1 )- (m2x * m2y)) / ((N * m3 )- (m4 * m4));
for(int i = 0 ; i < N; i++){
// calculate b
b1 += Y[i];
b2 += X[i];
}
b = (b1 - (m * b2)) / N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(command == "mb"){
cout << m << endl << b;
}
if(command == "func"){
cout << "y = ";
// m case
if(m == 0){
}else if(m == 1){
cout << "x";
}else if(m == -1){
cout << "-x";
}else if(m < -1){
cout << m << "x";
}else if(m > 1){
cout << m << "x";
}
// b case
if(b == 0 && m == 0){
cout << 0;
}else if(b == 0 && m != 0){
}
else if(b > 0){
cout << " + " << b;
}else if(b < 0){
cout << " - " << abs(b);
}
}
return 0;
} | # 0372, 2024-11-02 10:01:07, PPPPPPPPPPPPPPPP-PPPP-PP (91%)
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
float m ,b;
int N; string command;
cin >> N >> command;
float X[N+1], Y[N+1];
for(int i = 0 ; i < N ; i++)
{
/* code */
cin >> X[i] >> Y[i];
}
float m1 = 0, m2x = 0, m2y = 0, m3 = 0, m4 = 0;
float b1 = 0, b2 = 0;
for(int i = 0 ; i < N; i++){
// calulate m
m1 += X[i] * Y[i];
m2x += X[i];
m2y += Y[i];
m3 += X[i] * X[i];
m4 += X[i];
}
m = ((N * m1 )- (m2x * m2y)) / ((N * m3 )- (m4 * m4));
for(int i = 0 ; i < N; i++){
// calculate b
b1 += Y[i];
b2 += X[i];
}
b = (b1 - (m * b2)) / N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(command == "mb"){
cout << m << endl << b;
}
if(command == "func"){
cout << "y = ";
// m case
if(m == 0){
}else if(m == 1){
cout << "x";
}else if(m == -1){
cout << "-x";
}else if(m < -1){
cout << m << "x";
}else if(m > 1){
cout << m << "x";
}
// b case
if(b == 0 && m == 0){
cout << 0;
}else if(b == 0 && m != 0){
}
else if(b > 0 && m != 0){
cout << " + " << b;
}else if(b < 0 && m != 0){
cout << " - " << abs(b);
}else if(b > 0 && m == 0){
cout << "+ " << b;
}else if(b < 0 && m == 0){
cout << "- " << abs(b);
}
}
return 0;
} | # 0373, 2024-11-02 10:02:21, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
float m ,b;
int N; string command;
cin >> N >> command;
float X[N+1], Y[N+1];
for(int i = 0 ; i < N ; i++)
{
/* code */
cin >> X[i] >> Y[i];
}
float m1 = 0, m2x = 0, m2y = 0, m3 = 0, m4 = 0;
float b1 = 0, b2 = 0;
for(int i = 0 ; i < N; i++){
// calulate m
m1 += X[i] * Y[i];
m2x += X[i];
m2y += Y[i];
m3 += X[i] * X[i];
m4 += X[i];
}
m = ((N * m1 )- (m2x * m2y)) / ((N * m3 )- (m4 * m4));
for(int i = 0 ; i < N; i++){
// calculate b
b1 += Y[i];
b2 += X[i];
}
b = (b1 - (m * b2)) / N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(command == "mb"){
cout << m << endl << b;
}
if(command == "func"){
cout << "y = ";
// m case
if(m == 0){
}else if(m == 1){
cout << "x";
}else if(m == -1){
cout << "-x";
}else if(m < -1){
cout << m << "x";
}else if(m > 1){
cout << m << "x";
}
// b case
if(b == 0 && m == 0){
cout << 0;
}else if(b == 0 && m != 0){
}
else if(b > 0 && m != 0){
cout << " + " << b;
}else if(b < 0 && m != 0){
cout << " - " << abs(b);
}else if(b > 0 && m == 0){
cout << b;
}else if(b < 0 && m == 0){
cout << "-" << abs(b);
}
}
return 0;
} |
# 0374, 2024-11-02 13:09:36, PPPPPPPPPPP-P----P--P--- (58%)
#include <iostream>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
int main(){
int n;
string s;
cin>>n>>s;
vector<pair<float,float>> xy;
for(int i=0;i<n;i++){
float x,y;
cin>>x>>y;
xy.push_back(make_pair(x,y));
}
float sx=0;
float sy=0;
float sx2=0;
float sxy=0;
for(int i=0;i<n;i++){
sx+=xy[i].first;
sy+=xy[i].second;
sx2+=xy[i].first*xy[i].first;
sxy+=xy[i].first*xy[i].second;
}
float m=((n*sxy)-(sx*sy))/((n*sx2-sx*sx));
float b=(sy-(m*sx))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(s=="mb"){
cout<<m<<'\n';
cout<<b;
}else if(s=="func"){
cout<<"y = ";
if(m==(float)1){
cout<<"";
}else if(m==(float)-1){
cout<<'-';
}else{
cout<<m;
}
cout<<"x + "<<b;
}
} | # 0375, 2024-11-02 13:11:16, PPPPPPPPPPP-P--PPP--PP-- (70%)
#include <iostream>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
int main(){
int n;
string s;
cin>>n>>s;
vector<pair<float,float>> xy;
for(int i=0;i<n;i++){
float x,y;
cin>>x>>y;
xy.push_back(make_pair(x,y));
}
float sx=0;
float sy=0;
float sx2=0;
float sxy=0;
for(int i=0;i<n;i++){
sx+=xy[i].first;
sy+=xy[i].second;
sx2+=xy[i].first*xy[i].first;
sxy+=xy[i].first*xy[i].second;
}
float m=((n*sxy)-(sx*sy))/((n*sx2-sx*sx));
float b=(sy-(m*sx))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(s=="mb"){
cout<<m<<'\n';
cout<<b;
}else if(s=="func"){
cout<<"y = ";
if(m==(float)1){
cout<<"x + ";
}else if(m==(float)-1){
cout<<'-'<<"x + ";
}else if(m==(float)0){
cout<<"";
}else{
cout<<m<<"x + ";
}
cout<<b;
}
} | # 0376, 2024-11-02 13:13:31, PPPPPPPPPPPPPPP--P--P-PP (79%)
#include <iostream>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
int main(){
int n;
string s;
cin>>n>>s;
vector<pair<float,float>> xy;
for(int i=0;i<n;i++){
float x,y;
cin>>x>>y;
xy.push_back(make_pair(x,y));
}
float sx=0;
float sy=0;
float sx2=0;
float sxy=0;
for(int i=0;i<n;i++){
sx+=xy[i].first;
sy+=xy[i].second;
sx2+=xy[i].first*xy[i].first;
sxy+=xy[i].first*xy[i].second;
}
float m=((n*sxy)-(sx*sy))/((n*sx2-sx*sx));
float b=(sy-(m*sx))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(s=="mb"){
cout<<m<<'\n';
cout<<b;
}else if(s=="func"){
cout<<"y = ";
if(m==(float)1){
cout<<"x ";
}else if(m==(float)-1){
cout<<'-'<<"x ";
}else if(m==(float)0){
cout<<"";
}else{
cout<<m<<"x ";
}
if(b<0){
cout<<"- "<<-b;
}else{
cout<<"+ "<<b;
}
}
} | # 0377, 2024-11-02 13:16:17, PPPPPPPPPPPPPPPP-P--P-PP (83%)
#include <iostream>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
int main(){
int n;
string s;
cin>>n>>s;
vector<pair<float,float>> xy;
for(int i=0;i<n;i++){
float x,y;
cin>>x>>y;
xy.push_back(make_pair(x,y));
}
float sx=0;
float sy=0;
float sx2=0;
float sxy=0;
for(int i=0;i<n;i++){
sx+=xy[i].first;
sy+=xy[i].second;
sx2+=xy[i].first*xy[i].first;
sxy+=xy[i].first*xy[i].second;
}
float m=((n*sxy)-(sx*sy))/((n*sx2-sx*sx));
float b=(sy-(m*sx))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(s=="mb"){
cout<<m<<'\n';
cout<<b;
}else if(s=="func"){
cout<<"y = ";
if(m==(float)0&&b==(float)0){
cout<<"0";
return 0;
}
if(m==(float)1){
cout<<"x ";
}else if(m==(float)-1){
cout<<'-'<<"x ";
}else if(m==(float)0){
cout<<"";
}else{
cout<<m<<"x ";
}
if(b==(float)0){
cout<<"";
}if(b<0){
cout<<"- "<<-b;
}else{
cout<<"+ "<<b;
}
}
} | # 0378, 2024-11-02 13:19:08, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <iostream>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
int main(){
int n;
string s;
cin>>n>>s;
vector<pair<float,float>> xy;
for(int i=0;i<n;i++){
float x,y;
cin>>x>>y;
xy.push_back(make_pair(x,y));
}
float sx=0;
float sy=0;
float sx2=0;
float sxy=0;
for(int i=0;i<n;i++){
sx+=xy[i].first;
sy+=xy[i].second;
sx2+=xy[i].first*xy[i].first;
sxy+=xy[i].first*xy[i].second;
}
float m=((n*sxy)-(sx*sy))/((n*sx2-sx*sx));
float b=(sy-(m*sx))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(s=="mb"){
cout<<m<<'\n';
cout<<b;
}else if(s=="func"){
cout<<"y = ";
if(m==(float)0&&b==(float)0){
cout<<"0";
return 0;
}
if(m==(float)1){
cout<<"x ";
}else if(m==(float)-1){
cout<<'-'<<"x ";
}else if(m==(float)0){
cout<<"";
}else{
cout<<m<<"x ";
}
if(b==(float)0){
cout<<"";
}else if(b<0&&m==(float)0){
cout<<"-"<<-b;
}else if(b>0&&m==(float)0){
cout<<b;
}else if(b<0){
cout<<"- "<<-b;
}else{
cout<<"+ "<<b;
}
}
} |
# 0379, 2024-11-02 09:30:56, ------------------------ (0%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
float m = 0;
int n;
cin >> n >> s;
float b = 0;
float nn = n;
float x[n],y[n];
for (int i = 0 ; i < n ; i++)
{
cin >> x[i] >> y[i];
}
if (s=="mb")
{
float tmp1=0;
for(int i = 0 ; i< n ; i++ )
{
tmp1 += x[i]*y[i];
}
float tmp2=0;
for (int i = 0 ; i < n ; i++)
{
tmp2+=x[i];
}
float tmp3=0;
for (int i = 0 ; i < n ; i++)
{
tmp3+=y[i];
}
float tmp4 = 0;
for (int i = 0 ; i < n ; i++)
{
tmp4+= pow(x[i],2.0);
}
//cout << tmp1 << endl << tmp2 << endl << tmp3 << endl << tmp4 << endl;
m = ((nn*tmp1)-(tmp2*tmp3))/((nn*tmp4)-pow(tmp2,2.0));
b= (tmp2-(m*tmp1))/nn;
cout << m << endl << b;
}
else if (s=="func")
{
}
//cout << m;
} | # 0380, 2024-11-02 09:33:22, PPPPPPPPPP-------------- (41%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
float m = 0;
int n;
cin >> n >> s;
float b = 0;
float nn = n;
float x[n],y[n];
for (int i = 0 ; i < n ; i++)
{
cin >> x[i] >> y[i];
}
if (s=="mb")
{
float tmp1=0;
for(int i = 0 ; i< n ; i++ )
{
tmp1 += x[i]*y[i];
}
float tmp2=0;
for (int i = 0 ; i < n ; i++)
{
tmp2+=x[i];
}
float tmp3=0;
for (int i = 0 ; i < n ; i++)
{
tmp3+=y[i];
}
float tmp4 = 0;
for (int i = 0 ; i < n ; i++)
{
tmp4+= pow(x[i],2.0);
}
//cout << tmp1 << endl << tmp2 << endl << tmp3 << endl << tmp4 << endl;
m = ((nn*tmp1)-(tmp2*tmp3))/((nn*tmp4)-pow(tmp2,2.0));
b= (tmp3-(m*tmp2))/nn;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
cout << m << endl << b;
}
else if (s=="func")
{
}
//cout << m;
} | # 0381, 2024-11-02 09:41:19, PPPPPPPPPPPPPPPP-PPPP-PP (91%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
float m = 0;
int n;
cin >> n >> s;
float b = 0;
float nn = n;
float x[n],y[n];
for (int i = 0 ; i < n ; i++)
{
cin >> x[i] >> y[i];
}
float tmp1=0;
for(int i = 0 ; i< n ; i++ )
{
tmp1 += x[i]*y[i];
}
float tmp2=0;
for (int i = 0 ; i < n ; i++)
{
tmp2+=x[i];
}
float tmp3=0;
for (int i = 0 ; i < n ; i++)
{
tmp3+=y[i];
}
float tmp4 = 0;
for (int i = 0 ; i < n ; i++)
{
tmp4+= pow(x[i],2.0);
}
//cout << tmp1 << endl << tmp2 << endl << tmp3 << endl << tmp4 << endl;
m = ((nn*tmp1)-(tmp2*tmp3))/((nn*tmp4)-pow(tmp2,2.0));
b= (tmp3-(m*tmp2))/nn;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if (s=="mb") cout << m << endl << b;
else if (s=="func")
{
if (m==1||m==-1||m==0)
{
if (m==1)
{
cout << "y = x";
}
else if (m==-1)
{
cout << "y = -x";
}
else if (m==0)
{
if (b!=0)
{
cout << "y = " << b;
}
else if (b==0)
{
cout << "y = 0";
}
}
}
else
{
cout << "y = " <<m << "x";
}
if (b!=0)
{
if (b<0)
cout << " - " << b*-1.0;
else
cout << " + " << b;
}
}
//cout << m;
} | # 0382, 2024-11-02 09:42:53, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
float m = 0;
int n;
cin >> n >> s;
float b = 0;
float nn = n;
float x[n],y[n];
for (int i = 0 ; i < n ; i++)
{
cin >> x[i] >> y[i];
}
float tmp1=0;
for(int i = 0 ; i< n ; i++ )
{
tmp1 += x[i]*y[i];
}
float tmp2=0;
for (int i = 0 ; i < n ; i++)
{
tmp2+=x[i];
}
float tmp3=0;
for (int i = 0 ; i < n ; i++)
{
tmp3+=y[i];
}
float tmp4 = 0;
for (int i = 0 ; i < n ; i++)
{
tmp4+= pow(x[i],2.0);
}
//cout << tmp1 << endl << tmp2 << endl << tmp3 << endl << tmp4 << endl;
m = ((nn*tmp1)-(tmp2*tmp3))/((nn*tmp4)-pow(tmp2,2.0));
b= (tmp3-(m*tmp2))/nn;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if (s=="mb") cout << m << endl << b;
else if (s=="func")
{
if (m==1||m==-1||m==0)
{
if (m==1)
{
cout << "y = x";
}
else if (m==-1)
{
cout << "y = -x";
}
else if (m==0)
{
if (b!=0)
{
cout << "y = " << b;
return 0;
}
else if (b==0)
{
cout << "y = 0";
return 0;
}
}
}
else
{
cout << "y = " <<m << "x";
}
if (b!=0)
{
if (b<0)
cout << " - " << b*-1.0;
else
cout << " + " << b;
}
}
//cout << m;
} |
# 0383, 2024-11-02 13:02:13, PPPPPPPPPP-------------- (41%)
#include<bits/stdc++.h>
using namespace std;
int main(){
vector<float> x,y;
int n;
string how;
cin>>n;
cin>>how;
float nx,ny;
for(int i=0;i<n;i++){
cin>>nx>>ny;
x.push_back(nx);
y.push_back(ny);
}
// for(auto e:x){
// cout<<e<<" ";
// }
// cout<<endl;
// for(auto e:y){
// cout<<e<<" ";
// }
float sumxy=0,sumx=0,sumy=0,sumx2=0;
for(int i=0;i<x.size();i++){
sumxy+=x[i]*y[i];
}
for(int i=0;i<x.size();i++){
sumx+=x[i];
}
for(int i=0;i<x.size();i++){
sumy+=y[i];
}
for(int i=0;i<x.size();i++){
sumx2+=pow(x[i],2);
}
float m,b;
m=((n*sumxy)-((sumx)*(sumy)))/((n*sumx2)-(pow(sumx,2)));
b=((sumy)-(m*sumx))/n;
cout<<round(m*1000)/1000<<endl;
cout<<round(b*1000)/1000;
} | # 0384, 2024-11-02 13:16:41, PPPPPPPPPPPPPPPP--PP-PP- (83%)
#include<bits/stdc++.h>
using namespace std;
int main(){
vector<float> x,y;
int n;
string how;
cin>>n;
cin>>how;
float nx,ny;
for(int i=0;i<n;i++){
cin>>nx>>ny;
x.push_back(nx);
y.push_back(ny);
}
float sumxy=0,sumx=0,sumy=0,sumx2=0;
for(int i=0;i<x.size();i++){
sumxy+=x[i]*y[i];
}
for(int i=0;i<x.size();i++){
sumx+=x[i];
}
for(int i=0;i<x.size();i++){
sumy+=y[i];
}
for(int i=0;i<x.size();i++){
sumx2+=pow(x[i],2);
}
float m,b;
m=((n*sumxy)-((sumx)*(sumy)))/((n*sumx2)-(pow(sumx,2)));
b=((sumy)-(m*sumx))/n;
if(how=="mb"){
cout<<round(m*1000)/1000<<endl;
cout<<round(b*1000)/1000;
}
else if(how=="func"){
if(m==0&&b==0) cout<<"y = 0";
else if(m==0) cout<<"y = "<<round(b*1000)/1000;
else if(b==0){
if(m==1) cout<<"y = x";
else if(m==-1) cout<<"y = -x";
else cout<<"y = "<<round(m*1000)/1000<<"x";
}
else{
if(m==1 && b>0) cout<<"y = x + "<<round(b*1000)/1000;
else if(m==1 && b<0) cout<<"y = x - "<<abs(round(b*1000)/1000);
else if(m==-1 && b>0) cout<<"y = -x + "<<round(b*1000)/1000;
else if(m==-1 && b<0) cout<<"y = -x - "<<abs(round(b*1000)/1000);
else if(b>0) cout<<"y = "<<round(m*1000)/1000<<"x"<<" + "<<round(b*1000)/1000;
else cout<<"y = "<<round(m*1000)/1000<<"x"<<" - "<<abs(round(b*1000)/1000);
}
}
} | # 0385, 2024-11-02 13:20:23, PPPPPPPPPPPPPPPP--PP-PP- (83%)
#include<bits/stdc++.h>
using namespace std;
int main(){
vector<float> x,y;
int n;
string how;
cin>>n;
cin>>how;
float nx,ny;
for(int i=0;i<n;i++){
cin>>nx>>ny;
x.push_back(nx);
y.push_back(ny);
}
// for(auto e:x){
// cout<<e<<" ";
// }
// cout<<endl;
// for(auto e:y){
// cout<<e<<" ";
// }
float sumxy=0,sumx=0,sumy=0,sumx2=0;
for(int i=0;i<x.size();i++){
sumxy+=x[i]*y[i];
}
for(int i=0;i<x.size();i++){
sumx+=x[i];
}
for(int i=0;i<x.size();i++){
sumy+=y[i];
}
for(int i=0;i<x.size();i++){
sumx2+=pow(x[i],2);
}
float m,b;
m=((n*sumxy)-((sumx)*(sumy)))/((n*sumx2)-(pow(sumx,2)));
b=((sumy)-(m*sumx))/n;
if(how=="mb"){
cout<<round(m*1000)/1000<<endl;
cout<<round(b*1000)/1000;
}
else if(how=="func"){
if(m==0&&b==0) cout<<"y = 0";
else if(m==0) cout<<"y = "<<round(b*1000)/1000;
else if(b==0){
if(m==1) cout<<"y = x";
else if(m==-1) cout<<"y = -x";
else cout<<"y = "<<round(m*1000)/1000<<"x";
}
else{
if(m==1 && b>0) cout<<"y = x + "<<round(b*1000)/1000;
else if(m==1 && b<0) cout<<"y = x - "<<(round(abs(b*1000))/1000);
else if(m==-1 && b>0) cout<<"y = -x + "<<round(b*1000)/1000;
else if(m==-1 && b<0) cout<<"y = -x - "<<(round(abs(b*1000))/1000);
else if(b>0) cout<<"y = "<<round(m*1000)/1000<<"x"<<" + "<<round(b*1000)/1000;
else cout<<"y = "<<round(m*1000)/1000<<"x"<<" - "<<(round(abs(b*1000))/1000);
}
}
} | # 0386, 2024-11-02 13:56:20, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<bits/stdc++.h>
using namespace std;
int main(){
vector<float> x,y;
int n;
string how;
cin>>n;
cin>>how;
float nx,ny;
for(int i=0;i<n;i++){
cin>>nx>>ny;
x.push_back(nx);
y.push_back(ny);
}
// for(auto e:x){
// cout<<e<<" ";
// }
// cout<<endl;
// for(auto e:y){
// cout<<e<<" ";
// }
float sumxy=0,sumx=0,sumy=0,sumx2=0;
for(int i=0;i<x.size();i++){
sumxy+=x[i]*y[i];
}
for(int i=0;i<x.size();i++){
sumx+=x[i];
}
for(int i=0;i<x.size();i++){
sumy+=y[i];
}
for(int i=0;i<x.size();i++){
sumx2+=pow(x[i],2);
}
float m,b;
m=((n*sumxy)-((sumx)*(sumy)))/((n*sumx2)-(pow(sumx,2)));
b=((sumy)-(m*sumx))/n;
m=round(m*1000)/1000;
b=round(b*1000)/1000;
if(how=="mb"){
cout<<round(m*1000)/1000<<endl;
cout<<round(b*1000)/1000;
}
else if(how=="func"){
if(m==0&&b==0) cout<<"y = 0";
else if(m==0) cout<<"y = "<<round(b*1000)/1000;
else if(b==0){
if(m==1) cout<<"y = x";
else if(m==-1) cout<<"y = -x";
else cout<<"y = "<<round(m*1000)/1000<<"x";
}
else{
if(m==1 && b>0) cout<<"y = x + "<<round(b*1000)/1000;
else if(m==1 && b<0) cout<<"y = x - "<<(round(abs(b*1000))/1000);
else if(m==-1 && b>0) cout<<"y = -x + "<<round(b*1000)/1000;
else if(m==-1 && b<0) cout<<"y = -x - "<<(round(abs(b*1000))/1000);
else if(b>0) cout<<"y = "<<round(m*1000)/1000<<"x"<<" + "<<round(b*1000)/1000;
else cout<<"y = "<<round(m*1000)/1000<<"x"<<" - "<<(round(abs(b*1000))/1000);
}
}
} |
# 0387, 2024-11-02 13:16:48, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include <iostream>
#include <cmath>
#include <sstream>
float x[1010], y[1010];
int N;
float find_m() {
float sum_xy = 0;
float sum_x = 0;
float sum_y = 0;
float sum_x2 = 0;
for (int i=1; i <= N; ++i) {
sum_xy += x[i] * y[i];
sum_x += x[i];
sum_y += y[i];
sum_x2 += x[i] * x[i];
}
float m = ((N * sum_xy) - (sum_x * sum_y) ) / ((N * sum_x2 )- (sum_x * sum_x));
return m;
}
float find_b(float m) {
float sum_x = 0;
float sum_y = 0;
for (int i=1; i <= N; ++i) {
sum_x += x[i];
sum_y += y[i];
}
float b = (sum_y - (m * sum_x)) / N;
return b;
}
int main() {
std::string mode;
std::cin >> N >> mode;
for (int i=1; i <= N; ++i) {
std::cin >> x[i] >> y[i];
}
float m = find_m();
float b = find_b(m);
if (mode == "mb") {
std::cout << std::round(m * 1e3) / 1e3 << "\n" << std::round(b * 1e3) / 1e3 << "\n";
}
else if (mode == "func") {
std::stringstream ss;
if (std::round(m * 1e3) / 1e3 != 0) {
if (m == 1)
ss << "x";
else if (m == -1)
ss << "-x";
else
ss << std::round(m * 1e3) / 1e3 << "x";
}
if (std::round(m * 1e3) / 1e3 != 0 && std::round(b * 1e3) / 1e3 != 0) {
if (b >= 0)
ss << " + ";
else
ss << " - ";
}
if (std::round(b * 1e3) / 1e3 != 0 && std::round(m * 1e3) / 1e3 != 0 ) {
ss << std::round(std::abs(b) * 1e3) / 1e3;
}
else if (std::round(b * 1e3) / 1e3 != 0 && std::round(m * 1e3) / 1e3 == 0 ) {
ss << std::round(b * 1e3) / 1e3;
}
else if (std::round(b * 1e3) / 1e3 == 0 && std::round(m * 1e3) / 1e3 == 0) {
ss << 0;
}
std::cout << "y = " << ss.str() << "\n";
}
} | # 0388, 2024-11-02 13:19:49, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include <iostream>
#include <cmath>
#include <sstream>
float x[10100], y[10100];
int N;
float find_m() {
float sum_xy = 0;
float sum_x = 0;
float sum_y = 0;
float sum_x2 = 0;
for (int i=1; i <= N; ++i) {
sum_xy += x[i] * y[i];
sum_x += x[i];
sum_y += y[i];
sum_x2 += x[i] * x[i];
}
float m = ((N * sum_xy) - (sum_x * sum_y) ) / ((N * sum_x2 )- (sum_x * sum_x));
return m;
}
float find_b(float m) {
float sum_x = 0;
float sum_y = 0;
for (int i=1; i <= N; ++i) {
sum_x += x[i];
sum_y += y[i];
}
float b = (sum_y - (m * sum_x)) / N;
return b;
}
int main() {
std::string mode;
std::cin >> N >> mode;
for (int i=1; i <= N; ++i) {
std::cin >> x[i] >> y[i];
}
float m = find_m();
float b = find_b(m);
if (mode == "mb") {
std::cout << std::round(m * 1e3) / 1e3 << "\n" << std::round(b * 1e3) / 1e3 << "\n";
}
else if (mode == "func") {
std::stringstream ss;
if (std::round(m * 1e3) / 1e3 != 0) {
if (m == 1)
ss << "x";
else if (m == -1)
ss << "-x";
else
ss << std::round(m * 1e3) / 1e3 << "x";
}
if (std::round(m * 1e3) / 1e3 != 0 && std::round(b * 1e3) / 1e3 != 0) {
if (b >= 0)
ss << " + ";
else
ss << " - ";
}
if (std::round(b * 1e3) / 1e3 != 0 && std::round(m * 1e3) / 1e3 != 0 ) {
ss << std::round(std::abs(b) * 1e3) / 1e3;
}
else if (std::round(b * 1e3) / 1e3 != 0 && std::round(m * 1e3) / 1e3 == 0 ) {
ss << std::round(b * 1e3) / 1e3;
}
else if (std::round(b * 1e3) / 1e3 == 0 && std::round(m * 1e3) / 1e3 == 0) {
ss << 0;
}
std::cout << "y = " << ss.str() << "\n";
}
} | # 0389, 2024-11-02 13:20:05, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include <iostream>
#include <cmath>
#include <sstream>
float x[101000], y[101000];
int N;
float find_m() {
float sum_xy = 0;
float sum_x = 0;
float sum_y = 0;
float sum_x2 = 0;
for (int i=1; i <= N; ++i) {
sum_xy += x[i] * y[i];
sum_x += x[i];
sum_y += y[i];
sum_x2 += x[i] * x[i];
}
float m = ((N * sum_xy) - (sum_x * sum_y) ) / ((N * sum_x2 )- (sum_x * sum_x));
return m;
}
float find_b(float m) {
float sum_x = 0;
float sum_y = 0;
for (int i=1; i <= N; ++i) {
sum_x += x[i];
sum_y += y[i];
}
float b = (sum_y - (m * sum_x)) / N;
return b;
}
int main() {
std::string mode;
std::cin >> N >> mode;
for (int i=1; i <= N; ++i) {
std::cin >> x[i] >> y[i];
}
float m = find_m();
float b = find_b(m);
if (mode == "mb") {
std::cout << std::round(m * 1e3) / 1e3 << "\n" << std::round(b * 1e3) / 1e3 << "\n";
}
else if (mode == "func") {
std::stringstream ss;
if (std::round(m * 1e3) / 1e3 != 0) {
if (m == 1)
ss << "x";
else if (m == -1)
ss << "-x";
else
ss << std::round(m * 1e3) / 1e3 << "x";
}
if (std::round(m * 1e3) / 1e3 != 0 && std::round(b * 1e3) / 1e3 != 0) {
if (b >= 0)
ss << " + ";
else
ss << " - ";
}
if (std::round(b * 1e3) / 1e3 != 0 && std::round(m * 1e3) / 1e3 != 0 ) {
ss << std::round(std::abs(b) * 1e3) / 1e3;
}
else if (std::round(b * 1e3) / 1e3 != 0 && std::round(m * 1e3) / 1e3 == 0 ) {
ss << std::round(b * 1e3) / 1e3;
}
else if (std::round(b * 1e3) / 1e3 == 0 && std::round(m * 1e3) / 1e3 == 0) {
ss << 0;
}
std::cout << "y = " << ss.str() << "\n";
}
} | # 0390, 2024-11-02 13:22:11, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <iostream>
#include <cmath>
#include <sstream>
float x[101000], y[101000];
int N;
float find_m() {
float sum_xy = 0;
float sum_x = 0;
float sum_y = 0;
float sum_x2 = 0;
for (int i=1; i <= N; ++i) {
sum_xy += x[i] * y[i];
sum_x += x[i];
sum_y += y[i];
sum_x2 += x[i] * x[i];
}
float m = ((N * sum_xy) - (sum_x * sum_y) ) / ((N * sum_x2 )- (sum_x * sum_x));
return m;
}
float find_b(float m) {
float sum_x = 0;
float sum_y = 0;
for (int i=1; i <= N; ++i) {
sum_x += x[i];
sum_y += y[i];
}
float b = (sum_y - (m * sum_x)) / N;
return b;
}
int main() {
std::string mode;
std::cin >> N >> mode;
for (int i=1; i <= N; ++i) {
std::cin >> x[i] >> y[i];
}
float m = find_m();
float b = find_b(m);
if (mode == "mb") {
std::cout << std::round(m * 1e3) / 1e3 << "\n" << std::round(b * 1e3) / 1e3 << "\n";
}
else if (mode == "func") {
std::stringstream ss;
if (std::round(m * 1e3) / 1e3 != 0) {
if (std::round(m * 1e3) / 1e3 == 1)
ss << "x";
else if (std::round(m * 1e3) / 1e3 == -1)
ss << "-x";
else
ss << std::round(m * 1e3) / 1e3 << "x";
}
if (std::round(m * 1e3) / 1e3 != 0 && std::round(b * 1e3) / 1e3 != 0) {
if (b >= 0)
ss << " + ";
else
ss << " - ";
}
if (std::round(b * 1e3) / 1e3 != 0 && std::round(m * 1e3) / 1e3 != 0 ) {
ss << std::round(std::abs(b) * 1e3) / 1e3;
}
else if (std::round(b * 1e3) / 1e3 != 0 && std::round(m * 1e3) / 1e3 == 0 ) {
ss << std::round(b * 1e3) / 1e3;
}
else if (std::round(b * 1e3) / 1e3 == 0 && std::round(m * 1e3) / 1e3 == 0) {
ss << 0;
}
std::cout << "y = " << ss.str() << "\n";
}
} |
# 0391, 2024-11-02 10:33:59, xxxxxxxxxxxxxxxxxxxxxxxx (0%)
#include <bits/stdc++.h>
using namespace std ;
float xigma(float N, vector<float>& a) {
float acc ;
for (int i = 1 ; i <= N ; i++) {
acc += a[i] ;
}
return acc ;
}
int main() {
int n ; string con ;
cin >> n >> con ;
vector<float> x ,y ;
for (int i = 0 ; i < n ; i++) {
cin >> x[i] >> y[i] ;
}
// find m
float m1 = 0 ;
for (int i = 1 ; i <= n ; i++) {
m1 += x[i]*y[i] ;
}
m1 = m1*n ;
float m2 = xigma(n,x)*xigma(n,y) ;
float m3 = 0 ;
for (int i = 1 ; i <= n ; i++) {
m3 += x[i]*x[i] ;
}
m3 = m3*n ;
float m4 = pow(xigma(n, x), 2) ;
float m = (m1-m2)/(m3-m4) ;
// find b
float b = (xigma(n, y)-(m*xigma(n, x)))/n ;
if (con == "mb") {
cout << round(m*1e3)/1e3 << "\n" << round(b*1e3)/1e3 ;
}
else if (con == "func") {
cout << "y = " ;
if (m == 0 && b == 0) cout << 0 ;
else {
if (m == -1) cout << "-x " ;
else if (m != 0) cout << round(m*1e3)/1e3 << "x ";
if (b > 0) cout << "+ " << round(b*1e3)/1e3 ;
else if (b < 0) cout << "- " << -1*round(b*1e3)/1e3 ;
}
}
} | # 0392, 2024-11-02 10:40:39, PPPPPPPPPPPPPPPP---P---- (70%)
#include <bits/stdc++.h>
using namespace std ;
float xigma(float N, vector<float>& a) {
float acc = 0 ;
for (int i = 0 ; i < N ; i++) {
acc += a[i] ;
}
return acc ;
}
int main() {
int n ; string con ;
cin >> n >> con ;
vector<float> x ,y ;
float tempx, tempy ;
for (int i = 0 ; i < n ; i++) {
cin >> tempx >> tempy ;
x.push_back(tempx) ;
y.push_back(tempy) ;
}
// find m
float m1 = 0 ;
for (int i = 0 ; i < n ; i++) {
m1 += x[i]*y[i] ;
}
m1 = m1*n ;
float m2 = xigma(n,x)*xigma(n,y) ;
float m3 = 0 ;
for (int i = 0 ; i < n ; i++) {
m3 += x[i]*x[i] ;
}
m3 = m3*n ;
float m4 = pow(xigma(n, x), 2) ;
float m = (m1-m2)/(m3-m4) ;
// find b
float b = (xigma(n, y)-(m*xigma(n, x)))/n ;
if (con == "mb") {
cout << round(m*1e3)/1e3 << "\n" << round(b*1e3)/1e3 ;
}
else if (con == "func") {
cout << "y = " ;
if (m == 0 && b == 0) cout << 0 ;
else {
if (m == -1) cout << "-x " ;
else if (m != 0) cout << round(m*1e3)/1e3 << "x ";
if (b > 0) cout << "+ " << round(b*1e3)/1e3 ;
else if (b < 0) cout << "- " << -1*round(b*1e3)/1e3 ;
}
}
} | # 0393, 2024-11-02 10:47:58, PPPPPPPPPPPPPPP-PPPPPPPP (95%)
#include <bits/stdc++.h>
using namespace std ;
float xigma(float N, vector<float>& a) {
float acc = 0 ;
for (int i = 0 ; i < N ; i++) {
acc += a[i] ;
}
return acc ;
}
int main() {
int n ; string con ;
cin >> n >> con ;
vector<float> x ,y ;
float tempx, tempy ;
for (int i = 0 ; i < n ; i++) {
cin >> tempx >> tempy ;
x.push_back(tempx) ;
y.push_back(tempy) ;
}
// find m
float m1 = 0 ;
for (int i = 0 ; i < n ; i++) {
m1 += x[i]*y[i] ;
}
m1 = m1*n ;
float m2 = xigma(n,x)*xigma(n,y) ;
float m3 = 0 ;
for (int i = 0 ; i < n ; i++) {
m3 += x[i]*x[i] ;
}
m3 = m3*n ;
float m4 = pow(xigma(n, x), 2) ;
float m = (m1-m2)/(m3-m4) ;
// find b
float b = (xigma(n, y)-(m*xigma(n, x)))/n ;
if (con == "mb") {
cout << round(m*1e3)/1e3 << "\n" << round(b*1e3)/1e3 ;
}
else if (con == "func") {
cout << "y = " ;
if (round(m*1e3)/1e3 == 0 && round(b*1e3)/1e3 == 0) cout << 0 ;
if (round(m*1e3)/1e3 == 0 || round(m*1e3)/1e3 == (-0)) cout << round(b*1e3)/1e3 ;
else {
if (round(m*1e3)/1e3 == -1) cout << "-x " ;
else if (round(m*1e3)/1e3 == 1) cout << "x " ;
else if (round(m*1e3)/1e3 != 0) cout << round(m*1e3)/1e3 << "x ";
if (round(b*1e3)/1e3 > 0) cout << "+ " << round(b*1e3)/1e3 ;
else if (round(b*1e3)/1e3 < 0) cout << "- " << -1*round(b*1e3)/1e3 ;
}
}
} | # 0394, 2024-11-02 10:49:22, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std ;
float xigma(float N, vector<float>& a) {
float acc = 0 ;
for (int i = 0 ; i < N ; i++) {
acc += a[i] ;
}
return acc ;
}
int main() {
int n ; string con ;
cin >> n >> con ;
vector<float> x ,y ;
float tempx, tempy ;
for (int i = 0 ; i < n ; i++) {
cin >> tempx >> tempy ;
x.push_back(tempx) ;
y.push_back(tempy) ;
}
// find m
float m1 = 0 ;
for (int i = 0 ; i < n ; i++) {
m1 += x[i]*y[i] ;
}
m1 = m1*n ;
float m2 = xigma(n,x)*xigma(n,y) ;
float m3 = 0 ;
for (int i = 0 ; i < n ; i++) {
m3 += x[i]*x[i] ;
}
m3 = m3*n ;
float m4 = pow(xigma(n, x), 2) ;
float m = (m1-m2)/(m3-m4) ;
// find b
float b = (xigma(n, y)-(m*xigma(n, x)))/n ;
if (con == "mb") {
cout << round(m*1e3)/1e3 << "\n" << round(b*1e3)/1e3 ;
}
else if (con == "func") {
cout << "y = " ;
if (round(m*1e3)/1e3 == 0 && round(b*1e3)/1e3 == 0) cout << 0 ;
else if (round(m*1e3)/1e3 == 0 ) cout << round(b*1e3)/1e3 ;
else {
if (round(m*1e3)/1e3 == -1) cout << "-x " ;
else if (round(m*1e3)/1e3 == 1) cout << "x " ;
else if (round(m*1e3)/1e3 != 0) cout << round(m*1e3)/1e3 << "x ";
if (round(b*1e3)/1e3 > 0) cout << "+ " << round(b*1e3)/1e3 ;
else if (round(b*1e3)/1e3 < 0) cout << "- " << -1*round(b*1e3)/1e3 ;
}
}
} |
# 0395, 2024-11-02 13:10:18, -----PPPPP-----PPPPPPPPP (58%)
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <cmath>
using namespace std;
int main()
{
int n;
string s;
cin >> n;
cin >> s;
vector<pair<float, float>> vec(n);
for (int i = 0; i < n; i++)
{
cin >> vec[i].first >> vec[i].second;
}
float b = 0, m = 0;
float temp = 0, temp2 = 0;
for (int i = 0; i < n; i++)
{
temp += vec[i].first * vec[i].second;
}
temp *= n;
m += temp;
temp = 0;
for (int i = 0; i < n; i++)
{
temp += vec[i].first;
}
for (int i = 0; i < n; i++)
{
temp2 += vec[i].second;
}
m -= temp * temp2;
temp = 0;
temp2 = 0;
for (int i = 0; i < n; i++)
{
temp += vec[i].first * vec[i].first;
}
temp *= n;
for (int i = 0; i < n; i++)
{
temp2 += vec[i].first;
}
temp2 *= temp2;
temp -= temp2;
m /= temp;
m = round(m * 1e3) / 1e3;
temp = 0;
temp2 = 0;
for (int i = 0; i < n; i++)
{
b += vec[i].second;
}
for (int i = 0; i < n; i++)
{
temp += vec[i].first;
}
temp *= m;
b -= temp;
b /= n;
b = round(b * 1e3) / 1e3;
if (s == "mb")
{
cout << m << endl
<< b;
return 0;
}
cout << "y = ";
if(m==0&&b==0) {
cout<<0;
return 0;
}
if(m==0) {
cout<<b;
return 0;
}
if(m==1) {
cout<<"x ";
}
else if(m==-1) {
cout<<"-x ";
}
else{
cout<<m<<"x ";
}
if(b>0){
cout<<"+ "<<b;
return 0;
}
if(b<0) {
cout<<"- "<<abs(b);
return 0;
}
} | # 0396, 2024-11-02 13:11:14, -----PPPPP-----PPPPPPPPP (58%)
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <cmath>
using namespace std;
int main()
{
int n;
string s;
cin >> n;
cin >> s;
vector<pair<float, float>> vec(n);
for (int i = 0; i < n; i++)
{
cin >> vec[i].first >> vec[i].second;
}
float b = 0, m = 0;
float temp = 0, temp2 = 0;
for (int i = 0; i < n; i++)
{
temp += vec[i].first * vec[i].second;
}
temp *= n;
m += temp;
temp = 0;
for (int i = 0; i < n; i++)
{
temp += vec[i].first;
}
for (int i = 0; i < n; i++)
{
temp2 += vec[i].second;
}
m -= temp * temp2;
temp = 0;
temp2 = 0;
for (int i = 0; i < n; i++)
{
temp += vec[i].first * vec[i].first;
}
temp *= n;
for (int i = 0; i < n; i++)
{
temp2 += vec[i].first;
}
temp2 *= temp2;
temp -= temp2;
m /= temp;
m = round(m * 1e3) / 1e3;
temp = 0;
temp2 = 0;
for (int i = 0; i < n; i++)
{
b += vec[i].second;
}
for (int i = 0; i < n; i++)
{
temp += vec[i].first;
}
temp *= m;
b -= temp;
b /= n;
b = round(b * 1e3) / 1e3;
if (s == "mb")
{
cout << m << endl
<< b<<endl;
return 0;
}
cout << "y = ";
if(m==0&&b==0) {
cout<<0;
return 0;
}
if(m==0) {
cout<<b;
return 0;
}
if(m==1) {
cout<<"x ";
}
else if(m==-1) {
cout<<"-x ";
}
else{
cout<<m<<"x ";
}
if(b>0){
cout<<"+ "<<b;
return 0;
}
if(b<0) {
cout<<"- "<<abs(b);
return 0;
}
} | # 0397, 2024-11-02 13:16:03, -----PPPPP-------------- (20%)
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <cmath>
using namespace std;
int main()
{
int n;
string s;
cin >> n;
cin >> s;
vector<pair<float, float>> vec(n);
for (int i = 0; i < n; i++)
{
cin >> vec[i].first >> vec[i].second;
}
float b = 0, m = 0;
float temp = 0, temp2 = 0;
for (int i = 0; i < n; i++)
{
temp += vec[i].first * vec[i].second;
}
temp *= n;
m += temp;
temp = 0;
for (int i = 0; i < n; i++)
{
temp += vec[i].first;
}
for (int i = 0; i < n; i++)
{
temp2 += vec[i].second;
}
m -= temp * temp2;
temp = 0;
temp2 = 0;
for (int i = 0; i < n; i++)
{
temp += vec[i].first * vec[i].first;
}
temp *= n;
for (int i = 0; i < n; i++)
{
temp2 += vec[i].first;
}
temp2 *= temp2;
temp -= temp2;
m /= temp;
m = round(m * 1e3) / 1e3;
temp = 0;
temp2 = 0;
for (int i = 0; i < n; i++)
{
b += vec[i].second;
}
for (int i = 0; i < n; i++)
{
temp += vec[i].first;
}
temp *= m;
b -= temp;
b /= n;
b = round(b * 1e3) / 1e3;
if (s == "mb")
{
cout << m << endl
<< b<<endl;
return 0;
}
// cout << "y = ";
// if(m==0&&b==0) {
// cout<<0;
// return 0;
// }
// if(m==0) {
// cout<<b;
// return 0;
// }
// if(m==1) {
// cout<<"x ";
// }
// else if(m==-1) {
// cout<<"-x ";
// }
// else{
// cout<<m<<"x ";
// }
// if(b>0){
// cout<<"+ "<<b;
// return 0;
// }
// if(b<0) {
// cout<<"- "<<abs(b);
// return 0;
// }
} | # 0398, 2024-11-02 13:46:36, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <cmath>
using namespace std;
int main()
{
int n;
string s;
cin >> n;
cin >> s;
vector<pair<float, float>> vec(n);
for (int i = 0; i < n; i++)
{
cin >> vec[i].first >> vec[i].second;
}
float b = 0, m = 0;
float temp = 0, temp2 = 0;
for (int i = 0; i < n; i++)
{
temp += vec[i].first * vec[i].second;
}
temp *= n;
m += temp;
temp = 0;
for (int i = 0; i < n; i++)
{
temp += vec[i].first;
}
for (int i = 0; i < n; i++)
{
temp2 += vec[i].second;
}
m = m- (temp * temp2);
temp = 0;
temp2 = 0;
for (int i = 0; i < n; i++)
{
temp += vec[i].first * vec[i].first;
}
temp *= n;
for (int i = 0; i < n; i++)
{
temp2 += vec[i].first;
}
temp2 = temp2 * temp2;
temp = temp-temp2;
m = m/temp;
temp = 0;
temp2 = 0;
for (int i = 0; i < n; i++)
{
b += vec[i].second;
}
for (int i = 0; i < n; i++)
{
temp += vec[i].first;
}
temp *= m;
b -= temp;
b /= n;
b = round(b * 1e3) / 1e3;
m = round(m * 1e3) / 1e3;
if (s == "mb")
{
cout << m << endl
<< b<<endl;
return 0;
}
cout << "y = ";
if(m==0&&b==0) {
cout<<0;
return 0;
}
if(m==0) {
cout<<b;
return 0;
}
if(m==1) {
cout<<"x ";
}
else if(m==-1) {
cout<<"-x ";
}
else{
cout<<m<<"x ";
}
if(b>0){
cout<<"+ "<<b;
return 0;
}
if(b<0) {
cout<<"- "<<abs(b);
return 0;
}
} |
# 0399, 2024-11-02 13:13:53, PPPPPPPPPP-------PPPP--- (58%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
string input ; cin >> input;
float x[n+1],y[n+1];
for(int i=1 ; i<=n ; i++){
cin >> x[i] >> y[i];
}
float m[4]={0};
// for(auto t:m) cout << t << " ";
//m
float fx=0,fy=0;
for(int i=1 ; i<=n ; i++){
m[0]+=x[i]*y[i];
fx+=x[i];
fy+=y[i];
m[2]+=x[i]*x[i];
m[3]+=x[i];
}
m[0]*=n;
m[1] = fx*fy;
m[2] *=n;
float fak_m3 = m[3];
m[3]*=m[3];
float mm = (m[0] - m[1])/(m[2]-m[3]);
//b
float sb=0;
for(int i=1 ; i<=n ; i++){
sb+=y[i];
}
float bb=(sb - (mm*fak_m3))/n;
if(input == "mb"){
cout << round(mm*1e3)/1e3 <<endl;
cout << round(bb*1e3)/1e3 <<endl;
}
if(input == "func"){
cout << "y = " ;
mm = round(mm*1e3)/1e3 ;
bb = round(bb*1e3)/1e3 ;
string c_m;
if(mm==1) c_m="";
else if(mm==-1) c_m="-";
else c_m=to_string(mm);
if(c_m!="0" && bb!=0) cout << c_m << "x + " << bb<<endl;
else if(c_m=="0" && bb!=0) cout << bb << endl;
else if(c_m!="0" && bb==0) cout << c_m << "x" << endl;
else if(c_m=="0" && bb==0) cout << 0 << endl;
}
// full : y= mx+b
// y = b
// y = mx
// y= 0
} | # 0400, 2024-11-02 13:18:44, PPPPPPPPPP--------PP---- (50%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
string input ; cin >> input;
float x[n+1],y[n+1];
for(int i=1 ; i<=n ; i++){
cin >> x[i] >> y[i];
}
float m[4]={0};
// for(auto t:m) cout << t << " ";
//m
float fx=0,fy=0;
for(int i=1 ; i<=n ; i++){
m[0]+=x[i]*y[i];
fx+=x[i];
fy+=y[i];
m[2]+=x[i]*x[i];
m[3]+=x[i];
}
m[0]*=n;
m[1] = fx*fy;
m[2] *=n;
float fak_m3 = m[3];
m[3]*=m[3];
float mm = (m[0] - m[1])/(m[2]-m[3]);
//b
float sb=0;
for(int i=1 ; i<=n ; i++){
sb+=y[i];
}
float bb=(sb - (mm*fak_m3))/n;
if(input == "mb"){
cout << round(mm*1e3)/1e3 <<endl;
cout << round(bb*1e3)/1e3 <<endl;
}
if(input == "func"){
cout << "y = " ;
mm = round(mm*1e3)/1e3 ;
bb = round(bb*1e3)/1e3 ;
string c_m,c_b;
string h;
if(mm==1) c_m="";
else if(mm==-1) c_m="-";
else c_m=to_string(mm);
if(bb < 0) {
c_b=to_string(-(bb));
h = "-";
}
else {
c_b=to_string(bb);
h ="+";
}
if(c_m!="0" && bb!=0) cout << c_m << "x " << h << " " << c_b<<endl;
else if(c_m=="0" && bb!=0) cout << c_b << endl;
else if(c_m!="0" && bb==0) cout << c_m << "x" << endl;
else if(c_m=="0" && bb==0) cout << 0 << endl;
}
// full : y= mx+b
// y = b
// y = mx
// y= 0
} | # 0401, 2024-11-02 13:27:47, PPPPPPPPPPPPPPPP-PPPP-PP (91%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
string input ; cin >> input;
float x[n+1],y[n+1];
for(int i=1 ; i<=n ; i++){
cin >> x[i] >> y[i];
}
float m[4]={0};
// for(auto t:m) cout << t << " ";
//m
float fx=0,fy=0;
for(int i=1 ; i<=n ; i++){
m[0]+=x[i]*y[i];
fx+=x[i];
fy+=y[i];
m[2]+=x[i]*x[i];
m[3]+=x[i];
}
m[0]*=n;
m[1] = fx*fy;
m[2] *=n;
float fak_m3 = m[3];
m[3]*=m[3];
float mm = (m[0] - m[1])/(m[2]-m[3]);
//b
float sb=0;
for(int i=1 ; i<=n ; i++){
sb+=y[i];
}
float bb=(sb - (mm*fak_m3))/n;
if(input == "mb"){
cout << round(mm*1e3)/1e3 <<endl;
cout << round(bb*1e3)/1e3 <<endl;
}
if(input == "func"){
cout << "y = " ;
mm = round(mm*1e3)/1e3 ;
bb = round(bb*1e3)/1e3 ;
string c_m,c_b;
string h;
if(bb < 0) {
bb*=-1;
h = "-";
}
else {
h ="+";
}
// if(mm<0){
// }
// else {
if(mm==1 && bb!=0 ) cout << " x " << h << " " << bb<<endl;
else if(mm==-1 && bb!=0) cout << " -" << "x " << h << " " << bb<<endl;
else if(mm!=0 && bb!=0) cout << mm << "x " << h << " " << bb<<endl;
else if(mm==0 && bb!=0) cout << mm << endl;
else if(mm ==1 && bb==0) cout << " x" << endl;
else if(mm==-1 && bb==0) cout << " -" << "x" << endl;
else if(mm!=0 && bb==0) cout << mm << "x" << endl;
else if(mm==0 && bb==0) cout << 0 << endl;
// }
}
// m=1 + -
// full : y= mx+b
// y = b
// y = mx
// y= 0
} | # 0402, 2024-11-02 13:30:25, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
string input ; cin >> input;
float x[n+1],y[n+1];
for(int i=1 ; i<=n ; i++){
cin >> x[i] >> y[i];
}
float m[4]={0};
// for(auto t:m) cout << t << " ";
//m
float fx=0,fy=0;
for(int i=1 ; i<=n ; i++){
m[0]+=x[i]*y[i];
fx+=x[i];
fy+=y[i];
m[2]+=x[i]*x[i];
m[3]+=x[i];
}
m[0]*=n;
m[1] = fx*fy;
m[2] *=n;
float fak_m3 = m[3];
m[3]*=m[3];
float mm = (m[0] - m[1])/(m[2]-m[3]);
//b
float sb=0;
for(int i=1 ; i<=n ; i++){
sb+=y[i];
}
float bb=(sb - (mm*fak_m3))/n;
if(input == "mb"){
cout << round(mm*1e3)/1e3 <<endl;
cout << round(bb*1e3)/1e3 <<endl;
}
if(input == "func"){
cout << "y = " ;
mm = round(mm*1e3)/1e3 ;
bb = round(bb*1e3)/1e3 ;
string c_m,c_b;
string h;
float fak_bb = bb;
if(bb < 0) {
bb*=-1;
h = "-";
}
else {
h ="+";
}
// if(mm<0){
// }
// else {
if(mm==1 && bb!=0 ) cout << " x " << h << " " << bb<<endl;
else if(mm==-1 && bb!=0) cout << " -" << "x " << h << " " << bb<<endl;
else if(mm!=0 && bb!=0) cout << mm << "x " << h << " " << bb<<endl;
else if(mm==0 && bb!=0) cout << fak_bb << endl;
else if(mm ==1 && bb==0) cout << " x" << endl;
else if(mm==-1 && bb==0) cout << " -" << "x" << endl;
else if(mm!=0 && bb==0) cout << mm << "x" << endl;
else if(mm==0 && bb==0) cout << 0 << endl;
// }
}
// m=1 + -
// full : y= mx+b
// y = b
// y = mx
// y= 0
} |
# 0403, 2024-11-02 14:41:01, PPPPPPPPPP-------------- (41%)
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
using namespace std;
int main(){
int n,n1;
float a,c,m=0,b=0;
string what;
cin >> n >> what;
n1=n;
vector<pair<float,float>>xy;
while(n--){
cin >> a >> c;
xy.push_back(make_pair(a,c));
}
float x,y,f1=0,f2=0,f3=0,f4=0,f5=0,e1=0,e2=0;
for(auto i = xy.begin(),end = xy.end();i != end;++i){
x = (*i).first;
y = (*i).second;
f1 += x*y;
f2 += x;
f3 += y;
f4 += x*x;
f5 += x;
e1 += y;
e2 += x;
}
//cout << "/" << f1 << "/" << f2<< "/" << f3<< "/" << f4<< "/" << f5<< "/" << e1<< "/" << e2;
m = ((n1*f1)-(f2*f3))/((n1*f4)-(f5*f5));
//cout <<"/" << n<<"/" << (n1*f1)-(f2*f3) << "/" << (n1*f4)-(f5*f5)<< "/";
b = ((e1) - (m*e2))/n1;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(what == "mb"){
cout << m << endl << b;
}
} | # 0404, 2024-11-02 14:48:04, PPPPPPPPPPP-P--PPPPPPP-- (79%)
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
using namespace std;
int main(){
int n,n1;
float a,c,m=0,b=0;
string what;
cin >> n >> what;
n1=n;
vector<pair<float,float>>xy;
while(n--){
cin >> a >> c;
xy.push_back(make_pair(a,c));
}
float x,y,f1=0,f2=0,f3=0,f4=0,f5=0,e1=0,e2=0;
for(auto i = xy.begin(),end = xy.end();i != end;++i){
x = (*i).first;
y = (*i).second;
f1 += x*y;
f2 += x;
f3 += y;
f4 += x*x;
f5 += x;
e1 += y;
e2 += x;
}
//cout << "/" << f1 << "/" << f2<< "/" << f3<< "/" << f4<< "/" << f5<< "/" << e1<< "/" << e2;
m = ((n1*f1)-(f2*f3))/((n1*f4)-(f5*f5));
//cout <<"/" << n<<"/" << (n1*f1)-(f2*f3) << "/" << (n1*f4)-(f5*f5)<< "/";
b = ((e1) - (m*e2))/n1;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(what == "mb"){
cout << m << endl << b;
}
else if(what == "func"){
if(m==1) {
if(b!=0) cout << "y = x + " << b;
else cout << "y = x";
}
else if(m==-1) {
if(b!=0) cout << "y = -x + " << b;
else cout << "y = -x";
}
else if(m==0) {
if(b!=0) cout << "y = " << b;
else cout << "y = 0";
}
else cout << "y = " << m << "x + " << b;
}
} | # 0405, 2024-11-02 14:56:51, PPPPPPPPPPP-P--PPPPPPPPP (87%)
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
using namespace std;
int main(){
int n,n1;
float a,c,m=0,b=0;
string what;
cin >> n >> what;
n1=n;
vector<pair<float,float>>xy;
while(n--){
cin >> a >> c;
xy.push_back(make_pair(a,c));
}
float x,y,f1=0,f2=0,f3=0,f4=0,f5=0,e1=0,e2=0;
for(auto i = xy.begin(),end = xy.end();i != end;++i){
x = (*i).first;
y = (*i).second;
f1 += x*y;
f2 += x;
f3 += y;
f4 += x*x;
f5 += x;
e1 += y;
e2 += x;
}
//cout << "/" << f1 << "/" << f2<< "/" << f3<< "/" << f4<< "/" << f5<< "/" << e1<< "/" << e2;
m = ((n1*f1)-(f2*f3))/((n1*f4)-(f5*f5));
//cout <<"/" << n<<"/" << (n1*f1)-(f2*f3) << "/" << (n1*f4)-(f5*f5)<< "/";
b = ((e1) - (m*e2))/n1;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(what == "mb"){
cout << m << endl << b;
}
else if(what == "func"){
if(m==1) {
if(b>0) cout << "y = x + " << b;
else if(b<0) cout << "y = x - " << b*-1;
else if(b==0)cout << "y = x";
}
else if(m==-1) {
if(b>0) cout << "y = -x + " << b;
else if(b<0) cout << "y = -x - " << b*-1;
else if(b==0)cout << "y = -x";
}
else if(m==0) {
if(b>0) cout << "y = " << b;
else if(b<0) cout << "y = -" << b*-1;
else if(b==0)cout << "y = 0";
}
else cout << "y = " << m << "x + " << b;
}
} | # 0406, 2024-11-02 15:01:18, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
using namespace std;
int main(){
int n,n1;
float a,c,m=0,b=0;
string what;
cin >> n >> what;
n1=n;
vector<pair<float,float>>xy;
while(n--){
cin >> a >> c;
xy.push_back(make_pair(a,c));
}
float x,y,f1=0,f2=0,f3=0,f4=0,f5=0,e1=0,e2=0;
for(auto i = xy.begin(),end = xy.end();i != end;++i){
x = (*i).first;
y = (*i).second;
f1 += x*y;
f2 += x;
f3 += y;
f4 += x*x;
f5 += x;
e1 += y;
e2 += x;
}
//cout << "/" << f1 << "/" << f2<< "/" << f3<< "/" << f4<< "/" << f5<< "/" << e1<< "/" << e2;
m = ((n1*f1)-(f2*f3))/((n1*f4)-(f5*f5));
//cout <<"/" << n<<"/" << (n1*f1)-(f2*f3) << "/" << (n1*f4)-(f5*f5)<< "/";
b = ((e1) - (m*e2))/n1;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(what == "mb"){
cout << m << endl << b;
}
else if(what == "func"){
if(m==1) {
if(b>0) cout << "y = x + " << b;
else if(b<0) cout << "y = x - " << b*-1;
else if(b==0)cout << "y = x";
}
else if(m==-1) {
if(b>0) cout << "y = -x + " << b;
else if(b<0) cout << "y = -x - " << b*-1;
else if(b==0)cout << "y = -x";
}
else if(m==0) {
if(b>0) cout << "y = " << b;
else if(b<0) cout << "y = -" << b*-1;
else if(b==0)cout << "y = 0";
}
else if(m>1) {
if(b>0) cout << "y = "<< m << "x + " << b;
else if(b<0) cout << "y = " << m << "x - " << b*-1;
else if(b==0)cout << "y = "<< m << "x";
}
else if(m<-1) {
if(b>0) cout << "y = "<< m << "x + " << b;
else if(b<0) cout << "y = " << m << "x - " << b*-1;
else if(b==0)cout << "y = "<< m << "x";
}
}
} |
# 0407, 2024-11-02 13:23:28, -----P------------------ (4%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string ins;
cin >> n >> ins;
cin.ignore();
vector<pair<int,double>> xy;
for (int i = 0; i < n; i++) {
double x, y; cin >> x >> y;
xy.push_back(make_pair(x,y));
}
//find m,b
float m, b;
float sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0;
for (int i = 1; i <= n; i++) {
sum1 += xy[i].first * xy[i].second;
sum4 += xy[i].first;
sum2 += xy[i].second;
sum3 += pow(xy[i].first,2);
}
m = ((n*sum1) - (sum4*sum2)) / ((n*sum3) - pow(sum4,2));
b = ((sum2) - (m*sum4)) / n;
//display
if (ins == "mb") {
float p_m, p_b;
p_m = round(m*1e3)/1e3;
p_b = round(b*1e3)/1e3;
cout << p_m << endl;
cout << p_b << endl;
}
} | # 0408, 2024-11-02 13:29:40, PPPPPPPPPP-------------- (41%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string ins;
cin >> n >> ins;
cin.ignore();
vector<pair<float,float>> xy;
for (int i = 0; i < n; i++) {
float x, y; cin >> x >> y;
xy.push_back(make_pair(x,y));
}
//find m,b
float m, b;
float sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0;
for (int i = 0; i < n; i++) {
sum1 += xy[i].first * xy[i].second;
sum4 += xy[i].first;
sum2 += xy[i].second;
sum3 += pow(xy[i].first,2);
}
m = ((n*sum1) - (sum4*sum2)) / ((n*sum3) - pow(sum4,2));
b = ((sum2) - (m*sum4)) / n;
//display
if (ins == "mb") {
float p_m, p_b;
p_m = round(m*1e3)/1e3;
p_b = round(b*1e3)/1e3;
cout << p_m << endl;
cout << p_b << endl;
}
} | # 0409, 2024-11-02 13:42:33, PPPPPPPPPPPPPPPP--PP-PP- (83%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string ins;
cin >> n >> ins;
cin.ignore();
vector<pair<float,float>> xy;
for (int i = 0; i < n; i++) {
float x, y; cin >> x >> y;
xy.push_back(make_pair(x,y));
}
//find m,b
float m, b;
float sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0;
for (int i = 0; i < n; i++) {
sum1 += xy[i].first * xy[i].second;
sum4 += xy[i].first;
sum2 += xy[i].second;
sum3 += pow(xy[i].first,2);
}
m = ((n*sum1) - (sum4*sum2)) / ((n*sum3) - pow(sum4,2));
b = ((sum2) - (m*sum4)) / n;
//display
bool have = false;
float p_m, p_b;
p_m = round(m*1e3)/1e3;
p_b = round(b*1e3)/1e3;
if (ins == "mb") {
cout << p_m << endl;
cout << p_b << endl;
}
else if (ins == "func") {
cout << "y = ";
if (m == 1) {
cout << "x";
have = true;
}
else if (m == -1) {
cout << "-x";
have = true;
}
else if (m == 0) {
cout << p_b;
}
else {
cout << p_m << "x";
have = true;
}
if (have) {
if (p_b > 0) {
cout << " + " << p_b;
}
else if (p_b < 0) {
cout << " - " << abs(p_b);
}
}
}
return 0;
} | # 0410, 2024-11-02 13:46:53, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string ins;
cin >> n >> ins;
cin.ignore();
vector<pair<float,float>> xy;
for (int i = 0; i < n; i++) {
float x, y; cin >> x >> y;
xy.push_back(make_pair(x,y));
}
//find m,b
float m, b;
float sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0;
for (int i = 0; i < n; i++) {
sum1 += xy[i].first * xy[i].second;
sum4 += xy[i].first;
sum2 += xy[i].second;
sum3 += pow(xy[i].first,2);
}
m = ((n*sum1) - (sum4*sum2)) / ((n*sum3) - pow(sum4,2));
b = ((sum2) - (m*sum4)) / n;
//display
bool have = false;
float p_m, p_b;
p_m = round(m*1e3)/1e3;
p_b = round(b*1e3)/1e3;
if (ins == "mb") {
cout << p_m << endl;
cout << p_b << endl;
}
else if (ins == "func") {
cout << "y = ";
if (p_m == 1) {
cout << "x";
have = true;
}
else if (p_m == -1) {
cout << "-x";
have = true;
}
else if (abs(p_m) == 0) {
cout << p_b << endl;
}
else {
cout << p_m << "x";
have = true;
}
if (have) {
if (p_b > 0) {
cout << " + " << p_b << endl;
}
else if (p_b < 0) {
cout << " - " << abs(p_b) << endl;
}
}
}
return 0;
} |
# 0411, 2024-11-02 14:41:37, PPPPPPPPPPP-P--P-------- (54%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
float m,b;
string s,ansmx;
cin>>n>>s;
float x[n],y[n];
float ex=0,ey=0,exy=0,ex2=0;
for(int i=0;i<n;i++){
cin>>x[i]>>y[i];
ex+=x[i];
ey+=y[i];
ex2+=(x[i]*x[i]);
exy+=(x[i]*y[i]);
}
m=((n*exy)-(ex*ey)) / ((n*ex2)-(ex*ex));
b=(ey-(m*ex))/n;
if(s=="mb"){
cout<< round(m*1e3)/1e3<<endl<< round(b*1e3)/1e3;}
if(m==1){ansmx="x";}
if(s=="func"){
if(m==-1){
cout<<"y = " <<"-x + ";}
else if(m==1){
cout<<"y = " <<"x + ";}
else if(m==-1){
cout<<"y = " <<"-x + ";}
else { if(m!=0){
cout<<"y = "<< round(m*1e3)/1e3 <<"x + ";}
}
if(b!=0){cout<<round(b*1e3)/1e3;}
if(m==0&&b==0){cout<<"y = 0";}
}
} | # 0412, 2024-11-02 14:57:10, PPPPPPPPPPP-P---PP--PP-- (66%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
float m,b;
string s,ansmx;
cin>>n>>s;
float x[n],y[n];
float ex=0,ey=0,exy=0,ex2=0;
for(int i=0;i<n;i++){
cin>>x[i]>>y[i];
ex+=x[i];
ey+=y[i];
ex2+=(x[i]*x[i]);
exy+=(x[i]*y[i]);
}
m=((n*exy)-(ex*ey)) / ((n*ex2)-(ex*ex));
b=(ey-(m*ex))/n;
if(s=="mb"){
cout<< round(m*1e3)/1e3<<endl<< round(b*1e3)/1e3;}
if(s=="func"){
cout<<"y = ";
if(round(m*1e3)/1e3==-1){
cout<<"-x + ";}
else if(round(m*1e3)/1e3==1){
cout<<"x + ";}
else if(round(m*1e3)/1e3==-1){
cout<<"-x + ";}
else if(round(m*1e3)/1e3!=0){
cout<< round(m*1e3)/1e3 <<"x + ";}
if(round(b*1e3)/1e3!=0){cout<<round(b*1e3)/1e3;}
if(round(m*1e3)/1e3==0&&round(b*1e3)/1e3==0){cout<<"y = 0";}
}
} | # 0413, 2024-11-02 14:59:57, PPPPPPPPPPP-P--PPPPPPP-- (79%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
float m,b;
string s,ansmx;
cin>>n>>s;
float x[n],y[n];
float ex=0,ey=0,exy=0,ex2=0;
for(int i=0;i<n;i++){
cin>>x[i]>>y[i];
ex+=x[i];
ey+=y[i];
ex2+=(x[i]*x[i]);
exy+=(x[i]*y[i]);
}
m=((n*exy)-(ex*ey)) / ((n*ex2)-(ex*ex));
b=(ey-(m*ex))/n;
if(s=="mb"){
cout<< round(m*1e3)/1e3<<endl<< round(b*1e3)/1e3;}
if(s=="func"){
cout<<"y = ";
if(round(m*1e3)/1e3==-1){
cout<<"-x ";}
else if(round(m*1e3)/1e3==1){
cout<<"x ";}
else if(round(m*1e3)/1e3==-1){
cout<<"-x ";}
else if(round(m*1e3)/1e3!=0){
cout<< round(m*1e3)/1e3 <<"x ";}
if(round(m*1e3)/1e3!=0&&round(b*1e3)/1e3!=0){cout<<"+ "<<round(b*1e3)/1e3;}
if(round(m*1e3)/1e3==0&&round(b*1e3)/1e3!=0){cout<<round(b*1e3)/1e3;}
if(round(m*1e3)/1e3==0&&round(b*1e3)/1e3==0){cout<<"0";}
}
} | # 0414, 2024-11-02 15:03:30, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
float m,b;
string s,ansmx;
cin>>n>>s;
float x[n],y[n];
float ex=0,ey=0,exy=0,ex2=0;
for(int i=0;i<n;i++){
cin>>x[i]>>y[i];
ex+=x[i];
ey+=y[i];
ex2+=(x[i]*x[i]);
exy+=(x[i]*y[i]);
}
m=((n*exy)-(ex*ey)) / ((n*ex2)-(ex*ex));
b=(ey-(m*ex))/n;
if(s=="mb"){
cout<< round(m*1e3)/1e3<<endl<< round(b*1e3)/1e3;}
if(s=="func"){
cout<<"y = ";
if(round(m*1e3)/1e3==-1){
cout<<"-x ";}
else if(round(m*1e3)/1e3==1){
cout<<"x ";}
else if(round(m*1e3)/1e3==-1){
cout<<"-x ";}
else if(round(m*1e3)/1e3!=0){
cout<< round(m*1e3)/1e3 <<"x ";}
if(round(m*1e3)/1e3!=0&&round(b*1e3)/1e3>0){cout<<"+ "<<round(b*1e3)/1e3;}
if(round(m*1e3)/1e3!=0&&round(b*1e3)/1e3<0){cout<<"- "<<-(round(b*1e3)/1e3);}
if(round(m*1e3)/1e3==0&&round(b*1e3)/1e3!=0){cout<<round(b*1e3)/1e3;}
if(round(m*1e3)/1e3==0&&round(b*1e3)/1e3==0){cout<<"0";}
}
} |
# 0415, 2024-11-02 10:44:32, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
string method;
cin >> method;
float x;float y;
vector<pair<float,float>> v1;
for(int i = 0;i<n;i++){
cin >> x; cin >>y;
v1.push_back(make_pair(x,y));
}
float sec1=0,sec2=0,sec3=0,sec4=0,sec5=0;
for(int i = 0;i<n;i++){
sec1+=v1[i].first * v1[i].second;
sec2+=v1[i].first;
sec3+=v1[i].second;
sec4+=pow(v1[i].first,2);
}
sec5 = pow(sec2,2);
float m = ((n*sec1)-sec2*sec3)/((n*sec4)-sec5);
float b = (sec3-(m*sec2))/n;
if(method=="mb") {cout << round(m*1e3)/1e3 << endl; cout << round(b*1e3)/1e3 << endl;}
else if(method=="func"){
if(m==0&&b==0) cout << "y = 0";
else if(m==0) cout << "y = " << round(b*1e3)/1e3;
else if(b==0) {
if(m==1) cout << "y = x";
else if(m == -1) cout << "y = -x";
else cout << "y = " << round(m*1e3)/1e3 <<"x";}
else {
if(m==1) {
cout << "y = x ";
if(b>0) cout << "+ " << round(b*1e3)/1e3;
else cout <<"- " << -1.0*round(b*1e3)/1e3;
}
else {cout << "y = " << round(m*1e3)/1e3 <<"x ";
if(b>0) cout << "+ " << round(b*1e3)/1e3;
else cout <<"- " << -1.0*round(b*1e3)/1e3;
}
}
}
} | # 0416, 2024-11-02 10:45:57, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
string method;
cin >> method;
float x;float y;
vector<pair<float,float>> v1;
for(int i = 0;i<n;i++){
cin >> x; cin >>y;
v1.push_back(make_pair(x,y));
}
float sec1=0,sec2=0,sec3=0,sec4=0,sec5=0;
for(int i = 0;i<n;i++){
sec1+=v1[i].first * v1[i].second;
sec2+=v1[i].first;
sec3+=v1[i].second;
sec4+=pow(v1[i].first,2);
}
sec5 = pow(sec2,2);
float m = ((n*sec1)-sec2*sec3)/((n*sec4)-sec5);
float b = (sec3-(m*sec2))/n;
if(method=="mb") {cout << round(m*1e3)/1e3 << endl; cout << round(b*1e3)/1e3 << endl;}
else if(method=="func"){
if(m==0&&b==0) cout << "y = 0";
else if(m==0) cout << "y = " << round(b*1e3)/1e3;
else if(b==0) {
if(m==1) cout << "y = x";
else if(m == -1) cout << "y = -x";
else cout << "y = " << round(m*1e3)/1e3 <<"x";}
else {
if(m==1) {
cout << "y = x ";
if(b>0) cout << "+ " << round(b*1e3)/1e3;
else cout <<"- " << -1.0*round(b*1e3)/1e3;
}
else if(m==-1){
cout << "y = -x ";
if(b>0) cout << "+ " << round(b*1e3)/1e3;
else cout <<"- " << -1.0*round(b*1e3)/1e3;
}
else {cout << "y = " << round(m*1e3)/1e3 <<"x ";
if(b>0) cout << "+ " << round(b*1e3)/1e3;
else cout <<"- " << -1.0*round(b*1e3)/1e3;
}
}
}
} | # 0417, 2024-11-02 10:50:21, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
string method;
cin >> method;
float x;float y;
vector<pair<float,float>> v1;
for(int i = 0;i<n;i++){
cin >> x; cin >>y;
v1.push_back(make_pair(x,y));
}
float sec1=0,sec2=0,sec3=0,sec4=0,sec5=0;
for(int i = 0;i<n;i++){
sec1+=v1[i].first * v1[i].second;
sec2+=v1[i].first;
sec3+=v1[i].second;
sec4+=pow(v1[i].first,2);
}
sec5 = pow(sec2,2);
float m = ((n*sec1)-sec2*sec3)/((n*sec4)-sec5);
float b = (sec3-(m*sec2))/n;
if(method=="mb") {cout << round(m*1e3)/1e3 << endl; cout << round(b*1e3)/1e3 << endl;}
else if(method=="func"){
if(round(m*1e3)/1e3==0&&b==0) cout << "y = 0";
else if(round(m*1e3)/1e3==0) cout << "y = " << round(b*1e3)/1e3;
else if(b==0) {
if(m==1) cout << "y = x";
else if(m == -1) cout << "y = -x";
else cout << "y = " << round(m*1e3)/1e3 <<"x";}
else {
if(m==1) {
cout << "y = x ";
if(b>0) cout << "+ " << round(b*1e3)/1e3;
else cout <<"- " << -1.0*round(b*1e3)/1e3;
}
else if(m==-1){
cout << "y = -x ";
if(b>0) cout << "+ " << round(b*1e3)/1e3;
else cout <<"- " << -1.0*round(b*1e3)/1e3;
}
else {cout << "y = " << round(m*1e3)/1e3 <<"x ";
if(b>0) cout << "+ " << round(b*1e3)/1e3;
else cout <<"- " << -1.0*round(b*1e3)/1e3;
}
}
}
} | # 0418, 2024-11-02 10:51:45, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
string method;
cin >> method;
float x;float y;
vector<pair<float,float>> v1;
for(int i = 0;i<n;i++){
cin >> x; cin >>y;
v1.push_back(make_pair(x,y));
}
float sec1=0,sec2=0,sec3=0,sec4=0,sec5=0;
for(int i = 0;i<n;i++){
sec1+=v1[i].first * v1[i].second;
sec2+=v1[i].first;
sec3+=v1[i].second;
sec4+=pow(v1[i].first,2);
}
sec5 = pow(sec2,2);
float m = ((n*sec1)-sec2*sec3)/((n*sec4)-sec5);
float b = (sec3-(m*sec2))/n;
if(method=="mb") {cout << round(m*1e3)/1e3 << endl; cout << round(b*1e3)/1e3 << endl;}
else if(method=="func"){
if(round(m*1e3)/1e3==0&&round(b*1e3)/1e3==0) cout << "y = 0";
else if(round(m*1e3)/1e3==0) cout << "y = " << round(b*1e3)/1e3;
else if(round(b*1e3)/1e3==0) {
if(round(m*1e3)/1e3==1) cout << "y = x";
else if(round(m*1e3)/1e3 == -1) cout << "y = -x";
else cout << "y = " << round(m*1e3)/1e3 <<"x";}
else {
if(round(m*1e3)/1e3==1) {
cout << "y = x ";
if(b>0) cout << "+ " << round(b*1e3)/1e3;
else cout <<"- " << -1.0*round(b*1e3)/1e3;
}
else if(round(m*1e3)/1e3==-1){
cout << "y = -x ";
if(b>0) cout << "+ " << round(b*1e3)/1e3;
else cout <<"- " << -1.0*round(b*1e3)/1e3;
}
else {cout << "y = " << round(m*1e3)/1e3 <<"x ";
if(b>0) cout << "+ " << round(b*1e3)/1e3;
else cout <<"- " << -1.0*round(b*1e3)/1e3;
}
}
}
} |
# 0419, 2024-11-02 10:38:44, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
string opr;
cin >> opr;
float a[n+1], b[n+1];
for(int i=1; i<=n; i++){
cin >> a[i] >> b[i];
}
float first;
float sum1=0;
for(int i=1; i<=n; i++){
sum1 += (a[i]*b[i]);
}
first = n*sum1;
float second;
float sum2=0,sum3=0;
for(int i=1; i<=n; i++) sum2 += a[i];
for(int i=1; i<=n; i++) sum3 += b[i];
second = sum2*sum3;
float third;
float sum4=0;
for(int i=1; i<=n; i++) sum4 += (a[i]*a[i]);
third = n*sum4;
float fourth;
float sum5=0;
for(int i=1; i<=n; i++) sum5 += a[i];
fourth = sum5*sum5;
float m = (first-second) / (third - fourth);
float first2;
float sum21=0;
for(int i=1; i<=n; i++) sum21 += b[i];
first2 = sum21;
float second2;
float sum22=0;
for(int i=1; i<=n; i++) sum22 += a[i];
second2 = m*sum22;
float lst = (first2 - second2) / n;
//cout << "m: " << round(m*1e3)/1e3 << endl;
//cout << "b: " << round(lst*1e3)/1e3 << endl;
if(m==0 || m==-0) m = 0;
if(lst ==0 || lst == -0) lst = 0;
//cout << "m: " << round(m*1e3)/1e3 << endl;
//cout << "b: " << round(lst*1e3)/1e3 << endl;
if(opr == "mb") cout << round(m*1e3)/1e3 << endl << round(lst*1e3)/1e3;
else if(opr == "func"){
cout << "y = ";
if(m==0 && lst == 0) cout << 0;
else if((m==0 || m==-0) && lst!=0) cout << round(lst*1e3)/1e3;
else if(m==1 && lst == 0) cout << "x";
else if(m==1 && lst > 0) cout << "x + " << round(lst*1e3)/1e3;
else if(m==1 && lst < 0) cout << "x - " << -1.0*round(lst*1e3)/1e3;
else if(m==-1 && lst == 0) cout << "-x";
else if(m==-1 && lst > 0) cout << "-x + " << round(lst*1e3)/1e3;
else if(m==-1 && lst < 0) cout << "-x - " << -1.0*round(lst*1e3)/1e3;
else if(m != 0 && lst == 0) cout << round(m*1e3)/1e3 << "x";
else if((m>0||m<0) && lst > 0) cout << round(m*1e3)/1e3 << "x + " << round(lst*1e3)/1e3;
else if((m>0||m<0) && lst < 0) cout << round(m*1e3)/1e3 << "x - " << -1.0*round(lst*1e3)/1e3;
}
return 0;
} | # 0420, 2024-11-02 10:48:18, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
string opr;
cin >> opr;
float a[n+1], b[n+1];
for(int i=1; i<=n; i++){
cin >> a[i] >> b[i];
}
float first;
float sum1=0;
for(int i=1; i<=n; i++){
sum1 += (a[i]*b[i]);
}
first = n*sum1;
float second;
float sum2=0,sum3=0;
for(int i=1; i<=n; i++) sum2 += a[i];
for(int i=1; i<=n; i++) sum3 += b[i];
second = sum2*sum3;
float third;
float sum4=0;
for(int i=1; i<=n; i++) sum4 += (a[i]*a[i]);
third = n*sum4;
float fourth;
float sum5=0;
for(int i=1; i<=n; i++) sum5 += a[i];
fourth = sum5*sum5;
float m = (first-second) / (third - fourth);
float first2;
float sum21=0;
for(int i=1; i<=n; i++) sum21 += b[i];
first2 = sum21;
float second2;
float sum22=0;
for(int i=1; i<=n; i++) sum22 += a[i];
second2 = m*sum22;
float lst = (first2 - second2) / n;
//cout << "m: " << m << endl;
//cout << "b: " << round(lst*1e3)/1e3 << endl;
if(round(m*1e3)/1e3==-0) m = 0;
if(round(lst*1e3)/1e3 == -0) lst = 0;
//cout << "m: " << round(m*1e3)/1e3 << endl;
//cout << "b: " << round(lst*1e3)/1e3 << endl;
if(opr == "mb") cout << round(m*1e3)/1e3 << endl << round(lst*1e3)/1e3;
else if(opr == "func"){
cout << "y = ";
if(m==0 && lst == 0) cout << 0;
else if((m==0 || m==-0) && lst!=0) cout << round(lst*1e3)/1e3;
else if(m==1 && lst == 0) cout << "x";
else if(m==1 && lst > 0) cout << "x + " << round(lst*1e3)/1e3;
else if(m==1 && lst < 0) cout << "x - " << -1.0*round(lst*1e3)/1e3;
else if(m==-1 && lst == 0) cout << "-x";
else if(m==-1 && lst > 0) cout << "-x + " << round(lst*1e3)/1e3;
else if(m==-1 && lst < 0) cout << "-x - " << -1.0*round(lst*1e3)/1e3;
else if(m != 0 && lst == 0) cout << round(m*1e3)/1e3 << "x";
else if((m>0||m<0) && lst > 0) cout << round(m*1e3)/1e3 << "x + " << round(lst*1e3)/1e3;
else if((m>0||m<0) && lst < 0) cout << round(m*1e3)/1e3 << "x - " << -1.0*round(lst*1e3)/1e3;
}
return 0;
} | # 0421, 2024-11-02 11:59:11, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
string opr;
cin >> opr;
float a[n+1], b[n+1];
for(int i=1; i<=n; i++){
cin >> a[i] >> b[i];
}
float first;
float sum1=0;
for(int i=1; i<=n; i++){
sum1 += (a[i]*b[i]);
}
first = n*sum1;
float second;
float sum2=0,sum3=0;
for(int i=1; i<=n; i++) sum2 += a[i];
for(int i=1; i<=n; i++) sum3 += b[i];
second = sum2*sum3;
float third;
float sum4=0;
for(int i=1; i<=n; i++) sum4 += (a[i]*a[i]);
third = n*sum4;
float fourth;
float sum5=0;
for(int i=1; i<=n; i++) sum5 += a[i];
fourth = sum5*sum5;
float m = (first-second) / (third - fourth);
float first2;
float sum21=0;
for(int i=1; i<=n; i++) sum21 += b[i];
first2 = sum21;
float second2;
float sum22=0;
for(int i=1; i<=n; i++) sum22 += a[i];
second2 = m*sum22;
float lst = (first2 - second2) / (n*1.0);
if(round(m*1e3)/1e3==-0) m = 0;
if(round(lst*1e3)/1e3 == -0) lst = 0;
if(opr == "mb") cout << round(m*1e3)/1e3 << endl << round(lst*1e3)/1e3;
else if(opr == "func"){
cout << "y = ";
if(m==0 && lst == 0) cout << 0;
else if(m==0 && lst != 0) cout << round(lst*1e3)/1e3;
else if(m==1 && lst == 0) cout << "x";
else if(m==1 && lst > 0) cout << "x + " << round(lst*1e3)/1e3;
else if(m==1 && lst < 0) cout << "x - " << -1.0*round(lst*1e3)/1e3;
else if(m==-1 && lst == 0) cout << "-x";
else if(m==-1 && lst > 0) cout << "-x + " << round(lst*1e3)/1e3;
else if(m==-1 && lst < 0) cout << "-x - " << -1.0*round(lst*1e3)/1e3;
else if(m != 0 && lst == 0) cout << round(m*1e3)/1e3 << "x";
else if(m != 0 && lst > 0) cout << round(m*1e3)/1e3 << "x + " << round(lst*1e3)/1e3;
else if(m != 0 && lst < 0) cout << round(m*1e3)/1e3 << "x - " << -1.0*round(lst*1e3)/1e3;
}
return 0;
} | # 0422, 2024-11-02 12:08:31, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
string opr;
cin >> opr;
float a[n+1], b[n+1];
for(int i=1; i<=n; i++){
cin >> a[i] >> b[i];
}
float first;
float sum1=0;
for(int i=1; i<=n; i++){
sum1 += (a[i]*b[i]);
}
first = n*sum1;
float second;
float sum2=0,sum3=0;
for(int i=1; i<=n; i++) sum2 += a[i];
for(int i=1; i<=n; i++) sum3 += b[i];
second = sum2*sum3;
float third;
float sum4=0;
for(int i=1; i<=n; i++) sum4 += (a[i]*a[i]);
third = n*sum4;
float fourth;
float sum5=0;
for(int i=1; i<=n; i++) sum5 += a[i];
fourth = sum5*sum5;
float m = (first-second) / (third - fourth);
float first2;
float sum21=0;
for(int i=1; i<=n; i++) sum21 += b[i];
first2 = sum21;
float second2;
float sum22=0;
for(int i=1; i<=n; i++) sum22 += a[i];
second2 = m*sum22;
float lst = (first2 - second2) / n;
if(round(m*1e3)/1e3==-0) m = 0;
if(round(lst*1e3)/1e3 == -0) lst = 0;
if(opr == "mb") cout << round(m*1e3)/1e3 << endl << round(lst*1e3)/1e3;
else if(opr == "func"){
cout << "y = ";
if(m==0 && lst == 0) cout << 0;
else if(m==0 && lst != 0) cout << round(lst*1e3)/1e3;
else if(round(m*1e3)/1e3==1 && lst == 0) cout << "x";
else if(round(m*1e3)/1e3==1 && round(lst*1e3)/1e3 > 0) cout << "x + " << round(lst*1e3)/1e3;
else if(round(m*1e3)/1e3==1 && round(lst*1e3)/1e3 < 0) cout << "x - " << -1.0*round(lst*1e3)/1e3;
else if(round(m*1e3)/1e3==-1 && round(lst*1e3)/1e3 == 0) cout << "-x";
else if(round(m*1e3)/1e3==-1 && round(lst*1e3)/1e3 > 0) cout << "-x + " << round(lst*1e3)/1e3;
else if(round(m*1e3)/1e3==-1 && round(lst*1e3)/1e3 < 0) cout << "-x - " << -1.0*round(lst*1e3)/1e3;
else if(round(m*1e3)/1e3 != 0 && round(lst*1e3)/1e3 == 0) cout << round(m*1e3)/1e3 << "x";
else if(round(m*1e3)/1e3 != 0 && round(lst*1e3)/1e3 > 0) cout << round(m*1e3)/1e3 << "x + " << round(lst*1e3)/1e3;
else if(round(m*1e3)/1e3 != 0 && round(lst*1e3)/1e3 < 0) cout << round(m*1e3)/1e3 << "x - " << -1.0*round(lst*1e3)/1e3;
}
return 0;
} |
# 0423, 2024-11-02 10:49:21, PPPPPPPPPPPPPPPP--PP---- (75%)
#include <bits/stdc++.h>
using namespace std;
int main(){
string type;
int n;
cin>>n>>type;
vector<pair<float,float>> have;
for(int i=0;i<n;i++){
float x,y;
cin>>x>>y;
have.push_back({x,y});
}
float t1=0,t21=0,t22=0,b1=0,b2=0;
for(auto a:have){
t1 += a.first*a.second;
t21 += a.first;
t22 += a.second;
b1 +=a.first*a.first;;
b2 +=a.first;
}
float m=((n*t1)-(t21*t22))/((n*b1)-(b2*b2));
float b=(t22 - (m*(t21)))/n;
if(type=="mb"){
cout<< round(m*1e3)/1e3<<endl;
cout<< round(b*1e3)/1e3<<endl;
}
else{
if((m!=0)) {
cout<<"y = ";
if(m==1) cout<<"x ";
else if(m==-1) cout<<"-x ";
else cout<<round(m*1e3)/1e3<<"x ";
if(b>0) cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0) cout<<"- "<<abs(round(b*1e3)/1e3);
}
if((m==0)&&(b==0)) cout<<"y = "<<round(b*1e3)/1e3;
}
} | # 0424, 2024-11-02 11:23:27, PPPPPPPPPP-----PP----P-- (54%)
#include <bits/stdc++.h>
using namespace std;
int main(){
string type;
int n;
cin>>n>>type;
vector<pair<float,float>> have;
for(int i=0;i<n;i++){
float x,y;
cin>>x>>y;
have.push_back({x,y});
}
float t1=0,t21=0,t22=0,b1=0,b2=0;
for(auto a:have){
t1 += a.first*a.second;
t21 += a.first;
t22 += a.second;
b1 +=a.first*a.first;;
b2 +=a.first;
}
float m=((n*t1)-(t21*t22))/((n*b1)-(b2*b2));
float b=(t22 - (m*(t21)))/n;
//if(abs(m)==0) m=0;
if(type=="mb"){
cout<< round(m*1e3)/1e3<<endl;
cout<< round(b*1e3)/1e3<<endl;
}
else{
if((m<1)&&(m>-1)) cout<<"y = "<<round(b*1e3)/1e3;
else {
cout<<"y = ";
if(b>0){
if(m==1) cout<<"x ";
else if(m==-1) cout<<"-x ";
else if((m>1)&&(m<-1)) cout<<round(m*1e3)/1e3<<"x ";
cout<<"+ "<<round(b*1e3)/1e3;
}
else if(b<0){
if(m==1) cout<<"x ";
else if(m==-1) cout<<"-x ";
else if((m>1)&&(m<-1)) cout<<round(m*1e3)/1e3<<"x ";
cout<<"- "<<abs(round(b*1e3)/1e3);
}
}
//if(((m!=0)||(m!=-0))&&(b==0)) cout<<"y = "<<round(b*1e3)/1e3;
}
} | # 0425, 2024-11-02 11:28:34, PPPPPPPPPP-----PP----P-- (54%)
#include <bits/stdc++.h>
using namespace std;
int main(){
string type;
int n;
cin>>n>>type;
vector<pair<float,float>> have;
for(int i=0;i<n;i++){
float x,y;
cin>>x>>y;
have.push_back({x,y});
}
float t1=0,t21=0,t22=0,b1=0,b2=0;
for(auto a:have){
t1 += a.first*a.second;
t21 += a.first;
t22 += a.second;
b1 +=a.first*a.first;;
b2 +=a.first;
}
float m=((n*t1)-(t21*t22))/((n*b1)-(b2*b2));
float b=(t22 - (m*(t21)))/n;
//if(abs(m)==0) m=0;
if(type=="mb"){
cout<< round(m*1e3)/1e3<<endl;
cout<< round(b*1e3)/1e3<<endl;
}
else{
if((m<0.001)&&(m>-0.999)) cout<<"y = "<<round(b*1e3)/1e3;
else {
cout<<"y = ";
if(m==1) cout<<"x ";
else if(m==-1) cout<<"-x ";
else if((m>1)&&(m<-1)) cout<<round(m*1e3)/1e3<<"x ";
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0) cout<<"- "<<abs(round(b*1e3)/1e3);
else if(b==0) cout<<"0";
// if(b>0){
// if(m==1) cout<<"x ";
// else if(m==-1) cout<<"-x ";
// else if((m>1)&&(m<-1)) cout<<round(m*1e3)/1e3<<"x ";
// cout<<"+ "<<round(b*1e3)/1e3;
// }
// else if(b<0){
// if(m==1) cout<<"x ";
// else if(m==-1) cout<<"-x ";
// else if((m>1)&&(m<-1)) cout<<round(m*1e3)/1e3<<"x ";
// cout<<"- "<<abs(round(b*1e3)/1e3);
// }
}
//if(((m!=0)||(m!=-0))&&(b==0)) cout<<"y = "<<round(b*1e3)/1e3;
}
} | # 0426, 2024-11-02 11:30:11, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
int main(){
string type;
int n;
cin>>n>>type;
vector<pair<float,float>> have;
for(int i=0;i<n;i++){
float x,y;
cin>>x>>y;
have.push_back({x,y});
}
float t1=0,t21=0,t22=0,b1=0,b2=0;
for(auto a:have){
t1 += a.first*a.second;
t21 += a.first;
t22 += a.second;
b1 +=a.first*a.first;;
b2 +=a.first;
}
float m=((n*t1)-(t21*t22))/((n*b1)-(b2*b2));
float b=(t22 - (m*(t21)))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(type=="mb"){
cout<< m<<endl;
cout<< b <<endl;
}
else{
if((m!=0)) {
cout<<"y = ";
if(m==1) cout<<"x ";
else if(m==-1) cout<<"-x ";
else cout<<round(m*1e3)/1e3<<"x ";
if(b>0) cout<<"+ "<<round(b*1e3)/1e3;
else if(b<0) cout<<"- "<<abs(round(b*1e3)/1e3);
}
if((m==0)) cout<<"y = "<<round(b*1e3)/1e3;
}
} |
# 0427, 2024-11-02 14:10:33, ------------------------ (0%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, ln;
string opr;
cin>> n>> opr;
ln=n;
vector<pair<float, float>> point;
float m, b;
while(ln--){
float x, y;
cin>> x>> y;
point.push_back(make_pair(x, y));
}
// m= (nxy-sx*sy)/(nxx-nxp)
// b= (sy-mx)/n
float sxy=0, sx=0, sy=0, sxx=0, sxp;
for(auto e:point){
sxy+=e.first*e.second;
sx+=e.first;
sy+=e.second;
sxx+=e.first*e.first;
cout<< sxy<< " "<< sx<< " "<< sy<< " "<< sxx<< endl;
}
sxp=sx*sx;
m=((n*sxy)-(sx*sy))/(n*sxx-sxp);
b=(sy-(m*sx))/n;
//OUTPUT
if(opr=="mb") cout<< m<< endl<< b;
else{
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
cout<< "y = ";
if(m==0 && b==0){ cout<< "0"; return 0;}
//cout M
if(m==1) cout<< "x";
else if(m==-1) cout<< "-x";
else if(m!=0){
cout<< m<<"x";
}
//cout B
if(m!=0){
if(b>0) cout<< " + "<< b;
else if(b<0) cout<< " - "<< b*-1;
}
else{
cout<< b;
}
}
return 0;
} | # 0428, 2024-11-02 14:11:37, -----PPPPPPPPPPPPPPPPPPP (79%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, ln;
string opr;
cin>> n>> opr;
ln=n;
vector<pair<float, float>> point;
float m, b;
while(ln--){
float x, y;
cin>> x>> y;
point.push_back(make_pair(x, y));
}
// m= (nxy-sx*sy)/(nxx-nxp)
// b= (sy-mx)/n
float sxy=0, sx=0, sy=0, sxx=0, sxp;
for(auto e:point){
sxy+=e.first*e.second;
sx+=e.first;
sy+=e.second;
sxx+=e.first*e.first;
}
sxp=sx*sx;
m=((n*sxy)-(sx*sy))/(n*sxx-sxp);
b=(sy-(m*sx))/n;
//OUTPUT
if(opr=="mb") cout<< m<< endl<< b;
else{
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
cout<< "y = ";
if(m==0 && b==0){ cout<< "0"; return 0;}
//cout M
if(m==1) cout<< "x";
else if(m==-1) cout<< "-x";
else if(m!=0){
cout<< m<<"x";
}
//cout B
if(m!=0){
if(b>0) cout<< " + "<< b;
else if(b<0) cout<< " - "<< b*-1;
}
else{
cout<< b;
}
}
return 0;
} | # 0429, 2024-11-02 14:12:48, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, ln;
string opr;
cin>> n>> opr;
ln=n;
vector<pair<float, float>> point;
float m, b;
while(ln--){
float x, y;
cin>> x>> y;
point.push_back(make_pair(x, y));
}
// m= (nxy-sx*sy)/(nxx-nxp)
// b= (sy-mx)/n
float sxy=0, sx=0, sy=0, sxx=0, sxp;
for(auto e:point){
sxy+=e.first*e.second;
sx+=e.first;
sy+=e.second;
sxx+=e.first*e.first;
}
sxp=sx*sx;
m=((n*sxy)-(sx*sy))/(n*sxx-sxp);
b=(sy-(m*sx))/n;
//OUTPUT
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(opr=="mb") cout<< m<< endl<< b;
else{
cout<< "y = ";
if(m==0 && b==0){ cout<< "0"; return 0;}
//cout M
if(m==1) cout<< "x";
else if(m==-1) cout<< "-x";
else if(m!=0){
cout<< m<<"x";
}
//cout B
if(m!=0){
if(b>0) cout<< " + "<< b;
else if(b<0) cout<< " - "<< b*-1;
}
else{
cout<< b;
}
}
return 0;
} |
# 0430, 2024-11-02 09:49:24, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include <bits/stdc++.h>
using namespace std;
#define eps 1e-8
int main()
{
float point_cnt;
string mode;
cin >> point_cnt >> mode;
pair<float, float> point;
float sigma_xi = 0, sigma_yi = 0;
float sigma_mul = 0, sigma_xi_squared = 0;
for (int i = 0; i < point_cnt; i++)
{
cin >> point.first >> point.second;
sigma_xi += point.first;
sigma_yi += point.second;
sigma_mul += (point.first * point.second);
sigma_xi_squared += point.first * point.first;
}
// slope (m)
float m = ((point_cnt * sigma_mul) - (sigma_xi * sigma_yi))
/ ((point_cnt * sigma_xi_squared) - (sigma_xi * sigma_xi));
// intercept (b)
float b = (sigma_yi - (m * sigma_xi)) / point_cnt;
if (mode == "mb") {
cout << round(m * 1e3) / 1e3 << '\n';
cout << round(b * 1e3) / 1e3 << '\n';
return 0;
}
// equation printing
cout << "y = ";
bool skip_x = true;
if (m != 0) { // m != 0
skip_x = false;
if (m == -1) cout << "-x";
else if (m == 1) cout << 'x';
else cout << round(m * 1e3) / 1e3 << 'x';
}
if (skip_x) cout << round(b * 1e3) / 1e3;
else if (b != 0) {
cout << (b > 0 ? " + " : " - ") << (round(abs(b) * 1e3) / 1e3);
}
return 0;
} | # 0431, 2024-11-02 09:53:22, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include <bits/stdc++.h>
using namespace std;
#define eps 1e-8
int main()
{
float point_cnt;
string mode;
cin >> point_cnt >> mode;
pair<float, float> point;
float sigma_xi = 0, sigma_yi = 0;
float sigma_mul = 0, sigma_xi_squared = 0;
for (long long i = 0; i < point_cnt; i++)
{
cin >> point.first >> point.second;
sigma_xi += point.first;
sigma_yi += point.second;
sigma_mul += (point.first * point.second);
sigma_xi_squared += point.first * point.first;
}
// slope (m)
float m = ((point_cnt * sigma_mul) - (sigma_xi * sigma_yi))
/ ((point_cnt * sigma_xi_squared) - (sigma_xi * sigma_xi));
// intercept (b)
float b = (sigma_yi - (m * sigma_xi)) / point_cnt;
if (mode == "mb") {
cout << round(m * 1e3) / 1e3 << '\n';
cout << round(b * 1e3) / 1e3 << '\n';
return 0;
}
// equation printing
cout << "y = ";
bool skip_x = true;
if (m != 0) { // m != 0
skip_x = false;
if (m == -1) cout << "-x";
else if (m == 1) cout << 'x';
else cout << round(m * 1e3) / 1e3 << 'x';
}
if (skip_x) cout << round(b * 1e3) / 1e3;
else if (b != 0) {
cout << (b > 0 ? " + " : " - ") << (round(abs(b) * 1e3) / 1e3);
}
return 0;
} | # 0432, 2024-11-02 11:09:58, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
#define eps 1e-4
int main()
{
float point_cnt;
string mode;
cin >> point_cnt >> mode;
pair<float, float> point;
float sigma_xi = 0, sigma_yi = 0;
float sigma_mul = 0, sigma_xi_squared = 0;
for (long long i = 0; i < point_cnt; i++)
{
cin >> point.first >> point.second;
sigma_xi += point.first;
sigma_yi += point.second;
sigma_mul += (point.first * point.second);
sigma_xi_squared += point.first * point.first;
}
// slope (m)
float m = ((point_cnt * sigma_mul) - (sigma_xi * sigma_yi))
/ ((point_cnt * sigma_xi_squared) - (sigma_xi * sigma_xi));
// intercept (b)
float b = (sigma_yi - (m * sigma_xi)) / point_cnt;
if (mode == "mb") {
cout << round(m * 1e3) / 1e3 << '\n';
cout << round(b * 1e3) / 1e3 << '\n';
return 0;
}
// equation printing
cout << "y = ";
if (abs(m) < eps)
cout << (round(b * 1e3) / 1e3);
else {
if (!(abs(m - 1) < eps || abs(m + 1) < eps)) cout << (round(m * 1e3) / 1e3);
if (abs(m + 1) < eps) cout << '-';
cout << 'x';
if (abs(b) > eps)
cout << (b > 0 ? " + " : " - ") << (round(abs(b) * 1e3)/ 1e3);
}
return 0;
} |
# 0433, 2024-11-02 14:06:49, PPPPPPPPPPPPPPPPPPPPPP-P (95%)
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
using namespace std;
int main(){
long long n;
float x,y;
string com;
cin>>n>>com;
vector<float>keepx(n+10);
vector<float>keepy(n+10);
float sum_m_up_xy=0.0;
float sum_m_up_x=0.0;
float sum_m_up_y=0.0;
float sum_m_down_xpowin=0.0;
float sum_m_down_xpowout=0.0;
for(long long i=0; i<n;i++){
cin>>x>>y;
keepx[i]=x;
keepy[i]=y;
sum_m_up_xy+=x*y;
sum_m_up_x+=x;
sum_m_up_y+=y;
sum_m_down_xpowin+=(x*x);
}
sum_m_down_xpowout=sum_m_up_x*sum_m_up_x;
float m_up=(n*sum_m_up_xy)-(sum_m_up_x*sum_m_up_y);
float m_down=(n*sum_m_down_xpowin)-sum_m_down_xpowout;
float m= m_up/m_down;
float b_up=sum_m_up_y-(m*sum_m_up_x);
float b=b_up/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(com=="mb"){
cout<<m<<endl;
cout<<b<<endl;
}
if(com=="func"){
if(m==0 or b==0){
if(m==0 and b!=0){
cout<<"y = "<<b<<endl;
}
if(m!=0 and b==0){
if(m==1) cout<<"y = x"<<endl;
else if(m==-1) cout<<"y = -x"<<endl;
else{
cout<<"y = "<<m<<'x'<<endl;
}
}
if(m==0 and b==0) cout<<"y = 0"<<endl;
}
else if(m==1 or b==1){
if(m==1 and b!=1){
cout<<"y = x + "<<b<<endl;
}
if(m==1 and b==1) cout<<"y = x + 1"<<endl;
}
else{
if(m==-1){
if(b<0){
cout<<"y = -x - "<<abs(b)<<endl;
}
else{
cout<<"y = -x + "<<b<<endl;}
}
else{
if(b<0){
cout<<"y = "<<m<<'x'<<" - "<<abs(b)<<endl;
}
else{
cout<<"y = "<<m<<'x'<<" + "<<b<<endl;
}
}
}
}
//cout<<"m is "<<round(m*1e3)/1e3<<endl;
//cout<<"b is "<<round(b*1e3)/1e3<<endl;
} | # 0434, 2024-11-02 14:14:32, PPPPPPPPPPPPPPPPPPPPPP-P (95%)
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
using namespace std;
int main(){
long long n;
float x,y;
string com;
cin>>n>>com;
vector<float>keepx(n+10);
vector<float>keepy(n+10);
float sum_m_up_xy=0.0;
float sum_m_up_x=0.0;
float sum_m_up_y=0.0;
float sum_m_down_xpowin=0.0;
float sum_m_down_xpowout=0.0;
for(long long i=0; i<n;i++){
cin>>x>>y;
keepx[i]=x;
keepy[i]=y;
sum_m_up_xy+=x*y;
sum_m_up_x+=x;
sum_m_up_y+=y;
sum_m_down_xpowin+=(x*x);
}
sum_m_down_xpowout=sum_m_up_x*sum_m_up_x;
float m_up=(n*sum_m_up_xy)-(sum_m_up_x*sum_m_up_y);
float m_down=(n*sum_m_down_xpowin)-sum_m_down_xpowout;
float m= m_up/m_down;
float b_up=sum_m_up_y-(m*sum_m_up_x);
float b=b_up/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(com=="mb"){
cout<<m<<endl;
cout<<b<<endl;
}
if(com=="func"){
if(m==0 or b==0){
if(m==0 and b!=0){
cout<<"y = "<<b<<endl;
}
if(m!=0 and b==0){
if(m==1) cout<<"y = x"<<endl;
else if(m==-1) cout<<"y = -x"<<endl;
else{
if(m<0) cout<<"y = -"<<abs(m)<<'x'<<endl;
else{
cout<<"y = "<<m<<'x'<<endl;
}
}
}
if(m==0 and b==0) cout<<"y = 0"<<endl;
}
else if(m==1 or b==1){
if(m==1 and b!=1){
cout<<"y = x + "<<b<<endl;
}
if(m==1 and b==1) cout<<"y = x + 1"<<endl;
}
else{
if(m==-1){
if(b<0){
cout<<"y = -x - "<<abs(b)<<endl;
}
else{
cout<<"y = -x + "<<b<<endl;}
}
else{
if(b<0){
cout<<"y = "<<m<<'x'<<" - "<<abs(b)<<endl;
}
else{
cout<<"y = "<<m<<'x'<<" + "<<b<<endl;
}
}
}
}
//cout<<"m is "<<round(m*1e3)/1e3<<endl;
//cout<<"b is "<<round(b*1e3)/1e3<<endl;
} | # 0435, 2024-11-02 14:19:29, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
using namespace std;
int main(){
long long n;
float x,y;
string com;
cin>>n>>com;
vector<float>keepx(n+10);
vector<float>keepy(n+10);
float sum_m_up_xy=0.0;
float sum_m_up_x=0.0;
float sum_m_up_y=0.0;
float sum_m_down_xpowin=0.0;
float sum_m_down_xpowout=0.0;
for(long long i=0; i<n;i++){
cin>>x>>y;
keepx[i]=x;
keepy[i]=y;
sum_m_up_xy+=x*y;
sum_m_up_x+=x;
sum_m_up_y+=y;
sum_m_down_xpowin+=(x*x);
}
sum_m_down_xpowout=sum_m_up_x*sum_m_up_x;
float m_up=(n*sum_m_up_xy)-(sum_m_up_x*sum_m_up_y);
float m_down=(n*sum_m_down_xpowin)-sum_m_down_xpowout;
float m= m_up/m_down;
float b_up=sum_m_up_y-(m*sum_m_up_x);
float b=b_up/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(com=="mb"){
cout<<m<<endl;
cout<<b<<endl;
}
if(com=="func"){
if(m==0 or b==0){
if(m==0 and b!=0){
cout<<"y = "<<b<<endl;
}
if(m!=0 and b==0){
if(m==1) cout<<"y = x"<<endl;
else if(m==-1) cout<<"y = -x"<<endl;
else{
if(m<0) cout<<"y = -"<<abs(m)<<'x'<<endl;
else{
cout<<"y = "<<m<<'x'<<endl;
}
}
}
if(m==0 and b==0) cout<<"y = 0"<<endl;
}
else if(m==1 or b==1){
if(m==1 and b!=1){
if(b<0){
cout<<"y = x - "<<abs(b)<<endl;
}
else{
cout<<"y = x + "<<b<<endl;
}
}
if(m==1 and b==1) cout<<"y = x + 1"<<endl;
}
else{
if(m==-1){
if(b<0){
cout<<"y = -x - "<<abs(b)<<endl;
}
else{
cout<<"y = -x + "<<b<<endl;}
}
else{
if(b<0){
cout<<"y = "<<m<<'x'<<" - "<<abs(b)<<endl;
}
else{
cout<<"y = "<<m<<'x'<<" + "<<b<<endl;
}
}
}
}
//cout<<"m is "<<round(m*1e3)/1e3<<endl;
//cout<<"b is "<<round(b*1e3)/1e3<<endl;
} |
# 0436, 2024-11-02 09:34:58, PPPPPPPPPPP-P--P--PP-P-- (66%)
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
using namespace std;
int main(){
string op;
int n;
cin >> n >> op;
float sumX = 0 , sumY = 0 , sumXY = 0 , sumXsquare = 0;
for(int i = 0 ; i < n ; i++){
float a , b;
cin >> a >> b;
sumX = sumX + a;
sumY = sumY + b;
sumXY = sumXY + (a * b);
sumXsquare = sumXsquare + (a*a);
}
float m = ( (n * sumXY) - (sumX*sumY) ) / ( (n * sumXsquare) - (sumX * sumX) );
float b = ( sumY - (m * sumX) ) / n;
if(op == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if(op == "func"){
if(m == 1){
cout << "y = x";
if(b != 0)
cout << " + " << round(b*1e3)/1e3;
}
else if(m == -1){
cout << "y = -x";
if(b != 0)
cout << " + " << round(b*1e3)/1e3;
}
else if(m == 0){
cout << "y = ";
cout << round(b*1e3)/1e3;
}
else{
cout << "y = " << round(m*1e3)/1e3 << "x";
if(b != 0)
cout << " + " << round(b*1e3)/1e3;
}
}
return 0;
} | # 0437, 2024-11-02 09:38:20, PPPPPPPPPPP-P--PPPPPPP-- (79%)
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
using namespace std;
int main(){
string op;
int n;
cin >> n >> op;
float sumX = 0 , sumY = 0 , sumXY = 0 , sumXsquare = 0;
for(int i = 0 ; i < n ; i++){
float a , b;
cin >> a >> b;
sumX = sumX + a;
sumY = sumY + b;
sumXY = sumXY + (a * b);
sumXsquare = sumXsquare + (a*a);
}
float m = ( (n * sumXY) - (sumX*sumY) ) / ( (n * sumXsquare) - (sumX * sumX) );
float b = ( sumY - (m * sumX) ) / n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(op == "mb"){
cout << m << endl;
cout << b << endl;
}
else if(op == "func"){
if(m == 1){
cout << "y = x";
if(b != 0)
cout << " + " << b;
}
else if(m == -1){
cout << "y = -x";
if(b != 0)
cout << " + " << b;
}
else if(m == 0){
cout << "y = ";
cout << b;
}
else{
cout << "y = " << m << "x";
if(b != 0)
cout << " + " << b;
}
}
return 0;
} | # 0438, 2024-11-02 09:41:52, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
using namespace std;
int main(){
string op;
int n;
cin >> n >> op;
float sumX = 0 , sumY = 0 , sumXY = 0 , sumXsquare = 0;
for(int i = 0 ; i < n ; i++){
float a , b;
cin >> a >> b;
sumX = sumX + a;
sumY = sumY + b;
sumXY = sumXY + (a * b);
sumXsquare = sumXsquare + (a*a);
}
float m = ( (n * sumXY) - (sumX*sumY) ) / ( (n * sumXsquare) - (sumX * sumX) );
float b = ( sumY - (m * sumX) ) / n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(op == "mb"){
cout << m << endl;
cout << b << endl;
}
else if(op == "func"){
if(m == 1){
cout << "y = x";
if(b < 0)
cout << " - " << abs(b);
else if(b > 0)
cout << " + " << b;
}
else if(m == -1){
cout << "y = -x";
if(b < 0)
cout << " - " << abs(b);
else if(b > 0)
cout << " + " << b;
}
else if(m == 0){
cout << "y = ";
cout << b;
}
else{
cout << "y = " << m << "x";
if(b < 0)
cout << " - " << abs(b);
else if(b > 0)
cout << " + " << b;
}
}
return 0;
} |
# 0439, 2024-11-02 10:02:44, PPPPPPPPPPPPPPPP-P--P-PP (83%)
#include <bits/stdc++.h>
using namespace std ;
int main () {
vector<pair<float , float>> v ;
int k ;
float a ,d ;
string str ;
cin >> k >> str ;
float N = k ;
while (k--) {
cin >> a >> d ;
v.push_back(make_pair(a,d)) ;
}
float sum1 = 0 ;
float sum2 = 0 ;
float sum3 = 0 ;
float sum4 = 0 ;
float sum5 = 0 ;
for (int i = 0 ; i < N ; i++){
sum1 += (v[i].first * v[i].second) ;
sum2 += v[i].first ;
sum3 += v[i].second ;
sum4 += (v[i].first * v[i].first) ;
}
sum5 = sum2 * sum2 ;
float m = ((N * sum1) - (sum2 * sum3)) / ((N * sum4) - sum5) ;
float b = (sum3 - (m * sum2)) / N ;
m = round(m*1e3)/1e3 ;
b = round(b*1e3)/1e3 ;
if (str == "mb") {
cout << m << endl ;
cout << b << endl ;
}
if (str == "func") {
if (m==0 && b==0) {
cout << "y" << " = " << 0 ;
} else if (m==1 && b<0) {
cout << "y" << " = x - " << b*(-1) ;
} else if (m==1 && b>0){
cout << "y" << " = x + " << b;
} else if (m==-1 && b<0) {
cout << "y" << " = -x - " << b*(-1) ;
} else if (m==-1 && b>0){
cout << "y" << " = -x + " << b;
}
else if (b > 0) {
cout << "y" << " = " << m << "x + " << b;
} else if (b<0) {
cout << "y" << " = " << m << "x - " << b*(-1);
}
}
} | # 0440, 2024-11-02 12:01:23, PPPPPPPPPPPPPPPP-PPPP-PP (91%)
#include <bits/stdc++.h>
using namespace std ;
int main () {
vector<pair<float , float>> v ;
int k ;
float a ,d ;
string str ;
cin >> k >> str ;
float N = k ;
while (k--) {
cin >> a >> d ;
v.push_back(make_pair(a,d)) ;
}
float sum1 = 0 ;
float sum2 = 0 ;
float sum3 = 0 ;
float sum4 = 0 ;
float sum5 = 0 ;
for (int i = 0 ; i < N ; i++){
sum1 += (v[i].first * v[i].second) ;
sum2 += v[i].first ;
sum3 += v[i].second ;
sum4 += (v[i].first * v[i].first) ;
}
sum5 = sum2 * sum2 ;
float m = ((N * sum1) - (sum2 * sum3)) / ((N * sum4) - sum5) ;
float b = (sum3 - (m * sum2)) / N ;
m = round(m*1e3)/1e3 ;
b = round(b*1e3)/1e3 ;
if (str == "mb") {
cout << m << endl ;
cout << b << endl ;
}
if (str == "func") {
if (m==0 && b==0) {
cout << "y" << " = " << 0 ;
} else if (m==1 && b<0) {
cout << "y" << " = x - " << b*(-1) ;
} else if (m==1 && b>0){
cout << "y" << " = x + " << b;
} else if (m==-1 && b<0) {
cout << "y" << " = -x - " << b*(-1) ;
} else if (m==-1 && b>0){
cout << "y" << " = -x + " << b;
} else if (b==0) {
if (m==-1) {
cout << "y" << " = -x " ;
} else if (m==1) {
cout << "y" << " = x " ;
}
}
else if (b > 0) {
cout << "y" << " = " << m << "x + " << b;
} else if (b<0) {
cout << "y" << " = " << m << "x - " << b*(-1);
}
}
} | # 0441, 2024-11-02 12:05:34, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std ;
int main () {
vector<pair<float , float>> v ;
int k ;
float a ,d ;
string str ;
cin >> k >> str ;
float N = k ;
while (k--) {
cin >> a >> d ;
v.push_back(make_pair(a,d)) ;
}
float sum1 = 0 ;
float sum2 = 0 ;
float sum3 = 0 ;
float sum4 = 0 ;
float sum5 = 0 ;
for (int i = 0 ; i < N ; i++){
sum1 += (v[i].first * v[i].second) ;
sum2 += v[i].first ;
sum3 += v[i].second ;
sum4 += (v[i].first * v[i].first) ;
}
sum5 = sum2 * sum2 ;
float m = ((N * sum1) - (sum2 * sum3)) / ((N * sum4) - sum5) ;
float b = (sum3 - (m * sum2)) / N ;
m = round(m*1e3)/1e3 ;
b = round(b*1e3)/1e3 ;
if (str == "mb") {
cout << m << endl ;
cout << b << endl ;
}
if (str == "func") {
if (m==0 && b==0) {
cout << "y" << " = " << 0 ;
} else if (m==0) {
if (b>0) {
cout << "y" << " = " << b ;
} else if (b<0){
cout << "y" << " = -" << b*(-1) ;
}
}
else if (m==1 && b<0) {
cout << "y" << " = x - " << b*(-1) ;
} else if (m==1 && b>0){
cout << "y" << " = x + " << b;
} else if (m==-1 && b<0) {
cout << "y" << " = -x - " << b*(-1) ;
} else if (m==-1 && b>0){
cout << "y" << " = -x + " << b;
} else if (b==0) {
if (m==-1) {
cout << "y" << " = -x " ;
} else if (m==1) {
cout << "y" << " = x " ;
}
}
else if (b > 0) {
cout << "y" << " = " << m << "x + " << b;
} else if (b<0) {
cout << "y" << " = " << m << "x - " << b*(-1);
}
}
} |
# 0442, 2024-11-02 09:51:07, PPPPPPPPPPPPPPPPP-PP-PPP (91%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
vector<pair<double,double>> point;
double mr(int n){
double m=0;
double topleft=0;
double sumtopr1=0;
double sumtopr2=0;
double bottomleft=0;
for (int i = 0; i < n; i++)
{
topleft+= point[i].first*point[i].second;
sumtopr1 += point[i].first;
sumtopr2 += point[i].second;
bottomleft += point[i].first*point[i].first;
}
double bottomright = sumtopr1*sumtopr1;
m=((n*topleft)-(sumtopr1*sumtopr2))/((n*bottomleft)-bottomright);
return m;
}
double br(int n){
double b=0;
double topleft=0;
double topright=0;
for (int i = 0; i < n; i++)
{
topleft += point[i].second;
topright += point[i].first;
}
b= (topleft - (mr(n)*topright))/n;
return b;
}
int main () {
int n; string cmd;
cin >> n >> cmd;
for (int i = 0; i < n; i++)
{
double x, y;
cin >> x >> y;
point.push_back({x,y});
}
double m =round(mr(n) * 1e3)/1e3;
double b =round(br(n) * 1e3)/1e3;
if (cmd=="mb")
{
cout << m << endl;
cout << b << endl;
}
if (cmd == "func")
{
cout << "y = ";
if (m==0)
{
cout << b <<endl;
}else if(m==1){
cout << "x ";
if (b< 0)
{
cout << "- " << -b << endl;
}
}else if(m==-1){
cout << "-x ";
if (b< 0)
{
cout << "- " << -b << endl;
}else if(b>0) cout << "+ " << -b << endl;
}else{
if (b<0)
{
cout << m << "x - " << abs(b) << endl;
}else if (b>0){
cout << m << "x + " << abs(b) << endl;
}else if (b==0){
cout << m << "x" << endl;
}
}
}
} | # 0443, 2024-11-02 11:59:07, PPPPPPPPPPPPPPPPP-PPPPPP (95%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
vector<pair<double,double>> point;
double mr(int n){
double m=0;
double topleft=0;
double sumtopr1=0;
double sumtopr2=0;
double bottomleft=0;
for (int i = 0; i < n; i++)
{
topleft+= point[i].first*point[i].second;
sumtopr1 += point[i].first;
sumtopr2 += point[i].second;
bottomleft += point[i].first*point[i].first;
}
double bottomright = sumtopr1*sumtopr1;
m=((n*topleft)-(sumtopr1*sumtopr2))/((n*bottomleft)-bottomright);
return m;
}
double br(int n){
double b=0;
double topleft=0;
double topright=0;
for (int i = 0; i < n; i++)
{
topleft += point[i].second;
topright += point[i].first;
}
b= (topleft - (mr(n)*topright))/n;
return b;
}
int main () {
int n; string cmd;
cin >> n >> cmd;
for (int i = 0; i < n; i++)
{
double x, y;
cin >> x >> y;
point.push_back({x,y});
}
double m =round(mr(n) * 1e3)/1e3;
double b =round(br(n) * 1e3)/1e3;
if (cmd=="mb")
{
cout << m << endl;
cout << b << endl;
}
if (cmd == "func")
{
cout << "y = ";
if (m==0)
{
cout << b <<endl;
}else if(m==1){
cout << "x ";
if (b< 0)
{
cout << "- " << -b << endl;
}
}else if(m==-1){
cout << "-x ";
if (b< 0)
{
cout << "- " << -b << endl;
}else if(b>0) cout << "+ " << b << endl;
}else{
if (b<0)
{
cout << m << "x - " << abs(b) << endl;
}else if (b>0){
cout << m << "x + " << abs(b) << endl;
}else if (b==0){
cout << m << "x" << endl;
}
}
}
} | # 0444, 2024-11-02 12:00:16, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
vector<pair<double,double>> point;
double mr(int n){
double m=0;
double topleft=0;
double sumtopr1=0;
double sumtopr2=0;
double bottomleft=0;
for (int i = 0; i < n; i++)
{
topleft+= point[i].first*point[i].second;
sumtopr1 += point[i].first;
sumtopr2 += point[i].second;
bottomleft += point[i].first*point[i].first;
}
double bottomright = sumtopr1*sumtopr1;
m=((n*topleft)-(sumtopr1*sumtopr2))/((n*bottomleft)-bottomright);
return m;
}
double br(int n){
double b=0;
double topleft=0;
double topright=0;
for (int i = 0; i < n; i++)
{
topleft += point[i].second;
topright += point[i].first;
}
b= (topleft - (mr(n)*topright))/n;
return b;
}
int main () {
int n; string cmd;
cin >> n >> cmd;
for (int i = 0; i < n; i++)
{
double x, y;
cin >> x >> y;
point.push_back({x,y});
}
double m =round(mr(n) * 1e3)/1e3;
double b =round(br(n) * 1e3)/1e3;
if (cmd=="mb")
{
cout << m << endl;
cout << b << endl;
}
if (cmd == "func")
{
cout << "y = ";
if (m==0)
{
cout << b <<endl;
}else if(m==1){
cout << "x ";
if (b< 0)
{
cout << "- " << -b << endl;
}else if(b>0){
cout << "+ " << b << endl;
}
}else if(m==-1){
cout << "-x ";
if (b< 0)
{
cout << "- " << -b << endl;
}else if(b>0) cout << "+ " << b << endl;
}else{
if (b<0)
{
cout << m << "x - " << abs(b) << endl;
}else if (b>0){
cout << m << "x + " << abs(b) << endl;
}else if (b==0){
cout << m << "x" << endl;
}
}
}
} |
# 0445, 2024-11-02 10:18:38, -----PPP--PPPPPP---PP--P (50%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n;
string S;
cin >> n >> S;
float x[n], y[n];
float m,b;
for (int i = 0; i < n; i++)
{
cin >> x[i] >> y[i];
}
float bon1 = 0,bon2 = 0,bon3 = 0;
for (int i = 0; i < n; i++)
{
bon1 += x[i] * y[i];
}
for (int i = 0; i < n; i++)
{
bon2 += x[i];
}
for (int i = 0; i < n; i++)
{
bon3 += y[i];
}
m = (n*bon1) - (bon2*bon3);
float lang1 = 0 ,lang2 = 0;
for (int i = 0; i < n; i++)
{
lang1 += x[i] * x[i];
}
for (int i = 0; i < n; i++)
{
lang2 += x[i];
}
lang2 = lang2 * lang2;
m = m/((n*lang1) - lang2);
bon1 = 0;
bon2 = 0;
for (int i = 0; i < n; i++)
{
bon1 += y[i];
}
for (int i = 0; i < n; i++)
{
bon2 += x[i];
}
b = bon1 - (m*bon2);
b = b/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(S == "mb")
{
cout << m << '\n' << b;
}
if(S == "func")
{
cout << "y = ";
if(m == 0 && b == 0)
{
cout << 0;
return 0;
}
if(m == -1)
{
cout << "-x ";
}
else if(m == 0){}
else
{
cout << m << "x ";
}
}
if(b == 0){return 0;}
if(b < 0){cout << "- ";}
if(b > 0){cout << "+ ";}
cout << abs(b);
} | # 0446, 2024-11-02 10:21:18, ------PP--PPPPPPPPPPPPPP (66%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n;
string S;
cin >> n >> S;
float x[n], y[n];
float m,b;
for (int i = 0; i < n; i++)
{
cin >> x[i] >> y[i];
}
float bon1 = 0,bon2 = 0,bon3 = 0;
for (int i = 0; i < n; i++)
{
bon1 += x[i] * y[i];
}
for (int i = 0; i < n; i++)
{
bon2 += x[i];
}
for (int i = 0; i < n; i++)
{
bon3 += y[i];
}
m = (n*bon1) - (bon2*bon3);
float lang1 = 0 ,lang2 = 0;
for (int i = 0; i < n; i++)
{
lang1 += x[i] * x[i];
}
for (int i = 0; i < n; i++)
{
lang2 += x[i];
}
lang2 = lang2 * lang2;
m = m/((n*lang1) - lang2);
bon1 = 0;
bon2 = 0;
for (int i = 0; i < n; i++)
{
bon1 += y[i];
}
for (int i = 0; i < n; i++)
{
bon2 += x[i];
}
b = bon1 - (m*bon2);
b = b/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(S == "mb")
{
cout << m << '\n' << b;
}
if(S == "func")
{
cout << "y = ";
if(m == 0 && b == 0)
{
cout << 0;
return 0;
}
if(m == -1)
{
cout << "-x ";
}
else if(m == 0){}
else if(m == 1)
{
cout << "x ";
}
else
{
cout << m << "x ";
}
}
if(m == 0)
{
cout << b;
return 0;
}
if(b == 0){return 0;}
if(b < 0){cout << "- ";}
if(b > 0){cout << "+ ";}
cout << abs(b);
} | # 0447, 2024-11-02 10:24:00, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n;
string S;
cin >> n >> S;
float x[n], y[n];
float m,b;
for (int i = 0; i < n; i++)
{
cin >> x[i] >> y[i];
}
float bon1 = 0,bon2 = 0,bon3 = 0;
for (int i = 0; i < n; i++)
{
bon1 += x[i] * y[i];
}
for (int i = 0; i < n; i++)
{
bon2 += x[i];
}
for (int i = 0; i < n; i++)
{
bon3 += y[i];
}
m = (n*bon1) - (bon2*bon3);
float lang1 = 0 ,lang2 = 0;
for (int i = 0; i < n; i++)
{
lang1 += x[i] * x[i];
}
for (int i = 0; i < n; i++)
{
lang2 += x[i];
}
lang2 = lang2 * lang2;
m = m/((n*lang1) - lang2);
bon1 = 0;
bon2 = 0;
for (int i = 0; i < n; i++)
{
bon1 += y[i];
}
for (int i = 0; i < n; i++)
{
bon2 += x[i];
}
b = bon1 - (m*bon2);
b = b/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(S == "mb")
{
cout << m << '\n' << b;
}
if(S == "func")
{
cout << "y = ";
if(m == 0 && b == 0)
{
cout << 0;
return 0;
}
if(m == -1)
{
cout << "-x ";
}
else if(m == 0){}
else if(m == 1)
{
cout << "x ";
}
else
{
cout << m << "x ";
}
if(m == 0)
{
cout << b;
return 0;
}
if(b == 0){return 0;}
if(b < 0){cout << "- ";}
if(b > 0){cout << "+ ";}
cout << abs(b);
}
} |
# 0448, 2024-11-02 09:52:57, PPPPPPPPPP-------------- (41%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string com;
float tempx, tempy;
vector<float> x,y;
cin >> n >> com;
for(int i=1 ; i<=n ; i++){
cin >> tempx >> tempy;
x.push_back(tempx);
y.push_back(tempy);
}
float sum1=0.0,sum2=0.0,sum3=0.0,sum4=0.0;
for(int i=1;i<=n ;i++){
sum1 += x[i-1]*y[i-1];
}
for(int i=1;i<=n ;i++){
sum2 += x[i-1];
}
for(int i=1;i<=n ;i++){
sum3 += y[i-1];
}
for(int i=1;i<=n ;i++){
sum4 += x[i-1]*x[i-1];
}
float m = ((n*sum1)-(sum2*sum3))/((n*sum4)-(sum2*sum2));
float b = ((sum3)-(m*sum2))/n;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if(com == "mb"){
cout << m << endl << b << endl;
}
// else{
// float y =
// }
} | # 0449, 2024-11-02 09:56:24, PPPPPPPPPP-----PP----P-- (54%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string com;
float tempx, tempy;
vector<float> x,y;
cin >> n >> com;
for(int i=1 ; i<=n ; i++){
cin >> tempx >> tempy;
x.push_back(tempx);
y.push_back(tempy);
}
float sum1=0.0,sum2=0.0,sum3=0.0,sum4=0.0;
for(int i=1;i<=n ;i++){
sum1 += x[i-1]*y[i-1];
}
for(int i=1;i<=n ;i++){
sum2 += x[i-1];
}
for(int i=1;i<=n ;i++){
sum3 += y[i-1];
}
for(int i=1;i<=n ;i++){
sum4 += x[i-1]*x[i-1];
}
float m = ((n*sum1)-(sum2*sum3))/((n*sum4)-(sum2*sum2));
float b = ((sum3)-(m*sum2))/n;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if(com == "mb"){
cout << m << endl << b << endl;
}
else{
if(m==0) {
cout << "y = " << b;
}
else if(m==1){
cout <<"y = x +" << b;
}
else{
cout << "y = " << m << "x +" << b;
}
}
} | # 0450, 2024-11-02 10:03:16, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string com;
float tempx, tempy;
vector<float> x,y;
cin >> n >> com;
for(int i=1 ; i<=n ; i++){
cin >> tempx >> tempy;
x.push_back(tempx);
y.push_back(tempy);
}
float sum1=0.0,sum2=0.0,sum3=0.0,sum4=0.0;
for(int i=1;i<=n ;i++){
sum1 += x[i-1]*y[i-1];
}
for(int i=1;i<=n ;i++){
sum2 += x[i-1];
}
for(int i=1;i<=n ;i++){
sum3 += y[i-1];
}
for(int i=1;i<=n ;i++){
sum4 += x[i-1]*x[i-1];
}
float m = ((n*sum1)-(sum2*sum3))/((n*sum4)-(sum2*sum2));
float b = ((sum3)-(m*sum2))/n;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if(com == "mb"){
cout << m << endl << b << endl;
}
else{
if(b>0.0){
if(m==0.0) {
cout << "y = " << b;
}
else if(m==1.0){
cout <<"y = x + " << b;
}
else if(m==-1.0){
cout <<"y = -x + " << b;
}
else{
cout << "y = " << m << "x + " << b;
}
}
else if(b==0){
if(m==0.0) {
cout << "y = 0" ;
}
else if(m==1.0){
cout <<"y = x";
}
else if(m==-1.0){
cout <<"y = -x";
}
else{
cout << "y = " << m << "x";
}
}
else {
if(m==0.0) {
cout << "y = " << b;
}
else if(m==1.0){
cout <<"y = x - " << abs(b);
}
else if(m==-1.0){
cout <<"y = -x - " << abs(b);
}
else{
cout << "y = " << m << "x - " << abs(b);
}
}
}
} |
# 0451, 2024-11-02 09:48:08, PPPPPPPPPP-----P--PP-P-- (58%)
#include <bits/stdc++.h>
using namespace std;
float sumXY(const vector <pair<float,float>> &a) {
float sum = 0;
for (auto i : a) {
sum += (i.first * i.second);
}
return sum;
}
float sumX(const vector <pair<float,float>> &a) {
float sum = 0;
for (auto i : a) {
sum += i.first;
}
return sum;
}
float sumY(const vector <pair<float,float>> &a) {
float sum = 0;
for (auto i : a) {
sum += (i.second);
}
return sum;
}
float sumXX(const vector <pair<float,float>> &a) {
float sum = 0;
for (auto i : a) {
sum += pow(i.first, 2);
}
return sum;
}
float sumX2(const vector <pair<float,float>> &a) {
float sum = 0;
for (auto i : a) {
sum += i.first;
}
return pow(sum, 2);
}
int main() {
int N;
string input;
cin >> N >> input;
// Collect x, y
float x, y;
vector <pair<float,float>> vec;
for (int i = 0; i < N; ++i) {
cin >> x >> y;
vec.push_back({x, y});
}
// Calculate m, b
float m, b;
m = ((N * sumXY(vec)) - (sumX(vec) * sumY(vec))) / ((N * sumXX(vec)) - sumX2(vec));
b = (sumY(vec) - (m * sumX(vec))) / N;
if (input == "mb") {
cout << round(m*1e3) / 1e3 << endl << round(b*1e3) / 1e3;
}
else if (input == "func") {
// Create Funtion
string func = "y = ";
if (m == 0 && b == 0) {
cout << func << "0";
}
else if (m == 0 && b != 0) {
cout << func << b;
}
else if (m == 1) {
if (b == 0) {
cout << func << "x";
}
else if (b < 0) {
cout << func << "x - " << abs(b);
}
else if (b > 0) {
cout << func << "x + " << abs(b);
}
}
else if (m == -1) {
if (b == 0) {
cout << func << "-x";
}
else if (b < 0) {
cout << func << "x - " << abs(b);
}
else if (b > 0) {
cout << func << "x + " << abs(b);
}
}
else {
if (b == 0) {
cout << func << m << "x";
}
else if (b < 0) {
cout << func << m << "x - " << abs(b);
}
else if (b > 0) {
cout << func << m << "x + " << abs(b);
}
}
}
} | # 0452, 2024-11-02 09:51:49, PPPPPPPPPPPPPPPPPPPP-PP- (91%)
#include <bits/stdc++.h>
using namespace std;
float sumXY(const vector <pair<float,float>> &a) {
float sum = 0;
for (auto i : a) {
sum += (i.first * i.second);
}
return sum;
}
float sumX(const vector <pair<float,float>> &a) {
float sum = 0;
for (auto i : a) {
sum += i.first;
}
return sum;
}
float sumY(const vector <pair<float,float>> &a) {
float sum = 0;
for (auto i : a) {
sum += (i.second);
}
return sum;
}
float sumXX(const vector <pair<float,float>> &a) {
float sum = 0;
for (auto i : a) {
sum += pow(i.first, 2);
}
return sum;
}
float sumX2(const vector <pair<float,float>> &a) {
float sum = 0;
for (auto i : a) {
sum += i.first;
}
return pow(sum, 2);
}
int main() {
int N;
string input;
cin >> N >> input;
// Collect x, y
float x, y;
vector <pair<float,float>> vec;
for (int i = 0; i < N; ++i) {
cin >> x >> y;
vec.push_back({x, y});
}
// Calculate m, b
float m, b;
m = ((N * sumXY(vec)) - (sumX(vec) * sumY(vec))) / ((N * sumXX(vec)) - sumX2(vec));
b = (sumY(vec) - (m * sumX(vec))) / N;
m = round(m*1e3) / 1e3;
b = round(b*1e3) / 1e3;
if (input == "mb") {
cout << m << endl << b << endl;
}
else if (input == "func") {
// Create Funtion
string func = "y = ";
if (m == 0 && b == 0) {
cout << func << "0";
}
else if (m == 0 && b != 0) {
cout << func << b;
}
else if (m == 1) {
if (b == 0) {
cout << func << "x";
}
else if (b < 0) {
cout << func << "x - " << abs(b);
}
else if (b > 0) {
cout << func << "x + " << abs(b);
}
}
else if (m == -1) {
if (b == 0) {
cout << func << "-x";
}
else if (b < 0) {
cout << func << "x - " << abs(b);
}
else if (b > 0) {
cout << func << "x + " << abs(b);
}
}
else {
if (b == 0) {
cout << func << m << "x";
}
else if (b < 0) {
cout << func << m << "x - " << abs(b);
}
else if (b > 0) {
cout << func << m << "x + " << abs(b);
}
}
}
} | # 0453, 2024-11-02 09:53:15, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
float sumXY(const vector <pair<float,float>> &a) {
float sum = 0;
for (auto i : a) {
sum += (i.first * i.second);
}
return sum;
}
float sumX(const vector <pair<float,float>> &a) {
float sum = 0;
for (auto i : a) {
sum += i.first;
}
return sum;
}
float sumY(const vector <pair<float,float>> &a) {
float sum = 0;
for (auto i : a) {
sum += (i.second);
}
return sum;
}
float sumXX(const vector <pair<float,float>> &a) {
float sum = 0;
for (auto i : a) {
sum += pow(i.first, 2);
}
return sum;
}
float sumX2(const vector <pair<float,float>> &a) {
float sum = 0;
for (auto i : a) {
sum += i.first;
}
return pow(sum, 2);
}
int main() {
int N;
string input;
cin >> N >> input;
// Collect x, y
float x, y;
vector <pair<float,float>> vec;
for (int i = 0; i < N; ++i) {
cin >> x >> y;
vec.push_back({x, y});
}
// Calculate m, b
float m, b;
m = ((N * sumXY(vec)) - (sumX(vec) * sumY(vec))) / ((N * sumXX(vec)) - sumX2(vec));
b = (sumY(vec) - (m * sumX(vec))) / N;
m = round(m*1e3) / 1e3;
b = round(b*1e3) / 1e3;
if (input == "mb") {
cout << m << endl << b << endl;
}
else if (input == "func") {
// Create Funtion
string func = "y = ";
if (m == 0 && b == 0) {
cout << func << "0";
}
else if (m == 0 && b != 0) {
cout << func << b;
}
else if (m == 1) {
if (b == 0) {
cout << func << "x";
}
else if (b < 0) {
cout << func << "x - " << abs(b);
}
else if (b > 0) {
cout << func << "x + " << abs(b);
}
}
else if (m == -1) {
if (b == 0) {
cout << func << "-x";
}
else if (b < 0) {
cout << func << "-x - " << abs(b);
}
else if (b > 0) {
cout << func << "-x + " << abs(b);
}
}
else {
if (b == 0) {
cout << func << m << "x";
}
else if (b < 0) {
cout << func << m << "x - " << abs(b);
}
else if (b > 0) {
cout << func << m << "x + " << abs(b);
}
}
}
} |
# 0454, 2024-11-02 13:55:40, -----PPPPP-----PP----P-- (33%)
#include<iostream>
#include<cmath>
using namespace std;
int main() {
int n; string choose;
cin >> n >> choose;
float x[n+1], y[n+1];
for(int i = 1; i <= n; i++) {
cin >> x[i] >> y[i];
}
float m, b, mtop1 = 0, mtop21 = 0, mtop22 = 0, mbut1 = 0, mbut2 = 0, btop1 = 0, btop2 = 0, mbut, mtop, btop;
for(int i = 1; i <= n; i++) {
mtop1 += x[i]*y[i];
mtop21 += x[i];
mtop22 += y[i];
mbut1 += x[i]*x[i];
mbut2 += x[i];
btop1 += y[i];
btop2 += x[i];
}
mtop = (n*mtop1) - (mtop21*mtop22);
mbut = (n*mbut1) - (mbut2*mbut2);
m = mtop/mbut;
m = round(m * 1e3)/1e3;
btop = btop1 - (m * btop2);
b = btop/n;
b = round(b * 1e3)/1e3;
if(choose == "mb") {
cout << m << endl << b;
} else if(choose == "func") {
cout << "y = ";
if(m == 0 && b != 0) cout << b;
if(m != 0 && b == 0 && m != 1 && m != -1) cout << m << 'x';
if(m == 0 && b== 0) cout << '0';
if(m != 0 && b != 0) {
if(b > 0) {
if(m == -1 || m == 1) {
if(m == 1) cout << 'x + ' << b;
else cout << '-x + ' << b;
} else cout << m << 'x + ' << b;
} else {
if(m == -1 || m == 1) {
if(m == 1) cout << 'x - ' << b*(-1.0);
else cout << '-x - ' << b*(-1.0);
} else cout << m << 'x - ' << (-1.0)*b;
}
}
}
} | # 0455, 2024-11-02 13:59:42, PPPPPPPPPPPPPPPPPP--PPPP (91%)
#include<iostream>
#include<cmath>
using namespace std;
int main() {
int n; string choose;
cin >> n >> choose;
float x[n+1], y[n+1];
for(int i = 1; i <= n; i++) {
cin >> x[i] >> y[i];
}
float m, b, mtop1 = 0, mtop21 = 0, mtop22 = 0, mbut1 = 0, mbut2 = 0, btop1 = 0, btop2 = 0, mbut, mtop, btop;
for(int i = 1; i <= n; i++) {
mtop1 += x[i]*y[i];
mtop21 += x[i];
mtop22 += y[i];
mbut1 += x[i]*x[i];
mbut2 += x[i];
btop1 += y[i];
btop2 += x[i];
}
mtop = (n*mtop1) - (mtop21*mtop22);
mbut = (n*mbut1) - (mbut2*mbut2);
m = mtop/mbut;
btop = btop1 - (m * btop2);
b = btop/n;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if(choose == "mb") {
cout << m << endl << b;
} else if(choose == "func") {
cout << "y = ";
if(m == 0 && b != 0) cout << b;
if(m != 0 && b == 0 && m != 1 && m != -1) cout << m << 'x';
if(m == 0 && b== 0) cout << '0';
if(m != 0 && b != 0) {
if(b > 0) {
if(m == -1 || m == 1) {
if(m == 1) cout << "x + " << b;
else cout << "-x + " << b;
} else cout << m << "x + " << b;
} else {
if(m == -1 || m == 1) {
if(m == 1) cout << "x - " << b*(-1.0);
else cout << "-x - " << b*(-1.0);
} else cout << m << "x - " << (-1.0)*b;
}
}
}
} | # 0456, 2024-11-02 14:03:10, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<iostream>
#include<cmath>
using namespace std;
int main() {
int n; string choose;
cin >> n >> choose;
float x[n+1], y[n+1];
for(int i = 1; i <= n; i++) {
cin >> x[i] >> y[i];
}
float m, b, mtop1 = 0, mtop21 = 0, mtop22 = 0, mbut1 = 0, mbut2 = 0, btop1 = 0, btop2 = 0, mbut, mtop, btop;
for(int i = 1; i <= n; i++) {
mtop1 += x[i]*y[i];
mtop21 += x[i];
mtop22 += y[i];
mbut1 += x[i]*x[i];
mbut2 += x[i];
btop1 += y[i];
btop2 += x[i];
}
mtop = (n*mtop1) - (mtop21*mtop22);
mbut = (n*mbut1) - (mbut2*mbut2);
m = mtop/mbut;
btop = btop1 - (m * btop2);
b = btop/n;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if(choose == "mb") {
cout << m << endl << b;
} else if(choose == "func") {
cout << "y = ";
if(m == 0 && b != 0) cout << b;
if(m != 0 && b == 0 && m != 1 && m != -1) cout << m << 'x';
if(b == 0 && m == 1) cout << 'x';
if(b== 0 && m == -1) cout << "-x";
if(m == 0 && b== 0) cout << '0';
if(m != 0 && b != 0) {
if(b > 0) {
if(m == -1 || m == 1) {
if(m == 1) cout << "x + " << b;
else cout << "-x + " << b;
} else cout << m << "x + " << b;
} else {
if(m == -1 || m == 1) {
if(m == 1) cout << "x - " << b*(-1.0);
else cout << "-x - " << b*(-1.0);
} else cout << m << "x - " << (-1.0)*b;
}
}
}
} |
# 0457, 2024-11-02 09:30:10, PPPPPPPPPPPPPPP---PP--P- (75%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
string a;
float x,y,m,b,sx=0,sy=0,sx2=0,xy=0;
//vector<pair<float,float>> xy;
cin >> n >> a;
for(int i=0;i<n;i++){
cin >> x >> y;
sx+=x;
sy+=y;
sx2+=pow(x,2);
xy+=x*y;
}
m = ((n*xy)-(sx*sy))/((n*sx2)-pow(sx,2));
b = (sy-(m*sx))/n;
if(a=="mb"){
cout << round(m*1e3)/1e3 << "\n" <<round(b*1e3)/1e3 ;
}
if(a=="func"){
printf("y = ");
if(m!=1.0&&m!=-1.0) cout << round(m*1e3)/1e3 << "x ";
else if(m==1.0) cout << "x ";
else if (m==-1.0) cout <<"-x ";
if(b>0) cout << "+ " << round(b*1e3)/1e3;
else if (b<0) cout << "- " << abs(round(b*1e3)/1e3);
if(m==0&&b!=0) cout << round(b*1e3)/1e3;
else if(m==0&&b==0) cout << "0";
}
return 0;
} | # 0458, 2024-11-02 09:32:12, PPPPPPPPPPPPPPPP--PP--P- (79%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
string a;
float x,y,m,b,sx=0,sy=0,sx2=0,xy=0;
//vector<pair<float,float>> xy;
cin >> n >> a;
for(int i=0;i<n;i++){
cin >> x >> y;
sx+=x;
sy+=y;
sx2+=pow(x,2);
xy+=x*y;
}
m = ((n*xy)-(sx*sy))/((n*sx2)-pow(sx,2));
b = (sy-(m*sx))/n;
if(a=="mb"){
cout << round(m*1e3)/1e3 << "\n" <<round(b*1e3)/1e3 ;
}
if(a=="func"){
printf("y = ");
if(m!=1.0&&m!=-1.0&&m!=0) cout << round(m*1e3)/1e3 << "x ";
else if(m==1.0) cout << "x ";
else if (m==-1.0) cout <<"-x ";
if(b>0) cout << "+ " << round(b*1e3)/1e3;
else if (b<0) cout << "- " << abs(round(b*1e3)/1e3);
if(m==0) cout << round(b*1e3)/1e3;
}
return 0;
} | # 0459, 2024-11-02 09:37:25, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
string a;
float x,y,m,b,sx=0,sy=0,sx2=0,xy=0;
//vector<pair<float,float>> xy;
cin >> n >> a;
for(int i=0;i<n;i++){
cin >> x >> y;
sx+=x;
sy+=y;
sx2+=pow(x,2);
xy+=x*y;
}
m = ((n*xy)-(sx*sy))/((n*sx2)-pow(sx,2));
b = (sy-(m*sx))/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(a=="mb"){
cout << m << "\n" << b ;
}
if(a=="func"){
printf("y = ");
if(m!=1.0&&m!=-1.0&&(m!=0||m!=-0)) cout << m << "x ";
else if(m==1.0) cout << "x ";
else if (m==-1.0) cout <<"-x ";
if(b>0&&m!=0) cout << "+ " << b;
else if (b<0&&m!=0) cout << "- " << abs(b);
if(m==0) cout << b;
}
return 0;
} |
# 0460, 2024-11-02 10:27:45, PPPPPPPPPPP-P--PPPPPPP-- (79%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
float x,y,m,b;
string s;
vector <float> xi,yi;
cin>>n>>s;
for(int i=1;i<=n;i++){
cin>>x>>y;
xi.push_back(x);
yi.push_back(y);
}
float xiyi_mul=0.0,xi_sum=0.0, yi_sum=0.0 , xi_sq=0.0;
for(int i=0;i<n;i++){
xiyi_mul += xi[i]*yi[i];
xi_sum +=xi[i];
yi_sum +=yi[i];
xi_sq += (xi[i]*xi[i]);
}
m=((n*xiyi_mul) - ( xi_sum * yi_sum)) / (n*( xi_sq) - (xi_sum * xi_sum));
b=(yi_sum - m*(xi_sum))/n;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
//cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(s=="func"){
if(m==0.0 && b==0.0){
cout<<"y = 0"<<endl;
}
else if(m==0.0 || m==-0){
cout<< "y = "<<b<<endl;
}
else if(b==0.0){
if(m==-1.0){
cout<<"y = -x"<<endl;
}if(m==1.0){
cout<<"y = x"<<endl;
}
}else{
if(m==-1.0){
cout<<"y = -x + "<<b;
}else if(m==1.0){
cout<<"y = x + "<<b;
}else{
cout<<"y = "<< m <<"x + "<<b;
}
}
}
} | # 0461, 2024-11-02 10:38:37, PPPPPPPPPPPPPPPPPPPPPP-P (95%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
float x,y,m,b;
string s;
vector <float> xi,yi;
cin>>n>>s;
for(int i=1;i<=n;i++){
cin>>x>>y;
xi.push_back(x);
yi.push_back(y);
}
float xiyi_mul=0.0,xi_sum=0.0, yi_sum=0.0 , xi_sq=0.0;
for(int i=0;i<n;i++){
xiyi_mul += xi[i]*yi[i];
xi_sum +=xi[i];
yi_sum +=yi[i];
xi_sq += (xi[i]*xi[i]);
}
m=((n*xiyi_mul) - ( xi_sum * yi_sum)) / (n*( xi_sq) - (xi_sum * xi_sum));
b=(yi_sum - m*(xi_sum))/n;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
//cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(s=="func"){
if(m==0.0 && b==0.0 || m==-0 && b==0.0){
cout<<"y = 0"<<endl;
}
else if(m==0.0 || m==-0){
cout<< "y = "<<b<<endl;
}
else if(b==0.0){
if(m==-1.0){
cout<<"y = -x"<<endl;
}else if(m==1.0){
cout<<"y = x"<<endl;
}
}else{
if(m==-1.0){
if(b>0){
cout<<"y = -x + "<<b;}
else if(b<0){
cout<<"y = -x - "<<(-1)*b;
}
}else if(m==1.0){
cout<<"y = x + "<<b;
}else{
if(b>0){
cout<<"y = "<< m <<"x + "<<b;}
else if(b<0){
cout<<"y = "<< m <<"x - "<<(-1)*b;
}
}
}
}
} | # 0462, 2024-11-02 10:41:24, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
float x,y,m,b;
string s;
vector <float> xi,yi;
cin>>n>>s;
for(int i=1;i<=n;i++){
cin>>x>>y;
xi.push_back(x);
yi.push_back(y);
}
float xiyi_mul=0.0,xi_sum=0.0, yi_sum=0.0 , xi_sq=0.0;
for(int i=0;i<n;i++){
xiyi_mul += xi[i]*yi[i];
xi_sum +=xi[i];
yi_sum +=yi[i];
xi_sq += (xi[i]*xi[i]);
}
m=((n*xiyi_mul) - ( xi_sum * yi_sum)) / (n*( xi_sq) - (xi_sum * xi_sum));
b=(yi_sum - m*(xi_sum))/n;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
//cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(s=="func"){
if(m==0.0 && b==0.0 || m==-0 && b==0.0){
cout<<"y = 0"<<endl;
}
else if(m==0.0 || m==-0){
cout<< "y = "<<b<<endl;
}
else if(b==0.0){
if(m==-1.0){
cout<<"y = -x"<<endl;
}else if(m==1.0){
cout<<"y = x"<<endl;
}
}else{
if(m==-1.0){
if(b>0){
cout<<"y = -x + "<<b;}
else if(b<0){
cout<<"y = -x - "<<(-1)*b;
}
}else if(m==1.0){
if(b>0){
cout<<"y = x + "<<b;}
else if(b<0){
cout<<"y = x - "<<(-1)*b;
}
}else{
if(b>0){
cout<<"y = "<< m <<"x + "<<b;}
else if(b<0){
cout<<"y = "<< m <<"x - "<<(-1)*b;
}
}
}
}
} |
# 0463, 2024-11-02 14:05:27, PPPPPPPPPP-------------- (41%)
#include <bits/stdc++.h>
using namespace std;
int main(){
float n, x = 0, y = 0, xy = 0, xPow2 = 0;
string textOut;
cin >> n >> textOut;
for(int i=0; i<n; i++){
float xin, yin;
cin >> xin >> yin;
x += xin;
y += yin;
xy += (xin*yin);
xPow2 += (xin*xin);
}
// cout << x << endl << y << endl << xy << endl << xPow2 << endl;
float m = (((n*xy) - (x*y)) / ((n*xPow2) - (x*x)));
float b = ((y - (m*x)) / n);
if(textOut == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(textOut == "func"){
}
} | # 0464, 2024-11-02 14:07:10, PPPPPPPPPP-----P-------- (45%)
#include <bits/stdc++.h>
using namespace std;
int main(){
float n, x = 0, y = 0, xy = 0, xPow2 = 0;
string textOut;
cin >> n >> textOut;
for(int i=0; i<n; i++){
float xin, yin;
cin >> xin >> yin;
x += xin;
y += yin;
xy += (xin*yin);
xPow2 += (xin*xin);
}
// cout << x << endl << y << endl << xy << endl << xPow2 << endl;
float m = (((n*xy) - (x*y)) / ((n*xPow2) - (x*x)));
float b = ((y - (m*x)) / n);
if(textOut == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(textOut == "func"){
cout << "y = 0";
}
} | # 0465, 2024-11-02 14:55:01, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
int main(){
float n, x = 0, y = 0, xy = 0, xPow2 = 0;
string textOut;
cin >> n >> textOut;
for(int i=0; i<n; i++){
float xin, yin;
cin >> xin >> yin;
x += xin;
y += yin;
xy += (xin*yin);
xPow2 += (xin*xin);
}
// cout << x << endl << y << endl << xy << endl << xPow2 << endl;
float m = (((n*xy) - (x*y)) / ((n*xPow2) - (x*x)));
float b = ((y - (m*x)) / n);
if(textOut == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(textOut == "func"){
int aok = 0;
cout << "y = ";
//cout a
if(round(m*1e3)/1e3 == 0){
}
else if(round(m*1e3)/1e3 == 1){
cout << "x";
aok = 1;
}
else if(round(m*1e3)/1e3 == -1){
cout << "-x";
aok = 1;
}
else{
cout << round(m*1e3)/1e3 << "x";
aok = 1;
}
//cout b
if(aok == 1){
if(round(b*1e3)/1e3 >= 1){
cout << " + " << round(b*1e3)/1e3;
}
else if(round(b*1e3)/1e3 <= -1){
cout << " - " << abs(round(b*1e3)/1e3);
}
}
else{
if(round(b*1e3)/1e3 == 0){
cout << "0";
}
else{
cout << round(b*1e3)/1e3;
}
}
}
} |
# 0466, 2024-11-02 09:56:10, -----PPPPP-----P-----P-- (29%)
#include<iostream>
#include<cmath>
#include<vector>
#include<utility>
using namespace std;
int main(){
int n;
string command;
cin >> n >> command;
vector<pair<float,float>> list;
for(int i = 0; i < n; i++){
float x,y;
cin >> x >>y;
list.push_back(make_pair(x,y));
}
float m = 0,b = 0;
float zigmax = 0,x2 = 0,zigmay = 0,y2 = 0,mul = 0;
for(int i = 0; i < n; i++){
mul += list[i].first * list[i].second;
zigmax += list[i].first;
zigmay += list[i].second;
x2 += pow(list[i].first,2);
}
m = ((n * mul) -(zigmax * zigmay))/((n*x2) - pow(zigmax,2));
b= ((zigmay) - (m*zigmax))/n;
if(command == "mb"){
cout << round(m*1e3)/1e3 <<endl;
cout << b << endl;
}else if(command == "func"){
cout << "y = ";
if(m==0){
cout << b;
}else if(m == 1){
}else if(m == -1){
cout << "-x" << b;
}else{
cout << round(m*1e3)/1e3 << "x " << b;
}
}
} | # 0467, 2024-11-02 10:06:12, PPPPPPPPPPPPPPPPPP--PPPP (91%)
#include<iostream>
#include<cmath>
#include<vector>
#include<utility>
using namespace std;
int main(){
int n;
string command;
cin >> n >> command;
vector<pair<float,float>> list;
for(int i = 0; i < n; i++){
float x,y;
cin >> x >>y;
list.push_back(make_pair(x,y));
}
float m = 0,b = 0;
float zigmax = 0,x2 = 0,zigmay = 0,y2 = 0,mul = 0;
for(int i = 0; i < n; i++){
mul += list[i].first * list[i].second;
zigmax += list[i].first;
zigmay += list[i].second;
x2 += pow(list[i].first,2);
}
m = ((n * mul) -(zigmax * zigmay))/((n*x2) - pow(zigmax,2));
b= ((zigmay) - (m*zigmax))/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(command == "mb"){
cout << round(m*1e3)/1e3 <<endl;
cout << b << endl;
}else if(command == "func"){
cout << "y = ";
if(m == 0){
cout << b;
}else if(m == 1){
cout << "x";
if(b < 0){
cout << " - " << -b;
}else{
cout << " + " << b;
}
}else if(m == -1){
cout << "-x";
if(b < 0){
cout << " - " << -b;
}else{
cout << " + " << b;
}
}else{
cout << m << "x";
if(b < 0){
cout << " - " << -b;
}else{
cout << " + " << b;
}
}
}
} | # 0468, 2024-11-02 10:09:36, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<iostream>
#include<cmath>
#include<vector>
#include<utility>
using namespace std;
int main(){
int n;
string command;
cin >> n >> command;
vector<pair<float,float>> list;
for(int i = 0; i < n; i++){
float x,y;
cin >> x >>y;
list.push_back(make_pair(x,y));
}
float m = 0,b = 0;
float zigmax = 0,x2 = 0,zigmay = 0,y2 = 0,mul = 0;
for(int i = 0; i < n; i++){
mul += list[i].first * list[i].second;
zigmax += list[i].first;
zigmay += list[i].second;
x2 += pow(list[i].first,2);
}
m = ((n * mul) -(zigmax * zigmay))/((n*x2) - pow(zigmax,2));
b= ((zigmay) - (m*zigmax))/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(command == "mb"){
cout << round(m*1e3)/1e3 <<endl;
cout << b << endl;
}else if(command == "func"){
cout << "y = ";
if(m == 0){
cout << b;
}else if(m == 1){
cout << "x";
if(b < 0){
cout << " - " << -b;
}else if(b >0){
cout << " + " << b;
}
}else if(m == -1){
cout << "-x";
if(b < 0){
cout << " - " << -b;
}else if(b > 0){
cout << " + " << b;
}
}else{
cout << m << "x";
if(b < 0){
cout << " - " << -b;
}else if(b > 0){
cout << " + " << b;
}
}
}
} |
# 0469, 2024-11-02 10:32:41, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
string s; cin >> s;
vector<float> m,x,y;
for(int i{0} ; i<n ; i++){
float a,b;
cin >> a >> b;
x.push_back(a); y.push_back(b);
}
float m1=0,m2=0,m3=0,m4=0,m5=0,m6=0;
float b1=0,b2=0,bf=0;
for(int i=0 ; i<n ; i++){
m1 += x[i]*y[i];
m2 += x[i];
m3 += y[i];
m4 += x[i]*x[i];
}
m1 *= n;
m6 = m2*m3;
m4 *= n;
m5 += m2;
m5 = m2*m2;
float mf = (m1-m6)/(m4-m5);
b1=m3;
b2= mf*m2;
bf = (b1-b2)/n;
mf = round(mf * 1e3)/1e3;
bf = round(bf * 1e3)/1e3;
if(s == "mb"){
cout << round(mf * 1e3)/1e3 << endl;
cout << round(bf * 1e3)/1e3 << endl;
}
if(s == "func"){
if(mf==0 && bf==0) cout << "y = 0";
else if(mf==0) cout << "y = " << bf;
else if(bf==0){
if(mf==-1) cout << "y = " << "-x";
if(mf==1) cout << "y = " << "x";
}
else if(bf>0){
cout << "y = " << mf << "x" << " + " << bf ;
}
else if(bf<0){
cout << "y = " << mf << "x" << " - " << abs(bf) ;
}
}
} | # 0470, 2024-11-02 10:34:53, PPPPPPPPPP-P-PPPP-PP-PPP (83%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
string s; cin >> s;
vector<float> m,x,y;
for(int i{0} ; i<n ; i++){
float a,b;
cin >> a >> b;
x.push_back(a); y.push_back(b);
}
float m1=0,m2=0,m3=0,m4=0,m5=0,m6=0;
float b1=0,b2=0,bf=0;
for(int i=0 ; i<n ; i++){
m1 += x[i]*y[i];
m2 += x[i];
m3 += y[i];
m4 += x[i]*x[i];
}
m1 *= n;
m6 = m2*m3;
m4 *= n;
m5 += m2;
m5 = m2*m2;
float mf = (m1-m6)/(m4-m5);
b1=m3;
b2= mf*m2;
bf = (b1-b2)/n;
mf = round(mf * 1e3)/1e3;
bf = round(bf * 1e3)/1e3;
if(s == "mb"){
cout << round(mf * 1e3)/1e3 << endl;
cout << round(bf * 1e3)/1e3 << endl;
}
if(s == "func"){
if(mf==0 && bf==0) cout << "y = 0";
else if(mf==0) cout << "y = " << bf;
else if(bf==0){
if(mf==-1) cout << "y = " << "-x";
else if(mf==1) cout << "y = " << "x";
}
else if(bf>0){
if(mf==-1)cout << "y = " << "-x" << " - " << abs(bf) ;
else if(mf==1)cout << "y = " << "x" << " - " << abs(bf) ;
else cout << "y = " << mf << "x" << " - " << abs(bf) ;
}
else if(bf<0){
if(mf==-1)cout << "y = " << "-x" << " - " << abs(bf) ;
else if(mf==1)cout << "y = " << "x" << " - " << abs(bf) ;
else cout << "y = " << mf << "x" << " - " << abs(bf) ;
}
}
} | # 0471, 2024-11-02 10:35:24, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
string s; cin >> s;
vector<float> m,x,y;
for(int i{0} ; i<n ; i++){
float a,b;
cin >> a >> b;
x.push_back(a); y.push_back(b);
}
float m1=0,m2=0,m3=0,m4=0,m5=0,m6=0;
float b1=0,b2=0,bf=0;
for(int i=0 ; i<n ; i++){
m1 += x[i]*y[i];
m2 += x[i];
m3 += y[i];
m4 += x[i]*x[i];
}
m1 *= n;
m6 = m2*m3;
m4 *= n;
m5 += m2;
m5 = m2*m2;
float mf = (m1-m6)/(m4-m5);
b1=m3;
b2= mf*m2;
bf = (b1-b2)/n;
mf = round(mf * 1e3)/1e3;
bf = round(bf * 1e3)/1e3;
if(s == "mb"){
cout << round(mf * 1e3)/1e3 << endl;
cout << round(bf * 1e3)/1e3 << endl;
}
if(s == "func"){
if(mf==0 && bf==0) cout << "y = 0";
else if(mf==0) cout << "y = " << bf;
else if(bf==0){
if(mf==-1) cout << "y = " << "-x";
else if(mf==1) cout << "y = " << "x";
}
else if(bf>0){
if(mf==-1)cout << "y = " << "-x" << " + " << abs(bf) ;
else if(mf==1)cout << "y = " << "x" << " + " << abs(bf) ;
else cout << "y = " << mf << "x" << " + " << abs(bf) ;
}
else if(bf<0){
if(mf==-1)cout << "y = " << "-x" << " - " << abs(bf) ;
else if(mf==1)cout << "y = " << "x" << " - " << abs(bf) ;
else cout << "y = " << mf << "x" << " - " << abs(bf) ;
}
}
} |
# 0472, 2024-11-02 13:47:04, PPPPPPPPPPP-P--P-PP----- (62%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
string cmd;
cin >> n >> cmd;
float x[n+2],y[n+2];
for(int i=1;i<=n;i++)cin >> x[i] >> y[i];
float sumXiYi = 0;
for(int i=1;i<= n;i++) sumXiYi += x[i]*y[i]; // if ans not correct delte =
// if ans not correct delte =
float sumX = 0;
for(int i=1;i<= n;i++) sumX += x[i];
// if ans not correct delte =
float sumY = 0;
for(int i=1;i<= n;i++) sumY += y[i];
// if ans not correct delte =
float sumX2 = 0;
for(int i=1;i<= n;i++) sumX2 += pow(x[i],2);
float m = ((n*sumXiYi)-(sumX * sumY)) / (n*sumX2- pow(sumX,2));
float b = ((sumY)-(m * sumX)) / n;
m =round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(cmd == "mb") cout << m <<"\n" <<b;
else
{
if(m==0.0 && b==0.0) cout << "y = 0";
else if(m!=0.0 && b==0.0)
{
if(m==1) cout << "y = x";
else if(m==-1) cout << "y = -" << m<<"x";
else cout << "y = " << m<<"x";
}
else if(m!=0.0 && b!=0.0)
{
if(m==1) cout << "y = x + "<<b;
else if(m==-1) cout << "y = -" << m<<"x + " <<b;
else cout << "y = " << m<<"x" <<" + " <<b;
}
}
} | # 0473, 2024-11-02 13:57:27, PPPPPPPPPPPPPPPPP--PPP-P (87%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
string cmd;
cin >> n >> cmd;
float x[n+2],y[n+2];
for(int i=1;i<=n;i++)cin >> x[i] >> y[i];
float sumXiYi = 0;
for(int i=1;i<= n;i++) sumXiYi += x[i]*y[i]; // if ans not correct delte =
// if ans not correct delte =
float sumX = 0;
for(int i=1;i<= n;i++) sumX += x[i];
// if ans not correct delte =
float sumY = 0;
for(int i=1;i<= n;i++) sumY += y[i];
// if ans not correct delte =
float sumX2 = 0;
for(int i=1;i<= n;i++) sumX2 += pow(x[i],2);
float m = ((n*sumXiYi)-(sumX * sumY)) / (n*sumX2- pow(sumX,2));
float b = ((sumY)-(m * sumX)) / n;
m =round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(cmd == "mb") cout << m <<"\n" <<b;
else
{
if(m == 0.0) cout << "y = " <<b;
if(m!= 0.0 && b==0.0)
{
if(m==1) cout << "y = x";
if(m==-1) cout << "y = -x";
else cout << "y = " <<m<<"x";
}
if(m!= 0.0 && b != 0.0)
{
//m
if(m==1) cout << "y = x";
if(m==-1) cout << "y = -x";
else cout << "y = " <<m<<"x";
//b
if(b>0)cout << " + " << b;
else if(b<0) cout << " - " << b*-1;
}
}
} | # 0474, 2024-11-02 14:02:42, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
string cmd;
cin >> n >> cmd;
float x[n+2],y[n+2];
for(int i=1;i<=n;i++)cin >> x[i] >> y[i];
float sumXiYi = 0;
for(int i=1;i<= n;i++) sumXiYi += x[i]*y[i]; // if ans not correct delte =
// if ans not correct delte =
float sumX = 0;
for(int i=1;i<= n;i++) sumX += x[i];
// if ans not correct delte =
float sumY = 0;
for(int i=1;i<= n;i++) sumY += y[i];
// if ans not correct delte =
float sumX2 = 0;
for(int i=1;i<= n;i++) sumX2 += pow(x[i],2);
float m = ((n*sumXiYi)-(sumX * sumY)) / (n*sumX2- pow(sumX,2));
float b = ((sumY)-(m * sumX)) / n;
m =round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(cmd == "mb") cout << m <<"\n" <<b;
else
{
if(m!= 0.0 && b != 0.0)
{
//m
if(m==1) cout << "y = x";
else if(m==-1) cout << "y = -x";
else cout << "y = " <<m<<"x";
//b
if(b>0)cout << " + " << b;
else if(b<0) cout << " - " << b*-1;
return 0;
}
else if(m == 0.0) {cout << "y = " <<b; return 0;}
else if(m!= 0.0 && b==0.0)
{
if(m==1) cout << "y = x";
else if(m==-1) cout << "y = -x";
else cout << "y = " <<m<<"x";
return 0;
}
}
} |
# 0475, 2024-11-02 09:48:29, PPPPPPPPPP-----PP-P--P-- (58%)
#include<bits/stdc++.h>
using namespace std;
int main() {
int num;
string fun;
cin >> num >> fun;
float in1,in2,in3;
string ina,inb,inc;
vector<pair<float,float>> v;
for(int i = 0;i<num;i++){
cin >> in1 >> in2;
v.push_back(make_pair(in1,in2));
}
float m,b,temp;
float sum1 = 0,sum2 = 0,sum3 = 0,sum4 = 0,sum5 = 0;
for(int i = 0;i<num;i++){
sum1 = sum1 + v[i].first * v[i].second;
sum2 = sum2 + v[i].first;
sum3 = sum3 + v[i].second;
sum4 = sum4 + pow(v[i].first,2.0);
}
m = (num*sum1 - sum2*sum3)/(num*sum4 - pow(sum2,2.0));
b = (sum3 - m*sum2)/num;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if(fun == "mb"){
cout << m << endl << b;
return 0;
}
else cout << "y = ";
if(m != 0 && m!=1) cout << m << "x";
else if(m ==1)cout << "x";
if(m== 0)cout << b;
else if(b != 0)cout << "+ " << b;
} | # 0476, 2024-11-02 09:51:16, PPPPPPPPPPPPPPPPPPP--PP- (87%)
#include<bits/stdc++.h>
using namespace std;
int main() {
int num;
string fun;
cin >> num >> fun;
float in1,in2,in3;
string ina,inb,inc;
vector<pair<float,float>> v;
for(int i = 0;i<num;i++){
cin >> in1 >> in2;
v.push_back(make_pair(in1,in2));
}
float m,b,temp;
float sum1 = 0,sum2 = 0,sum3 = 0,sum4 = 0,sum5 = 0;
for(int i = 0;i<num;i++){
sum1 = sum1 + v[i].first * v[i].second;
sum2 = sum2 + v[i].first;
sum3 = sum3 + v[i].second;
sum4 = sum4 + pow(v[i].first,2.0);
}
m = (num*sum1 - sum2*sum3)/(num*sum4 - pow(sum2,2.0));
b = (sum3 - m*sum2)/num;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if(fun == "mb"){
cout << m << endl << b;
return 0;
}
else cout << "y = ";
if(m != 0 && m!=1) cout << m << "x";
else if(m ==1)cout << "x";
if(m== 0)cout << b;
else if(b != 0){
if(b < 0)cout << " - " << abs(b);
else cout << " + " << b;}
} | # 0477, 2024-11-02 09:53:48, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<bits/stdc++.h>
using namespace std;
int main() {
int num;
string fun;
cin >> num >> fun;
float in1,in2,in3;
string ina,inb,inc;
vector<pair<float,float>> v;
for(int i = 0;i<num;i++){
cin >> in1 >> in2;
v.push_back(make_pair(in1,in2));
}
float m,b,temp;
float sum1 = 0,sum2 = 0,sum3 = 0,sum4 = 0,sum5 = 0;
for(int i = 0;i<num;i++){
sum1 = sum1 + v[i].first * v[i].second;
sum2 = sum2 + v[i].first;
sum3 = sum3 + v[i].second;
sum4 = sum4 + pow(v[i].first,2.0);
}
m = (num*sum1 - sum2*sum3)/(num*sum4 - pow(sum2,2.0));
b = (sum3 - m*sum2)/num;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if(fun == "mb"){
cout << m << endl << b;
return 0;
}
else cout << "y = ";
if(m != 0 && m!=1&& m!= -1) cout << m << "x";
else if(m ==1)cout << "x";
else if(m == -1) cout << "-x";
if(m== 0)cout << b;
else if(b != 0){
if(b < 0)cout << " - " << abs(b);
else cout << " + " << b;}
} |
# 0478, 2024-11-02 09:53:28, PPPPPPPPPPPPPPP--PPPP-PP (87%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string command;
vector<float> x, y;
float fx = 0, sx1 = 0, sx2 = 0, bfx = 0, bsx = 0, temp1, temp2;
float m = 0, b = 0;
cin >> n >> command;
for (int i = 1; i <= n; ++i)
{
cin >> temp1 >> temp2;
x.push_back(temp1);
y.push_back(temp2);
}
for (int i = 1; i <= n; ++i)
{
fx += x[i - 1] * y[i - 1];
sx1 += x[i - 1];
sx2 += y[i - 1];
bfx += x[i - 1] * x[i - 1];
}
bsx = sx1 * sx1;
m = ((n * fx) - (sx1 * sx2)) / ((n * bfx) - bsx);
b = (sx2 - (m * sx1)) / n;
if (command == "mb")
{
cout << round(m * 1e3) / 1e3 << endl
<< round(b * 1e3) / 1e3 << endl;
}
else if (command == "func")
{
if (round(m * 1e3) / 1e3 == 0)
cout << round(b * 1e3) / 1e3 << endl;
else if (round(m * 1e3) / 1e3 == -1)
{
cout << "y = -x";
if (round(b * 1e3) / 1e3 < 0)
{
cout << " - " << -(round(b * 1e3) / 1e3);
}
else if (round(b * 1e3) / 1e3 > 0)
{
cout << " + " << round(b * 1e3) / 1e3;
}
}
else if(round(m * 1e3) / 1e3 ==1)
{
cout << "y = " << "x";
if (round(b * 1e3) / 1e3 < 0)
{
cout << " - " << -(round(b * 1e3) / 1e3);
}
else if (round(b * 1e3) / 1e3 > 0)
{
cout << " + " << round(b * 1e3) / 1e3;
}
}
else
{
cout << "y = " << round(m * 1e3) / 1e3 << "x";
if (round(b * 1e3) / 1e3 < 0)
{
cout << " - " << -(round(b * 1e3) / 1e3);
}
else if (round(b * 1e3) / 1e3 > 0)
{
cout << " + " << round(b * 1e3) / 1e3;
}
}
}
} | # 0479, 2024-11-02 10:43:13, PPPPPPPPPPPPPPP--PPPP-PP (87%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string command;
vector<float> x, y;
float fx = 0, sx1 = 0, sx2 = 0, bfx = 0, bsx = 0, temp1, temp2;
float m = 0, b = 0;
cin >> n >> command;
for (int i = 1; i <= n; ++i)
{
cin >> temp1 >> temp2;
x.push_back(temp1);
y.push_back(temp2);
}
for (int i = 1; i <= n; ++i)
{
fx += x[i - 1] * y[i - 1];
sx1 += x[i - 1];
sx2 += y[i - 1];
bfx += x[i - 1] * x[i - 1];
}
bsx = sx1 * sx1;
m = ((n * fx) - (sx1 * sx2)) / ((n * bfx) - bsx);
b = (sx2 - (m * sx1)) / n;
if (command == "mb")
{
cout << round(m * 1e3) / 1e3 << endl
<< round(b * 1e3) / 1e3 << endl;
}
else if (command == "func")
{
if (round(m * 1e3) / 1e3 == 0)
cout << round(b * 1e3) / 1e3 << endl;
else if (round(m * 1e3) / 1e3 == -1)
{
cout << "y = -x";
if (round(b * 1e3) / 1e3 < 0)
{
cout << " - " << -(round(b * 1e3) / 1e3);
}
else if (round(b * 1e3) / 1e3 > 0)
{
cout << " + " << round(b * 1e3) / 1e3;
}
}
else if(round(m * 1e3) / 1e3 ==1)
{
cout << "y = x";
if (round(b * 1e3) / 1e3 < 0)
{
cout << " - " << -(round(b * 1e3) / 1e3);
}
else if (round(b * 1e3) / 1e3 > 0)
{
cout << " + " << round(b * 1e3) / 1e3;
}
}
else
{
cout << "y = " << round(m * 1e3) / 1e3 << "x";
if (round(b * 1e3) / 1e3 < 0)
{
cout << " - " << -(round(b * 1e3) / 1e3);
}
else if (round(b * 1e3) / 1e3 > 0)
{
cout << " + " << round(b * 1e3) / 1e3;
}
}
}
} | # 0480, 2024-11-02 11:36:00, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string command;
vector<float> x, y;
float fx = 0, sx1 = 0, sx2 = 0, bfx = 0, bsx = 0, temp1, temp2;
float m = 0, b = 0;
cin >> n >> command;
for (int i = 1; i <= n; ++i)
{
cin >> temp1 >> temp2;
x.push_back(temp1);
y.push_back(temp2);
}
for (int i = 1; i <= n; ++i)
{
fx += x[i - 1] * y[i - 1];
sx1 += x[i - 1];
sx2 += y[i - 1];
bfx += x[i - 1] * x[i - 1];
}
bsx = sx1 * sx1;
m = ((n * fx) - (sx1 * sx2)) / ((n * bfx) - bsx);
b = (sx2 - (m * sx1)) / n;
if (command == "mb")
{
cout << round(m * 1e3) / 1e3 << endl
<< round(b * 1e3) / 1e3 << endl;
}
else if (command == "func")
{
if (round(m * 1e3) / 1e3 == 0)
cout << "y = " << round(b * 1e3) / 1e3 << endl;
else if (round(m * 1e3) / 1e3 == -1)
{
cout << "y = -x";
if (round(b * 1e3) / 1e3 < 0)
{
cout << " - " << -(round(b * 1e3) / 1e3);
}
else if (round(b * 1e3) / 1e3 > 0)
{
cout << " + " << round(b * 1e3) / 1e3;
}
}
else if(round(m * 1e3) / 1e3 ==1)
{
cout << "y = x";
if (round(b * 1e3) / 1e3 < 0)
{
cout << " - " << -(round(b * 1e3) / 1e3);
}
else if (round(b * 1e3) / 1e3 > 0)
{
cout << " + " << round(b * 1e3) / 1e3;
}
}
else
{
cout << "y = " << round(m * 1e3) / 1e3 << "x";
if (round(b * 1e3) / 1e3 < 0)
{
cout << " - " << -(round(b * 1e3) / 1e3);
}
else if (round(b * 1e3) / 1e3 > 0)
{
cout << " + " << round(b * 1e3) / 1e3;
}
}
}
} |
# 0481, 2024-11-02 13:51:22, PPPPPPPPPP-----P-------- (45%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n ;
cin >> n ;
float N = n ;
string cmd ;
cin >> cmd ;
float x[n] , y[n] ;
for(int i = 1 ; i <= n ; i++) {
cin >> x[i] >> y[i] ;
}
float m , b ;
float sxy = 0 , sx = 0 , sy = 0 , sx2 = 0 ;
if(cmd == "mb") {
for(int i = 1 ; i <= n ; i++) {
sxy += x[i] * y[i] ;
sx += x[i] ;
sy += y[i] ;
sx2 += pow((x[i]) , 2) ;
}
m = ((N * sxy) - ((sx) * (sy))) / ((N * sx2) - pow(sx , 2)) ;
b = (sy - (m * sx)) / N ;
cout << round(m * 1e3) / 1e3 << endl << round(b * 1e3) / 1e3 ;
}
else if(cmd == "func") {
if(m == 1 && b != 0) {
cout << "y = " << "x - " << b ;
return 0 ;
}
else if(m == -1 && b != 0) {
cout << "y = " << "-x - " << b ;
return 0 ;
}
else if(m != 0 && b != 0) {
cout << "y = " << m << "x - " << b ;
return 0 ;
}
else if(m == 1 && b == 0) {
cout << "y = " << "x" ;
return 0 ;
}
else if(m == -1 && b == 0) {
cout << "y = " << "-x" ;
return 0 ;
}
else if(m != 0 && b == 0) {
cout << "y = " << m << "x" ;
return 0 ;
}
else if(m == 0) {
cout << "y = " << b ;
return 0 ;
}
}
return 0 ;
} | # 0482, 2024-11-02 13:52:44, PPPPPPPPPP-----P--PP-P-- (58%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n ;
cin >> n ;
float N = n ;
string cmd ;
cin >> cmd ;
float x[n] , y[n] ;
for(int i = 1 ; i <= n ; i++) {
cin >> x[i] >> y[i] ;
}
float m , b ;
float sxy = 0 , sx = 0 , sy = 0 , sx2 = 0 ;
for(int i = 1 ; i <= n ; i++) {
sxy += x[i] * y[i] ;
sx += x[i] ;
sy += y[i] ;
sx2 += pow((x[i]) , 2) ;
}
m = ((N * sxy) - ((sx) * (sy))) / ((N * sx2) - pow(sx , 2)) ;
b = (sy - (m * sx)) / N ;
if(cmd == "mb") {
cout << round(m * 1e3) / 1e3 << endl << round(b * 1e3) / 1e3 ;
}
else if(cmd == "func") {
if(m == 1 && b != 0) {
cout << "y = " << "x - " << b ;
return 0 ;
}
else if(m == -1 && b != 0) {
cout << "y = " << "-x - " << b ;
return 0 ;
}
else if(m != 0 && b != 0) {
cout << "y = " << m << "x - " << b ;
return 0 ;
}
else if(m == 1 && b == 0) {
cout << "y = " << "x" ;
return 0 ;
}
else if(m == -1 && b == 0) {
cout << "y = " << "-x" ;
return 0 ;
}
else if(m != 0 && b == 0) {
cout << "y = " << m << "x" ;
return 0 ;
}
else if(m == 0) {
cout << "y = " << b ;
return 0 ;
}
}
return 0 ;
} | # 0483, 2024-11-02 14:02:34, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n ;
cin >> n ;
float N = n ;
string cmd ;
cin >> cmd ;
float x[n] , y[n] ;
for(int i = 1 ; i <= n ; i++) {
cin >> x[i] >> y[i] ;
}
float m , b ;
float sxy = 0 , sx = 0 , sy = 0 , sx2 = 0 ;
for(int i = 1 ; i <= n ; i++) {
sxy += x[i] * y[i] ;
sx += x[i] ;
sy += y[i] ;
sx2 += pow((x[i]) , 2) ;
}
m = ((N * sxy) - ((sx) * (sy))) / ((N * sx2) - pow(sx , 2)) ;
b = (sy - (m * sx)) / N ;
m = round(m * 1e3) / 1e3 ;
b = round(b * 1e3) / 1e3 ;
if(cmd == "mb") {
cout << m << endl << b ;
}
else if(cmd == "func") {
if(m == 1 && b < 0) {
cout << "y = " << "x - " << -1 * b ;
return 0 ;
}
else if(m == 1 && b > 0) {
cout << "y = " << "x + " << b ;
return 0 ;
}
else if(m == -1 && b < 0) {
cout << "y = " << "-x - " << -1 * b ;
return 0 ;
}
else if(m == -1 && b > 0) {
cout << "y = " << "-x + " << b ;
return 0 ;
}
else if(m != 0 && b < 0) {
cout << "y = " << m << "x - " << -1 * b ;
return 0 ;
}
else if(m != 0 && b > 0) {
cout << "y = " << m << "x + " << b ;
return 0 ;
}
else if(m == 1 && b == 0) {
cout << "y = " << "x" ;
return 0 ;
}
else if(m == -1 && b == 0) {
cout << "y = " << "-x" ;
return 0 ;
}
else if(m != 0 && b == 0) {
cout << "y = " << m << "x" ;
return 0 ;
}
else if(m == 0) {
cout << "y = " << b ;
return 0 ;
}
}
return 0 ;
} |
# 0484, 2024-11-02 09:58:32, -----PPP-------P--PP---- (25%)
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <tuple>
using namespace std;
int main(){
int n;
vector<pair<float, float>> data;
string command;
cin >> n >> command;
float tempx, tempy;
for(int i = 0; i < n; i++){
cin >> tempx >> tempy;
data.push_back({tempx, tempy});
}
float m, m1 = 0, m2 = 0, m3 = 0, m4 =0, m5 = 0, b, b2 = 0;
for(int i =1; i <= n; i++){
m1 += data[i].first*data[i].second;
m2 += data[i].first;
m3 += data[i].second;
m4 += pow(data[i].first, 2);
b2 += data[i].first;
}
m1 *= n;
m5 = pow(b2, 2);
m4 *= n;
m = (m1 - m2*m3)/(m4 - m5);
b = (m3 - m*b2)/n;
if(command == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
}
else if(command == "func"){
if(m == 0.0 && b == 0.0){
cout << "y = 0";
return 0;
}
else if(m == 0.0 && b != 0.0){
cout << "y = " << round(b*1e3)/1e3;
return 0;
}
cout << "y = ";
if( m == -1.0){
cout <<"-";
}
else if(m != 1.0){
cout << round(m*1e3)/1e3;
}
cout << "x";
if(b == 0) return 0;
if(b > 0.0){
cout <<" + " << round(b*1e3)/1e3;
}
else{
cout << " - " << -round(b*1e3)/1e3;
}
}
} | # 0485, 2024-11-02 10:09:06, PPPPPPPPPPPPPPPP--PP-PP- (83%)
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <tuple>
using namespace std;
int main(){
int n;
vector<pair<float, float>> data;
string command;
cin >> n >> command;
float tempx, tempy;
for(int i = 0; i < n; i++){
cin >> tempx >> tempy;
data.push_back({tempx, tempy});
}
float m, m1 = 0.0, m2 = 0.0, m3 = 0.0, m4 =0.0, m5 = 0.0, b, b2 = 0.0;
for(int i =0; i < n; i++){
m1 += data[i].first*data[i].second;
m2 += data[i].first;
m3 += data[i].second;
m4 += pow(data[i].first, 2);
}
m = (float(n)*m1 - m2*m3)/(float(n)*m4 - pow(m2,2));
b = (m3 - m*m2)/float(n);
if(command == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
}
else if(command == "func"){
if(m == 0.0 && b == 0.0){
cout << "y = 0";
return 0;
}
else if(m == 0.0 && b != 0.0){
cout << "y = " << round(b*1e3)/1e3;
return 0;
}
cout << "y = ";
if( m == -1.0){
cout <<"-";
}
else if(m != 1.0){
cout << round(m*1e3)/1e3;
}
cout << "x";
if(b == 0) return 0;
if(b > 0.0){
cout <<" + " << round(b*1e3)/1e3;
}
else{
cout << " - " << -round(b*1e3)/1e3;
}
}
} | # 0486, 2024-11-02 10:15:48, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <tuple>
using namespace std;
int main(){
int n;
vector<pair<float, float>> data;
string command;
cin >> n >> command;
float tempx, tempy;
for(int i = 0; i < n; i++){
cin >> tempx >> tempy;
data.push_back({tempx, tempy});
}
float m, m1 = 0.0, m2 = 0.0, m3 = 0.0, m4 =0.0, m5 = 0.0, b, b2 = 0.0;
for(int i =0; i < n; i++){
m1 += data[i].first*data[i].second;
m2 += data[i].first;
m3 += data[i].second;
m4 += pow(data[i].first, 2);
}
m = (float(n)*m1 - m2*m3)/(float(n)*m4 - pow(m2,2));
b = (m3 - m*m2)/float(n);
if(command == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
}
else if(command == "func"){
if(round(m*1e3)/1e3 == 0.0 && round(b*1e3)/1e3 == 0.0){
cout << "y = 0";
return 0;
}
else if(round(m*1e3)/1e3 == 0.0 && round(b*1e3)/1e3 != 0.0){
cout << "y = " << round(b*1e3)/1e3;
return 0;
}
cout << "y = ";
if( round(m*1e3)/1e3 == -1.0){
cout <<"-";
}
else if(round(m*1e3)/1e3 != 1.0){
cout << round(m*1e3)/1e3;
}
cout << "x";
if(round(b*1e3)/1e3 == 0) return 0;
if(round(b*1e3)/1e3 > 0.0){
cout <<" + " << round(b*1e3)/1e3;
}
else{
cout << " - " << -round(b*1e3)/1e3;
}
}
} |
# 0487, 2024-11-02 13:05:37, PPPPPPPPPP-------------- (41%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n;
cin >> n;
int n2 = n;
string type;
cin >> type;
float x,y;
float allx = 0, ally = 0, allxy = 0, x2 = 0;
while(n--){
cin >> x >> y;
allx += x;
ally += y;
allxy += (x*y);
x2 += pow(x, 2);
}
float m;
m = ((n2*allxy) - (allx*ally));
m = m/((n2*x2) - (allx*allx));
//cout << m << endl;
float b;
b = (ally - (m*allx)) / n2;
//cout << b << endl;
if(type=="mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
} | # 0488, 2024-11-02 13:15:06, PPPPPPPPPP-----P--PP-P-- (58%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n;
cin >> n;
int n2 = n;
string type;
cin >> type;
float x,y;
float allx = 0, ally = 0, allxy = 0, x2 = 0;
while(n--){
cin >> x >> y;
allx += x;
ally += y;
allxy += (x*y);
x2 += pow(x, 2);
}
float m;
m = ((n2*allxy) - (allx*ally));
m = m/((n2*x2) - (allx*allx));
//cout << m << endl;
float b;
b = (ally - (m*allx)) / n2;
//cout << b << endl;
if(type=="mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(type=="func"){
if(m==0 && b!=0){
cout << "y = " << round(b*1e3)/1e3 << endl;
}
else if(b==0 && m!=0){
if(m==1){
cout << "y = x" << endl;
}
else if(m==-1){
cout << "y = -x" << endl;
}
else{
cout << "y = " << round(m*1e3)/1e3 << "x" << endl;
}
}
else if(m==0 && b==0){
cout << "y = 0" << endl;
}
else if(m!=0 && b!=0){
cout << "y = " << round(m*1e3)/1e3 << "m " << round(b*1e3)/1e3 << endl;
}
}
} | # 0489, 2024-11-02 14:25:22, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n;
cin >> n;
int n2 = n;
string type;
cin >> type;
float x,y;
float allx = 0, ally = 0, allxy = 0, x2 = 0;
while(n--){
cin >> x >> y;
allx += x;
ally += y;
allxy += (x*y);
x2 += pow(x, 2);
}
float m;
m = ((n2*allxy) - (allx*ally));
m = m/((n2*x2) - (allx*allx));
//cout << m << endl;
float b;
b = (ally - (m*allx)) / n2;
//cout << b << endl;
if(type=="mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
m = round(m*1e3)/1e3 ;
if(type=="func"){
if((m==0 || m==-0) && b!=0){
if(b>0)
cout << "y = " << round(b*1e3)/1e3 << endl;
if(b<0)
cout << "y = " << round(b*1e3)/1e3 << endl;
}
else if(b==0 && m!=0){
if(m==1){
cout << "y = x" << endl;
}
else if(m==-1){
cout << "y = -x" << endl;
}
else{
cout << "y = " << round(m*1e3)/1e3 << "x" << endl;
}
}
else if(m==0 && b==0){
cout << "y = 0" << endl;
}
else if(m==1){
cout << "y = x" ;
if(b>0) cout << " + " << round(b*1e3)/1e3 << endl;
if(b<0) cout << " - " << abs(round(b*1e3)/1e3) << endl;
}
else if(m==-11){
cout << "y = -x" ;
if(b>0) cout << " + " << round(b*1e3)/1e3 << endl;
if(b<0) cout << " - " << abs(round(b*1e3)/1e3) << endl;
}
else if((m!=0 || m!=-0) && b!=0){
cout << "y = " ;
if(m==1 || m==-1){
if(m==1){
cout << "x" ;
}
if(m==-1){
cout << "-x";
}
}
else {
cout << round(m*1e3)/1e3 << "x" ;
}
if(b>0) cout << " + " << round(b*1e3)/1e3 << endl;
if(b<0) cout << " - " << abs(round(b*1e3)/1e3) << endl;
}
}
} |
# 0490, 2024-11-02 13:06:59, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
string op;
cin >> N >> op;
vector<pair<float,float>> points;
float x,y;
for(int i = 0;i < N;i++){
cin >> x >> y;
points.push_back(make_pair(x,y));
}
float m,b;
float sum1 = 0,sum2 = 0,sum3 = 0,sum4 = 0,sum5 = 0;
for(int i = 0;i <N;i++){
sum1 += points[i].first*points[i].second;
sum2+=points[i].first;
sum3+=points[i].second;
sum4+=(points[i].first)*(points[i].first);
sum5+=(points[i].first);
}
sum1*=N;
sum4*=N;
sum5*=sum5;
m = (sum1-(sum2*sum3))/(sum4-sum5);
b = (sum3-(m*sum2))/N;
if(op == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
}
else {
cout << "y = ";
if(m == 0&&b==0)cout << "0" << endl;
else if(m == 0)cout << round(b*1e3)/1e3 << endl;
else if(b == 0){
if(m == 1)cout << "x" << endl;
else if(m == -1)cout << "-x" << endl;
else cout << round(m*1e3)/1e3 << "x" << endl;
}
else{
if(m == 1)cout << "x";
else if(m == -1)cout << "-x";
else{
cout << round(m*1e3)/1e3 << "x" ;
}
if(b<0) cout << " - " << round(abs(b)*1e3)/1e3 << endl;
else cout << " + " << round(b*1e3)/1e3 << endl;
}
}
return 0;
} | # 0491, 2024-11-02 14:16:05, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
string op;
cin >> N >> op;
vector<pair<float,float>> points;
float x,y;
for(int i = 0;i < N;i++){
cin >> x >> y;
points.push_back(make_pair(x,y));
}
float m,b;
float sum1 = 0,sum2 = 0,sum3 = 0,sum4 = 0,sum5 = 0;
for(int i = 0;i <N;i++){
sum1 += points[i].first*points[i].second;
sum2+=points[i].first;
sum3+=points[i].second;
sum4+=(points[i].first)*(points[i].first);
sum5+=(points[i].first);
}
sum1*=N;
sum4*=N;
sum5*=sum5;
m = (sum1-(sum2*sum3))/(sum4-sum5);
b = (sum3-(m*sum2))/N;
if(abs(round(m*1e3)/1e3)==0)m = 0;
if(abs(round(b*1e3)/1e3)==0)b = 0;
if(op == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
}
else {
cout << "y = ";
if(m == 0&&b==0)cout << "0" << endl;
else if(m == 0)cout << round(b*1e3)/1e3 << endl;
else if(b == 0){
if(m == 1)cout << "x" << endl;
else if(m == -1)cout << "-x" << endl;
else cout << round(m*1e3)/1e3 << "x" << endl;
}
else{
if(m == 1)cout << "x";
else if(m == -1)cout << "-x";
else{
cout << round(m*1e3)/1e3 << "x" ;
}
if(b<0) cout << " - " << round(abs(b)*1e3)/1e3 << endl;
else cout << " + " << round(b*1e3)/1e3 << endl;
}
}
return 0;
} | # 0492, 2024-11-02 14:18:15, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
string op;
cin >> N >> op;
vector<pair<float,float>> points;
float x,y;
for(int i = 0;i < N;i++){
cin >> x >> y;
points.push_back(make_pair(x,y));
}
float m,b;
float sum1 = 0,sum2 = 0,sum3 = 0,sum4 = 0,sum5 = 0;
for(int i = 0;i <N;i++){
sum1 += points[i].first*points[i].second;
sum2+=points[i].first;
sum3+=points[i].second;
sum4+=(points[i].first)*(points[i].first);
sum5+=(points[i].first);
}
sum1*=N;
sum4*=N;
sum5*=sum5;
m = (sum1-(sum2*sum3))/(sum4-sum5);
b = (sum3-(m*sum2))/N;
if(abs(round(m*1e3)/1e3)==0)m = 0;
if(round(m*1e3/1e3)==1)m = 1;
if(round(m*1e3/1e3)==-1)m = -1;
if(abs(round(b*1e3)/1e3)==0)b = 0;
if(op == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
}
else {
cout << "y = ";
if(m == 0&&b==0)cout << "0" << endl;
else if(m == 0)cout << round(b*1e3)/1e3 << endl;
else if(b == 0){
if(m == 1)cout << "x" << endl;
else if(m == -1)cout << "-x" << endl;
else cout << round(m*1e3)/1e3 << "x" << endl;
}
else{
if(m == 1)cout << "x";
else if(m == -1)cout << "-x";
else{
cout << round(m*1e3)/1e3 << "x" ;
}
if(b<0) cout << " - " << round(abs(b)*1e3)/1e3 << endl;
else cout << " + " << round(b*1e3)/1e3 << endl;
}
}
return 0;
} |
# 0493, 2024-11-02 09:31:42, PPPPPPPPPP-------------- (41%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
string input;
cin >> N >> input;
float x[N],y[N];
for (int i = 0; i < N; i++)
{
cin >> x[i] >> y[i];
}
if(input == "mb"){
float a1 = 0,b1 = 0,c = 0,d = 0, e = 0;
for (int i = 0; i < N; i++)
{
a1 += x[i]*y[i];
b1 += x[i];
c += y[i];
d += pow(x[i],2);
}
e = pow(b1,2);
float m = ((N*a1)-(b1*c))/((N*d)-e);
float b = (c-(m*b1))/N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
cout << m << endl << b;
}
if(input == "func"){
float a1 = 0,b1 = 0,c = 0,d = 0, e = 0;
for (int i = 0; i < N; i++)
{
a1 += x[i]*y[i];
b1 += x[i];
c += y[i];
d += pow(x[i],2);
}
e = pow(b1,2);
float m = ((N*a1)-(b1*c))/(d-e);
float b = (c-(m*b1))/N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
cout << "y = " << m << "x + " << b;
}
} | # 0494, 2024-11-02 09:46:46, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
string input;
cin >> N >> input;
float x[N],y[N];
for (int i = 0; i < N; i++)
{
cin >> x[i] >> y[i];
}
if(input == "mb"){
float a1 = 0,b1 = 0,c = 0,d = 0, e = 0;
for (int i = 0; i < N; i++)
{
a1 += x[i]*y[i];
b1 += x[i];
c += y[i];
d += pow(x[i],2);
}
e = pow(b1,2);
float m = ((N*a1)-(b1*c))/((N*d)-e);
float b = (c-(m*b1))/N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
cout << m << endl << b;
}
if(input == "func"){
float a1 = 0,b1 = 0,c = 0,d = 0, e = 0;
for (int i = 0; i < N; i++)
{
a1 += x[i]*y[i];
b1 += x[i];
c += y[i];
d += pow(x[i],2);
}
e = pow(b1,2);
float m = ((N*a1)-(b1*c))/((N*d)-e);
float b = (c-(m*b1))/N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(m == 0 && b == 0){
cout << "y = 0";
}
else if (m == -1 && b == 0){
cout << "y = -x";
}
else if (m == 1 && b == 0){
cout << "y = " << "x";
}
else if(b == 0){
cout << "y = " << m << "x";
}
else if(m == 0){
cout << "y = " << b;
}
else if (b > 0){
if (m == 1){
cout << "y = " << "x + " << b;
}
else if (m == -1){
cout << "y = "<< "-x + " << b;
}
else {
cout << "y = " << m << "x + " << b;
}
}
else if (b < 0){
if (m == 1){
cout << "y = " << "x - " << abs(b);
}
else if (m == -1){
cout << "y = "<< "-x - " << abs(b);
}
else {
cout << "y = " << m << "x - " << abs(b);
}
}
}
} |
# 0495, 2024-11-02 09:55:17, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
int main(){
float n;
string cmd;
cin>>n>>cmd;
vector<float> x;
vector<float> y;
for(int i=0;i<n;i++){
float X,Y;
cin>>X>>Y;
x.push_back(X);
y.push_back(Y);
}
float m=0,b=0;
float zx=0,zy=0,zx2=0,zxy=0;
for(auto itrx=x.begin(),itry=y.begin();itrx!=x.end();itrx++,itry++){
zx+=*itrx;
zy+=*itry;
zx2+=(*itrx)*(*itrx);
zxy+=(*itrx)*(*itry);
}
m=(n*zxy-(zx*zy))/((n*zx2)-(zx*zx));
b=(zy-m*zx)/n;
if(cmd=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else{
if(m==0&&b==0)cout<<"y = 0";
else if(m==0)cout<<"y = "<<round(b*1e3)/1e3;
else if(m==1&&b==0)cout<<"y = x";
else if(m==-1&&b==0)cout<<"y = -x";
else if(m==1&&b>0)cout<<"y = x + "<<round(b*1e3)/1e3;
else if(m==-1&&b>0)cout<<"y = -x + "<<round(b*1e3)/1e3;
else if(m==1&&b<0)cout<<"y = x - "<<abs(round(b*1e3)/1e3);
else if(m==-1&&b<0)cout<<"y = -x - "<<abs(round(b*1e3)/1e3);
else if(b>0)cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
else cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);
}
} | # 0496, 2024-11-02 10:00:56, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<bits/stdc++.h>
using namespace std;
int main(){
float n;
string cmd;
cin>>n>>cmd;
vector<float> x;
vector<float> y;
for(int i=0;i<n;i++){
float X,Y;
cin>>X>>Y;
x.push_back(X);
y.push_back(Y);
}
float m=0,b=0;
float zx=0,zy=0,zx2=0,zxy=0;
for(auto itrx=x.begin(),itry=y.begin();itrx!=x.end();itrx++,itry++){
zx+=*itrx;
zy+=*itry;
zx2+=(*itrx)*(*itrx);
zxy+=(*itrx)*(*itry);
}
m=(n*zxy-(zx*zy))/((n*zx2)-(zx*zx));
b=(zy-m*zx)/n;
float roundm=round(m*1e3)/1e3;
float roundb=round(b*1e3)/1e3;
if(cmd=="mb"){
cout<<round(m*1e3)/1e3<<endl<<roundb;
}else{
if(roundm==0&&b==0)cout<<"y = 0";
else if(roundm==0)cout<<"y = "<<roundb;
else if(roundm==1&&b==0)cout<<"y = x";
else if(roundm==-1&&b==0)cout<<"y = -x";
else if(roundm==1&&b>0)cout<<"y = x + "<<roundb;
else if(roundm==-1&&b>0)cout<<"y = -x + "<<roundb;
else if(roundm==1&&b<0)cout<<"y = x - "<<abs(roundb);
else if(roundm==-1&&b<0)cout<<"y = -x - "<<abs(roundb);
else if(b>0)cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<roundb;
else cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<abs(roundb);
}
} |
# 0497, 2024-11-02 13:32:58, PPPPPPPPPPPPPPPPPPPP-PPP (95%)
#include<bits/stdc++.h>
using namespace std;
float sum1(float N, map<float,float> mx, map<float, float> my){
float total=0;
for(int i=1; i<=N; i++){
total+=mx[i]*my[i];
}
return total;
}
float sum2(float N, map<float,float> m1){
float total=0;
for(int i=1; i<=N; i++){
total+=m1[i]*m1[i];
}
return total;
}
float sum3(float N, map<float,float> mx){
float total=0;
for(int i=1; i<=N; i++){
total+=mx[i];
}
return total;
}
int main(){
float N;
string kind;
cin >> N >> kind;
float size=N;
float xi, yi;
map<float, float> mx, my;
int i=1;
while(N--){
cin >> xi >> yi;
mx[i]=xi;
my[i]=yi;
i++;
}
float m=((size*sum1(size, mx, my))-(sum3(size, mx)*sum3(size, my)))/((size*sum2(size,mx))-(sum3(size,mx)*sum3(size,mx)));
float b=((sum3(size, my))-(m*(sum3(size,mx))))/size;
m=round(m * 1e3)/1e3;
b=round(b * 1e3)/1e3;
if(kind=="func"){
if(m==0&&b==0){
cout << "y = 0" << endl;
}
else if(m==0){
cout << "y = " << b << endl;
}
else if(b==0){
if(m==1){
cout << "y = x" << endl;
}
else if(m==-1){
cout << "y = -x" << endl;
}
else{
cout << "y = " << m << "x" << endl;
}
}
else{
if(m==1 && b<0){
cout << "y = x - " << (-1)*b << endl;
}
else if(m==1 && b>0){
cout << "y = x + " << b << endl;
}
else if(m==-1 && b<0){
cout << "y = -x - " << (-1)*b << endl;
}
else if(m==-1 && b>0){
cout << "y = x + " << b << endl;
}
else{
if(b<0){
cout << "y = " << m << "x - " << (-1)*b << endl;
}
else if(b>0){
cout << "y = " << m << "x + " << b << endl;
}
}
}
}
else{
cout << m << endl << b << endl;
}
} | # 0498, 2024-11-02 14:27:18, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<bits/stdc++.h>
using namespace std;
float sum1(float N, map<float,float> mx, map<float, float> my){
float total=0;
for(int i=1; i<=N; i++){
total+=mx[i]*my[i];
}
return total;
}
float sum2(float N, map<float,float> m1){
float total=0;
for(int i=1; i<=N; i++){
total+=m1[i]*m1[i];
}
return total;
}
float sum3(float N, map<float,float> mx){
float total=0;
for(int i=1; i<=N; i++){
total+=mx[i];
}
return total;
}
int main(){
float N;
string kind;
cin >> N >> kind;
float size=N;
float xi, yi;
map<float, float> mx, my;
int i=1;
while(N--){
cin >> xi >> yi;
mx[i]=xi;
my[i]=yi;
i++;
}
float m=((size*sum1(size, mx, my))-(sum3(size, mx)*sum3(size, my)))/((size*sum2(size,mx))-(sum3(size,mx)*sum3(size,mx)));
float b=((sum3(size, my))-(m*(sum3(size,mx))))/size;
m=round(m * 1e3)/1e3;
b=round(b * 1e3)/1e3;
if(kind=="func"){
if(m==0&&b==0){
cout << "y = 0" << endl;
}
else if(m==0){
cout << "y = " << b << endl;
}
else if(b==0){
if(m==1){
cout << "y = x" << endl;
}
else if(m==-1){
cout << "y = -x" << endl;
}
else{
cout << "y = " << m << "x" << endl;
}
}
else{
if(m==1 && b<0){
cout << "y = x - " << (-1)*b << endl;
}
else if(m==1 && b>0){
cout << "y = x + " << b << endl;
}
else if(m==-1 && b<0){
cout << "y = -x - " << (-1)*b << endl;
}
else if(m==-1 && b>0){
cout << "y = -x + " << b << endl;
}
else{
if(b<0){
cout << "y = " << m << "x - " << (-1)*b << endl;
}
else if(b>0){
cout << "y = " << m << "x + " << b << endl;
}
}
}
}
else{
cout << m << endl << b << endl;
}
} |
# 0499, 2024-11-02 10:47:42, PPPPPPPPPPPPPPPPPP-PPPPP (95%)
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>
using namespace std;
float singma(const vector<float> &data){
float sum=0;
for(int i=0;i<data.size();i++){
sum+=data[i];
} return sum;
}
int main(){
float x,y;
int n;
string cmd;
vector<float> datax,datay;
float m,m1=0,m2=0,m3=0,m4=0,b;
cin>>n>>cmd;
for(int i=0;i<n;i++){
cin>>x>>y;
datax.push_back(x);
datay.push_back(y);
}
float sum=0;
for(int i=0;i<n;i++){
sum+=datax[i]*datay[i];
}m1=n*sum;
m2=singma(datax)*singma(datay);
sum=0;
for(int i=0;i<n;i++){
sum+=datax[i]*datax[i];
}m3=n*sum;
m4=singma(datax)*singma(datax);
m=(m1-m2)/(m3-m4);
b=(singma(datay)-(m*singma(datax)))/n;
if(cmd == "mb"){
cout<< round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else{
if(round(m*1e3)/1e3==0) cout<<"y = "<<b;
else if(round(b*1e3)/1e3==0 && round(m*1e3)/1e3!=-1) cout<<"y = "<<round(m*1e3)/1e3<<"x";
else if(round(b*1e3)/1e3==0 && round(m*1e3)/1e3==-1) cout<<"y = -x";
else if(round(m*1e3)/1e3==1 && round(b*1e3)/1e3>0) cout<<"y = x + "<<round(b*1e3)/1e3;
else if(round(m*1e3)/1e3==1 && round(b*1e3)/1e3<0) cout<<"y = x - "<<abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3==-1 && round(b*1e3)/1e3>0) cout<<"y = -x + "<<round(b*1e3)/1e3;
else if(round(m*1e3)/1e3==-1 && round(b*1e3)/1e3<0) cout<<"y = -x - "<<abs(round(b*1e3)/1e3);
else if(round(b*1e3)/1e3>0) cout<<"y = "<<round(m*1e3)/1e3<<"x"<<" + "<<round(b*1e3)/1e3;
else if(round(b*1e3)/1e3<0) cout<<"y = "<<round(m*1e3)/1e3<<"x"<<" - "<<abs(round(b*1e3)/1e3);
}
} | # 0500, 2024-11-02 10:50:48, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>
using namespace std;
float singma(const vector<float> &data){
float sum=0;
for(int i=0;i<data.size();i++){
sum+=data[i];
} return sum;
}
int main(){
float x,y;
int n;
string cmd;
vector<float> datax,datay;
float m,m1=0,m2=0,m3=0,m4=0,b;
cin>>n>>cmd;
for(int i=0;i<n;i++){
cin>>x>>y;
datax.push_back(x);
datay.push_back(y);
}
float sum=0;
for(int i=0;i<n;i++){
sum+=datax[i]*datay[i];
}m1=n*sum;
m2=singma(datax)*singma(datay);
sum=0;
for(int i=0;i<n;i++){
sum+=datax[i]*datax[i];
}m3=n*sum;
m4=singma(datax)*singma(datax);
m=(m1-m2)/(m3-m4);
b=(singma(datay)-(m*singma(datax)))/n;
if(cmd == "mb"){
cout<< round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else{
if(round(m*1e3)/1e3==0) cout<<"y = "<<b;
else if(round(b*1e3)/1e3==0 && round(m*1e3)/1e3==-1) cout<<"y = -x";
else if(round(b*1e3)/1e3==0 && round(m*1e3)/1e3==1) cout<<"y = x";
else if(round(b*1e3)/1e3==0 ) cout<<"y = "<<round(m*1e3)/1e3<<"x";
else if(round(m*1e3)/1e3==1 && round(b*1e3)/1e3>0) cout<<"y = x + "<<round(b*1e3)/1e3;
else if(round(m*1e3)/1e3==1 && round(b*1e3)/1e3<0) cout<<"y = x - "<<abs(round(b*1e3)/1e3);
else if(round(m*1e3)/1e3==-1 && round(b*1e3)/1e3>0) cout<<"y = -x + "<<round(b*1e3)/1e3;
else if(round(m*1e3)/1e3==-1 && round(b*1e3)/1e3<0) cout<<"y = -x - "<<abs(round(b*1e3)/1e3);
else if(round(b*1e3)/1e3>0) cout<<"y = "<<round(m*1e3)/1e3<<"x"<<" + "<<round(b*1e3)/1e3;
else if(round(b*1e3)/1e3<0) cout<<"y = "<<round(m*1e3)/1e3<<"x"<<" - "<<abs(round(b*1e3)/1e3);
}
} |
# 0501, 2024-11-02 13:28:30, PPPPPPPPPP-----P--PP-P-- (58%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main()
{
vector<float> x,y;
string key;
int N;
float xin,yin,mtopl=0,mtopL,mx=0,my=0,mbotl=0,mbotr=0,mbotL,mbotR,m,b;
cin >> N >> key;
for (int i = 0; i < N; i++)
{
cin >> xin >> yin;
mtopl += xin*yin;
mx += xin;
my += yin;
mbotl += pow(xin,2);
mbotr += xin;
x.push_back(xin);
y.push_back(yin);
}
mtopL = mtopl*N;
mbotL = mbotl*N;
mbotR = pow(mbotr,2);
//find m,b
m = (mtopL - mx*my)/(mbotL - mbotR);
b = (my - (m*mx)) / N;
if(key == "mb")
{
cout << round(m*1e3) /1e3 << endl;
cout << round(b*1e3) /1e3;
}
else if(key == "func")
{
if(m==1)
{
if(b == 0) cout << "y = x";
else if(b*-1 > 0) // b is negative
{
cout << "y = x - " << -b;
}
else if(b*-1 < 0) // b is positive
{
cout << "y = x + " << b;
}
}
else if(m==-1)
{
if(b == 0) cout << "y = -x";
else if(b*-1 > 0) // b is negative
{
cout << "y = -x - " << -b;
}
else if(b*-1 < 0) // b is positive
{
cout << "y = -x + " << b;
}
}
else if(m==0 || m == -0)
{
if(b == 0) cout << "y = 0";
else if(b*-1 > 0) // b is negative
{
cout << "y = " << b;
}
else if(b*-1 < 0) // b is positive
{
cout << "y = " << b;
}
}
else
{
if(b == 0) cout << "y = " << m << "x";
else if(b*-1 > 0) // b is negative
{
cout << "y = " << m << "x - " << -b;
}
else if(b*-1 < 0) // b is positive
{
cout << "y = " << m << "x + " << b;
}
}
}
return 0;
} | # 0502, 2024-11-02 13:34:59, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main()
{
vector<float> x,y;
string key;
int N;
float xin,yin,mtopl=0,mtopL,mx=0,my=0,mbotl=0,mbotr=0,mbotL,mbotR,m,b,M,B;
cin >> N >> key;
for (int i = 0; i < N; i++)
{
cin >> xin >> yin;
mtopl += xin*yin;
mx += xin;
my += yin;
mbotl += pow(xin,2);
mbotr += xin;
x.push_back(xin);
y.push_back(yin);
}
mtopL = mtopl*N;
mbotL = mbotl*N;
mbotR = pow(mbotr,2);
//find m,b
M = (mtopL - mx*my)/(mbotL - mbotR);
B = (my - (M*mx)) / N;
m = round(M*1e3) /1e3;
b = round(B*1e3) /1e3;
if(key == "mb")
{
cout << m << endl;
cout << b ;
}
else if(key == "func")
{
if(m==1)
{
if(b == 0) cout << "y = x";
else if(b*-1 > 0) // b is negative
{
cout << "y = x - " << -b;
}
else if(b*-1 < 0) // b is positive
{
cout << "y = x + " << b;
}
}
else if(m==-1)
{
if(b == 0) cout << "y = -x";
else if(b*-1 > 0) // b is negative
{
cout << "y = -x - " << -b;
}
else if(b*-1 < 0) // b is positive
{
cout << "y = -x + " << b;
}
}
else if(m==0 || m == -0)
{
if(b == 0) cout << "y = 0";
else if(b*-1 > 0) // b is negative
{
cout << "y = " << b;
}
else if(b*-1 < 0) // b is positive
{
cout << "y = " << b;
}
}
else
{
if(b == 0) cout << "y = " << m << "x";
else if(b*-1 > 0) // b is negative
{
cout << "y = " << m << "x - " << -b;
}
else if(b*-1 < 0) // b is positive
{
cout << "y = " << m << "x + " << b;
}
}
}
return 0;
} |
# 0503, 2024-11-02 10:05:44, PPPPPPPPPP-----P-------- (45%)
#include<iostream>
#include<map>
#include<vector>
#include<utility>
#include<cmath>
#define f(x) (x).first
#define s(x) (x).second
using namespace std;
int main(){
int n =0; string s;
cin >> n >> s;
vector<pair<float,float>> v;
if(s == "mb" || s == "func"){
for(int i =0; i < n; ++i){
float x,y;
cin >> x >> y;
v.push_back(make_pair(x,y));
}
float sum1=0,sum2=0,sum3 =0,sum4 =0,sum5=0, b1 =0, b2 =0;
for(int i =0; i <=n;++i){
sum1 += f(v[i]) * s(v[i]);
sum2 += f(v[i]);
sum3 += s(v[i]);
sum4 += f(v[i]) *f(v[i]);
sum5 += f(v[i]);
b1 += s(v[i]);
b2 += f(v[i]);
}
sum1 *= n;
sum4 *= n;
sum5 = sum5 *sum5;
float m = (sum1 - (sum2*sum3))/ (sum4 - sum5);
b2 *= m;
float b = (b1 - b2)/n;
if(s == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else{
cout << "y = " << round(m*1e3)/1e3;
if(b == 0) return 0;
if(round(b*1e3)/1e3 <0){
cout << " - ";
b *= -1;
}
cout << round(b*1e3)/1e3 << endl;
}
}
} | # 0504, 2024-11-02 10:14:00, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<iostream>
#include<map>
#include<vector>
#include<utility>
#include<cmath>
#define f(x) (x).first
#define s(x) (x).second
using namespace std;
int main(){
int n =0; string s;
cin >> n >> s;
vector<pair<float,float>> v;
if(s == "mb" || s == "func"){
for(int i =0; i < n; ++i){
float x,y;
cin >> x >> y;
v.push_back(make_pair(x,y));
}
float sum1=0,sum2=0,sum3 =0,sum4 =0,sum5=0, b1 =0, b2 =0;
for(int i =0; i <=n;++i){
sum1 += f(v[i]) * s(v[i]);
sum2 += f(v[i]);
sum3 += s(v[i]);
sum4 += f(v[i]) *f(v[i]);
sum5 += f(v[i]);
b1 += s(v[i]);
b2 += f(v[i]);
}
sum1 *= n;
sum4 *= n;
sum5 = sum5 *sum5;
float m = (sum1 - (sum2*sum3))/ (sum4 - sum5);
b2 *= m;
float b = (b1 - b2)/n;
if(s == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else{
cout << "y = " ;
if(round(m*1e3)/1e3 == 1) cout << "x";
else if(round(m*1e3)/1e3 == -1) cout << "-x";
else if(round(m*1e3)/1e3 != 0) cout << round(m*1e3)/1e3 << "x";
else if(round(m*1e3)/1e3 == 0){
cout << round(b*1e3)/1e3 << endl;
return 0;
}
if(b == 0) return 0;
if(round(b*1e3)/1e3 <0){
cout << " - ";
b *= -1;
}else{
cout << " + " ;
}
cout << round(b*1e3)/1e3 << endl;
}
}
} |
# 0505, 2024-11-02 13:36:09, PPPPPPPPPPPPPPPPPPPPP-PP (95%)
#include<bits/stdc++.h>
using namespace std;
double m(int n,vector<double>x,vector<double>y){
double first=0,second=0,third=0,fourth=0,fifth=0;
for (int i = 0; i < n; i++){
first+=x[i]*y[i];
second+=x[i];
third+=y[i];
fourth +=pow(x[i],2);
fifth +=x[i];
}
return (n*first - (second*third))/((n*fourth)-(pow(fifth,2)));
}
double b(int n,vector<double>x,vector<double>y){
double first=0 ,second=0;
for (int i = 0; i < n; i++){
first +=y[i];
second += x[i];
}
return (first -(m(n,x,y)*second))/n;
}
int main(){
int n;
string cmd;
cin>>n>>cmd;
vector<double>x;
vector<double> y;
double in1,in2;
for(int i =0; i<n;i++){
cin>>in1>>in2;
x.push_back(in1);
y.push_back(in2);
}
if (cmd=="mb"){
cout <<round(m(n,x,y)*1e3)/1e3<<endl;
cout<< round(b(n,x,y)*1e3)/1e3<<endl;
}
else{
double M = round(m(n,x,y)*1e3)/1e3;
double B = round(b(n,x,y)*1e3)/1e3;
string x;
if (M==0){
if (B>=0){
cout<<"y = "<<B;
}
else{
cout<<"y = "<<"- "<<abs(B);
}
}else if(M==1){
if (B>0){
cout<<"y = x "<<"+ "<<B;
}
else if(B==0) cout<<"y = x";
else{
cout<<"y = x "<<"- "<<abs(B);
}
}else if(M==-1){
if (B>0){
cout<<"y = -x "<<"+ "<<B;
}
else if(B==0) cout<<"y = -x";
else{
cout<<"y = -x "<<"- "<<abs(B);
}
}
else{
if (M>0){
cout<<"y = "<<M<<"x ";
if (B>0){
cout<<"+ "<<B;
}
else if(B <0){
cout<<"- "<<abs(B);
}
}
else{
cout<<"y = "<<M<<"x ";
if (B>0){
cout<<"+ "<<B;
}
else if(B <0){
cout<<"- "<<abs(B);
}
}
}
}
} | # 0506, 2024-11-02 13:37:12, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<bits/stdc++.h>
using namespace std;
double m(int n,vector<double>x,vector<double>y){
double first=0,second=0,third=0,fourth=0,fifth=0;
for (int i = 0; i < n; i++){
first+=x[i]*y[i];
second+=x[i];
third+=y[i];
fourth +=pow(x[i],2);
fifth +=x[i];
}
return (n*first - (second*third))/((n*fourth)-(pow(fifth,2)));
}
double b(int n,vector<double>x,vector<double>y){
double first=0 ,second=0;
for (int i = 0; i < n; i++){
first +=y[i];
second += x[i];
}
return (first -(m(n,x,y)*second))/n;
}
int main(){
int n;
string cmd;
cin>>n>>cmd;
vector<double>x;
vector<double> y;
double in1,in2;
for(int i =0; i<n;i++){
cin>>in1>>in2;
x.push_back(in1);
y.push_back(in2);
}
if (cmd=="mb"){
cout <<round(m(n,x,y)*1e3)/1e3<<endl;
cout<< round(b(n,x,y)*1e3)/1e3<<endl;
}
else{
double M = round(m(n,x,y)*1e3)/1e3;
double B = round(b(n,x,y)*1e3)/1e3;
string x;
if (M==0){
if (B>=0){
cout<<"y = "<<B;
}
else{
cout<<"y = "<<"-"<<abs(B);
}
}else if(M==1){
if (B>0){
cout<<"y = x "<<"+ "<<B;
}
else if(B==0) cout<<"y = x";
else{
cout<<"y = x "<<"- "<<abs(B);
}
}else if(M==-1){
if (B>0){
cout<<"y = -x "<<"+ "<<B;
}
else if(B==0) cout<<"y = -x";
else{
cout<<"y = -x "<<"- "<<abs(B);
}
}
else{
if (M>0){
cout<<"y = "<<M<<"x ";
if (B>0){
cout<<"+ "<<B;
}
else if(B <0){
cout<<"- "<<abs(B);
}
}
else{
cout<<"y = "<<M<<"x ";
if (B>0){
cout<<"+ "<<B;
}
else if(B <0){
cout<<"- "<<abs(B);
}
}
}
}
} |
# 0507, 2024-11-02 10:16:09, PPPPPPPPPPPPPPPPPPP-PPPP (95%)
#include<iostream>
#include<vector>
#include<cmath>
#include<utility>
#include<string>
int main(){
float x, y;
std::vector<std::pair<float, float>> xy;
int n;
std::string condition;
std::cin >> n >> condition;
int round1 = n;
while(round1--){
std::cin >> x >> y;
xy.push_back({x, y});
}
float x_y = 0, xi = 0, yi = 0, x_2 = 0;
for(auto &p : xy){
x_y += (p.first*p.second);
xi+= p.first;
yi += p.second;
x_2 += (pow(p.first, 2));
}
float m = ((n*x_y)-(xi*yi))/((n*x_2)-(pow(xi, 2)));
float b = (yi - m*xi)/n;
//std::cout << m << std::endl << b <<std::endl;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(condition == "mb"){
std::cout << m << std::endl << b;
}else{
if(m==0 && b==0){
std::cout << "y = 0";
}else if(m == 0 && b != 0){
if(b < 0){
std::cout << "y = -" << -b;
}else{
std::cout << "y = " << b;
}
}else if(m != 0 && b == 0){
if(m != -1 && m != 1){
std::cout << "y = " << m << "x";
}else{
if(y == -1){
std::cout << "y = -x";
}else{
std::cout << "y = x";
}
}
}else if(m != 0 && b != 0){
if(m != 1 && m != -1){
if(b < 0){
std::cout << "y = " << m << "x - " << -b;
}else{
std::cout << "y = " << m << "x + " << b;
}
}else{
if(m == 1){
if(b < 0){
std::cout << "y = x - " << -b;
}else{
std::cout << "y = x + " << b;
}
}else{
if(b < 0){
std::cout << "y = -x - " << -b;
}else{
std::cout << "y = -x + " << b;
}
}
}
}
}
} | # 0508, 2024-11-02 10:18:04, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<iostream>
#include<vector>
#include<cmath>
#include<utility>
#include<string>
int main(){
float x, y;
std::vector<std::pair<float, float>> xy;
int n;
std::string condition;
std::cin >> n >> condition;
int round1 = n;
while(round1--){
std::cin >> x >> y;
xy.push_back({x, y});
}
float x_y = 0, xi = 0, yi = 0, x_2 = 0;
for(auto &p : xy){
x_y += (p.first*p.second);
xi+= p.first;
yi += p.second;
x_2 += (pow(p.first, 2));
}
float m = ((n*x_y)-(xi*yi))/((n*x_2)-(pow(xi, 2)));
float b = (yi - m*xi)/n;
//std::cout << m << std::endl << b <<std::endl;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(condition == "mb"){
std::cout << m << std::endl << b;
}else{
if(m==0 && b==0){
std::cout << "y = 0";
}else if(m == 0 && b != 0){
if(b < 0){
std::cout << "y = -" << -b;
}else{
std::cout << "y = " << b;
}
}else if(m != 0 && b == 0){
if(m != -1 && m != 1){
std::cout << "y = " << m << "x";
}else{
if(m == -1){
std::cout << "y = -x";
}else{
std::cout << "y = x";
}
}
}else if(m != 0 && b != 0){
if(m != 1 && m != -1){
if(b < 0){
std::cout << "y = " << m << "x - " << -b;
}else{
std::cout << "y = " << m << "x + " << b;
}
}else{
if(m == 1){
if(b < 0){
std::cout << "y = x - " << -b;
}else{
std::cout << "y = x + " << b;
}
}else{
if(b < 0){
std::cout << "y = -x - " << -b;
}else{
std::cout << "y = -x + " << b;
}
}
}
}
}
} |
# 0509, 2024-11-02 10:11:18, PPPPPPPPPPP-P--PPPPPPP-- (79%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
string s;
cin >> N >> s;
vector<pair<float, float>> sth(N);
for(int i=0; i<N; i++){
float a, b;
cin >> sth[i].first >> sth[i].second;
}
float xy = 0, sumX = 0, sumY = 0, sumX2 = 0;
for(int i=0; i<N; i++){
xy += (sth[i].first * sth[i].second);
sumX += sth[i].first;
sumY += sth[i].second;
sumX2 += (sth[i].first * sth[i].first);
}
float m = (N*xy - sumX*sumY) / (N*sumX2 - sumX*sumX);
float b = (sumY - m*sumX) / N;
if(s == "mb"){
cout << (round(m*1e3)/1e3) << "\n" << (round(b*1e3)/1e3);
}else{
cout << "y = ";
if(round(m*1e3)/1e3 != 0.000){
if(fabs(round(m*1e3)/1e3) != 1.0){ cout << (round(m*1e3)/1e3); }
else if(round(m*1e3)/1e3 < 0.000){ cout << "-";}
cout << "x ";
if((round(b*1e3)/1e3) > 0.000){
cout << "+ " << (round(b*1e3)/1e3);
}else if((round(b*1e3)/1e3) < 0.000){
cout << (round(b*1e3)/1e3);
}
}else{
cout << (round(b*1e3)/1e3);
}
}
} | # 0510, 2024-11-02 12:02:27, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
string s;
cin >> N >> s;
vector<pair<float, float>> sth(N);
for(int i=0; i<N; i++){
float a, b;
cin >> sth[i].first >> sth[i].second;
}
float xy = 0, sumX = 0, sumY = 0, sumX2 = 0;
for(int i=0; i<N; i++){
xy += (sth[i].first * sth[i].second);
sumX += sth[i].first;
sumY += sth[i].second;
sumX2 += (sth[i].first * sth[i].first);
}
float m = (N*xy - sumX*sumY) / (N*sumX2 - sumX*sumX);
float b = (sumY - m*sumX) / N;
if(s == "mb"){
cout << (round(m*1e3)/1e3) << "\n" << (round(b*1e3)/1e3);
}else{
cout << "y = ";
if(round(m*1e3)/1e3 != 0.000){
if(fabs(round(m*1e3)/1e3) != 1.0){ cout << (round(m*1e3)/1e3); }
else if(round(m*1e3)/1e3 < 0.000){ cout << "-";}
cout << "x ";
if((round(b*1e3)/1e3) > 0.000){
cout << "+ " << (round(b*1e3)/1e3);
}else if((round(b*1e3)/1e3) < 0.000){
cout << "- " << fabs(round(b*1e3)/1e3);
}
}else{
cout << (round(b*1e3)/1e3);
}
}
} |
# 0511, 2024-11-02 13:08:03, -----PPPPP-----PPPPPPPPP (58%)
#include <iostream>
#include <cmath>
float m,b,X,Y;
int N;
std::string command;
float sumX, sumY, sumXY, sumXs;
int main()
{
std::cin >> N >> command;
for (int i = 0; i < N; i++)
{
std::cin >> X >> Y;
sumX += X;
sumY += Y;
sumXY += X*Y;
sumXs += X*X;
}
float ansM = ((N*sumXY) - sumX * sumY)/(N*sumXs - sumX*sumX);
ansM = round(ansM * 1e3)/1e3;
float ansB = (sumY - ansM * sumX)/(N);
ansB = round(ansB * 1e3)/1e3;
if (command == "mb")
{
std::cout << ansM << "\n" << ansB;
}
else if (command == "func")
{
std::cout << "y = ";
if (ansM == 0 && ansB == 0)
{
std::cout << "0";
}
else if (ansM == 0)
{
std::cout << ansB;
}
else if (ansB == 0)
{
if (ansM == 1)
{
std::cout << "x ";
}
else if (ansM == -1)
{
std::cout << "-x ";
}
else
{
std::cout << ansM << "x ";
}
}
else if (ansM != 0 && ansB != 0)
{
if (ansM == 1)
{
std::cout << "x ";
}
else if (ansM == -1)
{
std::cout << "-x ";
}
else
{
std::cout << ansM << "x ";
}
if (ansB > 0)
{
std::cout << "+ " << ansB;
}
else if (ansB < 0)
{
std::cout << "- " << -ansB;
}
}
}
} | # 0512, 2024-11-02 13:11:36, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <iostream>
#include <cmath>
float m,b,X,Y;
int N;
std::string command;
float sumX, sumY, sumXY, sumXs;
int main()
{
std::cin >> N >> command;
for (int i = 0; i < N; i++)
{
std::cin >> X >> Y;
sumX += X;
sumY += Y;
sumXY += X*Y;
sumXs += X*X;
}
float ansM = ((N*sumXY) - sumX * sumY)/(N*sumXs - sumX*sumX);
float ansB = (sumY - ansM * sumX)/(N);
ansM = round(ansM * 1e3)/1e3;
ansB = round(ansB * 1e3)/1e3;
if (command == "mb")
{
std::cout << ansM << "\n" << ansB;
}
else if (command == "func")
{
std::cout << "y = ";
if (ansM == 0 && ansB == 0)
{
std::cout << "0";
}
else if (ansM == 0)
{
std::cout << ansB;
}
else if (ansB == 0)
{
if (ansM == 1)
{
std::cout << "x ";
}
else if (ansM == -1)
{
std::cout << "-x ";
}
else
{
std::cout << ansM << "x ";
}
}
else if (ansM != 0 && ansB != 0)
{
if (ansM == 1)
{
std::cout << "x ";
}
else if (ansM == -1)
{
std::cout << "-x ";
}
else
{
std::cout << ansM << "x ";
}
if (ansB > 0)
{
std::cout << "+ " << ansB;
}
else if (ansB < 0)
{
std::cout << "- " << -ansB;
}
}
}
} |
# 0513, 2024-11-02 09:54:00, PPPPPPPPPPPPPPPPPPPPPP-- (91%)
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
float sigma (vector <float> a, int n) {
float sum = 0;
for (int i = 0; i < n; i++) {
sum += a[i];
}
return sum;
}
int main () {
int n;
string cmd;
vector <float> x, y;
cin >> n >> cmd;
for (int i = 0; i < n; i++) {
float xi, yi;
cin >> xi >> yi;
x.push_back(xi);
y.push_back(yi);
}
vector <float> xy, xp2;
for (int i = 0; i < n; i++) {
xy.push_back(x[i] * y[i]);
xp2.push_back(x[i] * x[i]);
}
float m = ((n * sigma(xy, n)) - (sigma(x, n) * sigma(y, n)))
/ ((n * sigma(xp2, n)) - (sigma(x, n) * sigma(x, n)));
float b = (sigma(y, n) - (m * sigma(x, n))) / n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (cmd == "mb") {
cout << m << endl;
cout << b << endl;
} else if (cmd == "func") {
cout << "y = ";
if (m == 0 || b == 0) {
if (m == 0 && b == 0) {
cout << "0" << endl;
}
if (m == 0 && b != 0) {
cout << b << endl;
}
if (m != 0 && b == 0) {
if (m == 1) {
cout << 'x' << endl;
} else if (m == -1) {
cout << "-x" << endl;
} else cout << m << 'x' << endl;
}
} else if (m == 1) {
cout << "x + " << b << endl;
} else if (m == -1) {
cout << "-x + " << b << endl;
} else if (b < 0) {
cout << m << "x - " << abs(b) << endl;
} else cout << m << "x + " << b << endl;
}
} | # 0514, 2024-11-02 09:56:23, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
float sigma (vector <float> a, int n) {
float sum = 0;
for (int i = 0; i < n; i++) {
sum += a[i];
}
return sum;
}
int main () {
int n;
string cmd;
vector <float> x, y;
cin >> n >> cmd;
for (int i = 0; i < n; i++) {
float xi, yi;
cin >> xi >> yi;
x.push_back(xi);
y.push_back(yi);
}
vector <float> xy, xp2;
for (int i = 0; i < n; i++) {
xy.push_back(x[i] * y[i]);
xp2.push_back(x[i] * x[i]);
}
float m = ((n * sigma(xy, n)) - (sigma(x, n) * sigma(y, n)))
/ ((n * sigma(xp2, n)) - (sigma(x, n) * sigma(x, n)));
float b = (sigma(y, n) - (m * sigma(x, n))) / n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (cmd == "mb") {
cout << m << endl;
cout << b << endl;
} else if (cmd == "func") {
cout << "y = ";
if (m == 0 || b == 0) {
if (m == 0 && b == 0) {
cout << "0" << endl;
}
if (m == 0 && b != 0) {
cout << b << endl;
}
if (m != 0 && b == 0) {
if (m == 1) {
cout << 'x' << endl;
} else if (m == -1) {
cout << "-x" << endl;
} else cout << m << 'x' << endl;
}
} else if (m == 1) {
if (b < 0) {
cout << "x - " << abs(b) << endl;
} else cout << "x + " << b << endl;
} else if (m == -1) {
if (b < 0) {
cout << "-x - " << abs(b) << endl;
} else cout << "-x + " << b << endl;
} else if (b < 0) {
cout << m << "x - " << abs(b) << endl;
} else cout << m << "x + " << b << endl;
}
} |
# 0515, 2024-11-02 13:18:34, PPPPPPPPPPPPPPPPPPPPP-PP (95%)
#include <bits/stdc++.h>
using namespace std;
float sum(int n, float arr[]) {
float s = 0;
for(int i = 1; i <= n; i++) {
s += arr[i];
}
return s;
}
int main() {
int n;
cin >> n;
string f;
cin >> f;
float m, b, x[n+1], y[n+1];
for(int i = 1; i <= n; i++) {
cin >> x[i] >> y[i];
}
float sumX = sum(n,x), sumY = sum(n,y);
//m
float a = 0, q = 0;
for(int i = 1; i <= n; i++) {
a += x[i] * y[i];
}
a *= n;
float upM = 0, downM = 0;
upM = a - (sumX * sumY);
for(int i = 1; i <= n; i++) {
q += x[i] * x[i];
}
q *= n;
downM = q - sumX*sumX;
m = upM / downM;
b = (sumY - (m*sumX))/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(f == "mb") {
cout << m << '\n' << b;
} else if(f == "func") {
cout << "y = ";
if(m == 0 && b == 0) {
cout << 0;
return 0;
}
if(m != 0) {
if(m == -1) {
cout << '-';
}
if(m != -1 && m != 1) {
cout << m;
}
cout << 'x';
}
if(b != 0) {
if(m != 0) {
if(b > 0)
cout << " + ";
else if(b < 0)
cout << " - ";
}
cout << abs(b);
}
}
} | # 0516, 2024-11-02 13:21:56, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
float sum(int n, float arr[]) {
float s = 0;
for(int i = 1; i <= n; i++) {
s += arr[i];
}
return s;
}
int main() {
int n;
cin >> n;
string f;
cin >> f;
float m, b, x[n+1], y[n+1];
for(int i = 1; i <= n; i++) {
cin >> x[i] >> y[i];
}
float sumX = sum(n,x), sumY = sum(n,y);
//m
float a = 0, q = 0;
for(int i = 1; i <= n; i++) {
a += x[i] * y[i];
}
a *= n;
float upM = 0, downM = 0;
upM = a - (sumX * sumY);
for(int i = 1; i <= n; i++) {
q += x[i] * x[i];
}
q *= n;
downM = q - sumX*sumX;
m = upM / downM;
b = (sumY - (m*sumX))/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(f == "mb") {
cout << m << '\n' << b;
} else if(f == "func") {
cout << "y = ";
if(m == 0 && b == 0) {
cout << 0;
return 0;
}
if(m != 0) {
if(m == -1) {
cout << '-';
}
if(m != -1 && m != 1) {
cout << m;
}
cout << 'x';
}
if(b != 0) {
if(m != 0) {
if(b > 0)
cout << " + ";
else if(b < 0)
cout << " - ";
cout << abs(b);
}
else {
cout << b;
}
}
}
} |
# 0517, 2024-11-02 13:16:31, PPPPPPPPPPPPPPP---PP---- (70%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main() {
int N;
string com;
cin >> N >> com;
vector<float> X(N+1),Y(N+1);
X[0] = 0;
Y[0] = 0;
for (int i = 1; i <= N; i++) {
float x,y;
cin >> x >> y;
X[i] = x;
Y[i] = y;
}
// for (auto e : X) cout << e << " ";
// cout << endl;
// for (auto e : Y) cout << e << " ";
// cout << endl;
float m1 = 0, m2 = 0, m3 = 0, m4 = 0, m5 = 0, M = 0, b1 = 0, b2 = 0, B = 0, m_f = 0, b_f = 0;
for (int i = 1; i <= N; i++) {
m1 += X[i] * Y[i];
m2 += X[i];
m3 += Y[i];
m4 += pow(X[i],2);
}
m1 = N * m1;
m4 = N * m4;
m5 = pow(m2,2);
M = (m1 - (m2 * m3)) / (m4 - m5);
b1 = m3;
b2 = M * m2;
B = (b1 - b2) / N;
m_f = round(M*1e3) / 1e3;
b_f = round(B*1e3) / 1e3;
if (com == "mb") {
cout << m_f << endl << b_f;
}
if (com == "func") {
cout << "y = ";
if (M == 1) cout << "x";
else if (M == -1) cout << "-x";
else cout << m_f << "x";
if (b_f < 0) cout << " - " << -1 * b_f;
else if (b_f > 0) cout << " + " << b_f;
}
return 0;
} | # 0518, 2024-11-02 13:22:37, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main() {
int N;
string com;
cin >> N >> com;
vector<float> X(N+1),Y(N+1);
X[0] = 0;
Y[0] = 0;
for (int i = 1; i <= N; i++) {
float x,y;
cin >> x >> y;
X[i] = x;
Y[i] = y;
}
// for (auto e : X) cout << e << " ";
// cout << endl;
// for (auto e : Y) cout << e << " ";
// cout << endl;
float m1 = 0, m2 = 0, m3 = 0, m4 = 0, m5 = 0, M = 0, b1 = 0, b2 = 0, B = 0, m_f = 0, b_f = 0;
for (int i = 1; i <= N; i++) {
m1 += X[i] * Y[i];
m2 += X[i];
m3 += Y[i];
m4 += pow(X[i],2);
}
m1 = N * m1;
m4 = N * m4;
m5 = pow(m2,2);
M = (m1 - (m2 * m3)) / (m4 - m5);
b1 = m3;
b2 = M * m2;
B = (b1 - b2) / N;
m_f = round(M*1e3) / 1e3;
b_f = round(B*1e3) / 1e3;
if (com == "mb") {
cout << m_f << endl << b_f;
}
if (com == "func") {
cout << "y = ";
if (m_f == 0 && b_f == 0) {
cout << "0";
return 0;
}
if (m_f == 1) cout << "x";
else if (m_f == -1) cout << "-x";
else if (m_f == 0) {
cout << b_f;
return 0;
}
else cout << m_f << "x";
if (b_f < 0) cout << " - " << -1 * b_f;
else if (b_f > 0) cout << " + " << b_f;
}
return 0;
} |
# 0519, 2024-11-02 09:42:03, -----PPPPP-----P-PPPP-PP (50%)
#include<bits/stdc++.h>
#include <cmath>
using namespace std;
int main(){
int n,cnt;string com;
cin >> n >> com;
cnt = n;
float x,y;
float sumx{0},sumy{0},sumxy{0},sumxs{0};
while(cnt--){
cin >> x >> y;
sumx += x;
sumy += y;
sumxy += x*y;
sumxs += x*x;
}
float m,b;
m = (n*sumxy-sumx*sumy)*1.0/(n*sumxs-sumx*sumx);
m = round(m*1e3)/1e3;
b = (sumy-m*sumx)*1.0/n;
b = round(b*1e3)/1e3;
if(com=="mb"){
cout << m << "\n" << b;
}else{
cout << "y = ";
if(m==0&&b==0){
cout << 0;
return 0;
}
if(m!=0){
if(m==-1) cout << "-" << "x";
else if(m!=1) cout << m << "x";
else cout << "x";
}
if(b!=0){
if(b>0) cout << " + " << b;
else cout << " - " << abs(b);
}
}
} | # 0520, 2024-11-02 09:50:32, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<bits/stdc++.h>
#include <cmath>
using namespace std;
int main(){
int n,cnt;string com;
cin >> n >> com;
cnt = n;
float x,y;
float sumx{0},sumy{0},sumxy{0},sumxs{0};
while(cnt--){
cin >> x >> y;
sumx += x;
sumy += y;
sumxy += x*y;
sumxs += x*x;
}
float m,b;
m = (n*sumxy-sumx*sumy)*1.0/(n*sumxs-sumx*sumx);
b = (sumy-m*sumx)*1.0/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(com=="mb"){
cout << m << "\n" << b;
}else{
cout << "y = ";
if(m==0&&b==0){
cout << 0;
return 0;
}
if(m!=0){
if(m==-1) cout << "-" << "x";
else if(m!=1) cout << m << "x";
else cout << "x";
}
if(b!=0){
if(b>0){
if(m!=0) cout << " + ";
cout << b;
}
else{
if(m!=0) cout << " - ";
else cout << "-";
cout << abs(b);
}
}
}
} |
# 0521, 2024-11-02 09:35:17, PPPPPPPPPPPPPPPPP----P-- (75%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,i;
vector<float> x,y;
float xi,yi,m,b,sumx=0,sumx2=0,sumy=0,sumxy=0;
string op;
cin >> n >> op;
for(i=0;i<n;i++){
cin >> xi >> yi;
x.push_back(xi);
y.push_back(yi);
}
for(i=0;i<n;i++){
sumxy=sumxy+x[i]*y[i];
sumx=sumx+x[i];
sumx2=sumx2+(x[i]*x[i]);
sumy=sumy+y[i];
}
m=((n*sumxy)-(sumx*sumy))/((n*sumx2)-sumx*sumx);
b=((sumy)-(m*sumx))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(op=="mb"){
cout << m << endl << b;
}
if(op=="func"){
if(m==0){
if(b==0){
cout << "y = 0";
}
else{
cout << "y = " << b;
}
}
else{
cout << "y = " << m << "x";
if(b>0){
cout << " + " << b;
}
if(b<0){
cout << " - " << b*-1;
}
}
}
} | # 0522, 2024-11-02 09:39:18, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,i;
vector<float> x,y;
float xi,yi,m,b,sumx=0,sumx2=0,sumy=0,sumxy=0;
string op;
cin >> n >> op;
for(i=0;i<n;i++){
cin >> xi >> yi;
x.push_back(xi);
y.push_back(yi);
}
for(i=0;i<n;i++){
sumxy=sumxy+x[i]*y[i];
sumx=sumx+x[i];
sumx2=sumx2+(x[i]*x[i]);
sumy=sumy+y[i];
}
m=((n*sumxy)-(sumx*sumy))/((n*sumx2)-sumx*sumx);
b=((sumy)-(m*sumx))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(op=="mb"){
cout << m << endl << b;
}
if(op=="func"){
if(m==0){
if(b==0){
cout << "y = 0";
}
else{
cout << "y = " << b;
}
}
else{
if(m==1){
cout << "y = " << "x";
}
if(m==-1){
cout << "y = " << "-x";
}
if(abs(m)!=1){
cout << "y = " << m << "x";
}
if(b>0){
cout << " + " << b;
}
if(b<0){
cout << " - " << b*-1;
}
}
}
} |
# 0523, 2024-11-02 14:40:48, PPPPPPPPPP-------------- (41%)
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<tuple>
#include <algorithm>
using namespace std;
void show(){
}
pair<float,float> mb(vector<pair<float,float>> data){
int N = data.size();
float xy ,x, y , xx; x=y=xx=xy=0;
for(int i = 0 ; i < N ; i++){
xy += data[i].first * data[i].second; // xy
x += data[i].first ; //x
y += data[i].second ; //y
xx += data[i].first * data[i].first ; //xx
}
float m = (N*xy - x*y)/(N*xx - x*x) ;
return { m , (y - m*x)/N };
}
void func(vector<pair<float,float>> x ){
}
int main(){
vector<pair<float,float>> data;
int num ; string mode;
cin>> num >> mode;
float x , y ;
while(num--){
cin >> x >> y ;
data.push_back({x,y});
}
if(mode == "mb"){
auto m = mb(data);
auto m1 = m.first, m2 = m.second;
cout << round(m1*1e3)/1e3 << endl << round(m2*1e3)/1e3<< endl;
}
else {
cout << "nope" << endl;
}
return 0;
} | # 0524, 2024-11-02 14:59:41, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<tuple>
#include <algorithm>
using namespace std;
void show(){
}
pair<float,float> mb(vector<pair<float,float>> data){
int N = data.size();
float xy ,x, y , xx; x=y=xx=xy=0;
for(int i = 0 ; i < N ; i++){
xy += data[i].first * data[i].second; // xy
x += data[i].first ; //x
y += data[i].second ; //y
xx += data[i].first * data[i].first ; //xx
}
float m = (N*xy - x*y)/(N*xx - x*x) ;
return { m , (y - m*x)/N };
}
void out(float m){
if(m == -1)cout << "-x";
else if(m == 1 )cout <<"x";
else cout<< m << "x";
}
int main(){
vector<pair<float,float>> data;
int num ; string mode;
cin>> num >> mode;
float x , y ;
while(num--){
cin >> x >> y ;
data.push_back({x,y});
}
auto MB = mb(data);
auto m = round(MB.first*1e3)/1e3, b = round(MB.second*1e3)/1e3;
if(mode == "mb"){
cout << m << endl << b << endl;
}
else {
//cout << "M=" << m << " // B = " << b << endl;
cout << "y = ";
if(m == 0 && b ==0)cout <<"0";
else if(m != 0 && b ==0)out(m);
else if(m == 0 && b != 0)cout<< b;
else {out(m); b>0? cout <<" + " << b : cout <<" - " << -b ; }
cout <<endl;
}
return 0;
} |
# 0525, 2024-11-02 09:42:47, PPPPPPPPPPPPPPPP-PPPP-PP (91%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
float M (int n, vector <float> x, vector <float> y) {
float sumxy = 0, sumx = 0, sumy = 0, sumx2 = 0;
for (int i=0;i<n;i++) {
sumxy += x[i] * y[i];
sumx += x[i];
sumy += y[i];
sumx2 += x[i] * x[i];
}
return ((n*sumxy) - (sumx*sumy)) / ((n*sumx2) - (sumx*sumx));
}
float B (int n, vector <float> x, vector <float> y) {
float sumx = 0, sumy = 0;
for (int i=0;i<n;i++) {
sumx += x[i];
sumy += y[i];
}
return (sumy - (M(n,x,y)*sumx)) / n;
}
int main () {
int n;
cin >> n;
string a;
cin >> a;
vector <float> x,y;
for (int i=0;i<n;i++) {
float xi,yi;
cin >> xi >> yi;
x.push_back(xi);
y.push_back(yi);
}
float mi = M(n,x,y) , bi = B(n,x,y);
float m = round(mi*1e3)/1e3, b = round(bi*1e3)/1e3;
if (a == "mb") {
cout << m << endl << b;
return 0;
}
if (a == "func") {
cout << "y = ";
if (m==0) cout << 0;
else if (m==1) cout << "x ";
else if (m==-1) cout << "-x ";
else cout << m << "x ";
if (b==0);
else if (b>0) cout << "+ " << b;
else cout << "- " << -b;
}
} | # 0526, 2024-11-02 11:51:16, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
float M (int n, vector <float> x, vector <float> y) {
float sumxy = 0, sumx = 0, sumy = 0, sumx2 = 0;
for (int i=0;i<n;i++) {
sumxy += x[i] * y[i];
sumx += x[i];
sumy += y[i];
sumx2 += x[i] * x[i];
}
return ((n*sumxy) - (sumx*sumy)) / ((n*sumx2) - (sumx*sumx));
}
float B (int n, vector <float> x, vector <float> y) {
float sumx = 0, sumy = 0;
for (int i=0;i<n;i++) {
sumx += x[i];
sumy += y[i];
}
return (sumy - (M(n,x,y)*sumx)) / n;
}
int main () {
int n;
cin >> n;
string a;
cin >> a;
vector <float> x,y;
for (int i=0;i<n;i++) {
float xi,yi;
cin >> xi >> yi;
x.push_back(xi);
y.push_back(yi);
}
float mi = M(n,x,y) , bi = B(n,x,y);
float m = round(mi*1e3)/1e3, b = round(bi*1e3)/1e3;
if (a == "mb") {
cout << m << endl << b;
return 0;
}
if (a == "func") {
cout << "y = ";
if (m==0 && b!=0) {
cout << b;
return 0;
}
if (m==0) cout << 0;
else if (m==1) cout << "x ";
else if (m==-1) cout << "-x ";
else cout << m << "x ";
if (b==0);
else if (b>0) cout << "+ " << b;
else cout << "- " << -b;
}
} |
# 0527, 2024-11-02 09:55:31, PPPPPPPPPP-----PP----P-- (54%)
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int n;
string s1;
float a,b;
float sumxy = 0, sumx = 0, sumy = 0, sumpow = 0;
float m, bb;
cin >> n >> s1;
for(int i=0;i<n;i++){
cin >> a >> b;
sumxy = sumxy + (a*b);
sumx = sumx + a;
sumy = sumy + b;
sumpow = sumpow + (a*a);
}
m = ((n*sumxy)-(sumx*sumy))/((n*sumpow)-(sumx*sumx));
bb = (sumy - (m*sumx))/n;
if(s1=="mb"){
cout << (round(m*1e3)/1e3) << endl << (round(bb*1e3)/1e3) << endl;
}else{
bool negbb = false;
cout << "y = ";
// if((round(m*1e3)/1e3)){
// negm = true;
// }
// if((round(m*1e3)/1e3)==0)
if((round(bb*1e3)/1e3)<0){
negbb = true;
}
if((round(m*1e3)/1e3)==0){
cout << bb;
return 0;
}else if((round(m*1e3)/1e3)==1){
cout << "x ";
}else if((round(m*1e3)/1e3)==-1){
cout << "-x ";
}else{
cout << (round(m*1e3)/1e3) << "x ";
}
if(negbb){
cout << "- " << ((round(m*1e3)/1e3)*(-1));
}else{
cout << "+ " << ((round(m*1e3)/1e3));
}
}
// cout << (round(m*1e3)/1e3) << endl << (round(bb*1e3)/1e3) << endl;
return 0;
} | # 0528, 2024-11-02 09:57:30, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int n;
string s1;
float a,b;
float sumxy = 0, sumx = 0, sumy = 0, sumpow = 0;
float m, bb;
cin >> n >> s1;
for(int i=0;i<n;i++){
cin >> a >> b;
sumxy = sumxy + (a*b);
sumx = sumx + a;
sumy = sumy + b;
sumpow = sumpow + (a*a);
}
m = ((n*sumxy)-(sumx*sumy))/((n*sumpow)-(sumx*sumx));
bb = (sumy - (m*sumx))/n;
if(s1=="mb"){
cout << (round(m*1e3)/1e3) << endl << (round(bb*1e3)/1e3) << endl;
}else{
bool negbb = false;
cout << "y = ";
// if((round(m*1e3)/1e3)){
// negm = true;
// }
// if((round(m*1e3)/1e3)==0)
if((round(bb*1e3)/1e3)<0){
negbb = true;
}
if((round(m*1e3)/1e3)==0){
cout << bb;
return 0;
}else if((round(m*1e3)/1e3)==1){
cout << "x ";
}else if((round(m*1e3)/1e3)==-1){
cout << "-x ";
}else{
cout << (round(m*1e3)/1e3) << "x ";
}
if((round(bb*1e3)/1e3)==0){
return 0;
}
if(negbb){
cout << "- " << ((round(bb*1e3)/1e3)*(-1));
}else{
cout << "+ " << ((round(bb*1e3)/1e3));
}
}
// cout << (round(m*1e3)/1e3) << endl << (round(bb*1e3)/1e3) << endl;
return 0;
} |
# 0529, 2024-11-02 10:05:09, ----------PPPPPPPPPPPPPP (58%)
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
using namespace std;
int main(){
int n;
string command;
std::cin >> n >> command;
float x[n] = {0.0};
float y[n] = {0.0};
for(int i = 0 ; i < n ; i++){
float xIn , yIn;
cin >> xIn >> yIn;
x[i] = xIn;
y[i] = yIn;
}
//sigma area (Stillwater + Mango + ComProg Rage + DigLo Situps)
float sumX,sumY,sumXY,sumXp2;
sumX = 0;
sumY = 0;
sumXY = 0;
sumXp2 = 0;
for(int i = 0 ; i < n ; i++){
//sigmaX
sumX += x[i];
//sigmaY
sumY += y[i];
//sigma X^2
sumXp2 += (x[i]*x[i]);
//sigma XY
sumXY += (x[i]*y[i]);
}
//calc M
float m = ((n*sumXY) - ( sumX*sumY )) / ( (n*sumXp2) - (sumX*sumX));
//calc b
float b = (sumY - (m*sumX)) / n;
//output
if(command == "mb"){
cout << "m=" << round(m*1e3)/1e3 << endl << "b=" << round(b*1e3)/1e3 << endl;
}else if( command == "func"){
cout << "y = ";
if( round(b*1e3)/1e3 == 0 && round(m*1e3)/1e3 == 0){
cout << "0";
}else{
//output x;
if( round(m*1e3)/1e3 == 1){
cout << "x";
}else if (round(m*1e3)/1e3 == -1){
cout << "-x";
}else if( round(m*1e3)/1e3 != 0){
cout << round(m*1e3)/1e3 << "x";
}
//output b;
if(round(m*1e3)/1e3 == 0 ){
cout << round(b*1e3)/1e3;
}else{
if( round(b*1e3)/1e3 > 0 ){
cout << " + " << round(b*1e3)/1e3;
}else if( round(b*1e3)/1e3 < 0 ){
cout << " - " << fabs(round(b*1e3)/1e3);
}
}
}
}
} | # 0530, 2024-11-02 10:05:52, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
using namespace std;
int main(){
int n;
string command;
std::cin >> n >> command;
float x[n] = {0.0};
float y[n] = {0.0};
for(int i = 0 ; i < n ; i++){
float xIn , yIn;
cin >> xIn >> yIn;
x[i] = xIn;
y[i] = yIn;
}
//sigma area (Stillwater + Mango + ComProg Rage + DigLo Situps)
float sumX,sumY,sumXY,sumXp2;
sumX = 0;
sumY = 0;
sumXY = 0;
sumXp2 = 0;
for(int i = 0 ; i < n ; i++){
//sigmaX
sumX += x[i];
//sigmaY
sumY += y[i];
//sigma X^2
sumXp2 += (x[i]*x[i]);
//sigma XY
sumXY += (x[i]*y[i]);
}
//calc M
float m = ((n*sumXY) - ( sumX*sumY )) / ( (n*sumXp2) - (sumX*sumX));
//calc b
float b = (sumY - (m*sumX)) / n;
//output
if(command == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
}else if( command == "func"){
cout << "y = ";
if( round(b*1e3)/1e3 == 0 && round(m*1e3)/1e3 == 0){
cout << "0";
}else{
//output x;
if( round(m*1e3)/1e3 == 1){
cout << "x";
}else if (round(m*1e3)/1e3 == -1){
cout << "-x";
}else if( round(m*1e3)/1e3 != 0){
cout << round(m*1e3)/1e3 << "x";
}
//output b;
if(round(m*1e3)/1e3 == 0 ){
cout << round(b*1e3)/1e3;
}else{
if( round(b*1e3)/1e3 > 0 ){
cout << " + " << round(b*1e3)/1e3;
}else if( round(b*1e3)/1e3 < 0 ){
cout << " - " << fabs(round(b*1e3)/1e3);
}
}
}
}
} |
# 0531, 2024-11-02 13:13:56, PPPPPPPPPPPPPPP---PP---- (70%)
#include <bits/stdc++.h>
using namespace std;
vector <pair<float,float>> myvtr;
int main() {
int n;
string order;
cin >> n >> order;
pair<float,float> lo;
for (int i = 0 ; i < n ; i++) {
cin >> lo.first >> lo.second;
myvtr.push_back(lo);
}
float sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0;
for (auto &it : myvtr) {
sum1 += (it.first*it.second);
sum2 += it.first;
sum3 += it.second;
sum4 += (it.first*it.first);
}
float m = (n * sum1 - sum2 * sum3) / (n * sum4 - sum2 * sum2);
float b = (sum3 - m * sum2) / n;
if (order == "mb"){
cout << round(m * 1e3) / 1e3 << endl << round(b * 1e3) / 1e3;
}
else {
cout << "y = ";
if (m == -1) cout << "-x ";
else if (m == 1) cout << "x ";
else if (m != 0) cout << round(m * 1e3) / 1e3 << "x ";
if (b > 0) cout << "+ ";
else if (b < 0) cout << "- ";
if (b != 0) cout << abs(round(b *1e3) / 1e3);
}
} | # 0532, 2024-11-02 13:20:19, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
vector <pair<float,float>> myvtr;
int main() {
int n;
string order;
cin >> n >> order;
pair<float,float> lo;
for (int i = 0 ; i < n ; i++) {
cin >> lo.first >> lo.second;
myvtr.push_back(lo);
}
float sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0;
for (auto &it : myvtr) {
sum1 += (it.first*it.second);
sum2 += it.first;
sum3 += it.second;
sum4 += (it.first*it.first);
}
float m = (n * sum1 - sum2 * sum3) / (n * sum4 - sum2 * sum2);
float b = (sum3 - m * sum2) / n;
m = round(m * 1e3) / 1e3;
b = round(b *1e3) / 1e3;
if (order == "mb"){
cout << m << endl << b;
}
else {
cout << "y = ";
if (m == -1.000) cout << "-x ";
else if (m == 1.000) cout << "x ";
else if (m != 0.000) cout << m << "x ";
if (m == 0) cout << b;
else {
if (b > 0.000) cout << "+ ";
else if (b < 0.000) cout << "- ";
if (b != 0.000) cout << abs(b); }
}
} |
# 0533, 2024-11-02 09:49:23, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <iostream>
#include <string>
#include <cmath>
int main(){
int N;
std::string instruct;
std::cin >> N >> instruct;
struct Coord{
float x;
float y;
};
Coord arr[N];
for(int i = 0; i < N; i++){
std::cin >> arr[i].x >> arr[i].y;
}
float sum_x = 0;
float sum_y = 0;
float sum_xy = 0;
float sum_xx = 0;
for(int i = 0; i < N; i++){
sum_x += arr[i].x;
sum_y += arr[i].y;
sum_xy += arr[i].x * arr[i].y;
sum_xx += arr[i].x * arr[i].x;
}
float m = ((N * sum_xy) - (sum_x * sum_y))/((N * sum_xx) - (sum_x * sum_x));
float b = (sum_y - (m * sum_x))/N;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if(instruct == "mb"){
std::cout << m << std::endl;
std::cout << b << std::endl;
}else if(instruct == "func"){
std::cout << "y = ";
if(m == -1){
std::cout << "-x ";
}else if(m == 1){
std::cout << "x ";
}else if(m != 0){
std::cout << m << "x ";
}else if(m == 0){
std::cout << b;
}
if(m != 0){
if(b > 0){
std::cout << "+ " << b;
}else if(b < 0){
std::cout << "- " << -b;
}
}
}
return 0;
} |
# 0534, 2024-11-02 14:20:13, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
float doM(vector<float> x,vector<float> y,int n){
float a,b,c,d,e;
a=0;
for (int i = 1; i <= n; i++)
{
a+= x[i]*y[i];
}
a*=n;
b=0,c=0;
for(int i=1;i<=n;i++)b+=x[i];
for(int i=1;i<=n;i++)c+=y[i];
d=0;
for(int i=1;i<=n;i++)d+=x[i]*x[i];
d*=n;
e=b;
return (a-b*c)/(d-e*e);
}
float doB(vector<float> x,vector<float> y,int n,float m){
float a=0,b=0;
for(int i=1;i<=n;i++)a+=y[i];
for(int i=1;i<=n;i++)b+=x[i];
b*=m;
return (a-b)/n;
}
void show(float m,float b){
cout << "y = ";
if(m==0&&b==0){
cout << 0;
return;
}
if(m==0){
cout << b;
return;
}
if(m==1)cout <<"x";
if(m==-1)cout <<"-x";
if(m!=1&&m!=-1)cout << m << "x";
if(b==0)return;
if(b>0) cout << " + ";
if(b<0) cout << " - ";
cout <<abs(b);
return;
}
main(){
int n;
string cmd;
cin >> n >> cmd;
vector<float> x(n+1),y(n+1);
for (int i = 1; i <= n; i++)
{
cin >> x[i] >> y[i];
}
float m,b;
m=doM(x,y,n);
b=doB(x,y,n,m);
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(cmd=="mb")cout << m<< endl << b;
else if(cmd=="func"){
show(m,b);
}
} |
# 0535, 2024-11-02 10:02:48, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
float calM(vector<pair<float, float>> pos, int n) {
float upM1,upM2, downM1, downM2;
upM1 = upM2 = downM1 = downM2 = 0;
for(auto p : pos) {
upM1 += p.first*p.second;
}
upM1 *= n;
float sumX = 0, sumY = 0;
for(auto p : pos) {
sumX += p.first;
sumY += p.second;
}
upM2 = sumX*sumY;
float sumX2 = 0;
for(auto p : pos) {
sumX2 += p.first*p.first;
}
downM1 = n * sumX2;
downM2 = sumX*sumX;
return (upM1-upM2)/(downM1-downM2);
}
float calB(vector<pair<float,float>> pos, int n, float m) {
float upB1 = 0, upB2 = 0;
for(auto p : pos) {
upB1 += p.second;
upB2 += p.first;
}
upB2 *= m;
return (upB1-upB2)/n;
}
int main() {
int n;
string s;
cin >> n >> s;
vector<pair<float,float>> pos;
for(int i = 0; i < n; ++i) {
float x,y; cin >> x >> y;
pos.push_back(make_pair(x,y));
}
float m = calM(pos,n);
float b = calB(pos,n,m);
//cout << m << ' ' << b << endl;
if(s == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
} else if(s == "func") {
if(round(m*1e3)/1e3 != 0 && round(b*1e3)/1e3 != 0) {
if(round(m*1e3)/1e3 == 1) cout << "y = x " ;
else if(round(m*1e3)/1e3 == -1) cout << "y = -x ";
else cout << "y = " << round(m*1e3)/1e3 << "x ";
if(round(b*1e3)/1e3 > 0) cout << "+ " << round(b*1e3)/1e3;
else cout << "- " << -1*(round(b*1e3)/1e3);
} else if(round(m*1e3)/1e3 == 0 && round(b*1e3)/1e3 != 0) {
cout << "y = " << round(b*1e3)/1e3;
} else if(round(b*1e3)/1e3 == 0 && round(m*1e3)/1e3) {
if(round(m*1e3)/1e3 == 1) cout << "y = x " ;
else if(round(m*1e3)/1e3 == -1) cout << "y = -x ";
else cout << "y = " << round(m*1e3)/1e3 << "x ";
} else {
cout << "y = 0";
}
}
} |
# 0536, 2024-11-02 10:02:01, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<iostream>
#include<cmath>
using namespace std;
float x[101010] = {};
float y[101010] = {};
float sum[6] = {};
void solve(int n){
float a1 = 0,a2 = 0,a3 = 0,a4 = 0;
for(int i=1;i<=n;i++){
a1 += x[i];
a2 += y[i];
a3 += x[i] * y[i];
a4 += x[i] * x[i];
}
sum[0] = a1;
sum[1] = a2;
sum[2] = a3;
sum[3] = a4;
}
int main(){
int n;
string str;
cin >> n >> str;
for(int i=1;i<=n;i++){
cin >> x[i] >> y[i];
}
solve(n);
float m,b;
m = ((n * sum[2]) - (sum[0] * sum[1])) / ((n * sum[3]) - (sum[0] * sum[0]));
b = ((sum[1] - (m * sum[0])) / n);
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(str == "mb"){
cout << m << '\n' << b;
}else{
if(m == 0 && b == 0)cout << "y = 0";
else if(m == 0 && b != 0)cout << "y = " << b;
else if(m == 1 && b == 0)cout << "y = x";
else if(m == 1 && b > 0)cout << "y = x + " << b;
else if(m == 1 && b < 0)cout << "y = x - " << -b;
else if(m > 0 && b > 0)cout << "y = " << m << "x + " << b;
else if(m > 0 && b == 0)cout << "y = " << m << "x";
else if(m > 0 && b < 0)cout << "y = " << m << "x - " << -b;
else if(m == -1 && b == 0)cout << "y = -x";
else if(m == -1 && b > 0)cout << "y = -x + " << b;
else if(m == -1 && b < 0)cout << "y = -x - " << -b;
else if(m < 0 && b > 0)cout << "y = " << m << "x + " << b;
else if(m < 0 && b == 0)cout << "y = " << m << "x";
else if(m < 0 && b < 0)cout << "y = " << m << "x - " << -b;
}
return 0;
} |
# 0537, 2024-11-02 10:37:56, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<iostream>
#include<vector>
#include<cmath>
using namespace std ;
int main()
{
int N ;
string f ;
cin >> N >> f ;
int M = N ;
float x = 0.0, y = 0.0 , m = 0.0 , b = 0.0 ;
vector<pair<float , float>> dot = {{0.0 , 0.0}} ;
while(N--) {
cin >> x >> y ;
dot.push_back({x , y}) ;
}
float xy = 0.0 , x_1 = 0.0 , x_2 = 0.0 , y_1 = 0.0 ;
for(int i = 1 ; i <= M ; i++) {
xy += dot[i].first * dot[i].second ;
}
for(int i = 1 ; i <= M ; i++) {
x_1 += dot[i].first ;
}
for(int i = 1 ; i <= M ; i++) {
x_2 += dot[i].first * dot[i].first ;
}
for(int i = 1 ; i <= M ; i++) {
y_1 += dot[i].second ;
}
m = ((M * xy) - x_1 * y_1) / ((M * x_2) - (x_1 * x_1)) ;
b = (y_1 - m * x_1) / M ;
m = round(m * 1e3) / 1e3 ;
b = round(b * 1e3) / 1e3 ;
if(f == "mb") cout << m << endl << b << endl ;
else if(f == "func") {
if(m == 0) {
if(b == 0) // m , b = 0
cout << "y = 0" ;
else // m = 0 , b != 0
cout << "y = " << b ;
return 0 ;
}
if(m == 1) {
if(b == 0) // m = 1 , b = 0
cout << "y = x" ;
else if(b < 0) // m = 1 , b < 0
cout << "y = " << "x - " << -1 * b ;
else if(b > 0) // m = 1 , b > 0
cout << "y = " << "x + " << b ;
return 0 ;
}
if(m == -1) {
if(b == 0) // m = -1 , b = 0
cout << "y = -x" ;
else if(b < 0) // m = -1 , b < 0
cout << "y = " << "-x - " << -1 * b ;
else if(b > 0) // m = -1 , b > 0
cout << "y = " << "-x + " << b ;
return 0 ;
}
if(m < 0) {
if(b == 0) // m < 0 , b = 0
cout << "y = " << m << "x" ;
else if(b < 0) // m < 0 , b < 0
cout << "y = " << m <<"x - " << -1 * b ;
else if(b > 0) // m < 0 , b > 0
cout << "y = " << m <<"x + " << b ;
return 0 ;
}
if(m > 0) {
if(b == 0) // m > 0 , b = 0
cout << "y = " << m << "x" ;
else if(b < 0) // m > 0 , b < 0
cout << "y = " << m <<"x - " << -1 * b ;
else if(b > 0) // m > 0 , b > 0
cout << "y = " << m <<"x + " << b ;
return 0 ;
}
}
} |
# 0538, 2024-11-02 10:10:57, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
int n;cin >> n;
string ask; cin >> ask;
vector<float> x_val,y_val;
for(int i = 0;i<n;i++)
{
float tempx,tempy;
cin >> tempx >> tempy;
x_val.push_back(tempx);
y_val.push_back(tempy);
}
float m;
float b;
//m
float sec1_m = 0.0;
for(int i = 0;i<n;i++){
sec1_m += x_val[i]*y_val[i];
}
sec1_m *= float(n);
float sec2_m = 0.0;
float sumx_m = 0.0;
float sumy_m = 0.0;
for(int i =0;i<n;i++){
sumx_m += x_val[i];
sumy_m += y_val[i];
}
sec2_m = sumx_m*sumy_m;
float sec3_m = 0.0;
float pow_sumx = 0.0;
for(int i =0;i<n;i++){
pow_sumx += pow(x_val[i],2);
}
sec3_m = pow_sumx*float(n);
float sec4_m = pow(sumx_m,2);
m = (sec1_m - sec2_m)/(sec3_m-sec4_m);
//b
float sec1_b = 0.0;
for(int i = 0;i<n;i++){
sec1_b += y_val[i];
}
b = (sec1_b- (m*sumx_m))/float(n);
if(ask == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if(ask == "func"){
cout << "y = ";
float out_m = round(m*1e3)/1e3 ;
float out_b = round(b*1e3)/1e3 ;
if(out_m == 0 && out_b == 0){
cout << 0;
return 0;
}
if(out_m == 0){
cout << out_b;
return 0;
}
if(out_m == 1 && out_b != 0){
cout<< "x " << (out_b < 0? "- ": "+ ") << fabs(out_b) ;
return 0;
}
if(out_m == -1 && out_b != 0){
cout<< "-x " << (out_b < 0? "- ": "+ ") << fabs(out_b) ;
return 0;
}
if(out_m == 1 && out_b == 0){
cout<< "x ";
return 0;
}
if(out_m == -1 && out_b == 0){
cout<< "-x ";
return 0;
}
cout<< out_m <<"x " << (out_b < 0? "- ": "+ ") << fabs(out_b) ;
}
} |
# 0539, 2024-11-02 10:14:03, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
int N;
string op;
cin >> N >> op;
vector<float> x(N);
vector<float> y(N);
for(int i=0;i<N;i++){
cin >> x[i] >> y[i];
}
float m,b,p=0.0,q=0.0,r=0.0,s=0.0;
for(int i=0;i<N; i++){
p += x[i]*y[i];
q += x[i];
r += y[i];
s += x[i]*x[i];
}
m = ((N*p-(q*r)))/((N*s)-(q*q));
b = (r-(m*q))/N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(op == "mb"){
cout << m << endl;
cout << b << endl;
}
if(op == "func"){
if(m == 0){
if(b != 0){
cout << "y = " << b << endl;
} else{
cout << "y = 0" << endl;
}
} else if(m == 1){
if(b > 0){
cout << "y = x + " << b << endl;
} else if(b < 0){
cout << "y = x - " << -b << endl;
} else{
cout << "y = x" << endl;
}
} else if(m == -1){
if(b > 0){
cout << "y = -x + " << b << endl;
} else if(b < 0){
cout << "y = -x - " << -b << endl;
} else{
cout << "y = -x" << endl;
}
} else if(b > 0){
cout << "y = "<< m << "x + " << b << endl;
} else if(b < 0){
cout << "y = "<< m << "x - " << -b << endl;
} else{
cout << "y = "<< m << "x" << endl;
}
}
} |
# 0540, 2024-11-02 13:16:04, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include<iostream>
#include<string>
#include<cmath>
int main(){
int n;
std::string A;
std::cin>>n>>A;
float x[n],y[n];
for(int i=0;i<n;i++)
{
std::cin>>x[i]>>y[i];
}
float sx=0,sy=0,sx2=0,sxy=0;
for(int i=0;i<n;i++)
{
sx+=x[i];
sy+=y[i];
sxy+=(x[i]*y[i]);
sx2+=(x[i]*x[i]);
}
float m=((n*sxy)-(sx*sy))/((n*sx2)-(sx*sx));
float b=(sy-(m*sx))/(n);
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if(A=="mb")
{
std::cout<<m<<"\n"<<b;
}
else if(A=="func")
{
std::cout<<"y = ";
if(m==0)std::cout<<b;
else if(m==-1)std::cout<<"-x";
else if(m==1)std::cout<<"x";
else std::cout<<" "<<m<<"x";
//if(b==0&&m==0)std::cout<<"0";
if(b>0&&m!=0)std::cout<<" + "<<b;
else if(b<0&&m!=0)std::cout<<" - "<<b*(-1);
}
} |
# 0541, 2024-11-02 10:16:56, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n;
string op;
cin>>n>>op;
float arr[n][2];
for (int i=0 ; i<n ; i++) {
cin>>arr[i][0]>>arr[i][1];
}
float m=0.0,b=0.0;
float m1=0.0, m2=0.0, m3=0.0, m4=0.0, m5=0.0;
float b1=0.0,b2=0.0;
for (int i=1 ; i<=n ; i++) {
m1 += arr[i-1][0]*arr[i-1][1];
m2 += arr[i-1][0];
m3 += arr[i-1][1];
m4 += arr[i-1][0]*arr[i-1][0];
m5 += arr[i-1][0];
b1 += arr[i-1][1];
b2 += arr[i-1][0];
}
m=((n*m1) - (m2*m3))/((n*m4) - (m5*m5));
b=(b1-(m*b2))/n;
m= round(m* 1e3)/1e3;
b= round(b* 1e3)/1e3;
if (op == "mb") {
cout << m<<endl<< b;
} else if (op == "func") {
if (m==0) {
cout<<"y = "<<b;
} else if (m==-1) {
if (b>0) {
cout<<"y = -x + "<<b;
} else if (b<0) {
cout<<"y = -x - "<<b*(-1.0);
} else {
cout<<"y = -x";
}
} else if (m==1) {
if (b>0) {
cout<<"y = x + "<<b;
} else if (b<0) {
cout<<"y = x - "<<b*(-1.0);
} else {
cout<<"y = x";
}
} else {
if (b>0) {
cout<<"y = "<<m<<"x + "<<b;
} else if (b<0) {
cout<<"y = "<<m<<"x - "<<b*(-1.0);
} else {
cout<<"y = "<<m<<"x";
}
}
}
} |
# 0542, 2024-11-02 14:07:19, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <cctype>
using namespace std;
int main(){
string cmd; float N;
cin >> N >> cmd;
int count = (int)N;
float m = 0, b = 0;
vector<float> xi , yi;
while (count--)
{
float xin, yin;
cin >> xin >> yin;
xi.push_back(xin); yi.push_back(yin);
}
float sigX = 0, sigY = 0, sigX2 = 0 , sigXY = 0;
for (int i = 1; i <= N; i++)
{
sigX += xi[i-1];
sigY += yi[i-1];
sigX2 += xi[i-1]*xi[i-1];
sigXY += xi[i-1]*yi[i-1];
}
m = (N*sigXY-sigX*sigY)/(N*sigX2 - sigX*sigX);
b = (sigY - m*sigX)/N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(cmd == "mb") {
cout << m << endl << b;
}
else{
cout << "y = ";
if(m==0){
cout << b; return 0;
}
else if(m==1){
cout << "x ";
}
else if(m==-1){
cout << "-x ";
}
else{
cout << round(m*1e3)/1e3 << "x ";
}
if(b>0) cout << "+ " << b;
if(b<0) cout << "- " << -b;
}
} |
# 0543, 2024-11-02 13:30:03, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <iostream>
#include <vector>
#include <math.h>
#include <cmath>
using namespace std;
vector<pair<float, float>> v;
int main(){
int a;
cin >> a;
string s;
cin >> s;
for(int i=0; i<a; i++){
float x, y;
cin >> x >> y;
pair<float, float> p = {x,y};
v.push_back(p);
}
float xiyi;
for(int i=0; i<a; i++){
xiyi += v[i].first*v[i].second;
}
xiyi *= a;
float xi;
for(int i=0; i<a; i++){
xi += v[i].first;
}
float yi;
for(int i=0; i<a; i++){
yi += v[i].second;
}
float xi_power2_1, xi_power2_2;
for(int i=0; i<a; i++){
xi_power2_1 += pow(v[i].first, 2);
}
xi_power2_1 *= a;
xi_power2_2 = pow(xi, 2);
float m = (xiyi - (xi*yi))/(xi_power2_1 - xi_power2_2);
float b = (yi - (m * xi))/a;
bool b_morethan_0 = 0;
if(round(b*1e3)/1e3 > 0) b_morethan_0 = 1;
// cout << round(m*1e3)/1e3 << "\n" << round(b*1e3)/1e3;
if(s=="mb"){
if((round(m*1e3)/1e3 == 0 | round(m*1e3)/1e3 == -0)&&
(round(b*1e3)/1e3 == 0 | round(b*1e3)/1e3 == -0)){
cout << 0 << '\n' << 0;
}
else cout << round(m*1e3)/1e3 << '\n' << round(b*1e3)/1e3 ;
//func
}else{
if((round(m*1e3)/1e3 == 0 | round(m*1e3)/1e3 == -0)&&
(round(b*1e3)/1e3 == 0 | round(b*1e3)/1e3 == -0)){
cout << "y = 0";
}
else if(round(m*1e3)/1e3==0 | round(m*1e3)/1e3== -0){
cout << "y = " << round(b*1e3)/1e3;
}
else if(round(b*1e3)/1e3==0 | round(b*1e3)/1e3== -0){
if(round(m*1e3)/1e3==1) cout << "y = x";
else if(round(m*1e3)/1e3==-1) cout << "y = -x";
else cout << "y = " << round(m*1e3)/1e3 << "x";
}else{
if(round(m*1e3)/1e3==1){
cout << "y = x";
if(b_morethan_0) cout << " + " << abs(round(b*1e3)/1e3);
else cout << " - " << abs(round(b*1e3)/1e3);
}
else if(round(m*1e3)/1e3==-1){
cout << "y = -x";
if(b_morethan_0) cout << " + " << abs(round(b*1e3)/1e3);
else cout << " - " << abs(round(b*1e3)/1e3);
}
else{
cout << "y = " << round(m*1e3)/1e3 << "x";
if(b_morethan_0) cout << " + " << abs(round(b*1e3)/1e3);
else cout << " - " << abs(round(b*1e3)/1e3);
}
}
}
cout << '\n';
}
/*
20 mb
1.1881 1.5293
1.7655 1.1602
1.8581 1.1016
2.2834 0.8302
2.7323 0.5438
3.0490 0.3426
3.2191 0.2325
3.5325 0.0332
3.7860 -0.1221
5.8511 -1.4411
6.0823 -1.5966
6.2641 -1.7018
6.6594 -1.9658
6.9622 -2.1554
7.5696 -2.5427
7.6285 -2.5792
7.9083 -2.7581
7.9242 -2.7681
9.6531 -3.8725
9.9108 -4.0347
20 func
-47.4275 -643.9849
-43.2994 -591.5547
-43.1769 -589.5735
-32.6425 -453.3533
-28.2735 -412.2329
-20.1902 -299.63
-6.3605 -140.4817
-5.6405 -128.4213
3.9611 -8.7905
4.7316 2.7213
4.1944 6.8667
16.9359 153.0378
19.2241 181.903
22.1265 222.7692
23.7411 227.653
34.6474 382.2777
41.1725 439.1405
39.5836 445.2155
47.5559 528.9183
47.6268 533.7816
*/ |
# 0544, 2024-11-02 14:13:29, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int N;
string f;
cin >> N >> f;
float a, a2;
vector<float> x;
vector<float> y;
float m1, m2, m3, m4, m5;
float sum = 0;
float m, b;
for (int i = 1; i <= N; i++)
{
cin >> a >> a2;
x.push_back(a);
y.push_back(a2);
}
x.insert(x.begin(), 0);
y.insert(y.begin(), 0);
for (int i = 1; i <= N; i++)
{
sum += x[i] * y[i];
}
m1 = N * sum;
sum = 0;
for (int i = 1; i <= N; i++)
{
sum += x[i];
}
m2 = sum;
sum = 0;
for (int i = 1; i <= N; i++)
{
sum += y[i];
}
m3 = sum;
sum = 0;
for (int i = 1; i <= N; i++)
{
sum += pow(x[i], 2);
}
m4 = N * sum;
sum = 0;
for (int i = 1; i <= N; i++)
{
sum += x[i];
}
m5 = sum * sum;
sum = 0;
m = (m1 - (m2 * m3)) / (m4 - m5);
float b1, b2;
for (int i = 1; i <= N; i++)
{
sum += y[i];
}
b1 = sum;
sum = 0;
for (int i = 1; i <= N; i++)
{
sum += x[i];
}
b2 = m * sum;
sum = 0;
b = (b1 - b2) / N;
if (f == "mb")
{
cout << round(m * 1e3) / 1e3 << endl
<< round(b * 1e3) / 1e3;
}
m = round(m * 1e3) / 1e3;
b = round(b * 1e3) / 1e3;
if (f == "func")
{
if (m == 0 && b == 0)
{
cout << "y = 0";
}
if (m == 0 && b != 0)
{
if (b > 0)
{
cout << "y = " << b;
}
else
{
cout << "y = -" << abs(b);
}
}
if(m!=0&&b==0)
{
if(m==1||m==-1)
{
if(m==1)
{
cout<<"y = x";
}
else
{cout<<"y = -x";}
}
else
{cout<<"y = "<<m<<"x";}
}
if (m != 0 && b != 0)
{
if (m == 1||m==-1)
{
if(m==1){
if (b > 0)
{
cout << "y = x + " << b;
}
else
{
cout << "y = x - " << abs(b);
}
}
else
{
if (b > 0)
{
cout << "y = -x + " << b;
}
else
{
cout << "y = -x - " << abs(b);
}
}
}
else
{
if (b > 0)
{
cout << "y = "<<m<<"x + " << b;
}
else
{
cout << "y = "<<m<<"x - " << abs(b);
}
}
}
}
} |
# 0545, 2024-11-02 11:33:43, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
float n;
float temp1,temp2;
string func;
vector <pair<float,float>> data;
cin >> n >> func;
float N = n;
while (n--) {
cin >> temp1 >> temp2;
data.push_back(make_pair(temp1,temp2));
}
float total1 = 0,total2 = 0,total3 = 0,total4 = 0;
for (auto p: data) {
total1 += (p.first*p.second);
total2 += (p.first);
total3 += (p.second);
total4 += (p.first*p.first);
}
float m = ((N*total1)-(total2*total3))/((N*total4)-(total2*total2));
float b = (total3 - (m*total2))/N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (func == "mb") {
cout << m << endl;
cout << b << endl;
} else if (func == "func") {
if (m == 0 && b == 0) {
cout << "y = 0";
} else if (m == 0) {
cout << "y = " << b;
} else if (m == -1 && b == 0) {
cout << "y = -x";
} else if (m == 1 && b == 0) {
cout << "y = x";
} else if (b == 0) {
cout << "y = " << m << "x";
} else if (m == -1 && b < 0) {
cout << "y = -x - " << -b;
} else if (m == -1) {
cout << "y = -x + " << b;
} else if (m == 1 && b < 0) {
cout << "y = x - " << -b;
} else if ( m == 1) {
cout << "y = x + " << b;
} else if (b > 0) {
cout << "y = " << m << "x + " << b;
} else {
cout << "y = " << m << "x - " << -b;
}
}
} |
# 0546, 2024-11-02 09:49:01, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int N;
vector<float> x;
vector<float> y;
float m() {
float sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0, sum5 = 0;
for (int i = 1; i <= N; i++) {
sum1 += x[i - 1]*y[i - 1];
sum2 += x[i - 1];
sum3 += y[i - 1];
sum4 += pow(x[i - 1], 2.0);
sum5 += x[i - 1];
}
return ((N * sum1) - (sum2 * sum3)) / ((N * sum4) - pow(sum5, 2.0));
}
float b(float m) {
float sum1 = 0, sum2 = 0;
for (int i = 1; i <= N; i++) {
sum1 += y[i - 1];
sum2 += x[i - 1];
}
return (sum1 - (m*sum2)) / N;
}
int main() {
string a;
cin >> N >> a;
for (int i = 0; i < N; i++) {
float x1, y1;
cin >> x1 >> y1;
x.push_back(x1);
y.push_back(y1);
}
float m1 = m();
float b1 = b(m1);
if (a == "mb") {
cout << round(m1 * 1e3) / 1e3 << endl << round(b1 * 1e3) / 1e3 << endl;
} else if (a == "func") {
m1 = round(m1 * 1e3) / 1e3;
b1 = round(b1 * 1e3) / 1e3;
cout << "y = ";
if (m1 == 0) {
cout << b1 << endl;
} else if (b1 == 0) {
if (m1 != 1 && m1 != -1) {
cout << m1 << "x" << endl;
} else if (m1 == 1) {
cout << "x" << endl;
} else {
cout << "-x" << endl;
}
} else {
if (m1 != 1 && m1 != -1) {
cout << m1 << "x ";
} else if (m1 == 1) {
cout << "x ";
} else {
cout << "-x ";
}
if (b1 > 0) {
cout << "+ " << b1 << endl;
} else {
cout << "- " << abs(b1) << endl;
}
}
}
} |
# 0547, 2024-11-02 09:48:44, PPPPPPPPPPPPPPPPPPPPPPPP (100%)
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <utility>
using namespace std;
int main(int argc, char const *argv[])
{
float n;
string command;
cin >> n >> command;
vector<pair<float, float>> dataList;
for (unsigned i = 0; i < n; i++)
{
float x, y;
cin >> x >> y;
dataList.push_back({x, y});
}
float m, b;
float mDividendLeft = 0;
float sumX = 0, sumY = 0, sumXExpo = 0;
for (unsigned i = 0; i < n; i++)
{
mDividendLeft += dataList[i].first * dataList[i].second;
sumX += dataList[i].first;
sumY += dataList[i].second;
sumXExpo += dataList[i].first * dataList[i].first;
}
m = (n * mDividendLeft - sumX * sumY) / (n * sumXExpo - sumX * sumX);
b = (sumY - m * sumX) / n;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if (command == "mb")
{
cout << m << endl;
cout << b << endl;
}
else if (command == "func")
{
if (m == 0 && b == 0)
{
cout << "y = 0";
}
else if (m == 0)
{
cout << "y = " << b;
}
else if (b == 0)
{
cout << "y = ";
if(m == -1){
cout << "-x";
}else if(m == 1){
cout << 'x';
}else {
cout << m << 'x';
}
}
else
{
cout << "y = ";
if(m == -1){
cout << "-x ";
}else if(m == 1){
cout << "x ";
}else {
cout << m << "x ";
}
if(b < 0){
cout << "- " << fabs(b);
}else{
cout << "+ " << b;
}
}
}
return 0;
} |
# 0548, 2024-11-02 10:46:03, PPPPPPPPPPPPP---PPPPPPPP (87%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
float x=0,y=0,sigma1=0,sigma2=0,sigma3=0,sigma4=0;
float m=0,b=0;
int n=0;
string a;
cin >> n >> a;
for(int i=1;i<=n;i++)
{
cin >> x >> y;
sigma1 += x*y;
sigma2 += x;
sigma3 += y;
sigma4 += x*x;
}
m = ((n*sigma1)-(sigma2*sigma3))/((n*sigma4)-(sigma2*sigma2));
b = ((sigma3) - (m*sigma2))/n ;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(a=="mb")
{
cout << m << endl << b << endl;
}
else if(a=="func")
{
if(m==0 && b ==0)
{
cout << "0";
}
else if(m==0 && b>=1)
cout << "y = " << b << endl;
else if(m==0 && b<=-1)
cout << "y = " << b << endl;
else if(m==1 && b==0)
cout << "y = " << "x" << endl;
else if(m==1 && b<=-1)
cout << "y = " << "x - " << abs(b) << endl;
else if(m==1 && b>= 1)
cout << "y = " << "x + " << b << endl;
else if(m==-1 && b<=-1)
cout << "y = " << "-x - " << abs(b) << endl;
else if(m==-1 && b>= 1)
cout << "y = " << "-x + " << b << endl;
else if(m==-1 && b==0)
cout << "y = " << "-x" << endl;
else if(m<-1 && b<=-1)
cout << "y = " << abs(m) << "x - " << abs(b) << endl;
else if(m>1 && b>= 1)
cout << "y = " << m << "x + " << b << endl;
else if(m>1 && b<= -1)
cout << "y = " << m << "x - " << abs(b) << endl;
else if(m<-1 && b>= 1)
cout << "y = " << m << "x + " << b << endl;
else if(m<-1 && b==0)
cout << "y = " << abs(m) << "x" << endl;
else if(m>1 && b== 0)
cout << "y = " << m << "x" << endl;
else
cout << "y = " << m << "x + " << b << endl;
}
}
/*
3 mb
1.0 -3.0
2.0 -3.0
4.4 -3.0
*/ | # 0549, 2024-11-02 10:54:22, PPPPPPPPPPPPP---PPPPPPPP (87%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
float x=0,y=0,sigma1=0,sigma2=0,sigma3=0,sigma4=0;
float m=0,b=0;
int n=0;
string a;
cin >> n >> a;
for(int i=1;i<=n;i++)
{
cin >> x >> y;
sigma1 += x*y;
sigma2 += x;
sigma3 += y;
sigma4 += x*x;
}
m = ((n*sigma1)-(sigma2*sigma3))/((n*sigma4)-(sigma2*sigma2));
b = ((sigma3) - (m*sigma2))/n ;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(a=="mb")
{
cout << m << endl << b << endl;
}
else if(a=="func")
{
if(m==0 && b ==0)
{
cout << "0";
}
else if(m==0 && b>=1)
cout << "y = " << b << endl;
else if(m==0 && b<=-1)
cout << "y = " << b << endl;
else if(m==1 && b==0)
cout << "y = " << "x" << endl;
else if(m==1 && b<=-1)
cout << "y = " << "x - " << abs(b) << endl;
else if(m==1 && b>= 1)
cout << "y = " << "x + " << b << endl;
else if(m==-1 && b<=-1)
cout << "y = " << "-x - " << abs(b) << endl;
else if(m==-1 && b>= 1)
cout << "y = " << "-x + " << b << endl;
else if(m==-1 && b==0)
cout << "y = " << "-x" << endl;
else if(m<-1 && b<=-1)
cout << "y = " << abs(m) << "x - " << abs(b) << endl;
else if(m>1 && b>= 1)
cout << "y = " << m << "x + " << b << endl;
else if(m>1 && b<= -1)
cout << "y = " << m << "x - " << abs(b) << endl;
else if(m<-1 && b>= 1)
cout << "y = " << m << "x + " << b << endl;
else if(m<-1 && b==0)
cout << "y = " << abs(m) << "x" << endl;
else if(m>1 && b==0)
cout << "y = " << m << "x" << endl;
}
} | # 0550, 2024-11-02 10:57:45, PPPPPPPPPPPP-PP-PPPPPPPP (91%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
float x=0,y=0,sigma1=0,sigma2=0,sigma3=0,sigma4=0;
float m=0,b=0;
int n=0;
string a;
cin >> n >> a;
for(int i=1;i<=n;i++)
{
cin >> x >> y;
sigma1 += x*y;
sigma2 += x;
sigma3 += y;
sigma4 += x*x;
}
m = ((n*sigma1)-(sigma2*sigma3))/((n*sigma4)-(sigma2*sigma2));
b = ((sigma3) - (m*sigma2))/n ;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(a=="mb")
{
cout << m << endl << b << endl;
}
else if(a=="func")
{
if(m==0 && b ==0)
{
cout << "0";
}
else if(m==0 && b>=1)
cout << "y = " << b << endl;
else if(m==0 && b<=-1)
cout << "y = " << b << endl;
else if(m==1 && b==0)
cout << "y = " << "x" << endl;
else if(m==1 && b<=-1)
cout << "y = " << "x - " << abs(b) << endl;
else if(m==1 && b>= 1)
cout << "y = " << "x + " << b << endl;
else if(m==-1 && b<=-1)
cout << "y = " << "-x - " << abs(b) << endl;
else if(m==-1 && b>= 1)
cout << "y = " << "-x + " << b << endl;
else if(m==-1 && b==0)
cout << "y = " << "-x" << endl;
else if(m>1 && b>= 1)
cout << "y = " << m << "x + " << b << endl;
else if(m>1 && b<= -1)
cout << "y = " << m << "x - " << abs(b) << endl;
else if(m>1 && b==0)
cout << "y = " << m << "x" << endl;
else if(m<-1 && b>= 1)
cout << "y = -" << m << "x + " << b << endl;
else if(m<-1 && b<=-1)
cout << "y = -" << abs(m) << "x - " << abs(b) << endl;
else if(m<-1 && b==0)
cout << "y = -" << abs(m) << "x" << endl;
}
} | # 0551, 2024-11-02 10:58:55, PPPPPPPPPPPPPPP-PPPPPPPP (95%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
float x=0,y=0,sigma1=0,sigma2=0,sigma3=0,sigma4=0;
float m=0,b=0;
int n=0;
string a;
cin >> n >> a;
for(int i=1;i<=n;i++)
{
cin >> x >> y;
sigma1 += x*y;
sigma2 += x;
sigma3 += y;
sigma4 += x*x;
}
m = ((n*sigma1)-(sigma2*sigma3))/((n*sigma4)-(sigma2*sigma2));
b = ((sigma3) - (m*sigma2))/n ;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(a=="mb")
{
cout << m << endl << b << endl;
}
else if(a=="func")
{
if(m==0 && b ==0)
{
cout << "0";
}
else if(m==0 && b>=1)
cout << "y = " << b << endl;
else if(m==0 && b<=-1)
cout << "y = " << b << endl;
else if(m==1 && b==0)
cout << "y = " << "x" << endl;
else if(m==1 && b<=-1)
cout << "y = " << "x - " << abs(b) << endl;
else if(m==1 && b>= 1)
cout << "y = " << "x + " << b << endl;
else if(m==-1 && b<=-1)
cout << "y = " << "-x - " << abs(b) << endl;
else if(m==-1 && b>= 1)
cout << "y = " << "-x + " << b << endl;
else if(m==-1 && b==0)
cout << "y = " << "-x" << endl;
else if(m>1 && b>= 1)
cout << "y = " << m << "x + " << b << endl;
else if(m>1 && b<= -1)
cout << "y = " << m << "x - " << abs(b) << endl;
else if(m>1 && b==0)
cout << "y = " << m << "x" << endl;
else if(m<-1 && b>= 1)
cout << "y = -" << abs(m) << "x + " << b << endl;
else if(m<-1 && b<=-1)
cout << "y = -" << abs(m) << "x - " << abs(b) << endl;
else if(m<-1 && b==0)
cout << "y = -" << abs(m) << "x" << endl;
}
} | # 0552, 2024-11-02 11:16:20, PPPPPPPPPPPPPPP-PPPPPPPP (95%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
float x=0,y=0,sigma1=0,sigma2=0,sigma3=0,sigma4=0;
float m=0,b=0;
int n=0;
string a;
cin >> n >> a;
for(int i=1;i<=n;i++)
{
cin >> x >> y;
sigma1 += x*y;
sigma2 += x;
sigma3 += y;
sigma4 += x*x;
}
m = ((n*sigma1)-(sigma2*sigma3))/((n*sigma4)-(sigma2*sigma2));
b = ((sigma3) - (m*sigma2))/n ;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(a=="mb")
{
cout << m << endl << b << endl;
}
else if(a=="func")
{
if(m==0 && b ==0)
{
cout << "0";
}
else if(m==0 && b>=1)
cout << "y = " << b << endl;
else if(m==0 && b<=-1)
cout << "y = " << b << endl;
else if(m==1 && b>= 1)
cout << "y = " << "x + " << b << endl;
else if(m==1 && b==0)
cout << "y = " << "x" << endl;
else if(m==1 && b<=-1)
cout << "y = " << "x - " << abs(b) << endl;
else if(m==-1 && b>= 1)
cout << "y = " << "-x + " << b << endl;
else if(m==-1 && b<=-1)
cout << "y = " << "-x - " << abs(b) << endl;
else if(m==-1 && b==0)
cout << "y = " << "-x" << endl;
else if(m>1 && b>= 1)
cout << "y = " << m << "x + " << b << endl;
else if(m>1 && b<= -1)
cout << "y = " << m << "x - " << abs(b) << endl;
else if(m>1 && b==0)
cout << "y = " << m << "x" << endl;
else if(m<-1 && b>= 1)
cout << "y = -" << abs(m) << "x + " << b << endl;
else if(m<-1 && b<=-1)
cout << "y = -" << abs(m) << "x - " << abs(b) << endl;
else if(m<-1 && b==0)
cout << "y = -" << abs(m) << "x" << endl;
}
} | # 0553, 2024-11-02 11:59:11, PPPPPPPPPPPPPPP-PPPPPPPP (95%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
float x=0,y=0,sigma1=0,sigma2=0,sigma3=0,sigma4=0;
float m=0,b=0;
int n=0;
string a;
cin >> n >> a;
for(int i=1;i<=n;i++)
{
cin >> x >> y;
sigma1 += x*y;
sigma2 += x;
sigma3 += y;
sigma4 += x*x;
}
m = ((n*sigma1)-(sigma2*sigma3))/((n*sigma4)-(sigma2*sigma2));
b = ((sigma3) - (m*sigma2))/n ;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(a=="mb")
{
cout << m << endl << b << endl;
}
else if(a=="func")
{
if(m==0 && b ==0)
{
cout << "0";
}
else if(m==0 && b>=1)
cout << "y = " << b << endl;
else if(m==0 && b<=-1)
cout << "y = " << b << endl;
else if(m==1 && b==0)
cout << "y = " << "x" << endl;
else if(m==1 && b<=-1)
cout << "y = " << "x - " << abs(b) << endl;
else if(m==1 && b>= 1)
cout << "y = " << "x + " << b << endl;
else if(m==-1 && b<=-1)
cout << "y = " << "-x - " << abs(b) << endl;
else if(m==-1 && b>= 1)
cout << "y = " << "-x + " << b << endl;
else if(m==-1 && b==0)
cout << "y = " << "-x" << endl;
else if(m>1 && b>= 1)
cout << "y = " << m << "x + " << b << endl;
else if(m>1 && b<= -1)
cout << "y = " << m << "x - " << abs(b) << endl;
else if(m>1 && b==0)
cout << "y = " << m << "x" << endl;
else if(m<-1 && b>= 1)
cout << "y = -" << abs(m) << "x + " << b << endl;
else if(m<-1 && b<=-1)
cout << "y = -" << abs(m) << "x - " << abs(b) << endl;
else if(m<-1 && b==0)
cout << "y = -" << abs(m) << "" << endl;
}
} | # 0554, 2024-11-02 11:59:36, PPPPPPPPPPPPP---PPPPPPPP (87%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
float x=0,y=0,sigma1=0,sigma2=0,sigma3=0,sigma4=0;
float m=0,b=0;
int n=0;
string a;
cin >> n >> a;
for(int i=1;i<=n;i++)
{
cin >> x >> y;
sigma1 += x*y;
sigma2 += x;
sigma3 += y;
sigma4 += x*x;
}
m = ((n*sigma1)-(sigma2*sigma3))/((n*sigma4)-(sigma2*sigma2));
b = ((sigma3) - (m*sigma2))/n ;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(a=="mb")
{
cout << m << endl << b << endl;
}
else if(a=="func")
{
if(m==0 && b ==0)
{
cout << "0";
}
else if(m==0 && b>=1)
cout << "y = " << b << endl;
else if(m==0 && b<=-1)
cout << "y = " << b << endl;
else if(m==1 && b==0)
cout << "y = " << "x" << endl;
else if(m==1 && b<=-1)
cout << "y = " << "x - " << abs(b) << endl;
else if(m==1 && b>= 1)
cout << "y = " << "x + " << b << endl;
else if(m==-1 && b<=-1)
cout << "y = " << "-x - " << abs(b) << endl;
else if(m==-1 && b>= 1)
cout << "y = " << "-x + " << b << endl;
else if(m==-1 && b==0)
cout << "y = " << "-x" << endl;
else if(m>1 && b>= 1)
cout << "y = " << m << "x + " << b << endl;
else if(m>1 && b<= -1)
cout << "y = " << m << "x - " << abs(b) << endl;
else if(m>1 && b==0)
cout << "y = " << m << "x" << endl;
else if(m<-1 && b>= 1)
cout << "y = -" << abs(m) << "x + " << b << endl;
else if(m<-1 && b<=-1)
cout << "y = -" << abs(m) << "" << abs(b) << endl;
else if(m<-1 && b==0)
cout << "y = -" << abs(m) << "x" << endl;
}
} | # 0555, 2024-11-02 12:00:30, PPPPPPPPPPPPPPP-PPPPPPPP (95%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
float x=0,y=0,sigma1=0,sigma2=0,sigma3=0,sigma4=0;
float m=0,b=0;
int n=0;
string a;
cin >> n >> a;
for(int i=1;i<=n;i++)
{
cin >> x >> y;
sigma1 += x*y;
sigma2 += x;
sigma3 += y;
sigma4 += x*x;
}
m = ((n*sigma1)-(sigma2*sigma3))/((n*sigma4)-(sigma2*sigma2));
b = ((sigma3) - (m*sigma2))/n ;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(a=="mb")
{
cout << m << endl << b << endl;
}
else if(a=="func")
{
if(m==0 && b ==0)
{
cout << "0";
}
else if(m==0 && b>=1)
cout << "y = " << b << endl;
else if(m==0 && b<=-1)
cout << "y = " << b << endl;
else if(m==1 && b==0)
cout << "y = " << "x" << endl;
else if(m==1 && b>= 1)
cout << "y = " << "x + " << b << endl;
else if(m==1 && b<=-1)
cout << "y = " << "x - " << abs(b) << endl;
else if(m==-1 && b>= 1)
cout << "y = " << "-x + " << b << endl;
else if(m==-1 && b<=-1)
cout << "y = " << "-x - " << abs(b) << endl;
else if(m==-1 && b==0)
cout << "y = " << "-x" << endl;
else if(m>1 && b>= 1)
cout << "y = " << m << "x + " << b << endl;
else if(m>1 && b<= -1)
cout << "y = " << m << "x - " << abs(b) << endl;
else if(m>1 && b==0)
cout << "y = " << m << "x" << endl;
else if(m<-1 && b>= 1)
cout << "y = -" << abs(m) << "x + " << b << endl;
else if(m<-1 && b<=-1)
cout << "y = -" << abs(m) << "x - " << abs(b) << endl;
else if(m<-1 && b==0)
cout << "y = -" << abs(m) << "x" << endl;
}
} | # 0556, 2024-11-02 12:00:42, PPPPPPPPPPPPPPP-PPPPPPPP (95%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
float x=0,y=0,sigma1=0,sigma2=0,sigma3=0,sigma4=0;
float m=0,b=0;
int n=0;
string a;
cin >> n >> a;
for(int i=1;i<=n;i++)
{
cin >> x >> y;
sigma1 += x*y;
sigma2 += x;
sigma3 += y;
sigma4 += x*x;
}
m = ((n*sigma1)-(sigma2*sigma3))/((n*sigma4)-(sigma2*sigma2));
b = ((sigma3) - (m*sigma2))/n ;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(a=="mb")
{
cout << m << endl << b << endl;
}
else if(a=="func")
{
if(m==0 && b ==0)
{
cout << "0";
}
else if(m==0 && b>=1)
cout << "y = " << b << endl;
else if(m==0 && b<=-1)
cout << "y = " << b << endl;
else if(m==1 && b==0)
cout << "y = " << "x" << endl;
else if(m==1 && b>= 1)
cout << "y = " << "x + " << b << endl;
else if(m==1 && b<=-1)
cout << "y = " << "x - " << abs(b) << endl;
else if(m==-1 && b>= 1)
cout << "y = " << "-x + " << b << endl;
else if(m==-1 && b<=-1)
cout << "y = " << "-x - " << abs(b) << endl;
else if(m==-1 && b==0)
cout << "y = " << "-x" << endl;
else if(m>1 && b>= 1)
cout << "y = " << m << "x + " << b << endl;
else if(m>1 && b<= -1)
cout << "y = " << m << "x - " << abs(b) << endl;
else if(m>1 && b==0)
cout << "y = " << m << "x" << endl;
else if(m<-1 && b>= 1)
cout << "y = -" << abs(m) << "x + " << b << endl;
else if(m<-1 && b<=-1)
cout << "y = -" << abs(m) << "x - " << abs(b) << endl;
else if(m<-1 && b==0)
cout << "y = -" << abs(m) << "x" << b << endl;
}
} | # 0557, 2024-11-02 12:00:59, PPPPPPPPPPPPPPP-PPPPPPPP (95%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
float x=0,y=0,sigma1=0,sigma2=0,sigma3=0,sigma4=0;
float m=0,b=0;
int n=0;
string a;
cin >> n >> a;
for(int i=1;i<=n;i++)
{
cin >> x >> y;
sigma1 += x*y;
sigma2 += x;
sigma3 += y;
sigma4 += x*x;
}
m = ((n*sigma1)-(sigma2*sigma3))/((n*sigma4)-(sigma2*sigma2));
b = ((sigma3) - (m*sigma2))/n ;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(a=="mb")
{
cout << m << endl << b << endl;
}
else if(a=="func")
{
if(m==0 && b ==0)
{
cout << "0";
}
else if(m==0 && b>=1)
cout << "y = " << b << endl;
else if(m==0 && b<=-1)
cout << "y = " << b << endl;
else if(m==1 && b==0)
cout << "y = " << "x" << endl;
else if(m==1 && b>= 1)
cout << "y = " << "x + " << b << endl;
else if(m==1 && b<=-1)
cout << "y = " << "x - " << abs(b) << endl;
else if(m==-1 && b>= 1)
cout << "y = " << "-x + " << b << endl;
else if(m==-1 && b<=-1)
cout << "y = " << "-x - " << abs(b) << endl;
else if(m==-1 && b==0)
cout << "y = " << "-x" << endl;
else if(m>1 && b>= 1)
cout << "y = " << m << "x + " << b << endl;
else if(m>1 && b<= -1)
cout << "y = " << m << "x - " << abs(b) << endl;
else if(m>1 && b==0)
cout << "y = " << m << "x" << endl;
else if(m<-1 && b>= 1)
cout << "y = -" << abs(m) << "x + " << b << endl;
else if(m<-1 && b<=-1)
cout << "y = -" << abs(m) << "x - " << abs(b) << endl;
}
} | # 0558, 2024-11-02 12:01:17, PPPPPPPPPPPPP---PPPPPPPP (87%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
float x=0,y=0,sigma1=0,sigma2=0,sigma3=0,sigma4=0;
float m=0,b=0;
int n=0;
string a;
cin >> n >> a;
for(int i=1;i<=n;i++)
{
cin >> x >> y;
sigma1 += x*y;
sigma2 += x;
sigma3 += y;
sigma4 += x*x;
}
m = ((n*sigma1)-(sigma2*sigma3))/((n*sigma4)-(sigma2*sigma2));
b = ((sigma3) - (m*sigma2))/n ;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(a=="mb")
{
cout << m << endl << b << endl;
}
else if(a=="func")
{
if(m==0 && b ==0)
{
cout << "0";
}
else if(m==0 && b>=1)
cout << "y = " << b << endl;
else if(m==0 && b<=-1)
cout << "y = " << b << endl;
else if(m==1 && b==0)
cout << "y = " << "x" << endl;
else if(m==1 && b>= 1)
cout << "y = " << "x + " << b << endl;
else if(m==1 && b<=-1)
cout << "y = " << "x - " << abs(b) << endl;
else if(m==-1 && b>= 1)
cout << "y = " << "-x + " << b << endl;
else if(m==-1 && b<=-1)
cout << "y = " << "-x - " << abs(b) << endl;
else if(m==-1 && b==0)
cout << "y = " << "-x" << endl;
else if(m>1 && b>= 1)
cout << "y = " << m << "x + " << b << endl;
else if(m>1 && b<= -1)
cout << "y = " << m << "x - " << abs(b) << endl;
else if(m>1 && b==0)
cout << "y = " << m << "x" << endl;
else if(m<-1 && b>= 1)
cout << "y = -" << abs(m) << "x + " << b << endl;
}
} | # 0559, 2024-11-02 12:01:31, PPPPPPPPPPPPPPP-PPPPPPPP (95%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
float x=0,y=0,sigma1=0,sigma2=0,sigma3=0,sigma4=0;
float m=0,b=0;
int n=0;
string a;
cin >> n >> a;
for(int i=1;i<=n;i++)
{
cin >> x >> y;
sigma1 += x*y;
sigma2 += x;
sigma3 += y;
sigma4 += x*x;
}
m = ((n*sigma1)-(sigma2*sigma3))/((n*sigma4)-(sigma2*sigma2));
b = ((sigma3) - (m*sigma2))/n ;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(a=="mb")
{
cout << m << endl << b << endl;
}
else if(a=="func")
{
if(m==0 && b ==0)
{
cout << "0";
}
else if(m==0 && b>=1)
cout << "y = " << b << endl;
else if(m==0 && b<=-1)
cout << "y = " << b << endl;
else if(m==1 && b==0)
cout << "y = " << "x" << endl;
else if(m==1 && b>= 1)
cout << "y = " << "x + " << b << endl;
else if(m==1 && b<=-1)
cout << "y = " << "x - " << abs(b) << endl;
else if(m==-1 && b>= 1)
cout << "y = " << "-x + " << b << endl;
else if(m==-1 && b<=-1)
cout << "y = " << "-x - " << abs(b) << endl;
else if(m==-1 && b==0)
cout << "y = " << "-x" << endl;
else if(m>1 && b>= 1)
cout << "y = " << m << "x + " << b << endl;
else if(m>1 && b<= -1)
cout << "y = " << m << "x - " << abs(b) << endl;
else if(m>1 && b==0)
cout << "y = " << m << "x" << endl;
else if(m<-1 && b>= 1)
cout << "y = -" << abs(m) << "x + " << b << endl;
else if(m<-1 && b<=-1)
cout << "y = -" << abs(m) << "x - " << abs(b) << endl;
}
} | # 0560, 2024-11-02 12:01:49, PPPPPPPPPPPPPPP-PPPPPPPP (95%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
float x=0,y=0,sigma1=0,sigma2=0,sigma3=0,sigma4=0;
float m=0,b=0;
int n=0;
string a;
cin >> n >> a;
for(int i=1;i<=n;i++)
{
cin >> x >> y;
sigma1 += x*y;
sigma2 += x;
sigma3 += y;
sigma4 += x*x;
}
m = ((n*sigma1)-(sigma2*sigma3))/((n*sigma4)-(sigma2*sigma2));
b = ((sigma3) - (m*sigma2))/n ;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(a=="mb")
{
cout << m << endl << b << endl;
}
else if(a=="func")
{
if(m==0 && b ==0)
{
cout << "0";
}
else if(m==0 && b>=1)
cout << "y = " << b << endl;
else if(m==0 && b<=-1)
cout << "y = " << b << endl;
else if(m==1 && b==0)
cout << "y = " << "x" << endl;
else if(m==1 && b>= 1)
cout << "y = " << "x + " << b << endl;
else if(m==1 && b<=-1)
cout << "y = " << "x - " << abs(b) << endl;
else if(m==-1 && b>= 1)
cout << "y = " << "-x + " << b << endl;
else if(m==-1 && b<=-1)
cout << "y = " << "-x - " << abs(b) << endl;
else if(m==-1 && b==0)
cout << "y = " << "-x" << endl;
else if(m>1 && b>= 1)
cout << "y = " << m << "x + " << b << endl;
else if(m>1 && b<= -1)
cout << "y = " << m << "x - " << abs(b) << endl;
else if(m<-1 && b>= 1)
cout << "y = -" << abs(m) << "x + " << b << endl;
else if(m<-1 && b<=-1)
cout << "y = -" << abs(m) << "x - " << abs(b) << endl;
}
} | # 0561, 2024-11-02 12:01:58, PPPPPPPPPPP-PPP-PPPPPPPP (91%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
float x=0,y=0,sigma1=0,sigma2=0,sigma3=0,sigma4=0;
float m=0,b=0;
int n=0;
string a;
cin >> n >> a;
for(int i=1;i<=n;i++)
{
cin >> x >> y;
sigma1 += x*y;
sigma2 += x;
sigma3 += y;
sigma4 += x*x;
}
m = ((n*sigma1)-(sigma2*sigma3))/((n*sigma4)-(sigma2*sigma2));
b = ((sigma3) - (m*sigma2))/n ;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(a=="mb")
{
cout << m << endl << b << endl;
}
else if(a=="func")
{
if(m==0 && b ==0)
{
cout << "0";
}
else if(m==0 && b>=1)
cout << "y = " << b << endl;
else if(m==0 && b<=-1)
cout << "y = " << b << endl;
else if(m==1 && b==0)
cout << "y = " << "x" << endl;
else if(m==1 && b>= 1)
cout << "y = " << "x + " << b << endl;
else if(m==1 && b<=-1)
cout << "y = " << "x - " << abs(b) << endl;
else if(m==-1 && b>= 1)
cout << "y = " << "-x + " << b << endl;
else if(m==-1 && b<=-1)
cout << "y = " << "-x - " << abs(b) << endl;
else if(m==-1 && b==0)
cout << "y = " << "-x" << endl;
else if(m>1 && b>= 1)
cout << "y = " << m << "x + " << b << endl;
else if(m<-1 && b>= 1)
cout << "y = -" << abs(m) << "x + " << b << endl;
else if(m<-1 && b<=-1)
cout << "y = -" << abs(m) << "x - " << abs(b) << endl;
}
} | # 0562, 2024-11-02 12:03:17, Compilation error (0%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
float x=0,y=0,sigma1=0,sigma2=0,sigma3=0,sigma4=0;
float m=0,b=0;
int n=0;
string a;
cin >> n >> a;
for(int i=1;i<=n;i++)
{
cin >> x >> y;
sigma1 += x*y;
sigma2 += x;
sigma3 += y;
sigma4 += x*x;
}
m = ((n*sigma1)-(sigma2*sigma3))/((n*sigma4)-(sigma2*sigma2));
b = ((sigma3) - (m*sigma2))/n ;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(a=="mb")
{
cout << m << endl << b << endl;
}
else if(a=="func")
{
else if(m==0 && b>=1)
cout << "y = " << b << endl;
else if(m==0 && b<=-1)
cout << "y = " << b << endl;
else if(m==1 && b==0)
cout << "y = " << "x" << endl;
else if(m==1 && b>= 1)
cout << "y = " << "x + " << b << endl;
else if(m==1 && b<=-1)
cout << "y = " << "x - " << abs(b) << endl;
else if(m==-1 && b>= 1)
cout << "y = " << "-x + " << b << endl;
else if(m==-1 && b<=-1)
cout << "y = " << "-x - " << abs(b) << endl;
else if(m==-1 && b==0)
cout << "y = " << "-x" << endl;
else if(m>1 && b>= 1)
cout << "y = " << m << "x + " << b << endl;
else if(m>1 && b<= -1)
cout << "y = " << m << "x - " << abs(b) << endl;
else if(m>1 && b==0)
cout << "y = " << m << "x" << endl;
else if(m<-1 && b>= 1)
cout << "y = -" << abs(m) << "x + " << b << endl;
else if(m<-1 && b<=-1)
cout << "y = -" << abs(m) << "x - " << abs(b) << endl;
else if(m<-1 && b==0)
cout << "y = -" << abs(m) << "x" << b << endl;
}
} | # 0563, 2024-11-02 12:03:32, PPPPPPPPPPPPPPP-PPPPPPPP (95%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
float x=0,y=0,sigma1=0,sigma2=0,sigma3=0,sigma4=0;
float m=0,b=0;
int n=0;
string a;
cin >> n >> a;
for(int i=1;i<=n;i++)
{
cin >> x >> y;
sigma1 += x*y;
sigma2 += x;
sigma3 += y;
sigma4 += x*x;
}
m = ((n*sigma1)-(sigma2*sigma3))/((n*sigma4)-(sigma2*sigma2));
b = ((sigma3) - (m*sigma2))/n ;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(a=="mb")
{
cout << m << endl << b << endl;
}
else if(a=="func")
{
if(m==0 && b>=1)
cout << "y = " << b << endl;
else if(m==0 && b<=-1)
cout << "y = " << b << endl;
else if(m==1 && b==0)
cout << "y = " << "x" << endl;
else if(m==1 && b>= 1)
cout << "y = " << "x + " << b << endl;
else if(m==1 && b<=-1)
cout << "y = " << "x - " << abs(b) << endl;
else if(m==-1 && b>= 1)
cout << "y = " << "-x + " << b << endl;
else if(m==-1 && b<=-1)
cout << "y = " << "-x - " << abs(b) << endl;
else if(m==-1 && b==0)
cout << "y = " << "-x" << endl;
else if(m>1 && b>= 1)
cout << "y = " << m << "x + " << b << endl;
else if(m>1 && b<= -1)
cout << "y = " << m << "x - " << abs(b) << endl;
else if(m>1 && b==0)
cout << "y = " << m << "x" << endl;
else if(m<-1 && b>= 1)
cout << "y = -" << abs(m) << "x + " << b << endl;
else if(m<-1 && b<=-1)
cout << "y = -" << abs(m) << "x - " << abs(b) << endl;
else if(m<-1 && b==0)
cout << "y = -" << abs(m) << "x" << b << endl;
}
} | # 0564, 2024-11-02 12:03:46, Compilation error (0%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
float x=0,y=0,sigma1=0,sigma2=0,sigma3=0,sigma4=0;
float m=0,b=0;
int n=0;
string a;
cin >> n >> a;
for(int i=1;i<=n;i++)
{
cin >> x >> y;
sigma1 += x*y;
sigma2 += x;
sigma3 += y;
sigma4 += x*x;
}
m = ((n*sigma1)-(sigma2*sigma3))/((n*sigma4)-(sigma2*sigma2));
b = ((sigma3) - (m*sigma2))/n ;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(a=="mb")
{
cout << m << endl << b << endl;
}
else if(a=="func")
{
if(m==0 && b>=1)
else if(m==0 && b<=-1)
cout << "y = " << b << endl;
else if(m==1 && b==0)
cout << "y = " << "x" << endl;
else if(m==1 && b>= 1)
cout << "y = " << "x + " << b << endl;
else if(m==1 && b<=-1)
cout << "y = " << "x - " << abs(b) << endl;
else if(m==-1 && b>= 1)
cout << "y = " << "-x + " << b << endl;
else if(m==-1 && b<=-1)
cout << "y = " << "-x - " << abs(b) << endl;
else if(m==-1 && b==0)
cout << "y = " << "-x" << endl;
else if(m>1 && b>= 1)
cout << "y = " << m << "x + " << b << endl;
else if(m>1 && b<= -1)
cout << "y = " << m << "x - " << abs(b) << endl;
else if(m>1 && b==0)
cout << "y = " << m << "x" << endl;
else if(m<-1 && b>= 1)
cout << "y = -" << abs(m) << "x + " << b << endl;
else if(m<-1 && b<=-1)
cout << "y = -" << abs(m) << "x - " << abs(b) << endl;
else if(m<-1 && b==0)
cout << "y = -" << abs(m) << "x" << b << endl;
}
} | # 0565, 2024-11-02 12:04:04, PPPPPPPPPPPPPPP--PPPPPPP (91%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
float x=0,y=0,sigma1=0,sigma2=0,sigma3=0,sigma4=0;
float m=0,b=0;
int n=0;
string a;
cin >> n >> a;
for(int i=1;i<=n;i++)
{
cin >> x >> y;
sigma1 += x*y;
sigma2 += x;
sigma3 += y;
sigma4 += x*x;
}
m = ((n*sigma1)-(sigma2*sigma3))/((n*sigma4)-(sigma2*sigma2));
b = ((sigma3) - (m*sigma2))/n ;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(a=="mb")
{
cout << m << endl << b << endl;
}
else if(a=="func")
{
if(m==0 && b<=-1)
cout << "y = " << b << endl;
else if(m==1 && b==0)
cout << "y = " << "x" << endl;
else if(m==1 && b>= 1)
cout << "y = " << "x + " << b << endl;
else if(m==1 && b<=-1)
cout << "y = " << "x - " << abs(b) << endl;
else if(m==-1 && b>= 1)
cout << "y = " << "-x + " << b << endl;
else if(m==-1 && b<=-1)
cout << "y = " << "-x - " << abs(b) << endl;
else if(m==-1 && b==0)
cout << "y = " << "-x" << endl;
else if(m>1 && b>= 1)
cout << "y = " << m << "x + " << b << endl;
else if(m>1 && b<= -1)
cout << "y = " << m << "x - " << abs(b) << endl;
else if(m>1 && b==0)
cout << "y = " << m << "x" << endl;
else if(m<-1 && b>= 1)
cout << "y = -" << abs(m) << "x + " << b << endl;
else if(m<-1 && b<=-1)
cout << "y = -" << abs(m) << "x - " << abs(b) << endl;
else if(m<-1 && b==0)
cout << "y = -" << abs(m) << "x" << b << endl;
}
} | # 0566, 2024-11-02 12:04:27, PPPPPPPPPPPPPPP-PPPPPPPP (95%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
float x=0,y=0,sigma1=0,sigma2=0,sigma3=0,sigma4=0;
float m=0,b=0;
int n=0;
string a;
cin >> n >> a;
for(int i=1;i<=n;i++)
{
cin >> x >> y;
sigma1 += x*y;
sigma2 += x;
sigma3 += y;
sigma4 += x*x;
}
m = ((n*sigma1)-(sigma2*sigma3))/((n*sigma4)-(sigma2*sigma2));
b = ((sigma3) - (m*sigma2))/n ;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(a=="mb")
{
cout << m << endl << b << endl;
}
else if(a=="func")
{
if(m==0 && b ==0)
{
cout << "0";
}
else if(m==0 && b>=1)
cout << "y = " << b << endl;
else if(m==0 && b<=-1)
cout << "y = " << b << endl;
else if(m==1 && b==0)
cout << "y = " << "x" << endl;
else if(m==1 && b>= 1)
cout << "y = " << "x + " << b << endl;
else if(m==1 && b<=-1)
cout << "y = " << "x - " << abs(b) << endl;
else if(m==-1 && b>= 1)
cout << "y = " << "-x + " << b << endl;
else if(m==-1 && b<=-1)
cout << "y = " << "-x - " << abs(b) << endl;
else if(m==-1 && b==0)
cout << "y = " << "-x" << endl;
else if(m>1 && b>= 1)
cout << "y = " << m << "x + " << b << endl;
else if(m>1 && b<= -1)
cout << "y = " << m << "x - " << abs(b) << endl;
else if(m>1 && b==0)
cout << "y = " << m << "x" << endl;
else if(m<-1 && b>= 1)
cout << "y = -" << abs(m) << "x + " << b << endl;
else if(m<-1 && b<=-1)
cout << "y = -" << abs(m) << "x - " << abs(b) << endl;
else if(m<-1 && b==0)
cout << "y = -" << abs(m) << "x" << b << endl;
}
} | # 0567, 2024-11-02 12:05:02, Compilation error (0%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
float x=0,y=0,sigma1=0,sigma2=0,sigma3=0,sigma4=0;
float m=0,b=0;
int n=0;
string a;
cin >> n >> a;
for(int i=1;i<=n;i++)
{
cin >> x >> y;
sigma1 += x*y;
sigma2 += x;
sigma3 += y;
sigma4 += x*x;
}
m = ((n*sigma1)-(sigma2*sigma3))/((n*sigma4)-(sigma2*sigma2));
b = ((sigma3) - (m*sigma2))/n ;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(a=="mb")
{
cout << m << endl << b
}
else if(a=="func")
{
if(m==0 && b ==0)
{
cout << "0";
}
else if(m==0 && b>=1)
cout << "y = " << b << endl;
else if(m==0 && b<=-1)
cout << "y = " << b << endl;
else if(m==1 && b==0)
cout << "y = " << "x" << endl;
else if(m==1 && b>= 1)
cout << "y = " << "x + " << b << endl;
else if(m==1 && b<=-1)
cout << "y = " << "x - " << abs(b) << endl;
else if(m==-1 && b>= 1)
cout << "y = " << "-x + " << b << endl;
else if(m==-1 && b<=-1)
cout << "y = " << "-x - " << abs(b) << endl;
else if(m==-1 && b==0)
cout << "y = " << "-x" << endl;
else if(m>1 && b>= 1)
cout << "y = " << m << "x + " << b << endl;
else if(m>1 && b<= -1)
cout << "y = " << m << "x - " << abs(b) << endl;
else if(m>1 && b==0)
cout << "y = " << m << "x" << endl;
else if(m<-1 && b>= 1)
cout << "y = -" << abs(m) << "x + " << b << endl;
else if(m<-1 && b<=-1)
cout << "y = -" << abs(m) << "x - " << abs(b) << endl;
else if(m<-1 && b==0)
cout << "y = -" << abs(m) << "x" << b << endl;
}
} | # 0568, 2024-11-02 12:05:09, PPPPPPPPPPPPPPP-PPPPPPPP (95%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
float x=0,y=0,sigma1=0,sigma2=0,sigma3=0,sigma4=0;
float m=0,b=0;
int n=0;
string a;
cin >> n >> a;
for(int i=1;i<=n;i++)
{
cin >> x >> y;
sigma1 += x*y;
sigma2 += x;
sigma3 += y;
sigma4 += x*x;
}
m = ((n*sigma1)-(sigma2*sigma3))/((n*sigma4)-(sigma2*sigma2));
b = ((sigma3) - (m*sigma2))/n ;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(a=="mb")
{
cout << m << endl << b ;
}
else if(a=="func")
{
if(m==0 && b ==0)
{
cout << "0";
}
else if(m==0 && b>=1)
cout << "y = " << b << endl;
else if(m==0 && b<=-1)
cout << "y = " << b << endl;
else if(m==1 && b==0)
cout << "y = " << "x" << endl;
else if(m==1 && b>= 1)
cout << "y = " << "x + " << b << endl;
else if(m==1 && b<=-1)
cout << "y = " << "x - " << abs(b) << endl;
else if(m==-1 && b>= 1)
cout << "y = " << "-x + " << b << endl;
else if(m==-1 && b<=-1)
cout << "y = " << "-x - " << abs(b) << endl;
else if(m==-1 && b==0)
cout << "y = " << "-x" << endl;
else if(m>1 && b>= 1)
cout << "y = " << m << "x + " << b << endl;
else if(m>1 && b<= -1)
cout << "y = " << m << "x - " << abs(b) << endl;
else if(m>1 && b==0)
cout << "y = " << m << "x" << endl;
else if(m<-1 && b>= 1)
cout << "y = -" << abs(m) << "x + " << b << endl;
else if(m<-1 && b<=-1)
cout << "y = -" << abs(m) << "x - " << abs(b) << endl;
else if(m<-1 && b==0)
cout << "y = -" << abs(m) << "x" << b << endl;
}
} | # 0569, 2024-11-02 12:06:19, PPPPPPPPPPPPPPP-PPPPPPPP (95%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
float x=0,y=0,sigma1=0,sigma2=0,sigma3=0,sigma4=0;
float m=0,b=0;
int n=0;
string a;
cin >> n >> a;
for(int i=1;i<=n;i++)
{
cin >> x >> y;
sigma1 += x*y;
sigma2 += x;
sigma3 += y;
sigma4 += x*x;
}
m = ((n*sigma1)-(sigma2*sigma3))/((n*sigma4)-(sigma2*sigma2));
b = ((sigma3) - (m*sigma2))/n ;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(a=="mb")
{
cout << m << endl << b << endl;
}
else if(a=="func")
{
if(m==0 && b ==0)
{
cout << "0";
}
else if(m==0 && b!=0)
cout << "y = " << b << endl;
else if(m==1 && b==0)
cout << "y = " << "x" << endl;
else if(m==1 && b>= 1)
cout << "y = " << "x + " << b << endl;
else if(m==1 && b<=-1)
cout << "y = " << "x - " << abs(b) << endl;
else if(m==-1 && b>= 1)
cout << "y = " << "-x + " << b << endl;
else if(m==-1 && b<=-1)
cout << "y = " << "-x - " << abs(b) << endl;
else if(m==-1 && b==0)
cout << "y = " << "-x" << endl;
else if(m>1 && b>= 1)
cout << "y = " << m << "x + " << b << endl;
else if(m>1 && b<= -1)
cout << "y = " << m << "x - " << abs(b) << endl;
else if(m>1 && b==0)
cout << "y = " << m << "x" << endl;
else if(m<-1 && b>= 1)
cout << "y = -" << abs(m) << "x + " << b << endl;
else if(m<-1 && b<=-1)
cout << "y = -" << abs(m) << "x - " << abs(b) << endl;
else if(m<-1 && b==0)
cout << "y = -" << abs(m) << "x" << b << endl;
}
} | # 0570, 2024-11-02 12:10:46, PPPPPPPPPPPPPPP-PPPPPPPP (95%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
float x=0,y=0,sigma1=0,sigma2=0,sigma3=0,sigma4=0;
float m=0,b=0;
int n=0;
string a;
cin >> n >> a;
for(int i=1;i<=n;i++)
{
cin >> x >> y;
sigma1 += x*y;
sigma2 += x;
sigma3 += y;
sigma4 += x*x;
}
m = ((n*sigma1)-(sigma2*sigma3))/((n*sigma4)-(sigma2*sigma2));
b = ((sigma3) - (m*sigma2))/n ;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(a=="mb")
{
cout << m << endl << b << endl;
}
else if(a=="func")
{
if(m==0 && b ==0)
{
cout << "0";
}
else if(m==0 && b!=0)
cout << "y = " << b << endl;
else if(m==1 && b==0)
cout << "y = " << "x" << endl;
else if(m==1 && b> 0)
cout << "y = " << "x + " << b << endl;
else if(m==1 && b< 0)
cout << "y = " << "x - " << abs(b) << endl;
else if(m==-1 && b> 0)
cout << "y = " << "-x + " << b << endl;
else if(m==-1 && b< 0)
cout << "y = " << "-x - " << abs(b) << endl;
else if(m==-1 && b==0)
cout << "y = " << "-x" << endl;
else if(m>1 && b> 0)
cout << "y = " << m << "x + " << b << endl;
else if(m>1 && b< 0)
cout << "y = " << m << "x - " << abs(b) << endl;
else if(m>1 && b==0)
cout << "y = " << m << "x" << endl;
else if(m<-1 && b> 0)
cout << "y = -" << abs(m) << "x + " << b << endl;
else if(m<-1 && b< 0)
cout << "y = -" << abs(m) << "x - " << abs(b) << endl;
else if(m<-1 && b==0)
cout << "y = -" << abs(m) << "x" << b << endl;
}
} | # 0571, 2024-11-02 12:11:31, PPPPPPPPPPPPPPP-PPPPPPPP (95%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
float x=0,y=0,sigma1=0,sigma2=0,sigma3=0,sigma4=0;
float m=0,b=0;
int n=0;
string a;
cin >> n >> a;
for(int i=1;i<=n;i++)
{
cin >> x >> y;
sigma1 += x*y;
sigma2 += x;
sigma3 += y;
sigma4 += x*x;
}
m = ((n*sigma1)-(sigma2*sigma3))/((n*sigma4)-(sigma2*sigma2));
b = ((sigma3) - (m*sigma2))/n ;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(a=="mb")
{
cout << m << endl << b << endl;
}
else if(a=="func")
{
if(m==0 && b ==0)
{
cout << "0";
}
else if(m==0 && b!=0)
cout << "y = " << b << endl;
else if(m==1 && b==0)
cout << "y = " << "x" << endl;
else if(m==1 && b> 0)
cout << "y = " << "x + " << b << endl;
else if(m==1 && b< 0)
cout << "y = " << "x - " << abs(b) << endl;
else if(m==-1 && b> 0)
cout << "y = " << "-x + " << b << endl;
else if(m==-1 && b< 0)
cout << "y = " << "-x - " << abs(b) << endl;
else if(m==-1 && b==0)
cout << "y = " << "-x" << endl;
else if(m>1 && b> 0)
cout << "y = " << m << "x + " << b << endl;
else if(m>1 && b< 0)
cout << "y = " << m << "x - " << abs(b) << endl;
else if(m>1 && b==0)
cout << "y = " << m << "x" << endl;
else if(m<0 && b> 0)
cout << "y = -" << abs(m) << "x + " << b << endl;
else if(m<0 && b< 0)
cout << "y = -" << abs(m) << "x - " << abs(b) << endl;
else if(m<0 && b==0)
cout << "y = -" << abs(m) << "x" << b << endl;
}
} | # 0572, 2024-11-02 12:11:47, PPPPPPPPPPPPPPP-PPPPPPPP (95%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
float x=0,y=0,sigma1=0,sigma2=0,sigma3=0,sigma4=0;
float m=0,b=0;
int n=0;
string a;
cin >> n >> a;
for(int i=1;i<=n;i++)
{
cin >> x >> y;
sigma1 += x*y;
sigma2 += x;
sigma3 += y;
sigma4 += x*x;
}
m = ((n*sigma1)-(sigma2*sigma3))/((n*sigma4)-(sigma2*sigma2));
b = ((sigma3) - (m*sigma2))/n ;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(a=="mb")
{
cout << m << endl << b << endl;
}
else if(a=="func")
{
if(m==0 && b ==0)
{
cout << "0";
}
else if(m==0 && b!=0)
cout << "y = " << b << endl;
else if(m==1 && b==0)
cout << "y = " << "x" << endl;
else if(m==1 && b> 0)
cout << "y = " << "x + " << b << endl;
else if(m==1 && b< 0)
cout << "y = " << "x - " << abs(b) << endl;
else if(m==-1 && b> 0)
cout << "y = " << "-x + " << b << endl;
else if(m==-1 && b< 0)
cout << "y = " << "-x - " << abs(b) << endl;
else if(m==-1 && b==0)
cout << "y = " << "-x" << endl;
else if(m>0 && b> 0)
cout << "y = " << m << "x + " << b << endl;
else if(m>0 && b< 0)
cout << "y = " << m << "x - " << abs(b) << endl;
else if(m>0 && b==0)
cout << "y = " << m << "x" << endl;
else if(m<0 && b> 0)
cout << "y = -" << abs(m) << "x + " << b << endl;
else if(m<0 && b< 0)
cout << "y = -" << abs(m) << "x - " << abs(b) << endl;
else if(m<0 && b==0)
cout << "y = -" << abs(m) << "x" << b << endl;
}
} |
# 0573, 2024-11-02 10:18:54, -----PPPPP-----PP--PPP-P (45%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios ::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
float N = n;
string ip;
cin >> ip;
float tmpx,tmpy,sumx=0.0,sumy=0.0,sumxy=0.0,sumpowx =0.0;
for(int i = 0 ; i< n ; i++)
{
cin >> tmpx >> tmpy;
sumx += tmpx;
sumy += tmpy;
sumxy += tmpx * tmpy;
sumpowx += tmpx * tmpx;
}
float xm = round((((N*sumxy)-(sumx*sumy))/((N*sumpowx)-(pow(sumx,2))))*1e3)/1e3;
float xb = round(((sumy - (xm * sumx))/(N))*1e3)/1e3;
if(ip == "mb")
{
cout << xm << "\n" << xb;
}
else
{
if (xm == 0 && xb == 0)
{
cout << "y = 0";
}
else if (xm == -1)
{
cout << "y = -x ";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << "+ " << xb;
}
else
{
cout << "- " << abs(xb);
}
}
else if (xm > 0 || xm > 0)
{
cout << "y = " << xm << "x ";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << "+ " << xb;
}
else
{
cout << "- " << abs(xb);
}
}
else if (xm == 0)
{
cout << "y = ";
if (xb == 0)
{
return 0;
}
else
{
cout << xb;
}
}
}
return 0;
} | # 0574, 2024-11-02 10:21:03, -----PPPPP-----PPPPPPPPP (58%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios ::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
float N = n;
string ip;
cin >> ip;
float tmpx,tmpy,sumx=0.0,sumy=0.0,sumxy=0.0,sumpowx =0.0;
for(int i = 0 ; i< n ; i++)
{
cin >> tmpx >> tmpy;
sumx += tmpx;
sumy += tmpy;
sumxy += tmpx * tmpy;
sumpowx += tmpx * tmpx;
}
float xm = round((((N*sumxy)-(sumx*sumy))/((N*sumpowx)-(pow(sumx,2))))*1e3)/1e3;
float xb = round(((sumy - (xm * sumx))/(N))*1e3)/1e3;
if(ip == "mb")
{
cout << xm << "\n" << xb;
}
else
{
if (xm == 0 && xb == 0)
{
cout << "y = 0";
}
else if (xm == -1)
{
cout << "y = -x ";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << "+ " << xb;
}
else
{
cout << "- " << abs(xb);
}
}
else if (xm == 1)
{
cout << "y = x ";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << "+ " << xb;
}
else
{
cout << "- " << abs(xb);
}
}
else if (xm > 0 || xm > 0)
{
cout << "y = " << xm << "x ";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << "+ " << xb;
}
else
{
cout << "- " << abs(xb);
}
}
else if (xm == 0)
{
cout << "y = ";
if (xb == 0)
{
return 0;
}
else
{
cout << xb;
}
}
}
return 0;
} | # 0575, 2024-11-02 10:25:18, -----PPPPP-----PPPPPPPPP (58%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios ::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
float N = n;
string ip;
cin >> ip;
float tmpx,tmpy,sumx=0.0,sumy=0.0,sumxy=0.0,sumpowx =0.0;
for(int i = 0 ; i< n ; i++)
{
cin >> tmpx >> tmpy;
sumx += tmpx;
sumy += tmpy;
sumxy += tmpx * tmpy;
sumpowx += tmpx * tmpx;
}
float xm = round((((N*sumxy)-(sumx*sumy))/((N*sumpowx)-(pow(sumx,2))))*1e3)/1e3;
float xb = round(((sumy - (xm * sumx))/(N))*1e3)/1e3;
if(ip == "mb")
{
cout << xm << "\n" << xb;
}
else
{
if (xm == 0 && xb == 0)
{
cout << "y = 0";
}
else if (xm == -1)
{
cout << "y = -x ";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << "+ " << xb;
}
else
{
cout << "- " << abs(xb);
}
}
else if (xm == 1)
{
cout << "y = x ";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << "+ " << xb;
}
else
{
cout << "- " << abs(xb);
}
}
else if (xm > 0 || xm > 0)
{
cout << "y = " << xm << "x ";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << "+ " << xb;
}
else
{
cout << "- " << abs(xb);
}
}
else if (xm == 0 && xb != 0)
{
cout << "y = "<< xb;
}
}
return 0;
} | # 0576, 2024-11-02 10:26:22, -----PPPPP-----PPPPPPPPP (58%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios ::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
float N = n;
string ip;
cin >> ip;
float tmpx,tmpy,sumx=0.0,sumy=0.0,sumxy=0.0,sumpowx =0.0;
for(int i = 0 ; i< n ; i++)
{
cin >> tmpx >> tmpy;
sumx += tmpx;
sumy += tmpy;
sumxy += tmpx * tmpy;
sumpowx += tmpx * tmpx;
}
float xm = round((((N*sumxy)-(sumx*sumy))/((N*sumpowx)-(pow(sumx,2))))*1e3)/1e3;
float xb = round(((sumy - (xm * sumx))/(N))*1e3)/1e3;
if(ip == "mb")
{
cout << xm << "\n" << xb;
}
else
{
if (xm == 0 && xb == 0)
{
cout << "y = 0";
}
else if (xm == -1)
{
cout << "y = -x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else
{
cout << " - " << abs(xb);
}
}
else if (xm == 1)
{
cout << "y = x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else
{
cout << " - " << abs(xb);
}
}
else if (xm > 0 || xm > 0)
{
cout << "y = " << xm << "x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else
{
cout << " - " << abs(xb);
}
}
else if (xm == 0 && xb != 0)
{
cout << "y = "<< xb;
}
}
return 0;
} | # 0577, 2024-11-02 10:28:30, -----PPPPP-----PPPPPPPPP (58%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios ::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
float N = n;
string ip;
cin >> ip;
float tmpx,tmpy,sumx=0.0,sumy=0.0,sumxy=0.0,sumpowx =0.0;
for(int i = 0 ; i< n ; i++)
{
cin >> tmpx >> tmpy;
sumx += tmpx;
sumy += tmpy;
sumxy += tmpx * tmpy;
sumpowx += tmpx * tmpx;
}
float xm = round((((N*sumxy)-(sumx*sumy))/((N*sumpowx)-(pow(sumx,2))))*1e3)/1e3;
float xb = round(((sumy - (xm * sumx))/(N))*1e3)/1e3;
if(ip == "mb")
{
cout << xm << "\n" << xb;
}
else if (ip == "func")
{
if (xm == 0 && xb == 0)
{
cout << "y = 0";
}
else if (xm == -1)
{
cout << "y = -x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else
{
cout << " - " << abs(xb);
}
}
else if (xm == 1)
{
cout << "y = x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else
{
cout << " - " << abs(xb);
}
}
else if (xm > 0 || xm > 0)
{
cout << "y = " << xm << "x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else
{
cout << " - " << abs(xb);
}
}
else if (xm == 0 && xb != 0)
{
cout << "y = "<< xb;
}
}
return 0;
} | # 0578, 2024-11-02 10:43:24, -----PPPPP-----PPPPPPPPP (58%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios ::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
float N = n;
string ip;
cin >> ip;
float tmpx = 0.0,tmpy = 0.0,sumx=0.0,sumy=0.0,sumxy=0.0,sumpowx =0.0;
for(int i = 0 ; i< n ; i++)
{
cin >> tmpx >> tmpy;
sumx += tmpx;
sumy += tmpy;
sumxy += tmpx * tmpy;
sumpowx += tmpx * tmpx;
}
float xm = round((((N*sumxy)-(sumx*sumy))/((N*sumpowx)-(pow(sumx,2))))*1e3)/1e3;
float xb = round(((sumy - (xm * sumx))/(N))*1e3)/1e3;
if(ip == "mb")
{
cout << xm << "\n" << xb;
}
else if (ip == "func")
{
if (xm == 0 && xb == 0)
{
cout << "y = 0";
}
else if (xm == -1)
{
cout << "y = -x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else
{
cout << " - " << abs(xb);
}
}
else if (xm == 1)
{
cout << "y = x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else
{
cout << " - " << abs(xb);
}
}
else if (xm > 0 || xm > 0)
{
cout << "y = " << xm << "x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else
{
cout << " - " << abs(xb);
}
}
else if (xm == 0 && xb != 0)
{
cout << "y = "<< xb;
}
}
return 0;
} | # 0579, 2024-11-02 10:43:41, -----PPPPP-----PPPPPPPPP (58%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
float N = n;
string ip;
cin >> ip;
float tmpx = 0.0,tmpy = 0.0,sumx=0.0,sumy=0.0,sumxy=0.0,sumpowx =0.0;
for(int i = 0 ; i< n ; i++)
{
cin >> tmpx >> tmpy;
sumx += tmpx;
sumy += tmpy;
sumxy += tmpx * tmpy;
sumpowx += tmpx * tmpx;
}
float xm = round((((N*sumxy)-(sumx*sumy))/((N*sumpowx)-(pow(sumx,2))))*1e3)/1e3;
float xb = round(((sumy - (xm * sumx))/(N))*1e3)/1e3;
if(ip == "mb")
{
cout << xm << "\n" << xb;
}
else if (ip == "func")
{
if (xm == 0 && xb == 0)
{
cout << "y = 0";
}
else if (xm == -1)
{
cout << "y = -x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else
{
cout << " - " << abs(xb);
}
}
else if (xm == 1)
{
cout << "y = x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else
{
cout << " - " << abs(xb);
}
}
else if (xm > 0 || xm > 0)
{
cout << "y = " << xm << "x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else
{
cout << " - " << abs(xb);
}
}
else if (xm == 0 && xb != 0)
{
cout << "y = "<< xb;
}
}
return 0;
} | # 0580, 2024-11-02 10:51:01, PPPPPP-PPPPP---PPPPPPPPP (83%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios ::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
float N = n;
string ip;
cin >> ip;
float tmpx = 0.0,tmpy = 0.0,sumx=0.0,sumy=0.0,sumxy=0.0,sumpowx =0.0;
for(int i = 0 ; i< n ; i++)
{
cin >> tmpx >> tmpy;
sumx += tmpx;
sumy += tmpy;
sumxy += tmpx * tmpy;
sumpowx += pow(tmpx,2);
}
float xm = round((((N*sumxy)-(sumx*sumy))/((N*sumpowx)-(pow(sumx,2))))*1e3)/1e3;
float xb = round(((sumy - (((((N*sumxy)-(sumx*sumy))/((N*sumpowx)-(pow(sumx,2))))) * sumx))/(N))*1e3)/1e3;
if(ip == "mb")
{
cout << xm << "\n" << xb;
}
else if (ip == "func")
{
if (xm == 0 && xb == 0)
{
cout << "y = 0";
}
else if (xm == -1)
{
cout << "y = -x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else
{
cout << " - " << abs(xb);
}
}
else if (xm == 1)
{
cout << "y = x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else
{
cout << " - " << abs(xb);
}
}
else if (xm > 0 || xm > 0)
{
cout << "y = " << xm << "x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else
{
cout << " - " << abs(xb);
}
}
else if (xm == 0 && xb != 0)
{
cout << "y = "<< xb;
}
}
return 0;
} | # 0581, 2024-11-02 12:01:32, PPPPPP-PPPPP---PPPPPPPPP (83%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios ::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
string ip;
cin >> ip;
float tmpx = 0.0,tmpy = 0.0,sumx=0.0,sumy=0.0,sumxy=0.0,sumpowx =0.0;
for(int i = 0 ; i< n ; i++)
{
cin >> tmpx >> tmpy;
sumx += tmpx;
sumy += tmpy;
sumxy += tmpx * tmpy;
sumpowx += pow(tmpx,2);
}
float xm = round((((n*sumxy)-(sumx*sumy))/((n*sumpowx)-(pow(sumx,2))))*1e3)/1e3;
float xb = round(((sumy - (((((n*sumxy)-(sumx*sumy))/((n*sumpowx)-(pow(sumx,2))))) * sumx))/(n))*1e3)/1e3;
if(ip == "mb")
{
cout << xm << "\n" << xb;
}
else if (ip == "func")
{
if (xm == 0 && xb == 0)
{
cout << "y = 0";
}
else if (xm == -1)
{
cout << "y = -x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else
{
cout << " - " << abs(xb);
}
}
else if (xm == 1)
{
cout << "y = x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else
{
cout << " - " << abs(xb);
}
}
else if (xm > 0 || xm > 0)
{
cout << "y = " << xm << "x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else
{
cout << " - " << abs(xb);
}
}
else if (xm == 0 && xb != 0)
{
cout << "y = "<< xb;
}
}
return 0;
} | # 0582, 2024-11-02 12:02:57, PPPPPP-PPPPP---PPPPPPPPP (83%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios ::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
string ip;
cin >> ip;
float tmpx = 0,tmpy = 0,sumx=0,sumy=0,sumxy=0,sumpowx =0;
for(int i = 0 ; i< n ; i++)
{
cin >> tmpx >> tmpy;
sumx += tmpx;
sumy += tmpy;
sumxy += tmpx * tmpy;
sumpowx += pow(tmpx,2);
}
float xm = round((((n*sumxy)-(sumx*sumy))/((n*sumpowx)-(pow(sumx,2))))*1e3)/1e3;
float xb = round(((sumy - (((((n*sumxy)-(sumx*sumy))/((n*sumpowx)-(pow(sumx,2))))) * sumx))/(n))*1e3)/1e3;
if(ip == "mb")
{
cout << xm << "\n" << xb;
}
else if (ip == "func")
{
if (xm == 0 && xb == 0)
{
cout << "y = 0";
}
else if (xm == -1)
{
cout << "y = -x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else
{
cout << " - " << abs(xb);
}
}
else if (xm == 1)
{
cout << "y = x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else
{
cout << " - " << abs(xb);
}
}
else if (xm > 0 || xm > 0)
{
cout << "y = " << xm << "x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else
{
cout << " - " << abs(xb);
}
}
else if (xm == 0 && xb != 0)
{
cout << "y = "<< xb;
}
}
return 0;
} | # 0583, 2024-11-02 12:04:43, PPPPPP-PPPPP---PPPPPPPPP (83%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios ::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
string ip;
cin >> ip;
float tmpx = 0,tmpy = 0,sumx=0,sumy=0,sumxy=0,sumpowx =0;
for(int i = 0 ; i< n ; i++)
{
cin >> tmpx >> tmpy;
sumx += tmpx;
sumy += tmpy;
sumxy += tmpx * tmpy;
sumpowx += pow(tmpx,2);
}
float xm = round((((n*sumxy)-(sumx*sumy))/((n*sumpowx)-(pow(sumx,2))))*1e3)/1e3;
float xb = round(((sumy - (((((n*sumxy)-(sumx*sumy))/((n*sumpowx)-(pow(sumx,2))))) * sumx))/n)*1e3)/1e3;
if(ip == "mb")
{
cout << xm << "\n" << xb;
}
else if (ip == "func")
{
if (xm == 0 && xb == 0)
{
cout << "y = 0";
}
else if (xm == -1)
{
cout << "y = -x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else
{
cout << " - " << abs(xb);
}
}
else if (xm == 1)
{
cout << "y = x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else
{
cout << " - " << abs(xb);
}
}
else if (xm > 0 || xm > 0)
{
cout << "y = " << xm << "x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else
{
cout << " - " << abs(xb);
}
}
else if (xm == 0 && xb != 0)
{
cout << "y = "<< xb;
}
}
return 0;
} | # 0584, 2024-11-02 12:07:32, PPPPPP-PPPPPPPPPPPPPPPPP (95%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios ::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
string ip;
cin >> ip;
float tmpx = 0,tmpy = 0,sumx=0,sumy=0,sumxy=0,sumpowx =0;
for(int i = 0 ; i< n ; i++)
{
cin >> tmpx >> tmpy;
sumx += tmpx;
sumy += tmpy;
sumxy += tmpx * tmpy;
sumpowx += pow(tmpx,2);
}
float xm = round((((n*sumxy)-(sumx*sumy))/((n*sumpowx)-(pow(sumx,2))))*1e3)/1e3;
float xb = round(((sumy - (((((n*sumxy)-(sumx*sumy))/((n*sumpowx)-(pow(sumx,2))))) * sumx))/n)*1e3)/1e3;
if(ip == "mb")
{
cout << xm << "\n" << xb;
}
else if (ip == "func")
{
if (xm == 0 && xb == 0)
{
cout << "y = 0";
}
else if (xm == -1)
{
cout << "y = -x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else if (xb < 0)
{
cout << " - " << abs(xb);
}
}
else if (xm == 1)
{
cout << "y = x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else if (xb < 0)
{
cout << " - " << abs(xb);
}
}
else if (xm > 0)
{
cout << "y = " << xm << "x";
if (xb == 0)
{
return 0;
}
else if (xb > 0)
{
cout << " + " << xb;
}
else if (xb < 0)
{
cout << " - " << abs(xb);
}
}
else if (xm < 0)
{
cout << "y = " << xm << "x";
if (xb == 0)
{
return 0;
}
else if (xb > 0)
{
cout << " + " << xb;
}
else if (xb < 0)
{
cout << " - " << abs(xb);
}
}
else if (xm == 0 && xb != 0)
{
cout << "y = "<< xb;
}
}
return 0;
} | # 0585, 2024-11-02 12:08:43, PPPPPP-PPPPPPPPP-PPPP-PP (87%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios ::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
string ip;
cin >> ip;
float tmpx = 0,tmpy = 0,sumx=0,sumy=0,sumxy=0,sumpowx =0;
for(int i = 0 ; i< n ; i++)
{
cin >> tmpx >> tmpy;
sumx += tmpx;
sumy += tmpy;
sumxy += tmpx * tmpy;
sumpowx += pow(tmpx,2);
}
float xm = round((((n*sumxy)-(sumx*sumy))/((n*sumpowx)-(pow(sumx,2))))*1e3)/1e3;
float xb = round(((sumy - (((((n*sumxy)-(sumx*sumy))/((n*sumpowx)-(pow(sumx,2))))) * sumx))/n)*1e3)/1e3;
if(ip == "mb")
{
cout << xm << "\n" << xb;
}
else if (ip == "func")
{
if (xm == 0 && xb == 0)
{
cout << "y = 0";
}
else if (xm == -1)
{
cout << "y = -x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else if (xb < 0)
{
cout << " - " << abs(xb);
}
}
else if (xm == 1)
{
cout << "y = x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else if (xb < 0)
{
cout << " - " << abs(xb);
}
}
else if (xm > 0)
{
cout << "y = " << xm << "x";
if (xb == 0)
{
return 0;
}
else if (xb > 0)
{
cout << " + " << xb;
}
else if (xb < 0)
{
cout << " - " << abs(xb);
}
}
else if (xm < 0)
{
cout << "y = " << xm << "x";
if (xb == 0)
{
return 0;
}
else if (xb > 0)
{
cout << " + " << xb;
}
else if (xb < 0)
{
cout << " - " << abs(xb);
}
}
}
return 0;
} | # 0586, 2024-11-02 12:08:56, PPPPPP-PPPPPPPPPPPPPPPPP (95%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios ::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
string ip;
cin >> ip;
float tmpx = 0,tmpy = 0,sumx=0,sumy=0,sumxy=0,sumpowx =0;
for(int i = 0 ; i< n ; i++)
{
cin >> tmpx >> tmpy;
sumx += tmpx;
sumy += tmpy;
sumxy += tmpx * tmpy;
sumpowx += pow(tmpx,2);
}
float xm = round((((n*sumxy)-(sumx*sumy))/((n*sumpowx)-(pow(sumx,2))))*1e3)/1e3;
float xb = round(((sumy - (((((n*sumxy)-(sumx*sumy))/((n*sumpowx)-(pow(sumx,2))))) * sumx))/n)*1e3)/1e3;
if(ip == "mb")
{
cout << xm << "\n" << xb;
}
else if (ip == "func")
{
if (xm == 0 && xb == 0)
{
cout << "y = 0";
}
else if (xm == -1)
{
cout << "y = -x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else if (xb < 0)
{
cout << " - " << abs(xb);
}
}
else if (xm == 1)
{
cout << "y = x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else if (xb < 0)
{
cout << " - " << abs(xb);
}
}
else if (xm > 0)
{
cout << "y = " << xm << "x";
if (xb == 0)
{
return 0;
}
else if (xb > 0)
{
cout << " + " << xb;
}
else if (xb < 0)
{
cout << " - " << abs(xb);
}
}
else if (xm < 0)
{
cout << "y = " << xm << "x";
if (xb == 0)
{
return 0;
}
else if (xb > 0)
{
cout << " + " << xb;
}
else if (xb < 0)
{
cout << " - " << abs(xb);
}
}
else if (xm == 0 && xb != 0)
{
cout << "y = "<< xb;
}
}
return 0;
} | # 0587, 2024-11-02 12:09:33, PPPPPP-PPPPPPPPPPPPPPPPP (95%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios ::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
string ip;
cin >> ip;
float tmpx = 0,tmpy = 0,sumx=0,sumy=0,sumxy=0,sumpowx =0;
for(int i = 0 ; i< n ; i++)
{
cin >> tmpx >> tmpy;
sumx += tmpx;
sumy += tmpy;
sumxy += tmpx * tmpy;
sumpowx += pow(tmpx,2);
}
float xm = round((((n*sumxy)-(sumx*sumy))/((n*sumpowx)-(pow(sumx,2))))*1e3)/1e3;
float xb = round(((sumy - (((((n*sumxy)-(sumx*sumy))/((n*sumpowx)-(pow(sumx,2))))) * sumx))/n)*1e3)/1e3;
if(ip == "mb")
{
cout << xm << "\n" << xb;
}
else if (ip == "func")
{
if (xm == 0 && xb == 0)
{
cout << "y = 0";
}
else if (xm == 0 && xb != 0)
{
cout << "y = "<< xb;
}
else if (xm == -1)
{
cout << "y = -x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else if (xb < 0)
{
cout << " - " << abs(xb);
}
}
else if (xm == 1)
{
cout << "y = x";
if (xb == 0)
{
return 0;
}
else if ( xb > 0)
{
cout << " + " << xb;
}
else if (xb < 0)
{
cout << " - " << abs(xb);
}
}
else if (xm > 0)
{
cout << "y = " << xm << "x";
if (xb == 0)
{
return 0;
}
else if (xb > 0)
{
cout << " + " << xb;
}
else if (xb < 0)
{
cout << " - " << abs(xb);
}
}
else if (xm < 0)
{
cout << "y = " << xm << "x";
if (xb == 0)
{
return 0;
}
else if (xb > 0)
{
cout << " + " << xb;
}
else if (xb < 0)
{
cout << " - " << abs(xb);
}
}
}
return 0;
} |
# 0588, 2024-11-02 12:52:43, -----PPPPP-------------- (20%)
#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int>> vv; //x,y
float sum_x(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].first);
}
return sum;
}
float sum_y(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].second);
}
return sum;
}
float sum_xy(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].first*vv[i].second);
}
return sum;
}
float sum_xx(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].first*vv[i].first);
}
return sum;
}
int main(){
int n; float m,b,x,y; string s;
cin>>n>>s;
for(int i=0;i<n;i++){
cin>>x>>y;
vv.push_back({x,y});
}
if(s=="mb"){
m=(n*sum_xy(n)-(sum_x(n)*sum_y(n)))/(n*sum_xx(n)-(pow(sum_x(n),2.0)));
b=(sum_y(n)-(m*sum_x(n)))/n;
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
}
else
return 0;
} | # 0589, 2024-11-02 13:02:32, -----PPPPP-----P--PP-P-- (37%)
#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int>> vv; //x,y
float sum_x(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].first);
}
return sum;
}
float sum_y(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].second);
}
return sum;
}
float sum_xy(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].first*vv[i].second);
}
return sum;
}
float sum_xx(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].first*vv[i].first);
}
return sum;
}
int main(){
int n; float m,b,x,y; string s;
cin>>n>>s;
for(int i=0;i<n;i++){
cin>>x>>y;
vv.push_back({x,y});
}
m=(n*sum_xy(n)-(sum_x(n)*sum_y(n)))/(n*sum_xx(n)-(pow(sum_x(n),2.0)));
b=(sum_y(n)-(m*sum_x(n)))/n;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
}
else{
b=round(b*1e3)/1e3;
m=round(m*1e3)/1e3;
if(m==1.0){
if(b==0.0) cout<<"y = x";
else if(b<0.0) cout<<"y = x "<<b;
else cout<<"y = x"<<" + "<<b;
}
else if(m==-1.0){
if(b==0.0) cout<<"y = -x";
else if(b<0.0) cout<<"y = -x "<<b;
else cout<<"y = -x"<<" + "<<b;
}
else if(m==0.0){
if(b==0.0) cout<<"y = 0";
else if(b<0.0) cout<<"y = "<<b;
else cout<<"y ="<<" + "<<b;
}
}
return 0;
} | # 0590, 2024-11-02 13:06:52, PPPPPPP-PP-----P-PPPPP-- (62%)
#include<bits/stdc++.h>
using namespace std;
vector<pair<float,float>> vv; //x,y
float sum_x(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].first);
}
return sum;
}
float sum_y(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].second);
}
return sum;
}
float sum_xy(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].first*vv[i].second);
}
return sum;
}
float sum_xx(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].first*vv[i].first);
}
return sum;
}
int main(){
int n; float m,b,x,y; string s;
cin>>n>>s;
for(int i=0;i<n;i++){
cin>>x>>y;
vv.push_back({x,y});
}
m=(n*sum_xy(n)-(sum_x(n)*sum_y(n)))/(n*sum_xx(n)-(pow(sum_x(n),2.0)));
b=(sum_y(n)-(m*sum_x(n)))/n;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
}
else{
b=round(b*1e3)/1e3;
m=round(m*1e3)/1e3;
if(m==1.0){
if(b==0.0) cout<<"y = x";
else if(b<0.0) cout<<"y = x "<<b;
else cout<<"y = x"<<" + "<<b;
}
else if(m==-1.0){
if(b==0.0) cout<<"y = -x";
else if(b<0.0) cout<<"y = -x "<<b;
else cout<<"y = -x"<<" + "<<b;
}
else if(m==0.0){
if(b==0.0) cout<<"y = 0";
else if(b<0.0) cout<<"y = "<<b;
else cout<<"y ="<<" + "<<b;
}
}
return 0;
} | # 0591, 2024-11-02 13:11:10, PPPPPPP-PPP-P--P-PPPPP-- (70%)
#include<bits/stdc++.h>
using namespace std;
vector<pair<float,float>> vv; //x,y
float sum_x(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].first);
}
return sum;
}
float sum_y(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].second);
}
return sum;
}
float sum_xy(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].first*vv[i].second);
}
return sum;
}
float sum_xx(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].first*vv[i].first);
}
return sum;
}
int main(){
int n; float m,b,x,y; string s;
cin>>n>>s;
for(int i=0;i<n;i++){
cin>>x>>y;
vv.push_back({x,y});
}
m=(n*sum_xy(n)-(sum_x(n)*sum_y(n)))/(n*sum_xx(n)-(pow(sum_x(n),2.0)));
b=(sum_y(n)-(m*sum_x(n)))/n;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
}
else{
b=round(b*1e3)/1e3;
m=round(m*1e3)/1e3;
if(m==1.0){
if(b==0.0) cout<<"y = x";
else if(b<0.0) cout<<"y = x "<<b;
else cout<<"y = x"<<" + "<<b;
}
else if(m==-1.0){
if(b==0.0) cout<<"y = -x";
else if(b<0.0) cout<<"y = -x "<<b;
else cout<<"y = -x"<<" + "<<b;
}
else if(m==0.0){
if(b==0.0) cout<<"y = 0";
else if(b<0.0) cout<<"y = "<<b;
else cout<<"y ="<<" + "<<b;
}
else{
if(b==0.0) cout<<"y = "<<m<<"x";
else if(b<0.0) cout<<"y = "<<m<< "x "<<b;
else cout<<"y = "<<m<<"x + "<<b;
}
}
return 0;
} | # 0592, 2024-11-02 13:13:54, PPPPPPP-PPP----P-PPPPP-- (66%)
#include<bits/stdc++.h>
using namespace std;
vector<pair<float,float>> vv; //x,y
float sum_x(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].first);
}
return sum;
}
float sum_y(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].second);
}
return sum;
}
float sum_xy(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].first*vv[i].second);
}
return sum;
}
float sum_xx(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].first*vv[i].first);
}
return sum;
}
int main(){
int n; float m,b,x,y; string s;
cin>>n>>s;
for(int i=0;i<n;i++){
cin>>x>>y;
vv.push_back({x,y});
}
m=(n*sum_xy(n)-(sum_x(n)*sum_y(n)))/(n*sum_xx(n)-(pow(sum_x(n),2.0)));
b=(sum_y(n)-(m*sum_x(n)))/n;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
}
else{
b=round(b*1e3)/1e3;
m=round(m*1e3)/1e3;
if(m==1.0){
if(b==0.0) cout<<"y = x";
else if(b<0.0) cout<<"y = x "<<b;
else cout<<"y = x"<<" + "<<b;
}
else if(m==-1.0){
if(b==0.0) cout<<"y = -x";
else if(b<0.0) cout<<"y = -x "<<b;
else cout<<"y = -x"<<" + "<<b;
}
else if(m==0.0){
if(b==0.0) cout<<"y = 0";
else if(b<0.0) cout<<"y = "<<b;
else cout<<"y ="<<" + "<<b;
}
else{
if(m>=0.0){
if(b==0.0) cout<<"y = "<<m<<"x";
else if(b<0.0) cout<<"y = "<<m<< "x "<<b;
else cout<<"y = "<<m<<"x + "<<b;
}
else{
if(b==0.0) cout<<"y = -"<<m<<"x";
else if(b<0.0) cout<<"y = -"<<m<< "x "<<b;
else cout<<"y = -"<<m<<"x + "<<b;
}
}
}
return 0;
} | # 0593, 2024-11-02 13:14:19, PPPPPPP-PPP-P--P-PPPPP-- (70%)
#include<bits/stdc++.h>
using namespace std;
vector<pair<float,float>> vv; //x,y
float sum_x(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].first);
}
return sum;
}
float sum_y(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].second);
}
return sum;
}
float sum_xy(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].first*vv[i].second);
}
return sum;
}
float sum_xx(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].first*vv[i].first);
}
return sum;
}
int main(){
int n; float m,b,x,y; string s;
cin>>n>>s;
for(int i=0;i<n;i++){
cin>>x>>y;
vv.push_back({x,y});
}
m=(n*sum_xy(n)-(sum_x(n)*sum_y(n)))/(n*sum_xx(n)-(pow(sum_x(n),2.0)));
b=(sum_y(n)-(m*sum_x(n)))/n;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
}
else{
b=round(b*1e3)/1e3;
m=round(m*1e3)/1e3;
if(m==1.0){
if(b==0.0) cout<<"y = x";
else if(b<0.0) cout<<"y = x "<<b;
else cout<<"y = x"<<" + "<<b;
}
else if(m==-1.0){
if(b==0.0) cout<<"y = -x";
else if(b<0.0) cout<<"y = -x "<<b;
else cout<<"y = -x"<<" + "<<b;
}
else if(m==0.0){
if(b==0.0) cout<<"y = 0";
else if(b<0.0) cout<<"y = "<<b;
else cout<<"y ="<<" + "<<b;
}
else{
if(b==0.0) cout<<"y = "<<m<<"x";
else if(b<0.0) cout<<"y = "<<m<< "x "<<b;
else cout<<"y = "<<m<<"x + "<<b;
}
}
return 0;
} | # 0594, 2024-11-02 14:11:35, PPPPPPP-PPPPPPPP-PPPPPPP (91%)
#include<bits/stdc++.h>
using namespace std;
vector<pair<float,float>> vv; //x,y
float sum_x(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].first);
}
return sum;
}
float sum_y(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].second);
}
return sum;
}
float sum_xy(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].first*vv[i].second);
}
return sum;
}
float sum_xx(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].first*vv[i].first);
}
return sum;
}
int main(){
int n; float m,b,x,y; string s;
cin>>n>>s;
for(int i=0;i<n;i++){
cin>>x>>y;
vv.push_back({x,y});
}
m=(n*sum_xy(n)-(sum_x(n)*sum_y(n)))/(n*sum_xx(n)-(pow(sum_x(n),2.0)));
b=(sum_y(n)-(m*sum_x(n)))/n;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
}
else{
b=round(b*1e3)/1e3;
m=round(m*1e3)/1e3;
if(m==1.0){
if(b==0.0) cout<<"y = x";
else if(b<0.0) {
cout<<"y = x - "<<abs(b);
}
else cout<<"y = x"<<" + "<<b;
}
else if(m==-1.0){
if(b==0.0) cout<<"y = -x";
else if(b<0.0) {
cout<<"y = -x - "<<abs(b);
}
else cout<<"y = -x"<<" + "<<b;
}
else if(m==0.0){
if(b==0.0) cout<<"y = 0";
else if(b<0.0) {
/////////////////
cout<<"y = "<<b;
}
else cout<<"y ="<<" + "<<b;
}
else{
if(b==0.0) cout<<"y = "<<m<<"x";
else if(b<0.0) {
///////////////
cout<<"y = "<<m<< "x - "<<abs(b);
}
else cout<<"y = "<<m<<"x + "<<b;
}
}
return 0;
} | # 0595, 2024-11-02 14:14:05, PPPPPPP-PPPPPPPPPPPPPPPP (95%)
#include<bits/stdc++.h>
using namespace std;
vector<pair<float,float>> vv; //x,y
float sum_x(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].first);
}
return sum;
}
float sum_y(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].second);
}
return sum;
}
float sum_xy(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].first*vv[i].second);
}
return sum;
}
float sum_xx(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].first*vv[i].first);
}
return sum;
}
int main(){
int n; float m,b,x,y; string s;
cin>>n>>s;
for(int i=0;i<n;i++){
cin>>x>>y;
vv.push_back({x,y});
}
m=(n*sum_xy(n)-(sum_x(n)*sum_y(n)))/(n*sum_xx(n)-(pow(sum_x(n),2.0)));
b=(sum_y(n)-(m*sum_x(n)))/n;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
}
else{
b=round(b*1e3)/1e3;
m=round(m*1e3)/1e3;
if(m==1.0){
if(b==0.0) cout<<"y = x";
else if(b<0.0) {
cout<<"y = x - "<<abs(b);
}
else cout<<"y = x"<<" + "<<b;
}
else if(m==-1.0){
if(b==0.0) cout<<"y = -x";
else if(b<0.0) {
cout<<"y = -x - "<<abs(b);
}
else cout<<"y = -x"<<" + "<<b;
}
else if(m==0.0){
if(b==0.0) cout<<"y = 0";
else if(b<0.0) {
/////////////////
cout<<"y = "<<b;
}
else cout<<"y = "<<b;
}
else{
if(b==0.0) cout<<"y = "<<m<<"x";
else if(b<0.0) {
///////////////
cout<<"y = "<<m<< "x - "<<abs(b);
}
else cout<<"y = "<<m<<"x + "<<b;
}
}
return 0;
} | # 0596, 2024-11-02 14:21:48, PPPPPPP-PPPPPPPPPPPPPPPP (95%)
#include<bits/stdc++.h>
using namespace std;
vector<pair<float,float>> vv; //x,y
float sum_x(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].first);
}
return sum;
}
float sum_y(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].second);
}
return sum;
}
float sum_xy(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].first*vv[i].second);
}
return sum;
}
float sum_xx(float n){
float sum=0;
for(float i=0;i<n;i++){
sum+=(vv[i].first*vv[i].first);
}
return sum;
}
int main(){
int n; float m,b,x,y; string s;
cin>>n>>s;
for(int i=0;i<n;i++){
cin>>x>>y;
vv.push_back({x,y});
}
m=(n*sum_xy(n)-(sum_x(n)*sum_y(n)))/(n*sum_xx(n)-(pow(sum_x(n),2.0)));
b=(sum_y(n)-(m*sum_x(n)))/n;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
}
else{
b=round(b*1e3)/1e3;
m=round(m*1e3)/1e3;
if(m==1.0){
if(b==0.0) cout<<"y = x";
else if(b<0.0) {
cout<<"y = x - "<<abs(b);
}
else cout<<"y = x + "<<b;
}
else if(m==-1.0){
if(b==0.0) cout<<"y = -x";
else if(b<0.0) {
cout<<"y = -x - "<<abs(b);
}
else cout<<"y = -x + "<<b;
}
else if(m==0.0){
if(b==0.0) cout<<"y = 0";
else if(b<0.0) {
/////////////////
cout<<"y = -"<<abs(b);
}
else cout<<"y = "<<b;
}
else{
if(b==0.0) cout<<"y = "<<m<<"x";
else if(b<0.0) {
///////////////
cout<<"y = "<<m<< "x - "<<abs(b);
}
else cout<<"y = "<<m<<"x + "<<b;
}
}
return 0;
} |
# 0597, 2024-11-02 09:36:36, PPPPPPPPPP-------------- (41%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
string option;
cin >> option;
if(option == "mb"){
vector<pair<float,float>> XandY;
for(int i =0 ;i < N;i++){
float x , y;
cin >> x >> y;
XandY.push_back(make_pair(x,y));
}
float term1 = 0;
for(int i =0;i<N;i++){
term1 += XandY[i].first * XandY[i].second;
}
term1 *= N;
float term2 = 0;
float term201 = 0;
float term202 = 0;
for(int i =0;i<N;i++){
term201 += XandY[i].first;
}
for(int i =0;i<N;i++){
term202 += XandY[i].second;
}
term2 = term201 * term202;
float term3;
for(int i =0;i<N;i++){
term3 += XandY[i].first*XandY[i].first;
}
term3 *= N;
float term4 = term201*term201;
float m = (term1 - term2) / (term3 - term4);
float term2b = term201*m;
float b = (term202-term2b)/N;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
cout << m << endl;
cout << b << endl;
}else if(0){
}
return 0;
} | # 0598, 2024-11-02 09:50:54, PPPPPPPPPP--------PP-P-- (54%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
string option;
cin >> option;
if(option == "mb"){
vector<pair<float,float>> XandY;
for(int i =0 ;i < N;i++){
float x , y;
cin >> x >> y;
XandY.push_back(make_pair(x,y));
}
float term1 = 0;
for(int i =0;i<N;i++){
term1 += XandY[i].first * XandY[i].second;
}
term1 *= N;
float term2 = 0;
float term201 = 0;
float term202 = 0;
for(int i =0;i<N;i++){
term201 += XandY[i].first;
}
for(int i =0;i<N;i++){
term202 += XandY[i].second;
}
term2 = term201 * term202;
float term3;
for(int i =0;i<N;i++){
term3 += XandY[i].first*XandY[i].first;
}
term3 *= N;
float term4 = term201*term201;
float m = (term1 - term2) / (term3 - term4);
float term2b = term201*m;
float b = (term202-term2b)/N;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
cout << m << endl;
cout << b << endl;
}else if(option == "func"){
vector<pair<float,float>> XandY;
for(int i =0 ;i < N;i++){
float x , y;
cin >> x >> y;
XandY.push_back(make_pair(x,y));
}
float term1 = 0;
for(int i =0;i<N;i++){
term1 += XandY[i].first * XandY[i].second;
}
term1 *= N;
float term2 = 0;
float term201 = 0;
float term202 = 0;
for(int i =0;i<N;i++){
term201 += XandY[i].first;
}
for(int i =0;i<N;i++){
term202 += XandY[i].second;
}
term2 = term201 * term202;
float term3;
for(int i =0;i<N;i++){
term3 += XandY[i].first*XandY[i].first;
}
term3 *= N;
float term4 = term201*term201;
float m = (term1 - term2) / (term3 - term4);
float term2b = term201*m;
float b = (term202-term2b)/N;
cout << "y = ";
if(m == -1){
cout << "-"<< "x ";
}else if(m == 1){
cout << "x ";
}else if(m ==0){
;
}
else{
cout << m << "x ";
}
if(b == 0){
}else if(b > 0 && m==0){
cout << b;
}else if(b < 0 && m==0){
cout << "-" << abs(b);
}else if(b > 0 && m!=0){
cout << "+ " << b;
}else if(b < 0 && m!=0){
cout << "- " << abs(b);
}
}
return 0;
} | # 0599, 2024-11-02 09:57:39, PPPPPPPPPPPPPPP---PP-P-- (75%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
string option;
cin >> option;
if(option == "mb"){
vector<pair<float,float>> XandY;
for(int i =0 ;i < N;i++){
float x , y;
cin >> x >> y;
XandY.push_back(make_pair(x,y));
}
float term1 = 0;
for(int i =0;i<N;i++){
term1 += XandY[i].first * XandY[i].second;
}
term1 *= N;
float term2 = 0;
float term201 = 0;
float term202 = 0;
for(int i =0;i<N;i++){
term201 += XandY[i].first;
}
for(int i =0;i<N;i++){
term202 += XandY[i].second;
}
term2 = term201 * term202;
float term3;
for(int i =0;i<N;i++){
term3 += XandY[i].first*XandY[i].first;
}
term3 *= N;
float term4 = term201*term201;
float m = (term1 - term2) / (term3 - term4);
float term2b = term201*m;
float b = (term202-term2b)/N;
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
cout << m << endl;
cout << b << endl;
}else if(option == "func"){
vector<pair<float,float>> XandY;
for(int i =0 ;i < N;i++){
float x , y;
cin >> x >> y;
XandY.push_back(make_pair(x,y));
}
float term1 = 0;
for(int i =0;i<N;i++){
term1 += XandY[i].first * XandY[i].second;
}
term1 *= N;
float term2 = 0;
float term201 = 0;
float term202 = 0;
for(int i =0;i<N;i++){
term201 += XandY[i].first;
}
for(int i =0;i<N;i++){
term202 += XandY[i].second;
}
term2 = term201 * term202;
float term3;
for(int i =0;i<N;i++){
term3 += XandY[i].first*XandY[i].first;
}
term3 *= N;
float term4 = term201*term201;
float m = (term1 - term2) / (term3 - term4);
float term2b = term201*m;
float b = (term202-term2b)/N;
//cout << m << endl;
//cout << b << endl;
cout << "y = ";
if(m == -1){
cout << "-"<< "x ";
}else if(m == 1){
cout << "x ";
}else if(m ==0){
;
}
else{
cout << round(m * 1e3)/1e3 << "x ";
}
if(b == 0){
}else if(b > 0 && m==0){
cout << round(b * 1e3)/1e3;
}else if(b < 0 && m==0){
cout << "-" << round(abs(b) * 1e3)/1e3;
}else if(b > 0 && m!=0){
cout << "+ " << round(abs(b) * 1e3)/1e3;
}else if(b < 0 && m!=0){
cout << "- " << round(abs(b) * 1e3)/1e3;
}
}
return 0;
} | # 0600, 2024-11-02 11:27:35, PPPPPPPPPPPPPPP---PP-P-- (75%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
string option;
cin >> option;
vector<pair<float,float>> XandY;
for(int i =0 ;i < N;i++){
float x , y;
cin >> x >> y;
XandY.push_back(make_pair(x,y));
}
float term1 = 0;
for(int i =0;i<N;i++){
term1 += XandY[i].first * XandY[i].second;
}
term1 *= N;
float term2 = 0;
float term201 = 0;
float term202 = 0;
for(int i =0;i<N;i++){
term201 += XandY[i].first;
}
for(int i =0;i<N;i++){
term202 += XandY[i].second;
}
term2 = term201 * term202;
float term3;
for(int i =0;i<N;i++){
term3 += XandY[i].first*XandY[i].first;
}
term3 *= N;
float term4 = term201*term201;
float m = (term1 - term2) / (term3 - term4);
float term2b = term201*m;
float b = (term202-term2b)/N;
if(option == "mb"){
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
cout << m << endl;
cout << b << endl;
}else if(option == "func"){
//cout << m << endl;
//cout << b << endl;
cout << "y = ";
if(m == -1){
cout << "-"<< "x ";
}else if(m == 1){
cout << "x ";
}else if(m ==0){
;
}
else{
cout << round(m * 1e3)/1e3 << "x ";
}
if(b == 0){
}else if(b > 0 && m==0){
cout << round(b * 1e3)/1e3;
}else if(b < 0 && m==0){
cout << "-" << round(abs(b) * 1e3)/1e3;
}else if(b > 0 && m!=0){
cout << "+ " << round(abs(b) * 1e3)/1e3;
}else if(b < 0 && m!=0){
cout << "- " << round(abs(b) * 1e3)/1e3;
}
}
return 0;
} | # 0601, 2024-11-02 11:30:24, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
string option;
cin >> option;
vector<pair<float,float>> XandY;
for(int i =0 ;i < N;i++){
float x , y;
cin >> x >> y;
XandY.push_back(make_pair(x,y));
}
float term1 = 0;
for(int i =0;i<N;i++){
term1 += XandY[i].first * XandY[i].second;
}
term1 *= N;
float term2 = 0;
float term201 = 0;
float term202 = 0;
for(int i =0;i<N;i++){
term201 += XandY[i].first;
}
for(int i =0;i<N;i++){
term202 += XandY[i].second;
}
term2 = term201 * term202;
float term3;
for(int i =0;i<N;i++){
term3 += XandY[i].first*XandY[i].first;
}
term3 *= N;
float term4 = term201*term201;
float m = (term1 - term2) / (term3 - term4);
float term2b = term201*m;
float b = (term202-term2b)/N;
if(option == "mb"){
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
cout << m << endl;
cout << b << endl;
}else if(option == "func"){
//cout << m << endl;
//cout << b << endl;
cout << "y = ";
if(m == -1){
cout << "-"<< "x ";
}else if(m == 1){
cout << "x ";
}else if(m ==0){
;
}
else{
cout << round(m * 1e3)/1e3 << "x ";
}
if(b == 0 && m==0){
cout << 0;
}else if(b > 0 && m==0){
cout << round(b * 1e3)/1e3;
}else if(b < 0 && m==0){
cout << "-" << round(abs(b) * 1e3)/1e3;
}else if(b > 0 && m!=0){
cout << "+ " << round(abs(b) * 1e3)/1e3;
}else if(b < 0 && m!=0){
cout << "- " << round(abs(b) * 1e3)/1e3;
}
}
return 0;
} | # 0602, 2024-11-02 11:33:20, P-P-PP-PPPP-P-PPP-PP-P-- (62%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
string option;
cin >> option;
vector<pair<float,float>> XandY;
for(int i =0 ;i < N;i++){
float x , y;
cin >> x >> y;
XandY.push_back(make_pair(x,y));
}
float term1 = 0;
for(int i =0;i<N;i++){
term1 += XandY[i].first * XandY[i].second;
}
term1 *= N;
float term2 = 0;
float term201 = 0;
float term202 = 0;
for(int i =0;i<N;i++){
term201 += XandY[i].first;
}
for(int i =0;i<N;i++){
term202 += XandY[i].second;
}
term2 = term201 * term202;
float term3;
for(int i =0;i<N;i++){
term3 += XandY[i].first*XandY[i].first;
}
term3 *= N;
float term4 = term201*term201;
float m = (term1 - term2) / (term3 - term4);
float term2b = term201*m;
float b = (term202-term2b)/N;
if(option == "mb"){
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
cout << m << endl;
cout << b << endl;
}else if(option == "func"){
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
// cout << m << endl;
// cout << b << endl;
cout << "y = ";
if(m == -1){
cout << "-"<< "x ";
}else if(m == 1){
cout << "x ";
}else if(m == 0){
;
}else{
cout << round(m * 1e3)/1e3 << "x ";
}
if(b == 0 && m==0){
cout << 0;
}else if(b > 0 && m==0){
cout << round(b * 1e3)/1e3;
}else if(b < 0 && m==0){
cout << "-" << round(abs(b) * 1e3)/1e3;
}else if(b > 0 && m!=0){
cout << "+ " << round(abs(b) * 1e3)/1e3;
}else if(b < 0 && m!=0){
cout << "- " << round(abs(b) * 1e3)/1e3;
}
}
return 0;
} | # 0603, 2024-11-02 11:37:36, PPPPPPPPPP-------------- (41%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
string option;
cin >> option;
vector<pair<float,float>> XandY;
for(int i =0 ;i < N;i++){
float x , y;
cin >> x >> y;
XandY.push_back(make_pair(x,y));
}
float term1 = 0;
for(int i =0;i<N;i++){
term1 += XandY[i].first * XandY[i].second;
}
term1 *= N;
float term2 = 0;
float term201 = 0;
float term202 = 0;
for(int i =0;i<N;i++){
term201 += XandY[i].first;
}
for(int i =0;i<N;i++){
term202 += XandY[i].second;
}
term2 = term201 * term202;
float term3;
for(int i =0;i<N;i++){
term3 += XandY[i].first*XandY[i].first;
}
term3 *= N;
float term4 = term201*term201;
float m = (term1 - term2) / (term3 - term4);
float term2b = term201*m;
float b = (term202-term2b)/N;
if(option == "mb"){
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
cout << m << endl;
cout << b << endl;
}else if(option == "func"){
cout << round(m * 1e3)/1e3 << endl;
cout << round(abs(b) * 1e3)/1e3 << endl;
cout << "y = ";
if(round(m * 1e3)/1e3 == -1){
cout << "-"<< "x ";
}else if(round(m * 1e3)/1e3 == 1){
cout << "x ";
}else if(round(m * 1e3)/1e3 == 0){
;
}else{
cout << round(m * 1e3)/1e3 << "x ";
}
if(b == 0 && m==0){
cout << 0;
}else if(b > 0 && m==0){
cout << round(b * 1e3)/1e3;
}else if(b < 0 && m==0){
cout << "-" << round(abs(b) * 1e3)/1e3;
}else if(b > 0 && m!=0){
cout << "+ " << round(abs(b) * 1e3)/1e3;
}else if(b < 0 && m!=0){
cout << "- " << round(abs(b) * 1e3)/1e3;
}
}
return 0;
} | # 0604, 2024-11-02 11:38:00, PPPPPPPPPPPPPPPP-PPPPPPP (95%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
string option;
cin >> option;
vector<pair<float,float>> XandY;
for(int i =0 ;i < N;i++){
float x , y;
cin >> x >> y;
XandY.push_back(make_pair(x,y));
}
float term1 = 0;
for(int i =0;i<N;i++){
term1 += XandY[i].first * XandY[i].second;
}
term1 *= N;
float term2 = 0;
float term201 = 0;
float term202 = 0;
for(int i =0;i<N;i++){
term201 += XandY[i].first;
}
for(int i =0;i<N;i++){
term202 += XandY[i].second;
}
term2 = term201 * term202;
float term3;
for(int i =0;i<N;i++){
term3 += XandY[i].first*XandY[i].first;
}
term3 *= N;
float term4 = term201*term201;
float m = (term1 - term2) / (term3 - term4);
float term2b = term201*m;
float b = (term202-term2b)/N;
if(option == "mb"){
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
cout << m << endl;
cout << b << endl;
}else if(option == "func"){
// cout << round(m * 1e3)/1e3 << endl;
// cout << round(abs(b) * 1e3)/1e3 << endl;
cout << "y = ";
if(round(m * 1e3)/1e3 == -1){
cout << "-"<< "x ";
}else if(round(m * 1e3)/1e3 == 1){
cout << "x ";
}else if(round(m * 1e3)/1e3 == 0){
;
}else{
cout << round(m * 1e3)/1e3 << "x ";
}
if(b == 0 && m==0){
cout << 0;
}else if(b > 0 && m==0){
cout << round(b * 1e3)/1e3;
}else if(b < 0 && m==0){
cout << "-" << round(abs(b) * 1e3)/1e3;
}else if(b > 0 && m!=0){
cout << "+ " << round(abs(b) * 1e3)/1e3;
}else if(b < 0 && m!=0){
cout << "- " << round(abs(b) * 1e3)/1e3;
}
}
return 0;
} | # 0605, 2024-11-02 11:39:51, PPPPPPPPPPPPPPPP-PPPPPPP (95%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
string option;
cin >> option;
vector<pair<float,float>> XandY;
for(int i =0 ;i < N;i++){
float x , y;
cin >> x >> y;
XandY.push_back(make_pair(x,y));
}
float term1 = 0;
for(int i =0;i<N;i++){
term1 += XandY[i].first * XandY[i].second;
}
term1 *= N;
float term2 = 0;
float term201 = 0;
float term202 = 0;
for(int i =0;i<N;i++){
term201 += XandY[i].first;
}
for(int i =0;i<N;i++){
term202 += XandY[i].second;
}
term2 = term201 * term202;
float term3;
for(int i =0;i<N;i++){
term3 += XandY[i].first*XandY[i].first;
}
term3 *= N;
float term4 = term201*term201;
float m = (term1 - term2) / (term3 - term4);
float term2b = term201*m;
float b = (term202-term2b)/N;
if(option == "mb"){
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
cout << m << endl;
cout << b << endl;
}else if(option == "func"){
// cout << round(m * 1e3)/1e3 << endl;
// cout << round(abs(b) * 1e3)/1e3 << endl;
cout << "y = ";
if(round(m * 1e3)/1e3 == -1){
cout << "-"<< "x ";
}else if(round(m * 1e3)/1e3 == 1){
cout << "x ";
}else if(round(m * 1e3)/1e3 == 0){
;
}else{
cout << round(m * 1e3)/1e3 << "x ";
}
if(b == 0 && m==0){
cout << 0;
}else if(b > 0 && m==0){
cout << round(b * 1e3)/1e3;
}else if(b < 0 && (m==0 || round(m * 1e3)/1e3 ==-0)){
cout << "-" << round(abs(b) * 1e3)/1e3;
}else if(b > 0 && m!=0){
cout << "+ " << round(abs(b) * 1e3)/1e3;
}else if(b < 0 && m!=0){
cout << "- " << round(abs(b) * 1e3)/1e3;
}
}
return 0;
} |
# 0606, 2024-11-02 10:14:41, ------------------------ (0%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
float x, y;
int n;
vector<float> xx,yy;
string order;
cin>>n;
for(int i=0; i<n; i++)
{
cin>>order;
if(order == "mb")
{
for(int i=0; i<n; i++)
{
cin>>x>>y;
xx.push_back(x);
yy.push_back(y);
}
float a=0,xy=0, sx=0,sy=0,x2=0,y2=0;
for(int i=1; i<=n; i++)
{
xy = xy + (xx[i]*yy[i]);
}
xy = n*xy;
for(int i=1; i<=n; i++)
{
sx = sx + xx[i];
}
for(int i=1; i<=n; i++)
{
sy = sy + yy[i];
}
for(int i=1; i<=n; i++)
{
x2 = x2 + pow(xx[i],2);
}
x2 = n*x2;
y2 = pow(sx,2);
float mm = ((xy-(sx*sy))/(x2-y2)) * sx;
cout<< (xy-(sx*sy))/(x2-y2)<<endl;
cout<<(sy-mm)/n;
}
else if(order == "func")
{
}
}
} | # 0607, 2024-11-02 10:20:43, ------------------------ (0%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
float x, y;
int n;
vector<float> xx,yy;
string order;
cin>>n;
for(int i=0; i<n; i++)
{
cin>>order;
if(order == "mb")
{
xx.push_back(0);
yy.push_back(0);
for(int i=0; i<n; i++)
{
cin>>x>>y;
xx.push_back(x);
yy.push_back(y);
}
float a=0,xy=0, sx=0,sy=0,x2=0,y2=0;
for(int i=1; i<=n; i++)
{
xy = xy + (xx[i]*yy[i]);
}
xy = n*xy;
for(int i=1; i<=n; i++)
{
sx = sx + xx[i];
}
for(int i=1; i<=n; i++)
{
sy = sy + yy[i];
}
for(int i=1; i<=n; i++)
{
x2 = x2 + pow(xx[i],2);
}
x2 = n*x2;
y2 = pow(sx,2);
float mm = ((xy-sx*sy)/(x2-y2)) * sx;
cout<< (xy-(sx*sy))/(x2-y2)<<endl;
cout<<(sy-mm)/n;
}
else if(order == "func")
{
}
}
} | # 0608, 2024-11-02 10:22:47, ------------------------ (0%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
float x, y;
int n;
vector<float> xx,yy;
string order;
cin>>n;
for(int i=0; i<n; i++)
{
cin>>order;
if(order == "mb")
{
xx.push_back(0);
yy.push_back(0);
for(int i=0; i<n; i++)
{
cin>>x>>y;
xx.push_back(x);
yy.push_back(y);
}
float a=0,xy=0, sx=0,sy=0,x2=0,y2=0;
for(int i=1; i<=n; i++)
{
xy = xy + (xx[i]*yy[i]);
}
xy = n*xy;
for(int i=1; i<=n; i++)
{
sx = sx + xx[i];
}
for(int i=1; i<=n; i++)
{
sy = sy + yy[i];
}
for(int i=1; i<=n; i++)
{
x2 = x2 + pow(xx[i],2);
}
x2 = n*x2;
y2 = pow(sx,2);
float mm = ((xy-sx*sy)/(x2-y2)) * sx;
cout<< round(((xy-(sx*sy))/(x2-y2))*1e3)/1e3<<endl;
cout<<round(((sy-mm)/n)*1e3)/1e3;
}
else if(order == "func")
{
}
}
} | # 0609, 2024-11-02 10:36:13, ------------------------ (0%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
float x, y;
int n;
vector<float> xx,yy;
string order;
cin>>n;
for(int i=0; i<n; i++)
{
cin>>order;
if(order == "mb")
{
xx.push_back(0);
yy.push_back(0);
for(int i=0; i<n; i++)
{
cin>>x>>y;
xx.push_back(x);
yy.push_back(y);
}
float a=0,xy=0, sx=0,sy=0,x2=0,y2=0;
for(int i=1; i<=n; i++)
{
xy = xy + (xx[i]*yy[i]);
}
xy = n*xy;
for(int i=1; i<=n; i++)
{
sx = sx + xx[i];
}
for(int i=1; i<=n; i++)
{
sy = sy + yy[i];
}
for(int i=1; i<=n; i++)
{
x2 = x2 + pow(xx[i],2);
}
x2 = n*x2;
y2 = pow(sx,2);
float mm = ((xy-sx*sy)/(x2-y2)) * sx;
cout<< round(((xy-(sx*sy))/(x2-y2))*1e3)/1e3<<endl;
cout<<round(((sy-mm)/n)*1e3)/1e3;
}
else if(order == "func")
{
xx.push_back(0);
yy.push_back(0);
for(int i=0; i<n; i++)
{
cin>>x>>y;
xx.push_back(x);
yy.push_back(y);
}
float a=0,xy=0, sx=0,sy=0,x2=0,y2=0;
for(int i=1; i<=n; i++)
{
xy = xy + (xx[i]*yy[i]);
}
xy = n*xy;
for(int i=1; i<=n; i++)
{
sx = sx + xx[i];
}
for(int i=1; i<=n; i++)
{
sy = sy + yy[i];
}
for(int i=1; i<=n; i++)
{
x2 = x2 + pow(xx[i],2);
}
x2 = n*x2;
y2 = pow(sx,2);
float mm = ((xy-sx*sy)/(x2-y2)) * sx;
float m = round(((xy-(sx*sy))/(x2-y2))*1e3)/1e3;
float b = round(((sy-mm)/n)*1e3)/1e3;
if(m ==0 && b == 0)
{
cout<<"y = 0";
}
else if (m ==0)
{
cout<<"y = "<<b;
}
else if(m==-1 && b ==0)
{
cout<<"y = -x";
}
else if (b ==0)
{
cout<<"y = "<<m<<"x";
}
else if(m==-1)
{
cout<<"y = -"<<"x + "<<b;
}
else{
cout<<"y = "<<m<<"x + "<<b;
}
}
}
} | # 0610, 2024-11-02 10:38:15, PPPPPPPPPPP-P--PP--PPP-- (70%)
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main()
{
float x, y;
int n;
vector<float> xx,yy;
string order;
cin>>n;
for(int i=0; i<n; i++)
{
cin>>order;
if(order == "mb")
{
xx.push_back(0);
yy.push_back(0);
for(int i=0; i<n; i++)
{
cin>>x>>y;
xx.push_back(x);
yy.push_back(y);
}
float a=0,xy=0, sx=0,sy=0,x2=0,y2=0;
for(int i=1; i<=n; i++)
{
xy = xy + (xx[i]*yy[i]);
}
xy = n*xy;
for(int i=1; i<=n; i++)
{
sx = sx + xx[i];
}
for(int i=1; i<=n; i++)
{
sy = sy + yy[i];
}
for(int i=1; i<=n; i++)
{
x2 = x2 + pow(xx[i],2);
}
x2 = n*x2;
y2 = pow(sx,2);
float mm = ((xy-sx*sy)/(x2-y2)) * sx;
cout<< round(((xy-(sx*sy))/(x2-y2))*1e3)/1e3<<endl;
cout<<round(((sy-mm)/n)*1e3)/1e3;
}
else if(order == "func")
{
xx.push_back(0);
yy.push_back(0);
for(int i=0; i<n; i++)
{
cin>>x>>y;
xx.push_back(x);
yy.push_back(y);
}
float a=0,xy=0, sx=0,sy=0,x2=0,y2=0;
for(int i=1; i<=n; i++)
{
xy = xy + (xx[i]*yy[i]);
}
xy = n*xy;
for(int i=1; i<=n; i++)
{
sx = sx + xx[i];
}
for(int i=1; i<=n; i++)
{
sy = sy + yy[i];
}
for(int i=1; i<=n; i++)
{
x2 = x2 + pow(xx[i],2);
}
x2 = n*x2;
y2 = pow(sx,2);
float mm = ((xy-sx*sy)/(x2-y2)) * sx;
float m = round(((xy-(sx*sy))/(x2-y2))*1e3)/1e3;
float b = round(((sy-mm)/n)*1e3)/1e3;
if(m ==0 && b == 0)
{
cout<<"y = 0";
}
else if (m ==0)
{
cout<<"y = "<<b;
}
else if(m==-1 && b ==0)
{
cout<<"y = -x";
}
else if (b ==0)
{
cout<<"y = "<<m<<"x";
}
else if(m==-1)
{
cout<<"y = -"<<"x + "<<b;
}
else{
cout<<"y = "<<m<<"x + "<<b;
}
}
return 0;
}
} | # 0611, 2024-11-02 10:43:56, PPPPPPPPPPP-P--PP--PPP-P (75%)
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main()
{
float x, y;
int n;
vector<float> xx,yy;
string order;
cin>>n;
for(int i=0; i<n; i++)
{
cin>>order;
if(order == "mb")
{
xx.push_back(0);
yy.push_back(0);
for(int i=0; i<n; i++)
{
cin>>x>>y;
xx.push_back(x);
yy.push_back(y);
}
float a=0,xy=0, sx=0,sy=0,x2=0,y2=0;
for(int i=1; i<=n; i++)
{
xy = xy + (xx[i]*yy[i]);
}
xy = n*xy;
for(int i=1; i<=n; i++)
{
sx = sx + xx[i];
}
for(int i=1; i<=n; i++)
{
sy = sy + yy[i];
}
for(int i=1; i<=n; i++)
{
x2 = x2 + pow(xx[i],2);
}
x2 = n*x2;
y2 = pow(sx,2);
float mm = ((xy-sx*sy)/(x2-y2)) * sx;
cout<< round(((xy-(sx*sy))/(x2-y2))*1e3)/1e3<<endl;
cout<<round(((sy-mm)/n)*1e3)/1e3;
}
else if(order == "func")
{
xx.push_back(0);
yy.push_back(0);
for(int i=0; i<n; i++)
{
cin>>x>>y;
xx.push_back(x);
yy.push_back(y);
}
float a=0,xy=0, sx=0,sy=0,x2=0,y2=0;
for(int i=1; i<=n; i++)
{
xy = xy + (xx[i]*yy[i]);
}
xy = n*xy;
for(int i=1; i<=n; i++)
{
sx = sx + xx[i];
}
for(int i=1; i<=n; i++)
{
sy = sy + yy[i];
}
for(int i=1; i<=n; i++)
{
x2 = x2 + pow(xx[i],2);
}
x2 = n*x2;
y2 = pow(sx,2);
float mm = ((xy-sx*sy)/(x2-y2)) * sx;
float m = round(((xy-(sx*sy))/(x2-y2))*1e3)/1e3;
float b = round(((sy-mm)/n)*1e3)/1e3;
if(m ==0 && b == 0)
{
cout<<"y = 0";
}
else if (m ==0)
{
cout<<"y = "<<b;
}
else if(m==-1 && b<0)
{
cout<<"y = -x - "<<(-1*b);
}
else if(m==-1 && b ==0)
{
cout<<"y = -x";
}
else if (b ==0)
{
cout<<"y = "<<m<<"x";
}
else if (b <0)
{
cout<<"y = - "<<(-1*b);
}
else if(m==-1)
{
cout<<"y = -"<<"x + "<<b;
}
else{
cout<<"y = "<<m<<"x + "<<b;
}
}
return 0;
}
} | # 0612, 2024-11-02 10:47:59, PPPPPPPPPPP-P--PPPPPPP-P (83%)
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main()
{
float x, y;
int n;
vector<float> xx,yy;
string order;
cin>>n;
for(int i=0; i<n; i++)
{
cin>>order;
if(order == "mb")
{
xx.push_back(0);
yy.push_back(0);
for(int i=0; i<n; i++)
{
cin>>x>>y;
xx.push_back(x);
yy.push_back(y);
}
float a=0,xy=0, sx=0,sy=0,x2=0,y2=0;
for(int i=1; i<=n; i++)
{
xy = xy + (xx[i]*yy[i]);
}
xy = n*xy;
for(int i=1; i<=n; i++)
{
sx = sx + xx[i];
}
for(int i=1; i<=n; i++)
{
sy = sy + yy[i];
}
for(int i=1; i<=n; i++)
{
x2 = x2 + pow(xx[i],2);
}
x2 = n*x2;
y2 = pow(sx,2);
float mm = ((xy-sx*sy)/(x2-y2)) * sx;
cout<< round(((xy-(sx*sy))/(x2-y2))*1e3)/1e3<<endl;
cout<<round(((sy-mm)/n)*1e3)/1e3;
}
else if(order == "func")
{
xx.push_back(0);
yy.push_back(0);
for(int i=0; i<n; i++)
{
cin>>x>>y;
xx.push_back(x);
yy.push_back(y);
}
float a=0,xy=0, sx=0,sy=0,x2=0,y2=0;
for(int i=1; i<=n; i++)
{
xy = xy + (xx[i]*yy[i]);
}
xy = n*xy;
for(int i=1; i<=n; i++)
{
sx = sx + xx[i];
}
for(int i=1; i<=n; i++)
{
sy = sy + yy[i];
}
for(int i=1; i<=n; i++)
{
x2 = x2 + pow(xx[i],2);
}
x2 = n*x2;
y2 = pow(sx,2);
float mm = ((xy-sx*sy)/(x2-y2)) * sx;
float m = round(((xy-(sx*sy))/(x2-y2))*1e3)/1e3;
float b = round(((sy-mm)/n)*1e3)/1e3;
if(m ==1 && b ==0)
{
cout<<"y = x";
}
else if(m ==1)
{
cout<<"y = x + "<<b;
}
else if(m ==0 && b == 0)
{
cout<<"y = 0";
}
else if (m ==0)
{
cout<<"y = "<<b;
}
else if(m==-1 && b<0)
{
cout<<"y = -x - "<<(-1*b);
}
else if(m==-1 && b ==0)
{
cout<<"y = -x";
}
else if (b ==0)
{
cout<<"y = "<<m<<"x";
}
else if (b <0)
{
cout<<"y = - "<<(-1*b);
}
else if(m==-1)
{
cout<<"y = -"<<"x + "<<b;
}
else{
cout<<"y = "<<m<<"x + "<<b;
}
}
return 0;
}
} | # 0613, 2024-11-02 10:54:01, PPPPPPPPPPPPPPPPPPPPPP-P (95%)
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main()
{
float x, y;
int n;
vector<float> xx,yy;
string order;
cin>>n;
for(int i=0; i<n; i++)
{
cin>>order;
if(order == "mb")
{
xx.push_back(0);
yy.push_back(0);
for(int i=0; i<n; i++)
{
cin>>x>>y;
xx.push_back(x);
yy.push_back(y);
}
float a=0,xy=0, sx=0,sy=0,x2=0,y2=0;
for(int i=1; i<=n; i++)
{
xy = xy + (xx[i]*yy[i]);
}
xy = n*xy;
for(int i=1; i<=n; i++)
{
sx = sx + xx[i];
}
for(int i=1; i<=n; i++)
{
sy = sy + yy[i];
}
for(int i=1; i<=n; i++)
{
x2 = x2 + pow(xx[i],2);
}
x2 = n*x2;
y2 = pow(sx,2);
float mm = ((xy-sx*sy)/(x2-y2)) * sx;
cout<< round(((xy-(sx*sy))/(x2-y2))*1e3)/1e3<<endl;
cout<<round(((sy-mm)/n)*1e3)/1e3;
}
else if(order == "func")
{
xx.push_back(0);
yy.push_back(0);
for(int i=0; i<n; i++)
{
cin>>x>>y;
xx.push_back(x);
yy.push_back(y);
}
float a=0,xy=0, sx=0,sy=0,x2=0,y2=0;
for(int i=1; i<=n; i++)
{
xy = xy + (xx[i]*yy[i]);
}
xy = n*xy;
for(int i=1; i<=n; i++)
{
sx = sx + xx[i];
}
for(int i=1; i<=n; i++)
{
sy = sy + yy[i];
}
for(int i=1; i<=n; i++)
{
x2 = x2 + pow(xx[i],2);
}
x2 = n*x2;
y2 = pow(sx,2);
float mm = ((xy-sx*sy)/(x2-y2)) * sx;
float m = round(((xy-(sx*sy))/(x2-y2))*1e3)/1e3;
float b = round(((sy-mm)/n)*1e3)/1e3;
if(m ==1 && b ==0)
{
cout<<"y = x";
}
else if(m ==1)
{
cout<<"y = x + "<<b;
}
else if(m ==0 && b == 0)
{
cout<<"y = 0";
}
else if (m ==0)
{
cout<<"y = "<<b;
}
else if(m==-1 && b<0)
{
cout<<"y = -x - "<<(-1*b);
}
else if(m==-1 && b ==0)
{
cout<<"y = -x";
}
else if (b ==0)
{
cout<<"y = "<<m<<"x";
}
else if (b <0)
{
cout<<"y = "<<m<<"x - "<<-1*b;
}
else if(m==-1)
{
cout<<"y = -"<<"x + "<<b;
}
else{
cout<<"y = "<<m<<"x + "<<b;
}
}
return 0;
}
} | # 0614, 2024-11-02 10:55:19, PPPPPPPPPPPPPPPPPPPPPP-P (95%)
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main()
{
float x, y;
int n;
vector<float> xx,yy;
string order;
cin>>n;
for(int i=0; i<n; i++)
{
cin>>order;
if(order == "mb")
{
xx.push_back(0);
yy.push_back(0);
for(int i=0; i<n; i++)
{
cin>>x>>y;
xx.push_back(x);
yy.push_back(y);
}
float a=0,xy=0, sx=0,sy=0,x2=0,y2=0;
for(int i=1; i<=n; i++)
{
xy = xy + (xx[i]*yy[i]);
}
xy = n*xy;
for(int i=1; i<=n; i++)
{
sx = sx + xx[i];
}
for(int i=1; i<=n; i++)
{
sy = sy + yy[i];
}
for(int i=1; i<=n; i++)
{
x2 = x2 + pow(xx[i],2);
}
x2 = n*x2;
y2 = pow(sx,2);
float mm = ((xy-sx*sy)/(x2-y2)) * sx;
cout<< round(((xy-(sx*sy))/(x2-y2))*1e3)/1e3<<endl;
cout<<round(((sy-mm)/n)*1e3)/1e3;
}
else if(order == "func")
{
xx.push_back(0);
yy.push_back(0);
for(int i=0; i<n; i++)
{
cin>>x>>y;
xx.push_back(x);
yy.push_back(y);
}
float a=0,xy=0, sx=0,sy=0,x2=0,y2=0;
for(int i=1; i<=n; i++)
{
xy = xy + (xx[i]*yy[i]);
}
xy = n*xy;
for(int i=1; i<=n; i++)
{
sx = sx + xx[i];
}
for(int i=1; i<=n; i++)
{
sy = sy + yy[i];
}
for(int i=1; i<=n; i++)
{
x2 = x2 + pow(xx[i],2);
}
x2 = n*x2;
y2 = pow(sx,2);
float mm = ((xy-sx*sy)/(x2-y2)) * sx;
float m = round(((xy-(sx*sy))/(x2-y2))*1e3)/1e3;
float b = round(((sy-mm)/n)*1e3)/1e3;
if(m ==1 && b ==0)
{
cout<<"y = x";
}
else if(m ==1)
{
cout<<"y = x + "<<b;
}
else if(m ==0 && b == 0)
{
cout<<"y = 0";
}
else if (m ==0)
{
cout<<"y = "<<b;
}
else if(m==-1 && b<0)
{
cout<<"y = -x - "<<(-1*b);
}
else if(m==-1 && b ==0)
{
cout<<"y = -x";
}
else if (b ==0)
{
cout<<"y = "<<m<<"x";
}
else if (b <0)
{
cout<<"y = "<<m<<"x - "<<-1*b;
}
else if (b <0 && m==0)
{
cout<<"y = "<<b;
}
else if(m==-1)
{
cout<<"y = -"<<"x + "<<b;
}
else{
cout<<"y = "<<m<<"x + "<<b;
}
}
return 0;
}
} |
# 0615, 2024-11-02 10:02:33, -----P---------P-------- (8%)
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
long long fac(int n) {
if(n>=1) {
return 1;
}
return n*fac(n-1);
}
int main() {
int n;
string want;
cin >> n >> want;
vector<float> xi;
vector<float> yi;
for(int i = 0;i < n;i++) {
float x,y;
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
float m,b;
float sumxi = 0;
float sumyi = 0;
for(int i = 1;i<=n;i++) {
sumxi += xi[i];
}
for(int i = 1;i<=n;i++) {
sumyi += yi[i];
}
float sumxiyi = 0;
for(int i = 1;i<=n;i++) {
sumxiyi += xi[i]*yi[i];
}
m = ((n*sumxiyi)-(sumxi*sumyi))/((n*pow(sumxi,2))-pow(sumxi,2));
b = (sumyi-(m*sumxi))/n;
if(want == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(want == "func") {
cout << "y = ";
if(m == 0 && b == 0) {
cout << "0";
} else {
if(m != 1) {
cout << round(m*1e3)/1e3 ;
} if (m == -1) {
cout << "-";
}
cout << "x +";
cout << round(b*1e3)/1e3 << endl;
}
}
} | # 0616, 2024-11-02 10:13:58, ------------------------ (0%)
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
long long fac(int n) {
if(n>=1) {
return 1;
}
return n*fac(n-1);
}
int main() {
int n;
string want;
cin >> n >> want;
vector<float> xi;
vector<float> yi;
for(int i = 0;i < n;i++) {
float x,y;
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
float m,b;
float sumxi = 0;
float sumyi = 0;
for(int i = 0;i<n;i++) {
sumxi += xi[i];
}
cout << sumxi << endl;
for(int i = 0;i<n;i++) {
sumyi += yi[i];
}
cout << sumyi << endl;
float sumxiyi = 0;
for(int i = 0;i<n;i++) {
sumxiyi += xi[i]*yi[i];
}
float sumxi2;
for(int i = 0;i<n;i++) {
sumxi2 += xi[i]*xi[i];
}
cout << sumxiyi << endl;
m = ((n*sumxiyi)-(sumxi*sumyi))/((n*sumxi2)-pow(sumxi,2));
b = (sumyi-(m*sumxi))/n;
if(want == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(want == "func") {
cout << "y = ";
if(m == 0 && b == 0) {
cout << "0";
} else {
if(m != 1) {
cout << round(m*1e3)/1e3 ;
} if (m == -1) {
cout << "-";
}
cout << "x +";
cout << round(b*1e3)/1e3 << endl;
}
}
} | # 0617, 2024-11-02 10:14:37, PPPPPPP-PP-----P-------- (41%)
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
long long fac(int n) {
if(n>=1) {
return 1;
}
return n*fac(n-1);
}
int main() {
int n;
string want;
cin >> n >> want;
vector<float> xi;
vector<float> yi;
for(int i = 0;i < n;i++) {
float x,y;
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
float m,b;
float sumxi = 0;
float sumyi = 0;
for(int i = 0;i<n;i++) {
sumxi += xi[i];
}
//cout << sumxi << endl;
for(int i = 0;i<n;i++) {
sumyi += yi[i];
}
//cout << sumyi << endl;
float sumxiyi = 0;
for(int i = 0;i<n;i++) {
sumxiyi += xi[i]*yi[i];
}
float sumxi2;
for(int i = 0;i<n;i++) {
sumxi2 += xi[i]*xi[i];
}
//cout << sumxiyi << endl;
m = ((n*sumxiyi)-(sumxi*sumyi))/((n*sumxi2)-pow(sumxi,2));
b = (sumyi-(m*sumxi))/n;
if(want == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(want == "func") {
cout << "y = ";
if(m == 0 && b == 0) {
cout << "0";
} else {
if(m != 1) {
cout << round(m*1e3)/1e3 ;
} if (m == -1) {
cout << "-";
}
cout << "x +";
cout << round(b*1e3)/1e3 << endl;
}
}
} | # 0618, 2024-11-02 10:34:39, PPPPPPP-PPP-P--PPPP--P-- (66%)
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
long long fac(int n) {
if(n>=1) {
return 1;
}
return n*fac(n-1);
}
int main() {
int n;
string want;
cin >> n >> want;
vector<float> xi;
vector<float> yi;
for(int i = 0;i < n;i++) {
float x,y;
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
float m,b;
float sumxi = 0;
float sumyi = 0;
for(int i = 0;i<n;i++) {
sumxi += xi[i];
}
//cout << sumxi << endl;
for(int i = 0;i<n;i++) {
sumyi += yi[i];
}
//cout << sumyi << endl;
float sumxiyi = 0;
for(int i = 0;i<n;i++) {
sumxiyi += xi[i]*yi[i];
}
float sumxi2;
for(int i = 0;i<n;i++) {
sumxi2 += xi[i]*xi[i];
}
//cout << sumxiyi << endl;
m = ((n*sumxiyi)-(sumxi*sumyi))/((n*sumxi2)-pow(sumxi,2));
b = (sumyi-(m*sumxi))/n;
if(want == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
float newm = round(m*1e3)/1e3 ;
float newb = round(b*1e3)/1e3 ;
//cout << newm <<endl;
//cout << newb <<endl;
if(want == "func") {
cout << "y = ";
if(newm == 0 && newb == 0) {
cout << "0";
} else if (newm == 0 && newb != 0 ) {
cout << newb;
} else if (newm != 0 && newb == 0) {
if(newm != 1) {
cout << newm;
} if (newm == -1) {
cout << "-";
}
cout << "x";
} else {
if(newm != 1) {
cout << newm;
} if (newm == -1) {
cout << "-";
}
cout << "x + ";
cout << newb << endl;
}
}
} | # 0619, 2024-11-02 10:46:20, PPPPPPP-PPP-P--PPPPPPP-- (75%)
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
long long fac(int n) {
if(n>=1) {
return 1;
}
return n*fac(n-1);
}
int main() {
int n;
string want;
cin >> n >> want;
vector<float> xi;
vector<float> yi;
for(int i = 0;i < n;i++) {
float x,y;
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
float m,b;
float sumxi = 0;
float sumyi = 0;
for(int i = 0;i<n;i++) {
sumxi += xi[i];
}
//cout << sumxi << endl;
for(int i = 0;i<n;i++) {
sumyi += yi[i];
}
//cout << sumyi << endl;
float sumxiyi = 0;
for(int i = 0;i<n;i++) {
sumxiyi += xi[i]*yi[i];
}
float sumxi2;
for(int i = 0;i<n;i++) {
sumxi2 += xi[i]*xi[i];
}
//cout << sumxiyi << endl;
m = ((n*sumxiyi)-(sumxi*sumyi))/((n*sumxi2)-pow(sumxi,2));
b = (sumyi-(m*sumxi))/n;
if(want == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
float newm = round(m*1e3)/1e3 ;
float newb = round(b*1e3)/1e3 ;
//cout << newm <<endl;
//cout << newb <<endl;
if(want == "func") {
cout << "y = ";
if(newm == 0 && newb == 0) {
cout << "0";
} else if (newm == 0 && newb != 0 ) {
cout << newb;
} else if (newm != 0 && newb == 0) {
if(newm != 1 && newm != -1) {
cout << newm;
} if (newm == -1) {
cout << "-";
}
cout << "x";
} else {
if(newm != 1 && newm != -1) {
cout << newm;
} if (newm == -1) {
cout << "-";
}
cout << "x";
if(newb > 0) {
cout << " + " << newb << endl;
} else if (newb < 0) {
cout << " " << newb << endl;
}
}
}
} | # 0620, 2024-11-02 10:48:29, PPPPPPP-PPP-P--PPPPPPP-- (75%)
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
long long fac(int n) {
if(n>=1) {
return 1;
}
return n*fac(n-1);
}
int main() {
int n;
string want;
cin >> n >> want;
vector<float> xi;
vector<float> yi;
for(int i = 0;i < n;i++) {
float x,y;
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
float m,b;
float sumxi = 0;
float sumyi = 0;
for(int i = 0;i<n;i++) {
sumxi += xi[i];
}
//cout << sumxi << endl;
for(int i = 0;i<n;i++) {
sumyi += yi[i];
}
//cout << sumyi << endl;
float sumxiyi = 0;
for(int i = 0;i<n;i++) {
sumxiyi += xi[i]*yi[i];
}
float sumxi2;
for(int i = 0;i<n;i++) {
sumxi2 += xi[i]*xi[i];
}
//cout << sumxiyi << endl;
m = ((n*sumxiyi)-(sumxi*sumyi))/((n*sumxi2)-pow(sumxi,2));
b = (sumyi-(m*sumxi))/n;
if(want == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
float newm = round(m*1e3)/1e3 ;
float newb = round(b*1e3)/1e3 ;
//cout << newm <<endl;
//cout << newb <<endl;
if(want == "func") {
cout << "y = ";
if(newm == 0 && newb == 0) {
cout << "0";
} else if (newm == 0 && newb != 0 ) {
cout << newb;
} else if (newm != 0 && newb == 0) {
if(newm != 1 && newm != -1) {
cout << newm;
} if (newm == -1) {
cout << "-";
}
cout << "x";
} else {
if(newm != 1 && newm != -1) {
cout << newm;
} if (newm == -1) {
cout << "-";
}
cout << "x";
if(newb > 0) {
cout << " + " << newb << endl;
} else if (newb < 0) {
cout << " " << newb << endl;
}
}
}
} | # 0621, 2024-11-02 11:45:23, ------------------------ (0%)
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
long long fac(int n) {
if(n>=1) {
return 1;
}
return n*fac(n-1);
}
int main() {
int n;
string want;
cin >> n >> want;
vector<float> xi;
vector<float> yi;
for(int i = 0;i < n;i++) {
float x,y;
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
float m,b;
float sumxi = 0;
float sumyi = 0;
for(int i = 0;i<n;i++) {
sumxi += xi[i];
}
//cout << sumxi << endl;
for(int i = 0;i<n;i++) {
sumyi += yi[i];
}
//cout << sumyi << endl;
float sumxiyi = 0;
for(int i = 0;i<n;i++) {
sumxiyi += xi[i]*yi[i];
}
//cout << sumxiyi << endl;
float sumxi2;
for(int i = 0;i<n;i++) {
sumxi2 += xi[i]*xi[i];
//cout << xi[i];
}
//cout << sumxi2 << endl;
m = ((n*sumxiyi)-(sumxi*sumyi))/((n*sumxi2)-pow(sumxi,2));
b = (sumyi-(m*sumxi))/n;
//cout << m << endl;
//cout << b << endl;
float newm = round(m*1e3)/1e3 ;
float newb = round(b*1e3)/1e3 ;
if(want == "mb") {
cout << newm<< endl;
cout << newb<< endl;
}
cout << newm <<endl;
cout << newb <<endl;
if(want == "func") {
cout << "y = ";
if(newm == 0 && newb == 0) {
cout << "0";
} else if (newm == 0 && newb != 0 ) {
cout << newb;
} else if (newm != 0 && newb == 0) {
if(newm != 1 && newm != -1) {
cout << newm;
} if (newm == -1) {
cout << "-";
}
cout << "x";
} else {
if(newm != 1 && newm != -1) {
cout << newm;
} if (newm == -1) {
cout << "-";
}
cout << "x";
if(newb > 0) {
cout << " + " << newb << endl;
} else if (newb < 0) {
float h = newb*2;
cout << " - " << newb - h << endl;
}
}
}
} | # 0622, 2024-11-02 11:45:55, PPPPPPP-PPPPPPPPPPPPPPPP (95%)
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
long long fac(int n) {
if(n>=1) {
return 1;
}
return n*fac(n-1);
}
int main() {
int n;
string want;
cin >> n >> want;
vector<float> xi;
vector<float> yi;
for(int i = 0;i < n;i++) {
float x,y;
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
float m,b;
float sumxi = 0;
float sumyi = 0;
for(int i = 0;i<n;i++) {
sumxi += xi[i];
}
//cout << sumxi << endl;
for(int i = 0;i<n;i++) {
sumyi += yi[i];
}
//cout << sumyi << endl;
float sumxiyi = 0;
for(int i = 0;i<n;i++) {
sumxiyi += xi[i]*yi[i];
}
//cout << sumxiyi << endl;
float sumxi2;
for(int i = 0;i<n;i++) {
sumxi2 += xi[i]*xi[i];
//cout << xi[i];
}
//cout << sumxi2 << endl;
m = ((n*sumxiyi)-(sumxi*sumyi))/((n*sumxi2)-pow(sumxi,2));
b = (sumyi-(m*sumxi))/n;
//cout << m << endl;
//cout << b << endl;
float newm = round(m*1e3)/1e3 ;
float newb = round(b*1e3)/1e3 ;
if(want == "mb") {
cout << newm<< endl;
cout << newb<< endl;
}
//cout << newm <<endl;
//cout << newb <<endl;
if(want == "func") {
cout << "y = ";
if(newm == 0 && newb == 0) {
cout << "0";
} else if (newm == 0 && newb != 0 ) {
cout << newb;
} else if (newm != 0 && newb == 0) {
if(newm != 1 && newm != -1) {
cout << newm;
} if (newm == -1) {
cout << "-";
}
cout << "x";
} else {
if(newm != 1 && newm != -1) {
cout << newm;
} if (newm == -1) {
cout << "-";
}
cout << "x";
if(newb > 0) {
cout << " + " << newb << endl;
} else if (newb < 0) {
float h = newb*2;
cout << " - " << newb - h << endl;
}
}
}
} |
# 0623, 2024-11-02 13:04:22, PPPPPPPPPP-------------- (41%)
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
string method;
cin >> n >> method;
float x[n], y[n];
for (int i=0;i<n;i++) {
cin >> x[i] >> y[i];
}
float sumx=0, sumy=0, sumxpow2=0, sumxy=0;
for (int i=0;i<n;i++) {
sumx+=x[i];
sumy+=y[i];
sumxpow2+=x[i]*x[i];
sumxy+=x[i]*y[i];
}
float m, b;
m = ((n*sumxy) - (sumx*sumy))/((n*sumxpow2)-(sumx*sumx));
b = (sumy - (m*sumx))/n;
if (method=="mb") {
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
} | # 0624, 2024-11-02 13:09:01, PPPPPPPPPPPPPPP--------- (62%)
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
string method;
cin >> n >> method;
float x[n], y[n];
for (int i=0;i<n;i++) {
cin >> x[i] >> y[i];
}
float sumx=0, sumy=0, sumxpow2=0, sumxy=0;
for (int i=0;i<n;i++) {
sumx+=x[i];
sumy+=y[i];
sumxpow2+=x[i]*x[i];
sumxy+=x[i]*y[i];
}
float m, b;
m = ((n*sumxy) - (sumx*sumy))/((n*sumxpow2)-(sumx*sumx));
b = (sumy - (m*sumx))/n;
if (method=="mb") {
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
if (method=="func") {
cout << "y = ";
if (m==1) {
cout << "x ";
}
else if (m==-1) {
cout << "-x ";
}
else {
cout << round(m*1e3)/1e3 << "x ";
}
if (b>0) cout << "+ ";
else cout << "- ";
cout << abs(round(b*1e3)/1e3);
}
} | # 0625, 2024-11-02 13:19:54, PPPPPPPPPP------P-PP-P-- (58%)
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
string method;
cin >> n >> method;
float x[n], y[n];
for (int i=0;i<n;i++) {
cin >> x[i] >> y[i];
}
float sumx=0, sumy=0, sumxpow2=0, sumxy=0;
for (int i=0;i<n;i++) {
sumx+=x[i];
sumy+=y[i];
sumxpow2+=x[i]*x[i];
sumxy+=x[i]*y[i];
}
float m, b;
m = ((n*sumxy) - (sumx*sumy))/((n*sumxpow2)-(sumx*sumx));
b = (sumy - (m*sumx))/n;
if (method=="mb") {
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
if (method=="func") {
cout << "y = ";
if (round(m*1e3)/1e3!=0||round(m*1e3)/1e3!=-0) {
if (m==1) {
cout << "x";
}
else if (m==-1) {
cout << "-x";
}
else {
cout << round(m*1e3)/1e3 << "x";
}
}
if (b!=0&&(round(m*1e3)/1e3!=0||round(m*1e3)/1e3!=-0)) {
if (b>0) cout << " + ";
else cout << " - ";
cout << abs(round(b*1e3)/1e3);
}
if (b!=0) {
cout << round(b*1e3)/1e3;
}
if (m==0&&b==0) {
cout << "y = 0";
}
}
} | # 0626, 2024-11-02 13:21:48, PPPPPPPPPPPPPPP-P-PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
string method;
cin >> n >> method;
float x[n], y[n];
for (int i=0;i<n;i++) {
cin >> x[i] >> y[i];
}
float sumx=0, sumy=0, sumxpow2=0, sumxy=0;
for (int i=0;i<n;i++) {
sumx+=x[i];
sumy+=y[i];
sumxpow2+=x[i]*x[i];
sumxy+=x[i]*y[i];
}
float m, b;
m = ((n*sumxy) - (sumx*sumy))/((n*sumxpow2)-(sumx*sumx));
b = (sumy - (m*sumx))/n;
if (method=="mb") {
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
if (method=="func") {
cout << "y = ";
if (round(m*1e3)/1e3!=0||round(m*1e3)/1e3!=-0) {
if (m==1) {
cout << "x";
}
else if (m==-1) {
cout << "-x";
}
else {
cout << round(m*1e3)/1e3 << "x";
}
}
bool bout=false;
if (b!=0&&(round(m*1e3)/1e3!=0||round(m*1e3)/1e3!=-0)) {
if (b>0) cout << " + ";
else cout << " - ";
cout << abs(round(b*1e3)/1e3);
bout=true;
}
if (b!=0&&!bout) {
cout << round(b*1e3)/1e3;
}
if (m==0&&b==0) {
cout << "y = 0";
}
}
} | # 0627, 2024-11-02 13:25:17, PPPPPPPPPPPPPPP-P-PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
string method;
cin >> n >> method;
float x[n], y[n];
for (int i=0;i<n;i++) {
cin >> x[i] >> y[i];
}
float sumx=0, sumy=0, sumxpow2=0, sumxy=0;
for (int i=0;i<n;i++) {
sumx+=x[i];
sumy+=y[i];
sumxpow2+=x[i]*x[i];
sumxy+=x[i]*y[i];
}
float m, b;
m = ((n*sumxy) - (sumx*sumy))/((n*sumxpow2)-(sumx*sumx));
b = (sumy - (m*sumx))/n;
if (method=="mb") {
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
if (method=="func") {
cout << "y = ";
if (round(m*1e3)/1e3!=0||round(m*1e3)/1e3!=-0) {
if (m==1) {
cout << "x";
}
else if (m==-1) {
cout << "-x";
}
else {
cout << round(m*1e3)/1e3 << "x";
}
}
bool bout=false;
if (round(b*1e3)/1e3!=0&&(round(m*1e3)/1e3!=0||round(m*1e3)/1e3!=-0)) {
if (round(b*1e3)/1e3>0) cout << " + ";
else cout << " - ";
cout << abs(round(b*1e3)/1e3);
bout=true;
}
if (round(b*1e3)/1e3!=0&&!bout) {
cout << round(b*1e3)/1e3;
}
if (round(m*1e3)/1e3==0&&round(b*1e3)/1e3==0) {
cout << "y = 0";
}
}
} | # 0628, 2024-11-02 13:30:46, PPPPPPPPPPPPPPP-PPPPPPPP (95%)
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
string method;
cin >> n >> method;
float x[n], y[n];
for (int i=0;i<n;i++) {
cin >> x[i] >> y[i];
}
float sumx=0, sumy=0, sumxpow2=0, sumxy=0;
for (int i=0;i<n;i++) {
sumx+=x[i];
sumy+=y[i];
sumxpow2+=x[i]*x[i];
sumxy+=x[i]*y[i];
}
float m, b;
m = ((n*sumxy) - (sumx*sumy))/((n*sumxpow2)-(sumx*sumx));
b = (sumy - (m*sumx))/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (method=="mb") {
cout << m << endl << b;
}
if (method=="func") {
cout << "y = ";
//-----
if (m!=0||m!=-0) {
if (m==1) {
cout << "x";
}
else if (m==-1) {
cout << "-x";
}
else {
cout << m << "x";
}
}
//------
if (b!=0&&(m!=0||m!=-0)) {
if (b>0) cout << " + ";
else cout << " - ";
cout << abs(b);
}
//------
if (b!=0&&m==0) {
cout << b;
}
if (m==0&&b==0) {
cout << "y = 0";
}
}
} | # 0629, 2024-11-02 13:33:05, PPPPPPPPPPPPPPP-PPPPPPPP (95%)
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
string method;
cin >> n >> method;
float x[n], y[n];
for (int i=0;i<n;i++) {
cin >> x[i] >> y[i];
}
float sumx=0, sumy=0, sumxpow2=0, sumxy=0;
for (int i=0;i<n;i++) {
sumx+=x[i];
sumy+=y[i];
sumxpow2+=x[i]*x[i];
sumxy+=x[i]*y[i];
}
float m, b;
m = ((n*sumxy) - (sumx*sumy))/((n*sumxpow2)-(sumx*sumx));
b = (sumy - (m*sumx))/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (method=="mb") {
cout << m << endl << b;
}
if (method=="func") {
cout << "y = ";
//-----
if (m!=0||m!=-0) {
if (m==1) {
cout << "x";
}
else if (m==-1) {
cout << "-x";
}
else {
cout << m << "x";
}
}
//------
if (b!=0&&(m!=0||m!=-0)) {
if (b>0) cout << " + ";
else if (b<0) cout << " - ";
cout << abs(b);
}
//------
if (b!=0&&m==0) {
cout << b;
}
if (m==0&&b==0) {
cout << "y = 0";
}
}
} |
# 0630, 2024-11-02 14:06:00, PPPPPPPPPP-----P--PP---- (54%)
#include<iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
int n;
string ord;
float sumx = 0,sumy = 0,sumxy = 0;
float psumx = 0;
float m = 0,b = 0;
cin >>n >>ord;
for (int i = 0; i < n; i++)
{
float x ,y;
cin >> x >> y;
sumx += x;
sumy +=y;
sumxy += x*y;
psumx += pow(x,2);
}
float abvx = (n*sumxy) - (sumx*sumy);
float blx = (n*psumx) - (sumx*sumx);
m = abvx/blx;
float abvb = sumy - (m * sumx);
b = abvb / n;
bool hasx = false;
bool hasy = false;
if (ord == "mb")
{
cout << round(m*1e3)/1e3 << endl<<round(b*1e3)/1e3<<endl;
}
else if (ord == "func")
{
if(m+b == 0){cout << "y = 0"; return 0;}
cout <<"y = ";
if (m == 1)
{
cout<< "x " ;
hasx = true;
}
else if (m == -1)
{
cout<< "-x " ;;
hasx = true;
}
else if (m == 0)
{
cout <<round(m*1e3)/1e3<<"x ";
hasx = true;
}
if (b < 0 && !hasx)
{
cout<< "-" << abs(round(b*1e3)/1e3);
hasy = true;
}
else if (b < 0 && hasx)
{
cout<< "- "<< abs(round(b*1e3)/1e3);
hasy = true;
}
else if (b > 0)
{
cout<< "+ "<< round(b*1e3)/1e3;
hasy = true;
}
}
} | # 0631, 2024-11-02 14:07:31, PPPPPPPPPP-----P-------- (45%)
#include<iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
int n;
string ord;
float sumx = 0,sumy = 0,sumxy = 0;
float psumx = 0;
float m = 0,b = 0;
cin >>n >>ord;
for (int i = 0; i < n; i++)
{
float x ,y;
cin >> x >> y;
sumx += x;
sumy +=y;
sumxy += x*y;
psumx += pow(x,2);
}
float abvx = (n*sumxy) - (sumx*sumy);
float blx = (n*psumx) - (sumx*sumx);
m = abvx/blx;
float abvb = sumy - (m * sumx);
b = abvb / n;
bool hasx = false;
bool hasy = false;
if (ord == "mb")
{
cout << round(m*1e3)/1e3 << endl<<round(b*1e3)/1e3<<endl;
}
else if (ord == "func")
{
if(m+b == 0){cout << "y = 0"; return 0;}
cout <<"y = ";
if (m == 1)
{
cout<< "x " ;
hasx = true;
}
else if (m == -1)
{
cout<< "-x " ;;
hasx = true;
}
else
{
cout <<round(m*1e3)/1e3<<"x ";
hasx = true;
}
if (b < 0 && !hasx)
{
cout<< "-" << abs(round(b*1e3)/1e3);
hasy = true;
}
else if (b < 0 && hasx)
{
cout<< "- "<< abs(round(b*1e3)/1e3);
hasy = true;
}
else if (b > 0)
{
cout<< "+ "<< round(b*1e3)/1e3;
hasy = true;
}
cout <<" "<< m;
}
} | # 0632, 2024-11-02 14:14:31, PPPPPPPPPPPP---P--PP-P-- (66%)
#include<iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
int n;
string ord;
float sumx = 0,sumy = 0,sumxy = 0;
float psumx = 0;
float m = 0,b = 0;
cin >>n >>ord;
for (int i = 0; i < n; i++)
{
float x ,y;
cin >> x >> y;
sumx += x;
sumy +=y;
sumxy += x*y;
psumx += pow(x,2);
}
float abvx = (n*sumxy) - (sumx*sumy);
float blx = (n*psumx) - (sumx*sumx);
m = abvx/blx;
float abvb = sumy - (m * sumx);
b = abvb / n;
bool hasx = false;
if (ord == "mb")
{
cout << round(m*1e3)/1e3 << endl<<round(b*1e3)/1e3<<endl;
}
else if (ord == "func")
{
if(m+b == 0){cout << "y = 0"; return 0;}
cout <<"y = ";
if (m == 1)
{
cout<< "x " ;
hasx = true;
}
else if (m == -1)
{
cout<< "-x " ;;
hasx = true;
}
else if(m < 0)
{
hasx = false;
}
else if(m > 0)
{
cout << round(m*1e3)/1e3<<"x ";
hasx = true;
}
if (b < 0 && !hasx)
{
cout<< "-" << abs(round(b*1e3)/1e3);
}
else if (b < 0 && hasx)
{
cout<< "- "<< abs(round(b*1e3)/1e3);
}
else if (b > 0)
{
cout<< "+ "<< round(b*1e3)/1e3;
}
//cout <<" ||||||"<< m;
}
} | # 0633, 2024-11-02 14:22:33, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
int n;
string ord;
float sumx = 0,sumy = 0,sumxy = 0;
float psumx = 0;
float m = 0,b = 0;
cin >>n >>ord;
for (int i = 0; i < n; i++)
{
float x ,y;
cin >> x >> y;
sumx += x;
sumy +=y;
sumxy += x*y;
psumx += pow(x,2);
}
float abvx = (n*sumxy) - (sumx*sumy);
float blx = (n*psumx) - (sumx*sumx);
m = abvx/blx;
float abvb = sumy - (m * sumx);
b = abvb / n;
bool hasx = false;
if (ord == "mb")
{
cout << round(m*1e3)/1e3 << endl<<round(b*1e3)/1e3<<endl;
}
else if (ord == "func")
{
if(m+b == 0){cout << "y = 0"; return 0;}
cout <<"y = ";
if (m == 1)
{
cout<< "x " ;
hasx = true;
}
else if (m == -1)
{
cout<< "-x " ;;
hasx = true;
}
else if(round(m*1e3)/1e3 < 0)
{
cout << round(m*1e3)/1e3<<"x ";
hasx = true;
}
else if(m > 0)
{
cout << round(m*1e3)/1e3<<"x ";
hasx = true;
}
if (b < 0 && !hasx)
{
cout<< "-" << abs(round(b*1e3)/1e3);
}
else if (b < 0 && hasx)
{
cout<< "- "<< abs(round(b*1e3)/1e3);
}
else if (b > 0)
{
cout<< "+ "<< round(b*1e3)/1e3;
}
//cout <<" ||||||"<< m;
}
} | # 0634, 2024-11-02 14:23:29, PPPPPPPPPPPPPPPP-PPPPPPP (95%)
#include<iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
int n;
string ord;
float sumx = 0,sumy = 0,sumxy = 0;
float psumx = 0;
float m = 0,b = 0;
cin >>n >>ord;
for (int i = 0; i < n; i++)
{
float x ,y;
cin >> x >> y;
sumx += x;
sumy +=y;
sumxy += x*y;
psumx += pow(x,2);
}
float abvx = (n*sumxy) - (sumx*sumy);
float blx = (n*psumx) - (sumx*sumx);
m = abvx/blx;
float abvb = sumy - (m * sumx);
b = abvb / n;
bool hasx = false;
if (ord == "mb")
{
cout << round(m*1e3)/1e3 << endl<<round(b*1e3)/1e3<<endl;
}
else if (ord == "func")
{
if(m+b == 0){cout << "y = 0"; return 0;}
cout <<"y = ";
if (round(m*1e3)/1e3 == 1)
{
cout<< "x " ;
hasx = true;
}
else if (round(m*1e3)/1e3 == -1)
{
cout<< "-x " ;;
hasx = true;
}
else if(round(m*1e3)/1e3 < 0)
{
cout << round(m*1e3)/1e3<<"x ";
hasx = true;
}
else if(round(m*1e3)/1e3 > 0)
{
cout << round(m*1e3)/1e3<<"x ";
hasx = true;
}
if (round(b*1e3)/1e3 < 0 && !hasx)
{
cout<< "-" << abs(round(b*1e3)/1e3);
}
else if (round(b*1e3)/1e3 < 0 && hasx)
{
cout<< "- "<< abs(round(b*1e3)/1e3);
}
else if (round(b*1e3)/1e3 > 0)
{
cout<< "+ "<< round(b*1e3)/1e3;
}
//cout <<" ||||||"<< m;
}
} | # 0635, 2024-11-02 15:20:50, PPPPPPPPPPPPPPPP-PPPPPPP (95%)
#include<iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
int n;
string ord;
float sumx = 0,sumy = 0,sumxy = 0;
float psumx = 0;
float m = 0,b = 0;
cin >>n >>ord;
for (int i = 0; i < n; i++)
{
float x ,y;
cin >> x >> y;
sumx += x;
sumy +=y;
sumxy += x*y;
psumx += pow(x,2);
}
float abvx = (n*sumxy) - (sumx*sumy);
float blx = (n*psumx) - (sumx*sumx);
m = abvx/blx;
float abvb = sumy - (m * sumx);
b = abvb / n;
bool hasx = false;
if (ord == "mb")
{
cout << round(m*1e3)/1e3 << endl<<round(b*1e3)/1e3<<endl;
}
else if (ord == "func")
{
if(m+b == 0){cout << "y = 0"; return 0;}
cout <<"y = ";
if (round(m*1e3)/1e3 == 1)
{
cout<< "x " ;
hasx = true;
}
else if (round(m*1e3)/1e3 == -1)
{
cout<< "-x " ;;
hasx = true;
}
else if(round(m*1e3)/1e3 < 0)
{
cout << round(m*1e3)/1e3<<"x ";
hasx = true;
}
else if(round(m*1e3)/1e3 > 0)
{
cout << round(m*1e3)/1e3<<"x ";
hasx = true;
}
if (round(b*1e3)/1e3 < 0 && !hasx)
{
cout<< "-" << abs(round(b*1e3)/1e3);
}
else if (round(b*1e3)/1e3 < 0 && hasx)
{
cout<< "- "<< abs(round(b*1e3)/1e3);
}
else if (round(b*1e3)/1e3 > 0)
{
cout<< "+ "<< round(b*1e3)/1e3;
}
//cout <<" ||||||"<< m;
}
} |
# 0636, 2024-11-02 13:38:56, PPPPPPPPPP-----P---PP--P (58%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
string s;
cin>>n>>s;
float x, y, m, b, cnt=0, sumx=0, sumy=0, sumxy=0, sumx2=0;
while (n--)
{
cin>>x>>y;
cnt++;
sumx+=x;
sumy+=y;
sumxy+=x*y;
sumx2+=pow(x,2);
}
m=((cnt*sumxy)-(sumx*sumy))/((cnt*sumx2)-pow(sumx,2));
b=(sumy-(m*sumx))/cnt;
if (s=="mb"){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3;
}
else if (s=="func"){
if (m==0&&b==0){
cout<<"y = 0";
}
else{
cout<<"y = ";
if (m>0) cout<<m<<"x";
else if (m==1) cout<<"x";
else if (m==0) cout<<"";
else if (m<0) cout<<"-x";
if (b>0) cout<<" + "<<b;
else if (b==0) cout<<"";
else if (b<0) cout<<" - "<<-b;
}
}
} | # 0637, 2024-11-02 14:25:11, PPPPPPPPPPPPPPPP-PPPPPPP (95%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
string s;
cin>>n>>s;
float x, y, m, b, cnt=0, sumx=0, sumy=0, sumxy=0, sumx2=0;
while (n--)
{
++cnt;
cin>>x>>y;
sumx+=x;
sumy+=y;
sumxy+=x*y;
sumx2+=x*x;
}
m=((cnt*sumxy)-(sumx*sumy))/((cnt*sumx2)-(sumx*sumx));
b=(sumy-(m*sumx))/cnt;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if (s=="mb"){
cout<<m<<endl;
cout<<b;
}
else if (s=="func"){
if (m==0&&b==0){
cout<<"y = 0";
}
else{
cout<<"y = ";
if (m>0&&m!=1) cout<<m<<"x";
else if (m>0&&m==1) cout<<"x";
else if (m<0&&m!=-1) cout<<m<<"x";
else if (m<0&&m==-1) cout<<"-x";
if (b>0) cout<<" + "<<b;
else if (b<0&&m==0) cout<<" "<<b;
else if (b<0) cout<<" - "<<-b;
}
}
} | # 0638, 2024-11-02 15:04:41, PPPPPPPPPPPPPPPP-PPPPPPP (95%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
string s;
cin>>n>>s;
float x, y, m, b, cnt=0, sumx=0, sumy=0, sumxy=0, sumx2=0;
while (n--)
{
++cnt;
cin>>x>>y;
sumx+=x;
sumy+=y;
sumxy+=x*y;
sumx2+=x*x;
}
m=((cnt*sumxy)-(sumx*sumy))/((cnt*sumx2)-(sumx*sumx));
b=(sumy-(m*sumx))/cnt;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if (s=="mb"){
cout<<m<<endl;
cout<<b;
}
else if (s=="func"){
if (m==0&&b==0){
cout<<"y = 0";
}
else{
cout<<"y = ";
if (m>0&&m!=1) cout<<m<<"x";
else if (m>0&&m==1) cout<<"x";
else if (m<0&&m!=-1) cout<<m<<"x";
else if (m<0&&m==-1) cout<<"-x";
if (b>0) cout<<" + "<<b;
else if (b<0&&m==0) cout<<b;
else if (b<0) cout<<" - "<<-b;
}
}
} | # 0639, 2024-11-02 15:06:44, PPPPPPPPPPPPPPPP-PPPPPPP (95%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
string s;
cin>>n>>s;
float x, y, m, b, cnt=0, sumx=0, sumy=0, sumxy=0, sumx2=0;
while (n--)
{
++cnt;
cin>>x>>y;
sumx+=x;
sumy+=y;
sumxy+=x*y;
sumx2+=x*x;
}
m=((cnt*sumxy)-(sumx*sumy))/((cnt*sumx2)-(sumx*sumx));
b=(sumy-(m*sumx))/cnt;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if (s=="mb"){
cout<<m<<endl;
cout<<b;
}
else if (s=="func"){
if (m==0&&b==0){
cout<<"y = 0";
}
else{
cout<<"y = ";
if (m>0&&m!=1) cout<<m<<"x";
else if (m>0&&m==1) cout<<"x";
else if (m<0&&m!=-1) cout<<m<<"x";
else if (m<0&&m==-1) cout<<"-x";
if (b>0) cout<<" + "<<b;
else if ((b>0||b<0)&&m==0) cout<<b;
else if (b<0) cout<<" - "<<-b;
}
}
} | # 0640, 2024-11-02 15:12:23, PPPPPPPPPPPPPPPP-PPPPPPP (95%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
string s;
cin>>n>>s;
float x, y, m, b, cnt=0, sumx=0, sumy=0, sumxy=0, sumx2=0;
while (n--)
{
++cnt;
cin>>x>>y;
sumx+=x;
sumy+=y;
sumxy+=x*y;
sumx2+=x*x;
}
m=((cnt*sumxy)-(sumx*sumy))/((cnt*sumx2)-(sumx*sumx));
b=(sumy-(m*sumx))/cnt;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if (s=="mb"){
cout<<m<<endl;
cout<<b;
}
else if (s=="func"){
if (m==0&&b==0){
cout<<"y = 0";
}
else{
cout<<"y = ";
if (m>0){
if (m!=1) cout<<m<<"x";
else if (m==1) cout<<"x";
}
else if (m<0){
if (m!=-1) cout<<m<<"x";
else if (m==-1) cout<<"-x";
}
if (b>0) cout<<" + "<<b;
else if (m==0) cout<<b;
else if (b<0) cout<<" - "<<-b;
}
}
} |
# 0641, 2024-11-02 12:55:22, -----P--PP-----P-----P-- (20%)
#include <iostream>
#include <vector>
#include <cmath>
#include <utility>
using namespace std;
int main(){
int N;
string cmd;
cin >> N >> cmd;
vector<pair<float,float> > num;
for(int i = 0;i<N;i++){
float x,y;
cin >> x >> y;
pair<float,float> temp = make_pair(x,y);
num.push_back(temp);
}
float m,b;
float sumXY=0,sumX=0,sumY=0,sumX2=0,sumY2=0;
for(auto XY:num){
sumXY+=XY.first*XY.second;
sumX+=XY.first;
sumY+=XY.second;
sumX2+=XY.first*XY.first;
sumY2+=XY.second*XY.second;
}
m = ((N*sumXY)-(sumX*sumY))/((N*sumX2)-sumY2);
b = (sumY-(m*sumX))/N;
if(cmd=="mb")cout << m << endl << b;
else {
if(m==0&&b==0)cout << "y = 0";
else if(m==0&&b!=0)cout << "y = " << b;
else if(m!=1&&m!=0&&b==0)cout << "y = " << m << 'x';
else if(m==1&&b==0)cout << "y = " << 'x';
else cout << "y = " << m << "x + " << b;
}
} | # 0642, 2024-11-02 12:57:16, -----P--PP-----PP----P-- (25%)
#include <iostream>
#include <vector>
#include <cmath>
#include <utility>
using namespace std;
int main(){
int N;
string cmd;
cin >> N >> cmd;
vector<pair<float,float> > num;
for(int i = 0;i<N;i++){
float x,y;
cin >> x >> y;
pair<float,float> temp = make_pair(x,y);
num.push_back(temp);
}
float m,b;
float sumXY=0,sumX=0,sumY=0,sumX2=0,sumY2=0;
for(auto XY:num){
sumXY+=XY.first*XY.second;
sumX+=XY.first;
sumY+=XY.second;
sumX2+=XY.first*XY.first;
sumY2+=XY.second*XY.second;
}
m = ((N*sumXY)-(sumX*sumY))/((N*sumX2)-sumY2);
b = (sumY-(m*sumX))/N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(cmd=="mb")cout << m << endl << b;
else {
if(m==0&&b==0)cout << "y = 0";
else if(m==0&&b!=0)cout << "y = " << b;
else if(m!=1&&m!=0&&b==0)cout << "y = " << m << 'x';
else if(m==1&&b==0)cout << "y = " << 'x';
else cout << "y = " << m << "x + " << b;
}
} | # 0643, 2024-11-02 13:06:01, -----P--PP-----P-----P-- (20%)
#include <iostream>
#include <vector>
#include <cmath>
#include <utility>
using namespace std;
int main(){
int N;
string cmd;
cin >> N >> cmd;
vector<pair<float,float> > num;
for(int i = 0;i<N;i++){
float x,y;
cin >> x >> y;
pair<float,float> temp = make_pair(x,y);
num.push_back(temp);
}
float m,b;
float sumXY=0,sumX=0,sumY=0,sumX2=0,sumY2=0;
for(auto XY:num){
sumXY+=XY.first*XY.second;
sumX+=XY.first;
sumY+=XY.second;
sumX2+=XY.first*XY.first;
sumY2+=XY.second*XY.second;
}
m = ((N*sumXY)-(sumX*sumY))/((N*sumX2)-sumY2);
b = (sumY-(m*sumX))/N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(cmd=="mb")cout << m << endl << b;
else {
if (m==0&&b==0)cout << "y = 0";
else if(m==0&&b>0)cout << "y = +" << abs(b);
else if(m==0&&b<0)cout << "y = -" << abs(b);
else if(m==-1&&b==0)cout << "y = -x";
else if(m==-1&&b>0)cout << "y = -x + " << abs(b);
else if(m==-1&&b<0)cout << "y = -x - "<< abs(b);
else if(m==1&&b==0)cout << "y = x";
else if(m==1&&b>0)cout << "y = x + " << abs(b);
else if(m==1&&b<0)cout << "y = x - " << abs(b);
else if(m>0&&b==0)cout << "y = "<< m << "x";
else if(m>0&&b>0)cout << "y = " << m << "x + " << abs(b);
else if(m>0&&b<0)cout << "y = " << m << "x - " << abs(b);
else if(m<0&&b==0)cout << "y = " << '-' << abs(m)<< 'x';
else if(m<0&&b>0)cout << "y = " << '-' << abs(m)<< "x + " << abs(b);
else if(m<0&&b<0)cout << "y = " << '-' << abs(m)<< "x - " << abs(b);
}
} | # 0644, 2024-11-02 13:07:15, -----P--PP-----P-----P-- (20%)
#include <iostream>
#include <vector>
#include <cmath>
#include <utility>
using namespace std;
int main(){
int N;
string cmd;
cin >> N >> cmd;
vector<pair<float,float> > num;
for(int i = 0;i<N;i++){
float x,y;
cin >> x >> y;
pair<float,float> temp = make_pair(x,y);
num.push_back(temp);
}
float m,b;
float sumXY=0,sumX=0,sumY=0,sumX2=0,sumY2=0;
for(auto XY:num){
sumXY+=XY.first*XY.second;
sumX+=XY.first;
sumY+=XY.second;
sumX2+=XY.first*XY.first;
sumY2+=XY.second*XY.second;
}
m = ((N*sumXY)-(sumX*sumY))/((N*sumX2)-sumY2);
b = (sumY-(m*sumX))/N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(cmd=="mb")cout << m << endl << b;
else {
if (m==0&&b==0)cout << "y = 0";
else if(m==0&&b>0)cout << "y = +" << abs(b);
else if(m==0&&b<0)cout << "y = -" << abs(b);
else if(m==-1&&b==0)cout << "y = -x";
else if(m==-1&&b>0)cout << "y = -x + " << abs(b);
else if(m==-1&&b<0)cout << "y = -x - "<< abs(b);
else if(m==1&&b==0)cout << "y = x";
else if(m==1&&b>0)cout << "y = x + " << abs(b);
else if(m==1&&b<0)cout << "y = x - " << abs(b);
else if(m>1&&b==0)cout << "y = "<< m << "x";
else if(m>1&&b>0)cout << "y = " << m << "x + " << abs(b);
else if(m>1&&b<0)cout << "y = " << m << "x - " << abs(b);
else if(m<-1&&b==0)cout << "y = " << '-' << abs(m)<< 'x';
else if(m<-1&&b>0)cout << "y = " << '-' << abs(m)<< "x + " << abs(b);
else if(m<-1&&b<0)cout << "y = " << '-' << abs(m)<< "x - " << abs(b);
}
} | # 0645, 2024-11-02 13:15:36, PPPPPPPPPPPPPPPP-PPPPPPP (95%)
#include <iostream>
#include <vector>
#include <cmath>
#include <utility>
using namespace std;
int main(){
float N;
string cmd;
cin >> N >> cmd;
vector<pair<float,float> > num;
for(int i = 0;i<N;i++){
float x,y;
cin >> x >> y;
pair<float,float> temp = make_pair(x,y);
num.push_back(temp);
}
float m,b;
float sumXY=0,sumX=0,sumY=0,sumX2=0,sumY2=0;
for(auto XY:num){
sumXY+=XY.first*XY.second;
sumX+=XY.first;
sumY+=XY.second;
sumX2+=XY.first*XY.first;
sumY2+=XY.second*XY.second;
}
m = ((N*sumXY)-(sumX*sumY))/((N*sumX2)-(sumX*sumX));
b = (sumY-(m*sumX))/N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(cmd=="mb")cout << m << endl << b;
else {
if (m==0&&b==0)cout << "y = 0";
else if(m==0&&b>0)cout << "y = +" << abs(b);
else if(m==0&&b<0)cout << "y = -" << abs(b);
else if(m==-1&&b==0)cout << "y = -x";
else if(m==-1&&b>0)cout << "y = -x + " << abs(b);
else if(m==-1&&b<0)cout << "y = -x - "<< abs(b);
else if(m==1&&b==0)cout << "y = x";
else if(m==1&&b>0)cout << "y = x + " << abs(b);
else if(m==1&&b<0)cout << "y = x - " << abs(b);
else if(m>1&&b==0)cout << "y = "<< m << "x";
else if(m>1&&b>0)cout << "y = " << m << "x + " << abs(b);
else if(m>1&&b<0)cout << "y = " << m << "x - " << abs(b);
else if(m<-1&&b==0)cout << "y = " << '-' << abs(m)<< 'x';
else if(m<-1&&b>0)cout << "y = " << '-' << abs(m)<< "x + " << abs(b);
else if(m<-1&&b<0)cout << "y = " << '-' << abs(m)<< "x - " << abs(b);
}
} |
# 0646, 2024-11-02 09:32:23, PPPPPPPPPPPPPPP---PP--P- (75%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
string s;
cin >> s;
float m, b, in1, in2;
vector<float> x, y;
x.push_back(-1); y.push_back(-1);
for(int i=0 ; i<n ; i++){
cin >> in1 >> in2;
x.push_back(in1); y.push_back(in2);
}
float a = 0, e = 0, c = 0, d = 0;
for(int i=1 ; i<= n ;i++){
a += x[i]*y[i];
e += x[i];
c += y[i];
d += pow(x[i], 2);
}
m = (n*a - e*c) / (n*d - pow(e, 2));
b = (c - (m*e))/n;
if(s == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
} else if(s == "func"){
cout << "y = ";
if(m==-1){
cout << "-";
}
else if(m!=1){
cout << round(m*1e3)/1e3;
}
cout << "x";
if(b<0){
cout << " - ";
cout << round(-b*1e3)/1e3;
}
else if(b>0){
cout << " + ";
cout << round(b*1e3)/1e3;
}
}
} | # 0647, 2024-11-02 09:43:20, PPPPPPPPPPPPPPPPP-PP-PP- (87%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
string s;
cin >> s;
float m, b, in1, in2;
vector<float> x, y;
x.push_back(-1); y.push_back(-1);
for(int i=0 ; i<n ; i++){
cin >> in1 >> in2;
x.push_back(in1); y.push_back(in2);
}
float a = 0, e = 0, c = 0, d = 0;
for(int i=1 ; i<= n ;i++){
a += x[i]*y[i];
e += x[i];
c += y[i];
d += pow(x[i], 2);
}
m = (n*a - e*c) / (n*d - pow(e, 2));
b = (c - (m*e))/n;
if(s == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
} else if(s == "func"){
cout << "y = ";
if(m==-1){
cout << "-";
}
else if(m!=1 && round(m*1e3)/1e3 != 0){
cout << round(m*1e3)/1e3;
}
if(round(m*1e3)/1e3 != 0) {
cout << "x";
if(b<0){
cout << " - ";
cout << round(-b*1e3)/1e3;
}
else if(b>0){
cout << " + ";
cout << round(b*1e3)/1e3;
}
}
else {
cout << round(b*1e3)/1e3;
}
}
} | # 0648, 2024-11-02 10:22:31, PPPPPPPPPPPPPPP-PPPPPPPP (95%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
string s;
cin >> s;
float m, b, in1, in2;
vector<float> x, y;
x.push_back(-1); y.push_back(-1);
for(int i=0 ; i<n ; i++){
cin >> in1 >> in2;
x.push_back(in1); y.push_back(in2);
}
float a = 0, e = 0, c = 0, d = 0;
for(int i=1 ; i<= n ;i++){
a += x[i]*y[i];
e += x[i];
c += y[i];
d += pow(x[i], 2);
}
m = (n*a - e*c) / (n*d - pow(e, 2));
b = (c - (m*e))/n;
if(s == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
} else if(s == "func"){
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
//cout << "MVAL = " << m << endl << "BVAL = " << b << endl;
cout << "y = ";
if(m==-1){
cout << "-";
}
else if(m!=1 && m != 0){
cout << m;
}
if(m != 0) {
cout << "x";
if(b<0){
cout << " - ";
cout << -b << endl;
}
else if(b>0){
cout << " + ";
cout << b << endl;
}
}
else {
if(b==-0) cout << -b << endl;
else {
cout << b << endl;
}
}
}
} | # 0649, 2024-11-02 10:26:05, PPPPPPPPPPPPPPPPPPPPP-PP (95%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
string s;
cin >> s;
float m, b, in1, in2;
vector<float> x, y;
x.push_back(-1); y.push_back(-1);
for(int i=0 ; i<n ; i++){
cin >> in1 >> in2;
x.push_back(in1); y.push_back(in2);
}
float a = 0, e = 0, c = 0, d = 0;
for(int i=1 ; i<= n ;i++){
a += x[i]*y[i];
e += x[i];
c += y[i];
d += pow(x[i], 2);
}
m = (n*a - e*c) / (n*d - pow(e, 2));
b = (c - (m*e))/n;
if(s == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
} else if(s == "func"){
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
cout << "y = ";
if(m==-1){
cout << "-";
}
else if(m!=1 && m != 0){
cout << m;
}
if(m != 0) {
cout << "x";
if(b<0){
cout << " - ";
cout << -b << endl;
}
else if(b>0){
cout << " + ";
cout << b << endl;
}
}
else {
cout << abs(b) << endl;
}
}
} | # 0650, 2024-11-02 10:29:10, PPPPPPPPPPPPPPPPPP--P-PP (87%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
string s;
cin >> s;
float m, b, in1, in2;
vector<float> x, y;
x.push_back(-1); y.push_back(-1);
for(int i=0 ; i<n ; i++){
cin >> in1 >> in2;
x.push_back(in1); y.push_back(in2);
}
float a = 0, e = 0, c = 0, d = 0;
for(int i=1 ; i<= n ;i++){
a += x[i]*y[i];
e += x[i];
c += y[i];
d += pow(x[i], 2);
}
m = (n*a - e*c) / (n*d - pow(e, 2));
b = (c - (m*e))/n;
if(s == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
} else if(s == "func"){
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
cout << "y = ";
if(m==-1){
cout << "-";
}
else if(m!=1 && m != 0){
cout << m;
}
if(m != 0) {
cout << "x";
if(b<0){
cout << " - ";
}
else if(b>0){
cout << " + ";
}
}
cout << abs(b) << endl;
}
} |
# 0651, 2024-11-02 13:55:51, PPPPPPPPPP-PPPPP-PPPP--- (79%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
int n;
string s;
cin >> n >> s;
int N = n;
vector<pair<float, float>> F;
while(n--){
float a, b;
cin >> a >> b;
F.push_back({a,b});
}
float m, b, ms1 = 0, ms2 = 0, ms3 = 0, ms4 = 0;
for(int i = 0; i <= N; i++){
ms1 += F[i].first * F[i].second;
}
ms1 *= N;
for(int i = 0; i <= N; i++){
ms2 += F[i].first;
}
for(int i = 0; i <= N; i++){
ms3 += F[i].second;
}
for(int i = 0; i <= N; i++){
ms4 += F[i].first * F[i].first;
}
ms4 *= N;
m = (ms1 - (ms2* ms3))/ (ms4-(ms2*ms2));
b = (ms3-(m*ms2))/N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (s == "mb"){
cout << m << endl;
cout << b << endl;
}
else if (s == "func"){
if (m == 0 && b == 0){
cout << "y = 0" << endl;
}
else if(m == 1 && b == 0){
cout << "y = x" << endl;
}
else if(m == 1 && b > 0){
cout << "y = x + " << b << endl;
}
else if(m == 1 && b < 0){
cout << "y = x " << b << endl;
}
else if(m == -1 && b == 0){
cout << "y = -x" << endl;
}
else if(m == -1 && b > 0){
cout << "y = -x + " << b << endl;
}
else if(m == -1 && b < 0){
cout << "y = -x " << b << endl;
}
else if (m > 0 && b > 0){
cout << "y = " << m << "+" << b << endl;
}
else if (m > 0 && b < 0){
cout << "y = " << m << "x - " << abs(b) << endl;
}
else if (m < 0 && b > 0){
cout << "y = -" << abs(m) << "x + " << b << endl;
}
else if (m < 0 && b < 0){
cout << "y = -" << abs(m) << "x - " << abs(b) << endl;
}
}
} | # 0652, 2024-11-02 13:56:56, PPPPPPPPPP-PPPPP-PPPP-PP (87%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
int n;
string s;
cin >> n >> s;
int N = n;
vector<pair<float, float>> F;
while(n--){
float a, b;
cin >> a >> b;
F.push_back({a,b});
}
float m, b, ms1 = 0, ms2 = 0, ms3 = 0, ms4 = 0;
for(int i = 0; i <= N; i++){
ms1 += F[i].first * F[i].second;
}
ms1 *= N;
for(int i = 0; i <= N; i++){
ms2 += F[i].first;
}
for(int i = 0; i <= N; i++){
ms3 += F[i].second;
}
for(int i = 0; i <= N; i++){
ms4 += F[i].first * F[i].first;
}
ms4 *= N;
m = (ms1 - (ms2* ms3))/ (ms4-(ms2*ms2));
b = (ms3-(m*ms2))/N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (s == "mb"){
cout << m << endl;
cout << b << endl;
}
else if (s == "func"){
if (m == 0 && b == 0){
cout << "y = 0" << endl;
}
else if(m == 1 && b == 0){
cout << "y = x" << endl;
}
else if(m == 1 && b > 0){
cout << "y = x + " << b << endl;
}
else if(m == 1 && b < 0){
cout << "y = x - " << abs(b) << endl;
}
else if(m == -1 && b == 0){
cout << "y = -x" << endl;
}
else if(m == -1 && b > 0){
cout << "y = -x + " << b << endl;
}
else if(m == -1 && b < 0){
cout << "y = -x - " << abs(b) << endl;
}
else if (m > 0 && b > 0){
cout << "y = " << m << "+" << b << endl;
}
else if (m > 0 && b < 0){
cout << "y = " << m << "x - " << abs(b) << endl;
}
else if (m < 0 && b > 0){
cout << "y = -" << abs(m) << "x + " << b << endl;
}
else if (m < 0 && b < 0){
cout << "y = -" << abs(m) << "x - " << abs(b) << endl;
}
}
} | # 0653, 2024-11-02 14:00:52, PPPPPPPPPP-PPPPPPPPPPPPP (95%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
int n;
string s;
cin >> n >> s;
int N = n;
vector<pair<float, float>> F;
while(n--){
float a, b;
cin >> a >> b;
F.push_back({a,b});
}
float m, b, ms1 = 0, ms2 = 0, ms3 = 0, ms4 = 0;
for(int i = 0; i <= N; i++){
ms1 += F[i].first * F[i].second;
}
ms1 *= N;
for(int i = 0; i <= N; i++){
ms2 += F[i].first;
}
for(int i = 0; i <= N; i++){
ms3 += F[i].second;
}
for(int i = 0; i <= N; i++){
ms4 += F[i].first * F[i].first;
}
ms4 *= N;
m = (ms1 - (ms2* ms3))/ (ms4-(ms2*ms2));
b = (ms3-(m*ms2))/N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (s == "mb"){
cout << m << endl;
cout << b << endl;
}
else if (s == "func"){
if (m == 0 && b == 0){
cout << "y = 0" << endl;
}
else if(m == 0 && b > 0){
cout << "y = " << b << endl;
}
else if(m == 0 && b < 0){
cout << "y = -" << abs(b) << endl;
}
else if(m == 1 && b == 0){
cout << "y = x" << endl;
}
else if(m == 1 && b > 0){
cout << "y = x + " << b << endl;
}
else if(m == 1 && b < 0){
cout << "y = x - " << abs(b) << endl;
}
else if(m == -1 && b == 0){
cout << "y = -x" << endl;
}
else if(m == -1 && b > 0){
cout << "y = -x + " << b << endl;
}
else if(m == -1 && b < 0){
cout << "y = -x - " << abs(b) << endl;
}
else if (m > 0 && b > 0){
cout << "y = " << m << "+" << b << endl;
}
else if (m > 0 && b < 0){
cout << "y = " << m << "x - " << abs(b) << endl;
}
else if (m < 0 && b > 0){
cout << "y = -" << abs(m) << "x + " << b << endl;
}
else if (m < 0 && b < 0){
cout << "y = -" << abs(m) << "x - " << abs(b) << endl;
}
}
} | # 0654, 2024-11-02 14:03:05, PPPPPPPPPP-PPPPPPPPPPPPP (95%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
int n;
string s;
cin >> n >> s;
int N = n;
vector<pair<float, float>> F;
while(n--){
float a, b;
cin >> a >> b;
F.push_back({a,b});
}
float m, b, ms1 = 0, ms2 = 0, ms3 = 0, ms4 = 0;
for(int i = 0; i <= N; i++){
ms1 += F[i].first * F[i].second;
}
ms1 *= N;
for(int i = 0; i <= N; i++){
ms2 += F[i].first;
}
for(int i = 0; i <= N; i++){
ms3 += F[i].second;
}
for(int i = 0; i <= N; i++){
ms4 += F[i].first * F[i].first;
}
ms4 *= N;
m = (ms1 - (ms2* ms3))/ (ms4-(ms2*ms2));
b = (ms3-(m*ms2))/N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (s == "mb"){
cout << m << endl;
cout << b << endl;
}
else if (s == "func"){
if (m == 0 && b == 0){
cout << "y = 0" << endl;
}
else if(m == 0 && b > 0){
cout << "y = " << b << endl;
}
else if(m == 0 && b < 0){
cout << "y = -" << abs(b) << endl;
}
else if(m == 1 && b == 0){
cout << "y = x" << endl;
}
else if(m == 1 && b > 0){
cout << "y = x + " << b << endl;
}
else if(m == 1 && b < 0){
cout << "y = x - " << abs(b) << endl;
}
else if(m == -1 && b == 0){
cout << "y = -x" << endl;
}
else if(m == -1 && b > 0){
cout << "y = -x + " << b << endl;
}
else if(m == -1 && b < 0){
cout << "y = -x - " << abs(b) << endl;
}
else if (m > 0 && b == 0){
cout << "y = " << m << endl;
}
else if (m > 0 && b > 0){
cout << "y = " << m << "+" << b << endl;
}
else if (m > 0 && b < 0){
cout << "y = " << m << "x - " << abs(b) << endl;
}
else if (m < 0 && b == 0){
cout << "y = -" << abs(m) << endl;
}
else if (m < 0 && b > 0){
cout << "y = -" << abs(m) << "x + " << b << endl;
}
else if (m < 0 && b < 0){
cout << "y = -" << abs(m) << "x - " << abs(b) << endl;
}
}
} |
# 0655, 2024-11-02 09:35:54, PPPPPPPPPP-----PP--P-P-- (58%)
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
using namespace std;
int main(){
string com;
float n, x, y, m, b, sigmaxy=0, sigmax1=0, sigmay1=0, sigmax2=0;
cin >> n >> com;
for (int i = 0; i < n; i++)
{
cin >> x >> y;
sigmaxy += x * y;
sigmax1 += x;
sigmay1 += y;
sigmax2 += x * x;
}
m = (n * sigmaxy - sigmax1 * sigmay1) / (n * sigmax2 - sigmax1 * sigmax1);
b = (sigmay1 - m * sigmax1) / n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (com == "mb") cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
else
{
cout << "y = ";
if (b != 0)
{
if(m == 0) cout << b;
else if (m == -1) cout << "-x " << b;
else if (b < 0) cout << m << x << " - " << -b;
else cout << m << x << " + " << b;
}
else
{
if(m == 0) cout << "0";
else if (m == -1) cout << "-x ";
else if (b < 0) cout << m << x << " - ";
else cout << m << x << " + ";
}
}
} | # 0656, 2024-11-02 09:36:59, PPPPPPPPPP-P-PPPP--P-P-- (70%)
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
using namespace std;
int main(){
string com;
float n, x, y, m, b, sigmaxy=0, sigmax1=0, sigmay1=0, sigmax2=0;
cin >> n >> com;
for (int i = 0; i < n; i++)
{
cin >> x >> y;
sigmaxy += x * y;
sigmax1 += x;
sigmay1 += y;
sigmax2 += x * x;
}
m = (n * sigmaxy - sigmax1 * sigmay1) / (n * sigmax2 - sigmax1 * sigmax1);
b = (sigmay1 - m * sigmax1) / n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (com == "mb") cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
else
{
cout << "y = ";
if (b != 0)
{
if(m == 0) cout << b;
else if (m == -1) cout << "-x " << b;
else if (b < 0) cout << m << "x" << " - " << -b;
else cout << m << x << " + " << b;
}
else
{
if(m == 0) cout << "0";
else if (m == -1) cout << "-x ";
else if (b < 0) cout << m << "x" << " - ";
else cout << m << x << " + ";
}
}
} | # 0657, 2024-11-02 09:43:09, PPPPPPPPPPPPPPPPPP-P-P-- (83%)
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
using namespace std;
int main(){
string com;
float n, x, y, m, b, sigmaxy=0, sigmax1=0, sigmay1=0, sigmax2=0;
cin >> n >> com;
for (int i = 0; i < n; i++)
{
cin >> x >> y;
sigmaxy += x * y;
sigmax1 += x;
sigmay1 += y;
sigmax2 += x * x;
}
m = (n * sigmaxy - sigmax1 * sigmay1) / (n * sigmax2 - sigmax1 * sigmax1);
b = (sigmay1 - m * sigmax1) / n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (com == "mb") cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
else
{
cout << "y = ";
if (b != 0)
{
if(m == 0) cout << b;
else if (m == -1) cout << "-x " << b;
else if (b < 0) cout << m << "x" << " - " << -b;
else if (m == 1) cout << "x" << " + " << b;
else cout << m << "x" << " + " << b;
}
else
{
if(m == 0) cout << "0";
else if (m == -1) cout << "-x ";
else if (m == 1) cout << "x" << " + " << b;
else cout << m << "x" << " + ";
}
}
} | # 0658, 2024-11-02 09:45:40, PPPPPPPPPPPPPPPPPP-PPPPP (95%)
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
using namespace std;
int main(){
string com;
float n, x, y, m, b, sigmaxy=0, sigmax1=0, sigmay1=0, sigmax2=0;
cin >> n >> com;
for (int i = 0; i < n; i++)
{
cin >> x >> y;
sigmaxy += x * y;
sigmax1 += x;
sigmay1 += y;
sigmax2 += x * x;
}
m = (n * sigmaxy - sigmax1 * sigmay1) / (n * sigmax2 - sigmax1 * sigmax1);
b = (sigmay1 - m * sigmax1) / n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (com == "mb") cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
else
{
cout << "y = ";
if (b < 0)
{
if(m == 0) cout << b;
else if (m == -1) cout << "-x - " << -b;
else if (m == 1) cout << "x" << " - " << -b;
else cout << m << "x" << " - " << -b;
}
else if (b == 0)
{
if(m == 0) cout << "0";
else if (m == -1) cout << "-x ";
else if (m == 1) cout << "x" << " + " << b;
else cout << m << "x" << " + " << b;
}
else
{
if(m == 0) cout << b;
else if (m == -1) cout << "-x + " << b;
else if (m == 1) cout << "x" << " + " << b;
else cout << m << "x" << " + " << b;
}
}
} |
# 0659, 2024-11-02 13:30:10, PPPPPPPPPPPPPPPP-PPPP-PP (91%)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
float F2(float x[],float y[],ll n){
float sum = 0;
for (ll i = 1; i <= n; i++){
sum += (x[i]*y[i]);
}
return sum;
}
float F1(float x[],ll n){
float sum = 0;
for (ll i = 1; i <= n; i++){
sum += x[i];
}
return sum;
}
float F1pow(float x[],ll n){
float sum = 0;
for (ll i = 1; i <= n; i++){
sum += pow(x[i],2);
}
return sum;
}
int main(){
ll n;
string command;
cin >> n >> command;
float x[n+1],y[n+1];
for (ll i = 1; i < n+1; i++){
cin >> x[i] >> y[i];
}
float m=0,b=0;
m = (n*F2(x,y,n)) - (F1(x,n)*F1(y,n));
m /= (n*F1pow(x,n))- (F1(x,n)*F1(x,n));
b = (F1(y,n) -(m*F1(x,n)))/n;
if(command == "mb"){
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
cout << m << endl << b;
}
else{
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if(m == 0 && b == 0){
cout << "y = 0";
}
else if(m == 0 && b != 0){
cout << "y = ";
if(b > 0){
cout << "+ " << b;
}
else{
cout << "- " << -1*b;
}
}
else if(m == 1 && b != 0){
cout << "y = x ";
if(b > 0){
cout << "+ " << b;
}
else{
cout << "- " << -1*b;
}
}
else if(m == 1 && b == 0){
cout << "y = x ";
}
else if(m == -1 && b != 0){
cout << "y = -x ";
if(b > 0){
cout << "+ " << b;
}
else{
cout << "- " << -1*b;
}
}
else if(m == -1 && b == 0){
cout << "y = -x";
}
else{
cout << "y = " << m <<"x ";
if(b > 0){
cout << "+ " << b;
}
else{
cout << "- " << -1*b;
}
}
}
} | # 0660, 2024-11-02 13:32:21, PPPPPPPPPPPPPPPP-PPPPPPP (95%)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
float F2(float x[],float y[],ll n){
float sum = 0;
for (ll i = 1; i <= n; i++){
sum += (x[i]*y[i]);
}
return sum;
}
float F1(float x[],ll n){
float sum = 0;
for (ll i = 1; i <= n; i++){
sum += x[i];
}
return sum;
}
float F1pow(float x[],ll n){
float sum = 0;
for (ll i = 1; i <= n; i++){
sum += pow(x[i],2);
}
return sum;
}
int main(){
ll n;
string command;
cin >> n >> command;
float x[n+1],y[n+1];
for (ll i = 1; i < n+1; i++){
cin >> x[i] >> y[i];
}
float m=0,b=0;
m = (n*F2(x,y,n)) - (F1(x,n)*F1(y,n));
m /= (n*F1pow(x,n))- (F1(x,n)*F1(x,n));
b = (F1(y,n) -(m*F1(x,n)))/n;
if(command == "mb"){
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
cout << m << endl << b;
}
else{
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if(m == 0 && b == 0){
cout << "y = 0";
}
else if(m == 0 && b != 0){
cout << "y = ";
if(b > 0){
cout << "+ " << b;
}
else{
cout << "-" << -1*b;
}
}
else if(m == 1 && b != 0){
cout << "y = x ";
if(b > 0){
cout << "+ " << b;
}
else{
cout << "- " << -1*b;
}
}
else if(m == 1 && b == 0){
cout << "y = x ";
}
else if(m == -1 && b != 0){
cout << "y = -x ";
if(b > 0){
cout << "+ " << b;
}
else{
cout << "- " << -1*b;
}
}
else if(m == -1 && b == 0){
cout << "y = -x";
}
else{
cout << "y = " << m <<"x ";
if(b > 0){
cout << "+ " << b;
}
else{
cout << "- " << -1*b;
}
}
}
} | # 0661, 2024-11-02 13:36:38, PPPPPPPPPPPPPPPP-PPPPPPP (95%)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
float F2(float x[],float y[],ll n){
float sum = 0;
for (ll i = 1; i <= n; i++){
sum += (x[i]*y[i]);
}
return sum;
}
float F1(float x[],ll n){
float sum = 0;
for (ll i = 1; i <= n; i++){
sum += x[i];
}
return sum;
}
float F1pow(float x[],ll n){
float sum = 0;
for (ll i = 1; i <= n; i++){
sum += pow(x[i],2);
}
return sum;
}
int main(){
ll n;
string command;
cin >> n >> command;
float x[n+1],y[n+1];
for (ll i = 1; i < n+1; i++){
cin >> x[i] >> y[i];
}
float m=0,b=0;
m = (n*F2(x,y,n)) - (F1(x,n)*F1(y,n));
m /= (n*F1pow(x,n))- (F1(x,n)*F1(x,n));
b = (F1(y,n) -(m*F1(x,n)))/n;
if(command == "mb"){
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if(m == (float)-0) m = (float)0;
cout << m << endl << b;
}
else{
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if(m == 0 && b == 0){
cout << "y = 0";
}
else if(m == 0 && b != 0){
cout << "y = ";
if(b > 0){
cout << "+ " << b;
}
else{
cout << "-" << -1*b;
}
}
else if(m == 1 && b != 0){
cout << "y = x ";
if(b > 0){
cout << "+ " << b;
}
else{
cout << "- " << -1*b;
}
}
else if(m == 1 && b == 0){
cout << "y = x ";
}
else if(m == -1 && b != 0){
cout << "y = -x ";
if(b > 0){
cout << "+ " << b;
}
else{
cout << "- " << -1*b;
}
}
else if(m == -1 && b == 0){
cout << "y = -x";
}
else{
cout << "y = " << m <<"x ";
if(b > 0){
cout << "+ " << b;
}
else{
cout << "- " << -1*b;
}
}
}
} | # 0662, 2024-11-02 14:40:14, PPPPPPPPPPPPPPPP-PPPPPPP (95%)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
float F2(float x[],float y[],ll n){
float sum = 0;
for (ll i = 1; i <= n; i++){
sum += (x[i]*y[i]);
}
return sum;
}
float F1(float x[],ll n){
float sum = 0;
for (ll i = 1; i <= n; i++){
sum += x[i];
}
return sum;
}
float F1pow(float x[],ll n){
float sum = 0;
for (ll i = 1; i <= n; i++){
sum += pow(x[i],2);
}
return sum;
}
int main(){
ll n;
string command;
cin >> n >> command;
float x[n+1],y[n+1];
for (ll i = 1; i < n+1; i++){
cin >> x[i] >> y[i];
}
float m=0,b=0;
m = (n*F2(x,y,n)) - (F1(x,n)*F1(y,n));
m /= (n*F1pow(x,n))- (F1(x,n)*F1(x,n));
b = (F1(y,n) -(m*F1(x,n)))/n;
if(command == "mb"){
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if(m == (float)-0) m = (float)0;
if(b == (float)-0) b = (float)0;
cout << m << endl << b;
}
else{
m = round(m * 1e3)/1e3;
b = round(b * 1e3)/1e3;
if(m == 0 && b == 0){
cout << "y = 0";
}
else if(m == 0 && b != 0){
cout << "y = ";
if(b > 0){
cout << "+ " << b;
}
else{
cout << "-" << -1*b;
}
}
else if(m == 1 && b != 0){
cout << "y = x ";
if(b > 0){
cout << "+ " << b;
}
else{
cout << "- " << -1*b;
}
}
else if(m == 1 && b == 0){
cout << "y = x ";
}
else if(m == -1 && b != 0){
cout << "y = -x ";
if(b > 0){
cout << "+ " << b;
}
else{
cout << "- " << -1*b;
}
}
else if(m == -1 && b == 0){
cout << "y = -x";
}
else{
cout << "y = " << m <<"x ";
if(b > 0){
cout << "+ " << b;
}
else{
cout << "- " << -1*b;
}
}
}
} |
# 0663, 2024-11-02 13:23:30, PPPPPPPPPPPPPPPP-PPPP-PP (91%)
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
using namespace std;
int sum(int N, int a)
{
int right = 0;
for(int i = 0; i < N; ++i)
{
right += a;
}
return right;
}
int main()
{
int N;
cin >> N;
string a;
cin >> a;
float x, y, m, b;
float out = 0, sum_X = 0, sum_Y = 0, sum_x2;
vector<float> X;
vector<float> Y;
for(int i = 0; i < N; ++i)
{
cin >> x >> y;
X.push_back(x);
Y.push_back(y);
}
for(int i = 0; i < N; ++i)
{
float XY = X[i]*Y[i];
float XX = X[i] * X[i];
out += XY;
sum_X += X[i];
sum_Y += Y[i];
sum_x2 += XX;
}
//cout << N*out << ' ' << sum_X*sum_Y << ' ' << sum_x2*sum_x2<< ' ' << N*sum_x2 << endl;
m = (N*out - (sum_X*sum_Y))/((sum_x2*N) - (sum_X*sum_X));
b = (sum_Y - (m*sum_X))/N;
if(a == "mb")
{
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
cout << m << endl;
cout << b << endl;
}
else if(a == "func")
{
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
cout << "y = ";
if(m == 1)
cout << "x ";
else if(m == -1)
cout << "-x ";
else if(m != 0)
cout << m << "x " ;
if(b > 0)
{
cout << "+ ";
cout << b;
}
else if(b < 0)
{
cout << "- ";
cout << -1 * b;
}
if(m == 0 && b == 0)
cout << "0";
}
//cout << m << ' ' << b;
} | # 0664, 2024-11-02 13:25:49, PPPPPPPPPPPPP--P-PPPPPP- (83%)
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
using namespace std;
int sum(int N, int a)
{
int right = 0;
for(int i = 0; i < N; ++i)
{
right += a;
}
return right;
}
int main()
{
int N;
cin >> N;
string a;
cin >> a;
float x, y, m, b;
float out = 0, sum_X = 0, sum_Y = 0, sum_x2;
vector<float> X;
vector<float> Y;
for(int i = 0; i < N; ++i)
{
cin >> x >> y;
X.push_back(x);
Y.push_back(y);
}
for(int i = 0; i < N; ++i)
{
float XY = X[i]*Y[i];
float XX = X[i] * X[i];
out += XY;
sum_X += X[i];
sum_Y += Y[i];
sum_x2 += XX;
}
//cout << N*out << ' ' << sum_X*sum_Y << ' ' << sum_x2*sum_x2<< ' ' << N*sum_x2 << endl;
m = (N*out - (sum_X*sum_Y))/((sum_x2*N) - (sum_X*sum_X));
b = (sum_Y - (m*sum_X))/N;
if(a == "mb")
{
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
cout << m << endl;
cout << b << endl;
}
else if(a == "func")
{
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
cout << "y = ";
if(m == 1)
cout << "x ";
else if(m == -1)
cout << "-x ";
else if(m != 0)
cout << m << "x " ;
if(b > 0)
{
cout << "+ ";
cout << b;
}
else if(b < 0 && m > 0)
{
cout << "- ";
cout << -1 * b;
}
else if(b < 0 && m == 0)
{
cout << b;
}
if(m == 0 && b == 0)
cout << "0";
}
//cout << m << ' ' << b;
} | # 0665, 2024-11-02 13:27:25, PPPPPPPPPPPPPPPP-PPPPPPP (95%)
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
using namespace std;
int sum(int N, int a)
{
int right = 0;
for(int i = 0; i < N; ++i)
{
right += a;
}
return right;
}
int main()
{
int N;
cin >> N;
string a;
cin >> a;
float x, y, m, b;
float out = 0, sum_X = 0, sum_Y = 0, sum_x2;
vector<float> X;
vector<float> Y;
for(int i = 0; i < N; ++i)
{
cin >> x >> y;
X.push_back(x);
Y.push_back(y);
}
for(int i = 0; i < N; ++i)
{
float XY = X[i]*Y[i];
float XX = X[i] * X[i];
out += XY;
sum_X += X[i];
sum_Y += Y[i];
sum_x2 += XX;
}
//cout << N*out << ' ' << sum_X*sum_Y << ' ' << sum_x2*sum_x2<< ' ' << N*sum_x2 << endl;
m = (N*out - (sum_X*sum_Y))/((sum_x2*N) - (sum_X*sum_X));
b = (sum_Y - (m*sum_X))/N;
if(a == "mb")
{
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
cout << m << endl;
cout << b << endl;
}
else if(a == "func")
{
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
cout << "y = ";
if(m == 1)
cout << "x ";
else if(m == -1)
cout << "-x ";
else if(m != 0)
cout << m << "x " ;
if(b > 0)
{
cout << "+ ";
cout << b;
}
else if(b < 0 && m != 0)
{
cout << "- ";
cout << -1 * b;
}
else if(b < 0 && m == 0)
{
cout << b;
}
if(m == 0 && b == 0)
cout << "0";
}
//cout << m << ' ' << b;
} | # 0666, 2024-11-02 15:03:35, PPPPPPPPPPPPPPPP-PPPPPPP (95%)
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
using namespace std;
int main()
{
int N;
cin >> N;
string a;
cin >> a;
float x, y, m, b;
float out = 0, sum_X = 0, sum_Y = 0, sum_x2;
vector<float> X;
vector<float> Y;
for(int i = 0; i < N; ++i)
{
cin >> x >> y;
X.push_back(x);
Y.push_back(y);
}
for(int i = 0; i < N; ++i)
{
float XY = X[i]*Y[i];
float XX = X[i] * X[i];
out += XY;
sum_X += X[i];
sum_Y += Y[i];
sum_x2 += XX;
}
//cout << N*out << ' ' << sum_X*sum_Y << ' ' << sum_x2*sum_x2<< ' ' << N*sum_x2 << endl;
m = (N*out - (sum_X*sum_Y))/((sum_x2*N) - (sum_X*sum_X));
b = (sum_Y - (m*sum_X))/N;
if(a == "mb")
{
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
cout << m << endl;
cout << b << endl;
}
else if(a == "func")
{
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
cout << "y = ";
if(m == 1)
cout << "x";
else if(m == -1)
cout << "-x";
else if(m != 0)
cout << m << "x" ;
if(b > 0)
{
cout << " + ";
cout << b;
}
else if(b < 0 && m != 0)
{
cout << " - ";
cout << -1 * b;
}
else if(b < 0 && m == 0)
{
cout << b;
}
if(m == 0 && b == 0)
cout << "0";
}
//cout << m << ' ' << b;
} |
# 0667, 2024-11-02 12:04:10, PPPPPPPPPPPPPPP-P---P--P (75%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string q;
vector<float> x;
vector<float> y;
cin >> n >> q;
if (q == "mb")
{
for (int i = 1; i <= n; i++)
{
float a, b;
cin >> a >> b;
x.push_back(a);
y.push_back(b);
}
float m1 = 0, m2 = 0, m3 = 0, m4 = 0;
for (int i = 0; i < n; i++)
{
m1 += x[i] * y[i];
m2 += x[i];
m3 += y[i];
m4 += x[i] * x[i];
}
m1 = m1 * n;
m4 = m4 * n;
// cout << m1 << " " << m2 << " " << m3 << " " << m4 << " " << m2 * m2 << "\n";
float m = ((m1 - (m2 * m3)) / (m4 - (m2 * m2)));
float b = ((m3 - (m * m2)) / n);
m = round(m * 1e3) / 1e3;
b = round(b * 1e3) / 1e3;
cout << m << "\n"
<< b;
}
if (q == "func")
{
for (int i = 1; i <= n; i++)
{
float a, b;
cin >> a >> b;
x.push_back(a);
y.push_back(b);
}
float m1 = 0, m2 = 0, m3 = 0, m4 = 0;
for (int i = 0; i < n; i++)
{
m1 += x[i] * y[i];
m2 += x[i];
m3 += y[i];
m4 += x[i] * x[i];
}
m1 = m1 * n;
m4 = m4 * n;
// cout << m1 << " " << m2 << " " << m3 << " " << m4 << " " << m2 * m2 << "\n";
float m = ((m1 - (m2 * m3)) / (m4 - (m2 * m2)));
float b = ((m3 - (m * m2)) / n);
m = round(m * 1e3) / 1e3;
b = round(b * 1e3) / 1e3;
if (m == 0 && b == 0)
cout << 0;
else
{
cout << "y = ";
if (m != 0)
{
if (m == 1)
cout << "x";
else if (m == -1)
cout << "-x";
else
cout << m << "x";
}
if (m != 0 && m != 1 && b != 0)
{
if(b>0) cout << " + ";
else cout << " - ";
}
if (b != 0&&b>0)
cout << b;
else cout << -b;
}
}
return 0;
} | # 0668, 2024-11-02 12:09:32, PPPPPPPPPPPPPPP-PPPPP-PP (91%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string q;
vector<float> x;
vector<float> y;
cin >> n >> q;
if (q == "mb")
{
for (int i = 1; i <= n; i++)
{
float a, b;
cin >> a >> b;
x.push_back(a);
y.push_back(b);
}
float m1 = 0, m2 = 0, m3 = 0, m4 = 0;
for (int i = 0; i < n; i++)
{
m1 += x[i] * y[i];
m2 += x[i];
m3 += y[i];
m4 += x[i] * x[i];
}
m1 = m1 * n;
m4 = m4 * n;
// cout << m1 << " " << m2 << " " << m3 << " " << m4 << " " << m2 * m2 << "\n";
float m = ((m1 - (m2 * m3)) / (m4 - (m2 * m2)));
float b = ((m3 - (m * m2)) / n);
m = round(m * 1e3) / 1e3;
b = round(b * 1e3) / 1e3;
cout << m << "\n"
<< b;
}
if (q == "func")
{
for (int i = 1; i <= n; i++)
{
float a, b;
cin >> a >> b;
x.push_back(a);
y.push_back(b);
}
float m1 = 0, m2 = 0, m3 = 0, m4 = 0;
for (int i = 0; i < n; i++)
{
m1 += x[i] * y[i];
m2 += x[i];
m3 += y[i];
m4 += x[i] * x[i];
}
m1 = m1 * n;
m4 = m4 * n;
// cout << m1 << " " << m2 << " " << m3 << " " << m4 << " " << m2 * m2 << "\n";
float m = ((m1 - (m2 * m3)) / (m4 - (m2 * m2)));
float b = ((m3 - (m * m2)) / n);
m = round(m * 1e3) / 1e3;
b = round(b * 1e3) / 1e3;
if (m == 0 && b == 0)
cout << 0;
else
{
cout << "y = ";
if (m != 0)
{
if (m == 1)
cout << "x";
else if (m == -1)
cout << "-x";
else
cout << m << "x";
}
if (m != 0 && b != 0)
{
if (b > 0)
cout << " + ";
else
cout << " - ";
}
if (b != 0)
{
if (b > 0)
cout << b;
else
cout << -b;
}
// if(m!=0)
// {
// if(m==1)
// {
// cout << "x";
// }
// else if(m==-1)
// {
// cout << "-x";
// }
// else cout << m <<"x";
// }
// if(b!=0&&m!=0)
// {
// if(b>0) cout << " + ";
// else cout << " - ";
// }
}
}
return 0;
} | # 0669, 2024-11-02 12:10:41, PPPPPPPPPPPPPPPPPPPPP-PP (95%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string q;
vector<float> x;
vector<float> y;
cin >> n >> q;
if (q == "mb")
{
for (int i = 1; i <= n; i++)
{
float a, b;
cin >> a >> b;
x.push_back(a);
y.push_back(b);
}
float m1 = 0, m2 = 0, m3 = 0, m4 = 0;
for (int i = 0; i < n; i++)
{
m1 += x[i] * y[i];
m2 += x[i];
m3 += y[i];
m4 += x[i] * x[i];
}
m1 = m1 * n;
m4 = m4 * n;
// cout << m1 << " " << m2 << " " << m3 << " " << m4 << " " << m2 * m2 << "\n";
float m = ((m1 - (m2 * m3)) / (m4 - (m2 * m2)));
float b = ((m3 - (m * m2)) / n);
m = round(m * 1e3) / 1e3;
b = round(b * 1e3) / 1e3;
cout << m << "\n"
<< b;
}
if (q == "func")
{
for (int i = 1; i <= n; i++)
{
float a, b;
cin >> a >> b;
x.push_back(a);
y.push_back(b);
}
float m1 = 0, m2 = 0, m3 = 0, m4 = 0;
for (int i = 0; i < n; i++)
{
m1 += x[i] * y[i];
m2 += x[i];
m3 += y[i];
m4 += x[i] * x[i];
}
m1 = m1 * n;
m4 = m4 * n;
// cout << m1 << " " << m2 << " " << m3 << " " << m4 << " " << m2 * m2 << "\n";
float m = ((m1 - (m2 * m3)) / (m4 - (m2 * m2)));
float b = ((m3 - (m * m2)) / n);
m = round(m * 1e3) / 1e3;
b = round(b * 1e3) / 1e3;
if (m == 0 && b == 0)
cout << "y = 0";
else
{
cout << "y = ";
if (m != 0)
{
if (m == 1)
cout << "x";
else if (m == -1)
cout << "-x";
else
cout << m << "x";
}
if (m != 0 && b != 0)
{
if (b > 0)
cout << " + ";
else
cout << " - ";
}
if (b != 0)
{
if (b > 0)
cout << b;
else
cout << -b;
}
}
}
return 0;
} |
# 0670, 2024-11-02 13:52:43, PPPPPP-PPPPPPPPPPPPPPPPP (95%)
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
struct XY
{
float x = 0;
float y = 0;
};
float sumXiYi(std::vector<XY> vec)
{
float xiyi = 0;
for (auto i : vec)
{
xiyi += (i.x * i.y);
}
return xiyi;
}
float sumXi(std::vector<XY> vec, bool squared = false)
{
float xi = 0;
for (auto i : vec)
{
if (squared)
xi += std::pow(i.x, 2);
else
xi += i.x;
}
return xi;
}
float sumYi(std::vector<XY> vec)
{
float yi = 0;
for (auto i : vec)
{
yi += i.y;
}
return yi;
}
float calcM(std::vector<XY> vec)
{
float top = ((vec.size() * sumXiYi(vec)) - (sumXi(vec) * sumYi(vec)));
float bottom = ((vec.size() * sumXi(vec, true)) - std::pow(sumXi(vec), 2));
return (top / bottom);
}
float calcB(std::vector<XY> vec)
{
float top = (sumYi(vec) - (calcM(vec) * sumXi(vec)));
float bottom = vec.size();
return top / bottom;
}
float roundThree(float num)
{
return std::round(num * 1e3) / 1e3;
}
int main()
{
int amt;
std::string type;
std::cin >> amt >> type;
std::vector<XY> pairs;
for (int i = 0; i < amt; ++i)
{
XY tmp;
std::cin >> tmp.x >> tmp.y;
pairs.push_back(tmp);
}
if (type == "mb")
{
std::cout << roundThree(calcM(pairs)) << std::endl
<< roundThree(calcB(pairs));
}
else
{
std::cout << "y = ";
float m = roundThree(calcM(pairs));
float b = roundThree(calcB(pairs));
if (m == 0 && b == 0)
{
std::cout << 0;
return 0;
}
if (m != 0)
{
if (m == 1)
std::cout << "x";
else if (m == -1)
std::cout << "-x";
else
std::cout << m << "x";
if (b == 0)
return 0;
std::string bStr = std::to_string(b);
if (bStr[0] == '-')
std::cout << " - ";
else
std::cout << " + ";
std::cout << std::abs(b);
}
else
{
std::cout << b;
}
}
} | # 0671, 2024-11-02 14:45:58, PPPPPP-PPPPPPPPPPPPPPPPP (95%)
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
struct XY
{
float x = 0;
float y = 0;
};
float sumXiYi(std::vector<XY> vec)
{
float xiyi = 0;
for (auto i : vec)
{
xiyi += (i.x * i.y);
}
return xiyi;
}
float sumXi(std::vector<XY> vec, bool squared = false)
{
float xi = 0;
for (auto i : vec)
{
if (squared)
xi += std::pow(i.x, 2);
else
xi += i.x;
}
return xi;
}
float sumYi(std::vector<XY> vec)
{
float yi = 0;
for (auto i : vec)
{
yi += i.y;
}
return yi;
}
float calcM(std::vector<XY> vec)
{
float top = ((vec.size() * sumXiYi(vec)) - (sumXi(vec) * sumYi(vec)));
float bottom = ((vec.size() * sumXi(vec, true)) - std::pow(sumXi(vec), 2));
return (top / bottom);
}
float calcB(std::vector<XY> vec)
{
float top = (sumYi(vec) - (calcM(vec) * sumXi(vec)));
float bottom = vec.size();
return top / bottom;
}
float roundThree(float num)
{
return std::round(num * 1e3) / 1e3;
}
int main()
{
int amt;
std::string type;
std::cin >> amt >> type;
std::vector<XY> pairs;
for (int i = 0; i < amt; ++i)
{
XY tmp;
std::cin >> tmp.x >> tmp.y;
pairs.push_back(tmp);
}
if (type == "mb")
{
std::cout << roundThree(calcM(pairs)) << std::endl
<< roundThree(calcB(pairs));
}
else
{
std::cout << "y = ";
float m = roundThree(calcM(pairs));
float b = roundThree(calcB(pairs));
if (m == 0 && b == 0)
{
std::cout << 0;
return 0;
}
if (m != 0)
{
if (m == 1)
std::cout << "x";
else if (m == -1)
std::cout << "-x";
else
std::cout << m << "x";
if (b == 0)
return 0;
std::string bStr = std::to_string(b);
if (bStr[0] == '-')
std::cout << " - ";
else
std::cout << " + ";
std::cout << std::abs(b);
}
else
{
std::cout << b;
}
}
} | # 0672, 2024-11-02 14:52:52, PPPPPP-PPPPPPPPPPPPPPPPP (95%)
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
struct XY
{
float x = 0;
float y = 0;
};
float sumXiYi(std::vector<XY> vec)
{
float xiyi = 0;
for (auto i : vec)
{
xiyi += (i.x * i.y);
}
return xiyi;
}
float sumXi(std::vector<XY> vec, bool squared = false)
{
float xi = 0;
for (auto i : vec)
{
if (squared)
xi += std::pow(i.x, 2);
else
xi += i.x;
}
return xi;
}
float sumYi(std::vector<XY> vec)
{
float yi = 0;
for (auto i : vec)
{
yi += i.y;
}
return yi;
}
float calcM(std::vector<XY> vec)
{
float top = ((vec.size() * sumXiYi(vec)) - (sumXi(vec) * sumYi(vec)));
float bottom = ((vec.size() * sumXi(vec, true)) - std::pow(sumXi(vec), 2));
return (top / bottom);
}
float calcB(std::vector<XY> vec)
{
float top = (sumYi(vec) - (calcM(vec) * sumXi(vec)));
float bottom = vec.size();
return (top / bottom);
}
float roundThree(float num)
{
return (std::round(num * 1e3) / 1e3);
}
int main()
{
int amt;
std::string type;
std::cin >> amt >> type;
std::vector<XY> pairs;
for (int i = 0; i < amt; ++i)
{
XY tmp;
std::cin >> tmp.x >> tmp.y;
pairs.push_back(tmp);
}
if (type == "mb")
{
std::cout << roundThree(calcM(pairs)) << std::endl
<< roundThree(calcB(pairs));
}
else
{
std::cout << "y = ";
float m = roundThree(calcM(pairs));
float b = roundThree(calcB(pairs));
if (m == 0 && b == 0)
{
std::cout << 0;
return 0;
}
if (m != 0)
{
if (m == 1)
std::cout << "x";
else if (m == -1)
std::cout << "-x";
else
std::cout << m << "x";
if (b == 0)
return 0;
std::string bStr = std::to_string(b);
if (bStr[0] == '-')
std::cout << " - ";
else
std::cout << " + ";
std::cout << std::abs(b);
}
else
{
std::cout << b;
}
}
} |
# 0673, 2024-11-02 13:39:43, ----------PPPPPPPPPPPPPP (58%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int N;
cin>>N;
int r = N;
string cmd;
cin>>cmd;
float m,b;
vector<float> X;
vector<float> Y;
vector<float> XY;
float x,y;
float xi, yi, xiyi, xi2;
while(r--){
cin>>x;
X.push_back(x);
cin>>y;
Y.push_back(y);
XY.push_back(x*y);
}
for(auto e: X){
xi += e;
xi2 += e*e;
}
for(auto e: Y){
yi += e;
}
for(auto e: XY){
xiyi += e;
}
m = ((N*xiyi) - (xi*yi)) / ((N*xi2) - (xi*xi));
b = (yi - (m*xi)) / N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(cmd=="cmd") cout<<m<<endl<<b;
else {
if(m==0 && b!= 0){
cout<<"y = "<<b;
} else if(b==0 && m!=0){
if(m==1){
cout<<"y = x";
} else if(m==-1){
cout<<"y = -x";
} else {
cout<<"y = "<<m<<"x";
}
} else if(m==0 && b==0){
cout<<"y = 0";
} else {
if(b<0){
if(m==1){
cout<<"y = x - "<<abs(b);
} else if(m==-1){
cout<<"y = -x - "<<abs(b);
} else {
cout<<"y = "<<m<<"x - "<<abs(b);
}
} else if(b>0){
if(m==1){
cout<<"y = x + "<<abs(b);
} else if(m==-1){
cout<<"y = -x + "<<abs(b);
} else {
cout<<"y = "<<m<<"x + "<<abs(b);
}
}
}
}
} | # 0674, 2024-11-02 13:40:53, PPPPP-PPPPPPPPPPPPPPPPPP (95%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int N;
cin>>N;
int r = N;
string cmd;
cin>>cmd;
float m,b;
vector<float> X;
vector<float> Y;
vector<float> XY;
float x,y;
float xi, yi, xiyi, xi2;
while(r--){
cin>>x;
X.push_back(x);
cin>>y;
Y.push_back(y);
XY.push_back(x*y);
}
for(auto e: X){
xi += e;
xi2 += e*e;
}
for(auto e: Y){
yi += e;
}
for(auto e: XY){
xiyi += e;
}
m = ((N*xiyi) - (xi*yi)) / ((N*xi2) - (xi*xi));
b = (yi - (m*xi)) / N;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(cmd=="mb") cout<<m<<endl<<b;
else {
if(m==0 && b!= 0){
cout<<"y = "<<b;
} else if(b==0 && m!=0){
if(m==1){
cout<<"y = x";
} else if(m==-1){
cout<<"y = -x";
} else {
cout<<"y = "<<m<<"x";
}
} else if(m==0 && b==0){
cout<<"y = 0";
} else {
if(b<0){
if(m==1){
cout<<"y = x - "<<abs(b);
} else if(m==-1){
cout<<"y = -x - "<<abs(b);
} else {
cout<<"y = "<<m<<"x - "<<abs(b);
}
} else if(b>0){
if(m==1){
cout<<"y = x + "<<abs(b);
} else if(m==-1){
cout<<"y = -x + "<<abs(b);
} else {
cout<<"y = "<<m<<"x + "<<abs(b);
}
}
}
}
} |
# 0675, 2024-11-02 13:16:21, PPPPPPPPPPPPPPP-PPPPPPPP (95%)
#include<iostream>
#include<cmath>
#include<string>
using namespace std;
int main()
{
int n;
string f;
cin>>n>>f;
float x,y,m,b;
float total_x=0,total_y=0,total_pow_x=0,total_xy=0;
for(int i=0;i<n;++i)
{
cin>>x>>y;
total_x+=x;
total_y+=y;
total_xy+=(x*y);
total_pow_x+=(x*x);
}
m=((n*total_xy)-(total_x*total_y))/((n*total_pow_x)-(total_x*total_x));
b=(total_y-(m*total_x))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(f=="mb")
{
cout<<m<<endl;
cout<<b;
}
else
{
cout<<"y = ";
if(m==0&&b==0) cout<<"0";
if(m==1) cout<<"x";
else if(m==-1) cout<<"-x";
else if(m!=0) cout<<m<<"x";
if(m==0) cout<<b;
else if(b>0) cout<<" + "<<b;
else if(b<0) cout<<" - "<<b*-1;
}
return 0;
} | # 0676, 2024-11-02 13:48:07, PPPPPPPPPPPPPPP-PPPPPPPP (95%)
#include<iostream>
#include<cmath>
#include<string>
using namespace std;
int main()
{
int n;
string f;
cin>>n>>f;
float x,y,m,b;
float total_x=0,total_y=0,total_pow_x=0,total_xy=0;
for(int i=0;i<n;++i)
{
cin>>x>>y;
total_x+=x;
total_y+=y;
total_xy+=(x*y);
total_pow_x+=(x*x);
}
m=((n*total_xy)-(total_x*total_y))/((n*total_pow_x)-(total_x*total_x));
b=(total_y-(m*total_x))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(f=="mb")
{
cout<<m<<endl;
cout<<b;
}
else
{
cout<<"y = ";
if(m==0&&b==0) cout<<"0";
if(m==1) cout<<"x";
else if(m==-1) cout<<"-x";
else if(m!=0) cout<<m<<"x";
if(m==0) cout<<b;
else if(b>0) cout<<" + "<<b;
else if(b<0) cout<<" - "<<b*-1;
}
return 0;
} |
# 0677, 2024-11-02 09:53:02, ------------------------ (0%)
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>
using namespace std;
float callM (vector<pair<float,float>> &list, float N)
{
vector<float> sums;
float sum1;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].first * list[i-1].second;
}
sums.push_back(N*sum1);
float sum2,sum3;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
for (int i = 1; i <= N; i++)
{
sum3 += list[i-1].second;
}
sums.push_back(sum2*sum3);
float sum4;
for (int i = 1; i <= N; i++)
{
sum4 += list[i-1].first * list[i-1].first;
}
sums.push_back(N*sum4);
float sum5;
for (int i = 1; i <= N; i++)
{
sum5 += list[i-1].first;
}
sums.push_back(sum5*sum5);
float m;
m = (sums[0]-sums[1]) / (sums[2] - sums[3]);
return m;
}
float callB (vector<pair<float,float>> &list, float N)
{
vector<float> sums;
float sum1;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].second;
}
sums.push_back(sum1);
float sum2;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
sums.push_back(callM(list,N) * sum2);
float b;
b = (sum1 - sum2) / N;
return b;
}
int main()
{
float N;
cin >> N;
string cal;
cin >> cal;
float x,y;
vector<pair<float,float>> list;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
list.push_back(make_pair(x,y));
}
float m,b;
m = callM(list,N);
b = callB(list,N);
if (cal == "mb")
{
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
return 0;
}
if (cal == "func")
{
if (m == 0 && b == 0)
{
cout << "y = 0";
return 0;
}
if (m == 1)
{
cout << "y = " << round(b*1e3)/1e3;
return 0;
}
if (m == -1 && b >= 0)
{
cout << "y = -x + " << round(b*1e3)/1e3;
return 0;
}
if (m == -1 && b < 0)
{
cout << "y = -x - " << round(b*1e3)/1e3;
return 0;
}
if (b >= 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
return 0;
}
if (b < 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3;
return 0;
}
}
} | # 0678, 2024-11-02 09:55:43, ---P--------P----------- (8%)
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>
using namespace std;
float callM (vector<pair<float,float>> list, float N)
{
vector<float> sums;
float sum1;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].first * list[i-1].second;
}
sums.push_back(N*sum1);
float sum2,sum3;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
for (int i = 1; i <= N; i++)
{
sum3 += list[i-1].second;
}
sums.push_back(sum2*sum3);
float sum4;
for (int i = 1; i <= N; i++)
{
sum4 += list[i-1].first * list[i-1].first;
}
sums.push_back(N*sum4);
float sum5;
for (int i = 1; i <= N; i++)
{
sum5 += list[i-1].first;
}
sums.push_back(sum5*sum5);
float m;
m = (sums[0]-sums[1]) / (sums[2] - sums[3]);
return m;
}
float callB (vector<pair<float,float>> list, float N)
{
vector<float> sums;
float sum1;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].second;
}
sums.push_back(sum1);
float sum2;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
sums.push_back(callM(list,N) * sum2);
float b;
b = (sums[0] - sums[1]) / N;
return b;
}
int main()
{
float N;
cin >> N;
string cal;
cin >> cal;
float x,y;
vector<pair<float,float>> list;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
list.push_back(make_pair(x,y));
}
float m,b;
m = callM(list,N);
b = callB(list,N);
if (cal == "mb")
{
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
return 0;
}
if (cal == "func")
{
if (m == 0 && b == 0)
{
cout << "y = 0";
return 0;
}
if (m == 1)
{
cout << "y = " << round(b*1e3)/1e3;
return 0;
}
if (m == -1 && b >= 0)
{
cout << "y = -x + " << round(b*1e3)/1e3;
return 0;
}
if (m == -1 && b < 0)
{
cout << "y = -x - " << round(b*1e3)/1e3;
return 0;
}
if (b >= 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
return 0;
}
if (b < 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3;
return 0;
}
}
} | # 0679, 2024-11-02 10:04:31, ------------------------ (0%)
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>
using namespace std;
float callM (vector<pair<float,float>> &list, float N)
{
vector<float> sums;
float sum1;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].first * list[i-1].second;
}
sums.push_back(N*sum1);
float sum2,sum3;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
for (int i = 1; i <= N; i++)
{
sum3 += list[i-1].second;
}
sums.push_back(sum2*sum3);
float sum4;
for (int i = 1; i <= N; i++)
{
sum4 += list[i-1].first * list[i-1].first;
}
sums.push_back(N*sum4);
float sum5;
for (int i = 1; i <= N; i++)
{
sum5 += list[i-1].first;
}
sums.push_back(sum5*sum5);
float m;
m = (sums[0]-sums[1]) / (sums[2] - sums[3]);
return m;
}
float callB (vector<pair<float,float>> &list, float N)
{
vector<float> sums;
float sum1;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].second;
}
sums.push_back(sum1);
float sum2;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
sums.push_back(callM(list,N) * sum2);
float b;
b = (sums[0] - sums[1]) / N;
return b;
}
int main()
{
float N;
cin >> N;
string cal;
cin >> cal;
float x,y;
vector<pair<float,float>> list;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
list.push_back(make_pair(x,y));
}
float m,b;
m = callM(list,N);
b = callB(list,N);
if (cal == "mb")
{
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
return 0;
}
if (cal == "func")
{
if (m == 0 && b == 0)
{
cout << "y = 0";
return 0;
}
if (m == 1)
{
cout << "y = " << round(b*1e3)/1e3;
return 0;
}
if (m == -1 && b >= 0)
{
cout << "y = -x + " << round(b*1e3)/1e3;
return 0;
}
if (m == -1 && b < 0)
{
cout << "y = -x - " << round(b*1e3)/1e3;
return 0;
}
if (b >= 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
return 0;
}
if (b < 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3;
return 0;
}
}
} | # 0680, 2024-11-02 10:06:10, ------------------------ (0%)
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>
using namespace std;
float callM (const vector<pair<float,float>> &list, float N)
{
vector<float> sums;
float sum1;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].first * list[i-1].second;
}
sums.push_back(N*sum1);
float sum2,sum3;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
for (int i = 1; i <= N; i++)
{
sum3 += list[i-1].second;
}
sums.push_back(sum2*sum3);
float sum4;
for (int i = 1; i <= N; i++)
{
sum4 += list[i-1].first * list[i-1].first;
}
sums.push_back(N*sum4);
float sum5;
for (int i = 1; i <= N; i++)
{
sum5 += list[i-1].first;
}
sums.push_back(sum5*sum5);
float m;
m = (sums[0]-sums[1]) / (sums[2] - sums[3]);
return m;
}
float callB (const vector<pair<float,float>> &list, float N)
{
vector<float> sums;
float sum1;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].second;
}
sums.push_back(sum1);
float sum2;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
sums.push_back(callM(list,N) * sum2);
float b;
b = (sums[0] - sums[1]) / N;
return b;
}
int main()
{
float N;
cin >> N;
string cal;
cin >> cal;
float x,y;
vector<pair<float,float>> list;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
list.push_back(make_pair(x,y));
}
float m,b;
m = callM(list,N);
b = callB(list,N);
if (cal == "mb")
{
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
return 0;
}
if (cal == "func")
{
if (m == 0 && b == 0)
{
cout << "y = 0";
return 0;
}
if (m == 1)
{
cout << "y = " << round(b*1e3)/1e3;
return 0;
}
if (m == -1 && b >= 0)
{
cout << "y = -x + " << round(b*1e3)/1e3;
return 0;
}
if (m == -1 && b < 0)
{
cout << "y = -x - " << round(b*1e3)/1e3;
return 0;
}
if (b >= 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
return 0;
}
if (b < 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3;
return 0;
}
}
} | # 0681, 2024-11-02 10:11:22, ------------------------ (0%)
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>
using namespace std;
float callM (const vector<pair<float,float>> &list, float N)
{
vector<float> sums;
float sum1;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].first * list[i-1].second;
}
sums.push_back(N*sum1);
float sum2,sum3;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
for (int i = 1; i <= N; i++)
{
sum3 += list[i-1].second;
}
sums.push_back(sum2*sum3);
float sum4;
for (int i = 1; i <= N; i++)
{
sum4 += list[i-1].first * list[i-1].first;
}
sums.push_back(N*sum4);
float sum5;
for (int i = 1; i <= N; i++)
{
sum5 += list[i-1].first;
}
sums.push_back(sum5*sum5);
float m;
m = (sums[0]-sums[1]) / (sums[2] - sums[3]);
return m;
}
float callB (const vector<pair<float,float>> &list, float N)
{
vector<float> sums;
float sum1;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].second;
}
sums.push_back(sum1);
float sum2;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
sums.push_back(callM(list,N) * sum2);
float b;
b = (sums[0] - sums[1]) / N;
return b;
}
int main()
{
float N;
cin >> N;
string cal;
cin >> cal;
double x,y;
vector<pair<float,float>> list;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
list.push_back(make_pair(x,y));
}
float m,b;
m = callM(list,N);
b = callB(list,N);
if (cal == "mb")
{
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
return 0;
}
if (cal == "func")
{
if (m == 0 && b == 0)
{
cout << "y = 0";
return 0;
}
if (m == 1)
{
cout << "y = " << round(b*1e3)/1e3;
return 0;
}
if (m == -1 && b >= 0)
{
cout << "y = -x + " << round(b*1e3)/1e3;
return 0;
}
if (m == -1 && b < 0)
{
cout << "y = -x - " << round(b*1e3)/1e3;
return 0;
}
if (b >= 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
return 0;
}
if (b < 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3;
return 0;
}
}
} | # 0682, 2024-11-02 10:13:05, ------------------------ (0%)
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>
using namespace std;
float callM (const vector<pair<double,double>> &list, float N)
{
vector<float> sums;
float sum1;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].first * list[i-1].second;
}
sums.push_back(N*sum1);
float sum2,sum3;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
for (int i = 1; i <= N; i++)
{
sum3 += list[i-1].second;
}
sums.push_back(sum2*sum3);
float sum4;
for (int i = 1; i <= N; i++)
{
sum4 += list[i-1].first * list[i-1].first;
}
sums.push_back(N*sum4);
float sum5;
for (int i = 1; i <= N; i++)
{
sum5 += list[i-1].first;
}
sums.push_back(sum5*sum5);
float m;
m = (sums[0]-sums[1]) / (sums[2] - sums[3]);
return m;
}
float callB (const vector<pair<double,double>> &list, float N)
{
vector<float> sums;
float sum1;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].second;
}
sums.push_back(sum1);
float sum2;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
sums.push_back(callM(list,N) * sum2);
float b;
b = (sums[0] - sums[1]) / N;
return b;
}
int main()
{
float N;
cin >> N;
string cal;
cin >> cal;
double x,y;
vector<pair<double,double>> list;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
list.push_back(make_pair(x,y));
}
float m,b;
m = callM(list,N);
b = callB(list,N);
if (cal == "mb")
{
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
return 0;
}
if (cal == "func")
{
if (m == 0 && b == 0)
{
cout << "y = 0";
return 0;
}
if (m == 1)
{
cout << "y = " << round(b*1e3)/1e3;
return 0;
}
if (m == -1 && b >= 0)
{
cout << "y = -x + " << round(b*1e3)/1e3;
return 0;
}
if (m == -1 && b < 0)
{
cout << "y = -x - " << round(b*1e3)/1e3;
return 0;
}
if (b >= 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
return 0;
}
if (b < 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3;
return 0;
}
}
} | # 0683, 2024-11-02 10:50:34, ------------------------ (0%)
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>
using namespace std;
float callM (const vector<pair<double,double>> &list, int N)
{
vector<float> sums;
float sum1;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].first * list[i-1].second;
}
sums.push_back(sum1*N);
float sum2,sum3;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
for (int i = 1; i <= N; i++)
{
sum3 += list[i-1].second;
}
sums.push_back(sum2*sum3);
float sum4;
for (int i = 1; i <= N; i++)
{
sum4 += list[i-1].first * list[i-1].first;
}
sums.push_back(sum4*N);
float sum5;
for (int i = 1; i <= N; i++)
{
sum5 += list[i-1].first;
}
sums.push_back(sum5*sum5);
float m;
m = (sums[0]-sums[1]) / (sums[2] - sums[3]);
return m;
}
float callB (const vector<pair<double,double>> &list, int N)
{
vector<float> sums;
float sum1;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].second;
}
sums.push_back(sum1);
float sum2;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
sums.push_back(callM(list,N) * sum2);
float b;
b = (sums[0] - sums[1]) / N;
return b;
}
int main()
{
int N;
cin >> N;
string cal;
cin >> cal;
double x,y;
vector<pair<double,double>> list;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
list.push_back(make_pair(x,y));
}
float m,b;
m = callM(list,N);
b = callB(list,N);
if (cal == "mb")
{
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
return 0;
}
if (cal == "func")
{
if (m == 0 && b == 0)
{
cout << "y = 0";
return 0;
}
if (m == 1)
{
cout << "y = " << round(b*1e3)/1e3;
return 0;
}
if (m == -1 && b >= 0)
{
cout << "y = -x + " << round(b*1e3)/1e3;
return 0;
}
if (m == -1 && b < 0)
{
cout << "y = -x - " << round(b*1e3)/1e3;
return 0;
}
if (b >= 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
return 0;
}
if (b < 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3;
return 0;
}
}
} | # 0684, 2024-11-02 11:55:18, PPPPPPPPPPP-P--P-------- (54%)
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>
using namespace std;
double callM (const vector<pair<double,double>> list, int N)
{
vector<float> sums;
float sum1 = 0;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].first * list[i-1].second;
}
sums.push_back(sum1*N);
float sum2 = 0,sum3 = 0;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
for (int i = 1; i <= N; i++)
{
sum3 += list[i-1].second;
}
sums.push_back(sum2*sum3);
float sum4 = 0;
for (int i = 1; i <= N; i++)
{
sum4 += list[i-1].first * list[i-1].first;
}
sums.push_back(sum4*N);
float sum5 = 0;
for (int i = 1; i <= N; i++)
{
sum5 += list[i-1].first;
}
sums.push_back(sum5*sum5);
float m;
m = (sums[0]-sums[1]) / (sums[2] - sums[3]);
return m;
}
double callB (const vector<pair<double,double>> list, int N)
{
vector<float> sums;
float sum1 = 0;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].second;
}
sums.push_back(sum1);
float sum2 = 0;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
sums.push_back(callM(list,N) * sum2);
float b;
b = (sums[0] - sums[1]) / N;
return b;
}
int main()
{
int N;
cin >> N;
string cal;
cin >> cal;
double x,y;
vector<pair<double,double>> num;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
num.push_back(make_pair(x,y));
}
double m,b;
m = callM(num,N);
b = callB(num,N);
if (cal == "mb")
{
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
return 0;
}
if (cal == "func")
{
if (m == 0 && b == 0)
{
cout << "y = 0";
return 0;
}
if (m == 1)
{
cout << "y = " << round(b*1e3)/1e3;
return 0;
}
if (m == -1 && b >= 0)
{
cout << "y = -x + " << round(b*1e3)/1e3;
return 0;
}
if (m == -1 && b < 0)
{
cout << "y = -x - " << round(b*1e3)/1e3;
return 0;
}
if (b >= 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
return 0;
}
if (b < 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3;
return 0;
}
}
} | # 0685, 2024-11-02 11:56:05, PPPPPPPPPPP-P--P-------- (54%)
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>
using namespace std;
float callM (const vector<pair<float,float>> list, int N)
{
vector<float> sums;
float sum1 = 0;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].first * list[i-1].second;
}
sums.push_back(sum1*N);
float sum2 = 0,sum3 = 0;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
for (int i = 1; i <= N; i++)
{
sum3 += list[i-1].second;
}
sums.push_back(sum2*sum3);
float sum4 = 0;
for (int i = 1; i <= N; i++)
{
sum4 += list[i-1].first * list[i-1].first;
}
sums.push_back(sum4*N);
float sum5 = 0;
for (int i = 1; i <= N; i++)
{
sum5 += list[i-1].first;
}
sums.push_back(sum5*sum5);
float m;
m = (sums[0]-sums[1]) / (sums[2] - sums[3]);
return m;
}
float callB (const vector<pair<float,float>> list, int N)
{
vector<float> sums;
float sum1 = 0;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].second;
}
sums.push_back(sum1);
float sum2 = 0;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
sums.push_back(callM(list,N) * sum2);
float b;
b = (sums[0] - sums[1]) / N;
return b;
}
int main()
{
int N;
cin >> N;
string cal;
cin >> cal;
float x,y;
vector<pair<float,float>> num;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
num.push_back(make_pair(x,y));
}
float m,b;
m = callM(num,N);
b = callB(num,N);
if (cal == "mb")
{
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
return 0;
}
if (cal == "func")
{
if (m == 0 && b == 0)
{
cout << "y = 0";
return 0;
}
if (m == 1)
{
cout << "y = " << round(b*1e3)/1e3;
return 0;
}
if (m == -1 && b >= 0)
{
cout << "y = -x + " << round(b*1e3)/1e3;
return 0;
}
if (m == -1 && b < 0)
{
cout << "y = -x - " << round(b*1e3)/1e3;
return 0;
}
if (b >= 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
return 0;
}
if (b < 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3;
return 0;
}
}
} | # 0686, 2024-11-02 11:59:42, PPPPPPPPPPP-P--P-------- (54%)
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>
using namespace std;
float callM (const vector<pair<float,float>> list, int N)
{
vector<float> sums;
float sum1 = 0;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].first * list[i-1].second;
}
sums.push_back(sum1*N);
float sum2 = 0,sum3 = 0;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
for (int i = 1; i <= N; i++)
{
sum3 += list[i-1].second;
}
sums.push_back(sum2*sum3);
float sum4 = 0;
for (int i = 1; i <= N; i++)
{
sum4 += list[i-1].first * list[i-1].first;
}
sums.push_back(sum4*N);
float sum5 = 0;
for (int i = 1; i <= N; i++)
{
sum5 += list[i-1].first;
}
sums.push_back(sum5*sum5);
float m;
m = (sums[0]-sums[1]) / (sums[2] - sums[3]);
return m;
}
float callB (const vector<pair<float,float>> list, int N)
{
vector<float> sums;
float sum1 = 0;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].second;
}
sums.push_back(sum1);
float sum2 = 0;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
sums.push_back(callM(list,N) * sum2);
float b;
b = (sums[0] - sums[1]) / N;
return b;
}
int main()
{
int N;
cin >> N;
string cal;
cin >> cal;
float x,y;
vector<pair<float,float>> num;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
num.push_back(make_pair(x,y));
}
float m,b;
m = callM(num,N);
b = callB(num,N);
if (cal == "mb")
{
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
return 0;
}
if (cal == "func")
{
if (m == 0 && b == 0)
{
cout << "y = 0";
return 0;
}
if (m == 1 && b >= 0)
{
cout << "y = x + " << round(b*1e3)/1e3;
return 0;
}
if (m == 1 && b < 0)
{
cout << "y = x - " << round(b*1e3)/1e3;
return 0;
}
if (m == -1 && b >= 0)
{
cout << "y = -x + " << round(b*1e3)/1e3;
return 0;
}
if (m == -1 && b < 0)
{
cout << "y = -x - " << round(b*1e3)/1e3;
return 0;
}
if (b >= 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
return 0;
}
if (b < 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3;
return 0;
}
}
} | # 0687, 2024-11-02 12:04:13, PPPPPPPPPPPPPPPP-----P-- (70%)
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>
using namespace std;
float callM (const vector<pair<float,float>> list, int N)
{
vector<float> sums;
float sum1 = 0;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].first * list[i-1].second;
}
sums.push_back(sum1*N);
float sum2 = 0,sum3 = 0;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
for (int i = 1; i <= N; i++)
{
sum3 += list[i-1].second;
}
sums.push_back(sum2*sum3);
float sum4 = 0;
for (int i = 1; i <= N; i++)
{
sum4 += list[i-1].first * list[i-1].first;
}
sums.push_back(sum4*N);
float sum5 = 0;
for (int i = 1; i <= N; i++)
{
sum5 += list[i-1].first;
}
sums.push_back(sum5*sum5);
float m;
m = (sums[0]-sums[1]) / (sums[2] - sums[3]);
return m;
}
float callB (const vector<pair<float,float>> list, int N)
{
vector<float> sums;
float sum1 = 0;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].second;
}
sums.push_back(sum1);
float sum2 = 0;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
sums.push_back(callM(list,N) * sum2);
float b;
b = (sums[0] - sums[1]) / N;
return b;
}
int main()
{
int N;
cin >> N;
string cal;
cin >> cal;
float x,y;
vector<pair<float,float>> num;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
num.push_back(make_pair(x,y));
}
float m,b;
m = callM(num,N);
b = callB(num,N);
if (cal == "mb")
{
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
return 0;
}
if (cal == "func")
{
if (m == 0 && b == 0)
{
cout << "y = 0";
return 0;
}
if (m == 0 && b != 0)
{
cout << "y = " << round(b*1e3)/1e3;
return 0;
}
if (m == 1 && b >= 0)
{
cout << "y = x + " << round(b*1e3)/1e3;
return 0;
}
if (m == 1 && b < 0)
{
cout << "y = x - " << round(-b*1e3)/1e3;
return 0;
}
if (m == -1 && b >= 0)
{
cout << "y = -x + " << round(b*1e3)/1e3;
return 0;
}
if (m == -1 && b < 0)
{
cout << "y = -x - " << round(-b*1e3)/1e3;
return 0;
}
if (b >= 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
return 0;
}
if (b < 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(-b*1e3)/1e3;
return 0;
}
}
} | # 0688, 2024-11-02 12:06:13, PPPPPPPPPPPPPPPPP----P-- (75%)
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>
using namespace std;
float callM (const vector<pair<float,float>> list, int N)
{
vector<float> sums;
float sum1 = 0;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].first * list[i-1].second;
}
sums.push_back(sum1*N);
float sum2 = 0,sum3 = 0;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
for (int i = 1; i <= N; i++)
{
sum3 += list[i-1].second;
}
sums.push_back(sum2*sum3);
float sum4 = 0;
for (int i = 1; i <= N; i++)
{
sum4 += list[i-1].first * list[i-1].first;
}
sums.push_back(sum4*N);
float sum5 = 0;
for (int i = 1; i <= N; i++)
{
sum5 += list[i-1].first;
}
sums.push_back(sum5*sum5);
float m;
m = (sums[0]-sums[1]) / (sums[2] - sums[3]);
return m;
}
float callB (const vector<pair<float,float>> list, int N)
{
vector<float> sums;
float sum1 = 0;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].second;
}
sums.push_back(sum1);
float sum2 = 0;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
sums.push_back(callM(list,N) * sum2);
float b;
b = (sums[0] - sums[1]) / N;
return b;
}
int main()
{
int N;
cin >> N;
string cal;
cin >> cal;
float x,y;
vector<pair<float,float>> num;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
num.push_back(make_pair(x,y));
}
float m,b;
m = callM(num,N);
b = callB(num,N);
if (cal == "mb")
{
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
return 0;
}
if (cal == "func")
{
if (m == 0 && b == 0)
{
cout << "y = 0";
return 0;
}
if (round(m*1e3)/1e3 == 0 && b != 0)
{
cout << "y = " << round(b*1e3)/1e3;
return 0;
}
if (m == 1 && b >= 0)
{
cout << "y = x + " << round(b*1e3)/1e3;
return 0;
}
if (m == 1 && b < 0)
{
cout << "y = x - " << round(-b*1e3)/1e3;
return 0;
}
if (m == -1 && b >= 0)
{
cout << "y = -x + " << round(b*1e3)/1e3;
return 0;
}
if (m == -1 && b < 0)
{
cout << "y = -x - " << round(-b*1e3)/1e3;
return 0;
}
if (b >= 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
return 0;
}
if (b < 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(-b*1e3)/1e3;
return 0;
}
}
} | # 0689, 2024-11-02 12:08:21, PPPPPPPPPPPPPPPPPP--PPPP (91%)
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>
using namespace std;
float callM (const vector<pair<float,float>> list, int N)
{
vector<float> sums;
float sum1 = 0;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].first * list[i-1].second;
}
sums.push_back(sum1*N);
float sum2 = 0,sum3 = 0;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
for (int i = 1; i <= N; i++)
{
sum3 += list[i-1].second;
}
sums.push_back(sum2*sum3);
float sum4 = 0;
for (int i = 1; i <= N; i++)
{
sum4 += list[i-1].first * list[i-1].first;
}
sums.push_back(sum4*N);
float sum5 = 0;
for (int i = 1; i <= N; i++)
{
sum5 += list[i-1].first;
}
sums.push_back(sum5*sum5);
float m;
m = (sums[0]-sums[1]) / (sums[2] - sums[3]);
return m;
}
float callB (const vector<pair<float,float>> list, int N)
{
vector<float> sums;
float sum1 = 0;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].second;
}
sums.push_back(sum1);
float sum2 = 0;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
sums.push_back(callM(list,N) * sum2);
float b;
b = (sums[0] - sums[1]) / N;
return b;
}
int main()
{
int N;
cin >> N;
string cal;
cin >> cal;
float x,y;
vector<pair<float,float>> num;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
num.push_back(make_pair(x,y));
}
float m,b;
m = callM(num,N);
b = callB(num,N);
if (cal == "mb")
{
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
return 0;
}
if (cal == "func")
{
if (m == 0 && b == 0)
{
cout << "y = 0";
return 0;
}
if (round(m*1e3)/1e3 == 0 && b != 0)
{
cout << "y = " << round(b*1e3)/1e3;
return 0;
}
if (round(m*1e3)/1e3 == 1 && b >= 0)
{
cout << "y = x + " << round(b*1e3)/1e3;
return 0;
}
if (round(m*1e3)/1e3 == 1 && b < 0)
{
cout << "y = x - " << round(-b*1e3)/1e3;
return 0;
}
if (round(m*1e3)/1e3 == -1 && b >= 0)
{
cout << "y = -x + " << round(b*1e3)/1e3;
return 0;
}
if (round(m*1e3)/1e3 == -1 && b < 0)
{
cout << "y = -x - " << round(-b*1e3)/1e3;
return 0;
}
if (b >= 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
return 0;
}
if (b < 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(-b*1e3)/1e3;
return 0;
}
}
} | # 0690, 2024-11-02 12:08:57, PPPPPPPPPP-----PPP--PPPP (70%)
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>
using namespace std;
float callM (const vector<pair<float,float>> list, int N)
{
vector<float> sums;
float sum1 = 0;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].first * list[i-1].second;
}
sums.push_back(sum1*N);
float sum2 = 0,sum3 = 0;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
for (int i = 1; i <= N; i++)
{
sum3 += list[i-1].second;
}
sums.push_back(sum2*sum3);
float sum4 = 0;
for (int i = 1; i <= N; i++)
{
sum4 += list[i-1].first * list[i-1].first;
}
sums.push_back(sum4*N);
float sum5 = 0;
for (int i = 1; i <= N; i++)
{
sum5 += list[i-1].first;
}
sums.push_back(sum5*sum5);
float m;
m = (sums[0]-sums[1]) / (sums[2] - sums[3]);
return m;
}
float callB (const vector<pair<float,float>> list, int N)
{
vector<float> sums;
float sum1 = 0;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].second;
}
sums.push_back(sum1);
float sum2 = 0;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
sums.push_back(callM(list,N) * sum2);
float b;
b = (sums[0] - sums[1]) / N;
return b;
}
int main()
{
int N;
cin >> N;
string cal;
cin >> cal;
float x,y;
vector<pair<float,float>> num;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
num.push_back(make_pair(x,y));
}
float m,b;
m = callM(num,N);
b = callB(num,N);
if (cal == "mb")
{
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
return 0;
}
if (cal == "func")
{
if (m == 0 && b == 0)
{
cout << "y = 0";
return 0;
}
if (round(m*1e3)/1e3 == 0 && b != 0)
{
cout << "y = " << round(b*1e3)/1e3;
return 0;
}
if (round(m*1e3)/1e3 == 1 && b >= 0)
{
cout << "y = x + " << round(b*1e3)/1e3;
return 0;
}
if (round(m*1e3)/1e3 == 1 && b < 0)
{
cout << "y = x - " << round(-b*1e3)/1e3;
return 0;
}
if (round(m*1e3)/1e3 == -1 && b >= 0)
{
cout << "y = -x + " << round(b*1e3)/1e3;
return 0;
}
if (round(m*1e3)/1e3 == -1 && b < 0)
{
cout << "y = -x - " << round(-b*1e3)/1e3;
return 0;
}
if (round(-b*1e3)/1e3 >= 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
return 0;
}
if (round(-b*1e3)/1e3 < 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(-b*1e3)/1e3;
return 0;
}
}
} | # 0691, 2024-11-02 12:09:11, PPPPPPPPPPPPPPPPPP--PPPP (91%)
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>
using namespace std;
float callM (const vector<pair<float,float>> list, int N)
{
vector<float> sums;
float sum1 = 0;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].first * list[i-1].second;
}
sums.push_back(sum1*N);
float sum2 = 0,sum3 = 0;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
for (int i = 1; i <= N; i++)
{
sum3 += list[i-1].second;
}
sums.push_back(sum2*sum3);
float sum4 = 0;
for (int i = 1; i <= N; i++)
{
sum4 += list[i-1].first * list[i-1].first;
}
sums.push_back(sum4*N);
float sum5 = 0;
for (int i = 1; i <= N; i++)
{
sum5 += list[i-1].first;
}
sums.push_back(sum5*sum5);
float m;
m = (sums[0]-sums[1]) / (sums[2] - sums[3]);
return m;
}
float callB (const vector<pair<float,float>> list, int N)
{
vector<float> sums;
float sum1 = 0;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].second;
}
sums.push_back(sum1);
float sum2 = 0;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
sums.push_back(callM(list,N) * sum2);
float b;
b = (sums[0] - sums[1]) / N;
return b;
}
int main()
{
int N;
cin >> N;
string cal;
cin >> cal;
float x,y;
vector<pair<float,float>> num;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
num.push_back(make_pair(x,y));
}
float m,b;
m = callM(num,N);
b = callB(num,N);
if (cal == "mb")
{
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
return 0;
}
if (cal == "func")
{
if (m == 0 && b == 0)
{
cout << "y = 0";
return 0;
}
if (round(m*1e3)/1e3 == 0 && b != 0)
{
cout << "y = " << round(b*1e3)/1e3;
return 0;
}
if (round(m*1e3)/1e3 == 1 && b >= 0)
{
cout << "y = x + " << round(b*1e3)/1e3;
return 0;
}
if (round(m*1e3)/1e3 == 1 && b < 0)
{
cout << "y = x - " << round(-b*1e3)/1e3;
return 0;
}
if (round(m*1e3)/1e3 == -1 && b >= 0)
{
cout << "y = -x + " << round(b*1e3)/1e3;
return 0;
}
if (round(m*1e3)/1e3 == -1 && b < 0)
{
cout << "y = -x - " << round(-b*1e3)/1e3;
return 0;
}
if (b >= 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
return 0;
}
if (b < 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(-b*1e3)/1e3;
return 0;
}
}
} | # 0692, 2024-11-02 12:10:08, PPPPPPPPPPPPPPPPPP--PPPP (91%)
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>
using namespace std;
float callM (const vector<pair<float,float>> list, int N)
{
vector<float> sums;
float sum1 = 0;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].first * list[i-1].second;
}
sums.push_back(sum1*N);
float sum2 = 0,sum3 = 0;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
for (int i = 1; i <= N; i++)
{
sum3 += list[i-1].second;
}
sums.push_back(sum2*sum3);
float sum4 = 0;
for (int i = 1; i <= N; i++)
{
sum4 += list[i-1].first * list[i-1].first;
}
sums.push_back(sum4*N);
float sum5 = 0;
for (int i = 1; i <= N; i++)
{
sum5 += list[i-1].first;
}
sums.push_back(sum5*sum5);
float m;
m = (sums[0]-sums[1]) / (sums[2] - sums[3]);
return m;
}
float callB (const vector<pair<float,float>> list, int N)
{
vector<float> sums;
float sum1 = 0;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].second;
}
sums.push_back(sum1);
float sum2 = 0;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
sums.push_back(callM(list,N) * sum2);
float b;
b = (sums[0] - sums[1]) / N;
return b;
}
int main()
{
int N;
cin >> N;
string cal;
cin >> cal;
float x,y;
vector<pair<float,float>> num;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
num.push_back(make_pair(x,y));
}
float m,b;
m = callM(num,N);
b = callB(num,N);
if (cal == "mb")
{
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
return 0;
}
if (cal == "func")
{
if (round(m*1e3)/1e3 == 0 && b == 0)
{
cout << "y = 0";
return 0;
}
if (round(m*1e3)/1e3 == 0 && b != 0)
{
cout << "y = " << round(b*1e3)/1e3;
return 0;
}
if (round(m*1e3)/1e3 == 1 && b >= 0)
{
cout << "y = x + " << round(b*1e3)/1e3;
return 0;
}
if (round(m*1e3)/1e3 == 1 && b < 0)
{
cout << "y = x - " << round(-b*1e3)/1e3;
return 0;
}
if (round(m*1e3)/1e3 == -1 && b >= 0)
{
cout << "y = -x + " << round(b*1e3)/1e3;
return 0;
}
if (round(m*1e3)/1e3 == -1 && b < 0)
{
cout << "y = -x - " << round(-b*1e3)/1e3;
return 0;
}
if (b >= 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
return 0;
}
if (b < 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(-b*1e3)/1e3;
return 0;
}
}
} | # 0693, 2024-11-02 12:11:11, PPPPPPPPPPPPPPPPPP--PPPP (91%)
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>
using namespace std;
float callM (const vector<pair<float,float>> list, int N)
{
vector<float> sums;
float sum1 = 0;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].first * list[i-1].second;
}
sums.push_back(sum1*N);
float sum2 = 0,sum3 = 0;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
for (int i = 1; i <= N; i++)
{
sum3 += list[i-1].second;
}
sums.push_back(sum2*sum3);
float sum4 = 0;
for (int i = 1; i <= N; i++)
{
sum4 += list[i-1].first * list[i-1].first;
}
sums.push_back(sum4*N);
float sum5 = 0;
for (int i = 1; i <= N; i++)
{
sum5 += list[i-1].first;
}
sums.push_back(sum5*sum5);
float m;
m = (sums[0]-sums[1]) / (sums[2] - sums[3]);
return m;
}
float callB (const vector<pair<float,float>> list, int N)
{
vector<float> sums;
float sum1 = 0;
for (int i = 1; i <= N; i++)
{
sum1 += list[i-1].second;
}
sums.push_back(sum1);
float sum2 = 0;
for (int i = 1; i <= N; i++)
{
sum2 += list[i-1].first;
}
sums.push_back(callM(list,N) * sum2);
float b;
b = (sums[0] - sums[1]) / N;
return b;
}
int main()
{
int N;
cin >> N;
string cal;
cin >> cal;
float x,y;
vector<pair<float,float>> num;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
num.push_back(make_pair(x,y));
}
float m,b;
m = callM(num,N);
b = callB(num,N);
if (cal == "mb")
{
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
return 0;
}
if (cal == "func")
{
if (round(m*1e3)/1e3 == 0 && b == 0)
{
cout << "y = 0";
return 0;
}
if (round(m*1e3)/1e3 == 0 && b != 0)
{
cout << "y = " << round(b*1e3)/1e3;
return 0;
}
if (round(m*1e3)/1e3 == 1 && b >= 0)
{
cout << "y = x + " << round(b*1e3)/1e3;
return 0;
}
if (round(m*1e3)/1e3 == 1 && b < 0)
{
cout << "y = x - " << round(-b*1e3)/1e3;
return 0;
}
if (round(m*1e3)/1e3 == -1 && b >= 0)
{
cout << "y = -x + " << round(b*1e3)/1e3;
return 0;
}
if (round(m*1e3)/1e3 == -1 && b < 0)
{
cout << "y = -x - " << round(-b*1e3)/1e3;
return 0;
}
if (round(b*1e3)/1e3 >= 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
return 0;
}
if (round(b*1e3)/1e3 < 0)
{
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(-b*1e3)/1e3;
return 0;
}
}
} |
# 0694, 2024-11-02 10:58:59, --P-P--P---------------- (12%)
#include <iostream>
#include <vector>
#include <cmath>
#define f first
#define s second
using namespace std;
int main(){
int n;
string s;
cin>>n>>s;
vector<pair<float,float>> mem(n);
for(int i=0;i<n;i++){
cin>>mem[i].f>>mem[i].s;
}
if(s=="mb"){
float m,mxy,mx,my,mxp,b,bx,by;
for(int i=0;i<n;i++){
mxy+=mem[i].f*mem[i].s;
mx+=mem[i].f;
my+=mem[i].s;
mxp+=pow(mem[i].f,2);
}
m=((n*mxy)-mx*my) / ((n*mxp)-pow(mx,2));
for(int i=0;i<n;i++){
bx+=mem[i].f;
by+=mem[i].s;
}
b = (by-(m*bx))/n;
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3<<endl;
}
return 0;
} | # 0695, 2024-11-02 11:10:01, P-P------P-----P-----P-- (20%)
#include <iostream>
#include <vector>
#include <cmath>
#define f first
#define s second
using namespace std;
int main(){
int n;
string s;
cin>>n>>s;
vector<pair<float,float>> mem(n);
for(int i=0;i<n;i++){
cin>>mem[i].f>>mem[i].s;
}
float m,mxy,mx,my,mxp,b,bx,by;
for(int i=0;i<n;i++){
mxy+=mem[i].f*mem[i].s;
mx+=mem[i].f;
my+=mem[i].s;
mxp+=pow(mem[i].f,2);
}
m=((n*mxy)-mx*my)/((n*mxp)-pow(mx,2));
for(int i=0;i<n;i++){
bx+=mem[i].f;
by+=mem[i].s;
}
b = (by-(m*bx))/n;
m=round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(s=="mb"){
cout<<m<<endl<<b<<endl;
}
if(s=="func"){
if(m==0&&b==0)
cout<<"y = 0";
else if(b==0){
if(m==-1)
cout<<"y = -x";
else cout<<"y = "<<m<<"x";
}
else if(m==0)
cout<<"y = "<<b;
else cout<<"y = "<<m<<"x - "<<b;
}
return 0;
} | # 0696, 2024-11-02 11:10:11, ----P-P-PP-----P-------- (20%)
#include <iostream>
#include <vector>
#include <cmath>
#define f first
#define s second
using namespace std;
int main(){
int n;
string s;
cin>>n>>s;
vector<pair<float,float>> mem(n);
for(int i=0;i<n;i++){
cin>>mem[i].f>>mem[i].s;
}
float m,mxy,mx,my,mxp,b,bx,by;
for(int i=0;i<n;i++){
mxy+=mem[i].f*mem[i].s;
mx+=mem[i].f;
my+=mem[i].s;
mxp+=pow(mem[i].f,2);
}
m=((n*mxy)-mx*my)/((n*mxp)-pow(mx,2));
for(int i=0;i<n;i++){
bx+=mem[i].f;
by+=mem[i].s;
}
b = (by-(m*bx))/n;
m=round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(s=="mb"){
cout<<m<<endl<<b<<endl;
}
if(s=="func"){
if(m==0&&b==0)
cout<<"y = 0";
else if(b==0){
if(m==-1)
cout<<"y = -x";
else cout<<"y = "<<m<<"x";
}
else if(m==0)
cout<<"y = "<<b;
else cout<<"y = "<<m<<"x - "<<b;
}
return 0;
} | # 0697, 2024-11-02 11:12:55, PPPPPPPPPP-----PP--P-P-- (58%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n;
string s;
cin>>n>>s;
float x[n],y[n];
for(int i=0;i<n;i++){
cin>>x[i]>>y[i];
}
float m,mxy,mx,my,mxp,b,bx,by;
for(int i=0;i<n;i++){
mxy+=x[i]*y[i];
mx+=x[i];
my+=y[i];
mxp+=pow(x[i],2);
}
m=((n*mxy)-mx*my)/((n*mxp)-pow(mx,2));
for(int i=0;i<n;i++){
bx+=x[i];
by+=y[i];
}
b = (by-(m*bx))/n;
m=round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(s=="mb"){
cout<<m<<endl<<b<<endl;
}
if(s=="func"){
if(m==0&&b==0)
cout<<"y = 0";
else if(b==0){
if(m==-1)
cout<<"y = -x";
else cout<<"y = "<<m<<"x";
}
else if(m==0)
cout<<"y = "<<b;
else cout<<"y = "<<m<<"x - "<<b;
}
return 0;
} | # 0698, 2024-11-02 11:13:08, PPPPPPPPPP-----PP--P-P-- (58%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n;
string s;
cin>>n>>s;
float x[n],y[n];
for(int i=0;i<n;i++){
cin>>x[i]>>y[i];
}
float m,mxy,mx,my,mxp,b,bx,by;
for(int i=0;i<n;i++){
mxy+=x[i]*y[i];
mx+=x[i];
my+=y[i];
mxp+=pow(x[i],2);
}
m=((n*mxy)-mx*my)/((n*mxp)-pow(mx,2));
for(int i=0;i<n;i++){
bx+=x[i];
by+=y[i];
}
b = (by-(m*bx))/n;
m=round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(s=="mb"){
cout<<m<<endl<<b<<endl;
}
if(s=="func"){
if(m==0&&b==0)
cout<<"y = 0";
else if(b==0){
if(m==-1)
cout<<"y = -x";
else cout<<"y = "<<m<<"x";
}
else if(m==0)
cout<<"y = "<<b;
else cout<<"y = "<<m<<"x - "<<b;
}
return 0;
} | # 0699, 2024-11-02 11:15:07, PPPPPPPPPP-----PP--P-P-- (58%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n;
string s;
cin>>n>>s;
float x[n],y[n];
for(int i=0;i<n;i++){
cin>>x[i]>>y[i];
}
float m,mxy,mx,my,mxp,b,bx,by;
for(int i=0;i<n;i++){
mxy+=x[i]*y[i];
mx+=x[i];
my+=y[i];
mxp+=pow(x[i],2);
}
m=((n*mxy)-mx*my)/((n*mxp)-pow(mx,2));
for(int i=0;i<n;i++){
bx+=x[i];
by+=y[i];
}
b = (by-(m*bx))/n;
m=round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(s=="mb"){
if(m==-0) m=0;
if(b==-0) b=0;
cout<<m<<endl<<b<<endl;
}
if(s=="func"){
if(m==0&&b==0)
cout<<"y = 0";
else if(b==0){
if(m==-1)
cout<<"y = -x";
else cout<<"y = "<<m<<"x";
}
else if(m==0)
cout<<"y = "<<b;
else cout<<"y = "<<m<<"x - "<<b;
}
return 0;
} | # 0700, 2024-11-02 11:19:11, PPPPPPPPPP-----PP-PP-P-- (62%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n;
string s;
cin>>n>>s;
float x[n],y[n];
for(int i=0;i<n;i++){
cin>>x[i]>>y[i];
}
float m,mxy,mx,my,mxp,b,bx,by;
for(int i=0;i<n;i++){
mxy+=x[i]*y[i];
mx+=x[i];
my+=y[i];
mxp+=pow(x[i],2);
}
m=((n*mxy)-mx*my)/((n*mxp)-pow(mx,2));
for(int i=0;i<n;i++){
bx+=x[i];
by+=y[i];
}
b = (by-(m*bx))/n;
m=round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(s=="mb"){
if(m==-0) m=0;
if(b==-0) b=0;
cout<<m<<endl<<b<<endl;
}
if(s=="func"){
if(m==0&&b==0)
cout<<"y = 0";
else if(b==0){
if(m==-1)
cout<<"y = -x";
else if(m==1)
cout<<"y = x";
else cout<<"y = "<<m<<"x";
}
else if(m==0)
cout<<"y = "<<b;
else if(m==1)
cout<<"y = x - "<<b;
else cout<<"y = "<<m<<"x - "<<b;
}
return 0;
} | # 0701, 2024-11-02 11:53:28, PPPPPPPPPP-----PP-PP-P-- (62%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n;
string s;
cin>>n>>s;
float x[n],y[n];
for(int i=0;i<n;i++){
cin>>x[i]>>y[i];
}
float m,mxy,mx,my,mxp,b,bx,by;
for(int i=0;i<n;i++){
mxy+=x[i]*y[i];
mx+=x[i];
my+=y[i];
mxp+=pow(x[i],2);
}
m=((n*mxy)-mx*my)/((n*mxp)-pow(mx,2));
for(int i=0;i<n;i++){
bx+=x[i];
by+=y[i];
}
b = (by-(m*bx))/n;
m=round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(s=="mb"){
if(m==-0) m=0;
if(b==-0) b=0;
cout<<m<<endl<<b<<endl;
}
if(s=="func"){
if(m==0&&b==0)
cout<<"y = 0";
else if(b==0){
if(m==-1)
cout<<"y = -x";
else if(m==1)
cout<<"y = x";
else cout<<"y = "<<m<<"x";
}
else if(m==0)
cout<<"y = "<<b;
else if(m==1)
cout<<"y = x - "<<b;
else if(m==1&&b<0)
cout<<"y = x - "<<(-1*b);
else cout<<"y = "<<m<<"x - "<<b;
}
return 0;
} | # 0702, 2024-11-02 11:53:48, PPPPPPPPPP-----PP-PP-P-- (62%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n;
string s;
cin>>n>>s;
float x[n],y[n];
for(int i=0;i<n;i++){
cin>>x[i]>>y[i];
}
float m,mxy,mx,my,mxp,b,bx,by;
for(int i=0;i<n;i++){
mxy+=x[i]*y[i];
mx+=x[i];
my+=y[i];
mxp+=pow(x[i],2);
}
m=((n*mxy)-mx*my)/((n*mxp)-pow(mx,2));
for(int i=0;i<n;i++){
bx+=x[i];
by+=y[i];
}
b = (by-(m*bx))/n;
m=round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(s=="mb"){
if(m==-0) m=0;
if(b==-0) b=0;
cout<<m<<endl<<b<<endl;
}
if(s=="func"){
if(m==0&&b==0)
cout<<"y = 0";
else if(b==0){
if(m==-1)
cout<<"y = -x";
else if(m==1)
cout<<"y = x";
else cout<<"y = "<<m<<"x";
}
else if(m==0)
cout<<"y = "<<b;
else if(m==1)
cout<<"y = x - "<<b;
else if(m==1&&b<0)
cout<<"y = x + "<<(-1*b);
else cout<<"y = "<<m<<"x - "<<b;
}
return 0;
} | # 0703, 2024-11-02 11:55:09, PPPPPPPPPP-----PP-PP-P-- (62%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n;
string s;
cin>>n>>s;
float x[n],y[n];
for(int i=0;i<n;i++){
cin>>x[i]>>y[i];
}
float m,mxy,mx,my,mxp,b,bx,by;
for(int i=0;i<n;i++){
mxy+=x[i]*y[i];
mx+=x[i];
my+=y[i];
mxp+=pow(x[i],2);
}
m=((n*mxy)-mx*my)/((n*mxp)-pow(mx,2));
for(int i=0;i<n;i++){
bx+=x[i];
by+=y[i];
}
b = (by-(m*bx))/n;
m=round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(s=="mb"){
if(m==-0) m=0;
if(b==-0) b=0;
cout<<m<<endl<<b<<endl;
}
if(s=="func"){
if(m==0&&b==0)
cout<<"y = 0";
else if(b==0){
if(m==-1)
cout<<"y = -x";
else if(m==1)
cout<<"y = x";
else cout<<"y = "<<m<<"x";
}
else if(m==0)
cout<<"y = "<<b;
else if(m==1)
cout<<"y = x - "<<b;
else if(m==1&&b<0)
cout<<"y = x + "<<(-1*b);
else if(m>1&&b<0)
cout<<"y = "<<m<<"x + "<<b*-1;
else cout<<"y = "<<m<<"x - "<<b;
}
return 0;
} | # 0704, 2024-11-02 11:58:32, PPPPPPPPPP--------PP---- (50%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n;
string s;
cin>>n>>s;
float x[n],y[n];
for(int i=0;i<n;i++){
cin>>x[i]>>y[i];
}
float m,mxy,mx,my,mxp,b,bx,by;
for(int i=0;i<n;i++){
mxy+=x[i]*y[i];
mx+=x[i];
my+=y[i];
mxp+=pow(x[i],2);
}
m=((n*mxy)-mx*my)/((n*mxp)-pow(mx,2));
for(int i=0;i<n;i++){
bx+=x[i];
by+=y[i];
}
b = (by-(m*bx))/n;
m=round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(s=="mb"){
if(m==-0) m=0;
if(b==-0) b=0;
cout<<m<<endl<<b<<endl;
}
if(s=="func"){
if(m==0){
}
else if(m==1)
cout<<"y = x ";
else if(m==-1)
cout<<"y = -x";
else cout<<"y = "<<m<<"x";
if(b==0){
}
else if(b>0)
cout<<"- "<<b;
else if(b<0)
cout<<"+ "<<b;
}
return 0;
} | # 0705, 2024-11-02 12:00:14, PPPPPPPPPP--------PP---- (50%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n;
string s;
cin>>n>>s;
float x[n],y[n];
for(int i=0;i<n;i++){
cin>>x[i]>>y[i];
}
float m,mxy,mx,my,mxp,b,bx,by;
for(int i=0;i<n;i++){
mxy+=x[i]*y[i];
mx+=x[i];
my+=y[i];
mxp+=pow(x[i],2);
}
m=((n*mxy)-mx*my)/((n*mxp)-pow(mx,2));
for(int i=0;i<n;i++){
bx+=x[i];
by+=y[i];
}
b = (by-(m*bx))/n;
m=round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(s=="mb"){
if(m==-0) m=0;
if(b==-0) b=0;
cout<<m<<endl<<b<<endl;
}
if(s=="func"){
if(m==0){
if(b==0){
}
else if(b>0)
cout<<"y = "<<b;
else if(b<0)
cout<<"y = "<<b*-1;
}
else if(m==1)
cout<<"y = x ";
else if(m==-1)
cout<<"y = -x";
else cout<<"y = "<<m<<"x";
if(b==0){
}
else if(b>0)
cout<<"- "<<b;
else if(b<0)
cout<<"+ "<<b*-1;
}
return 0;
} | # 0706, 2024-11-02 12:02:33, PPPPPPPPPP--------PP---- (50%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n;
string s;
cin>>n>>s;
float x[n],y[n];
for(int i=0;i<n;i++){
cin>>x[i]>>y[i];
}
float m,mxy,mx,my,mxp,b,bx,by;
for(int i=0;i<n;i++){
mxy+=x[i]*y[i];
mx+=x[i];
my+=y[i];
mxp+=pow(x[i],2);
}
m=((n*mxy)-mx*my)/((n*mxp)-pow(mx,2));
for(int i=0;i<n;i++){
bx+=x[i];
by+=y[i];
}
b = (by-(m*bx))/n;
m=round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(s=="mb"){
if(m==-0) m=0;
if(b==-0) b=0;
cout<<m<<endl<<b<<endl;
}
if(s=="func"){
if(m==0){
if(b==0){
}
else if(b>0)
cout<<"y = "<<b;
else if(b<0)
cout<<"y = "<<b*-1;
}
else if(m==1)
cout<<"y = x ";
else if(m==-1)
cout<<"y = -x ";
else cout<<"y = "<<m<<"x ";
if(b==0){
}
else if(b>0)
cout<<"- "<<b;
else if(b<0)
cout<<"+ "<<b*-1;
}
return 0;
} | # 0707, 2024-11-02 12:07:13, PPPPPPPPPPPPPPP--PPPP-PP (87%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n;
string s;
cin>>n>>s;
float x[n],y[n];
for(int i=0;i<n;i++){
cin>>x[i]>>y[i];
}
float m,mxy,mx,my,mxp,b,bx,by;
for(int i=0;i<n;i++){
mxy+=x[i]*y[i];
mx+=x[i];
my+=y[i];
mxp+=pow(x[i],2);
}
m=((n*mxy)-mx*my)/((n*mxp)-pow(mx,2));
for(int i=0;i<n;i++){
bx+=x[i];
by+=y[i];
}
b = (by-(m*bx))/n;
m=round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(s=="mb"){
if(m==-0) m=0;
if(b==-0) b=0;
cout<<m<<endl<<b<<endl;
}
if(s=="func"){
// cout<<m<<endl<<b<<endl;
if(m==0){
if(b==0){
}
else
cout<<"y = "<<b;
}
else if(m==1)
cout<<"y = x ";
else if(m==-1)
cout<<"y = -x ";
else cout<<"y = "<<m<<"x ";
if(b==0){
}
else if(b>0)
cout<<"+ "<<b;
else if(b<0)
cout<<"- "<<b*-1;
}
return 0;
} | # 0708, 2024-11-02 12:08:16, PPPPPPPPPPPPPPPP-PPPP-PP (91%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n;
string s;
cin>>n>>s;
float x[n],y[n];
for(int i=0;i<n;i++){
cin>>x[i]>>y[i];
}
float m,mxy,mx,my,mxp,b,bx,by;
for(int i=0;i<n;i++){
mxy+=x[i]*y[i];
mx+=x[i];
my+=y[i];
mxp+=pow(x[i],2);
}
m=((n*mxy)-mx*my)/((n*mxp)-pow(mx,2));
for(int i=0;i<n;i++){
bx+=x[i];
by+=y[i];
}
b = (by-(m*bx))/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(s=="mb"){
if(m==-0) m=0;
if(b==-0) b=0;
cout<<m<<endl<<b<<endl;
}
if(s=="func"){
// cout<<m<<endl<<b<<endl;
if(m==0){
if(b==0){
cout<<"y = 0";
}
else
cout<<"y = "<<b;
}
else if(m==1)
cout<<"y = x ";
else if(m==-1)
cout<<"y = -x ";
else cout<<"y = "<<m<<"x ";
if(b==0){
}
else if(b>0)
cout<<"+ "<<b;
else if(b<0)
cout<<"- "<<b*-1;
}
return 0;
} |
# 0709, 2024-11-02 13:06:11, PPPPP-PPPP-------------- (37%)
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
int n;
vector<float> x;
vector<float> y;
float xi,yi;
string type;
cin>>n>>type;
for(int i=0;i<n;i++){
cin>>xi>>yi;
x.push_back(xi);
y.push_back(yi);
}
float m,b;
float m1,m2,m3,m4=0;
for(int i=1;i<=n;i++){
m1+=(x[i-1]*y[i-1]);
m2+=x[i-1];
m3+=y[i-1];
m4+=(x[i-1]*x[i-1]);
}
m=((n*m1)-((m2)*(m3)))/((n*m4)-(m2*m2));
b=(m3-(m*m2))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
cout<<m<<endl<<b;
} | # 0710, 2024-11-02 13:12:35, P----PP-P--P------------ (20%)
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
int n;
vector<float> x;
vector<float> y;
float xi,yi;
string type;
cin>>n>>type;
for(int i=0;i<n;i++){
cin>>xi>>yi;
x.push_back(xi);
y.push_back(yi);
}
float m,b;
float m1,m2,m3,m4=0;
for(int i=1;i<=n;i++){
m1+=(x[i-1]*y[i-1]);
m2+=x[i-1];
m3+=y[i-1];
m4+=(x[i-1]*x[i-1]);
}
m=((n*m1)-((m2)*(m3)))/((n*m4)-(m2*m2));
b=(m3-(m*m2))/n;
m=abs(round(m*1e3)/1e3);
b=abs(round(b*1e3)/1e3);
if(type=="mb"){
cout<<m<<endl<<b;
}
else if(type=="func"){
cout<<"y = "<<m<<"x"<<" - "<<b;
}
} | # 0711, 2024-11-02 13:37:37, PPPPP-PPPP-------------- (37%)
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
int n;
vector<float> x;
vector<float> y;
float xi,yi;
string type;
cin>>n>>type;
for(int i=0;i<n;i++){
cin>>xi>>yi;
x.push_back(xi);
y.push_back(yi);
}
float m,b;
float m1,m2,m3,m4=0;
for(int i=1;i<=n;i++){
m1+=(x[i-1]*y[i-1]);
m2+=x[i-1];
m3+=y[i-1];
m4+=(x[i-1]*x[i-1]);
}
m=((n*m1)-((m2)*(m3)))/((n*m4)-(m2*m2));
b=(m3-(m*m2))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(type=="mb"){
cout<<m<<endl<<b;
}
else if(type=="func"){
cout<<"m="<<m<<"b="<<b<<endl;
cout<<"y = ";
if(m==0&&b!=0) cout<<b;
else if(m==1) cout<<"x";
else if(m==-1) cout<<"-x";
else cout<<m<<"x";
if(b==0&&m==0) cout<<"0";
else if(b>0) cout<<" + "<<abs(b);
else if(b<0) cout<<" - "<<abs(b);
}
} | # 0712, 2024-11-02 13:40:38, PPPPP-PPPP-------------- (37%)
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
int n;
vector<float> x;
vector<float> y;
float xi,yi;
string type;
cin>>n>>type;
for(int i=0;i<n;i++){
cin>>xi>>yi;
x.push_back(xi);
y.push_back(yi);
}
float m,b;
float m1,m2,m3,m4=0;
for(int i=1;i<=n;i++){
m1+=(x[i-1]*y[i-1]);
m2+=x[i-1];
m3+=y[i-1];
m4+=(x[i-1]*x[i-1]);
}
m=((n*m1)-((m2)*(m3)))/((n*m4)-(m2*m2));
b=(m3-(m*m2))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
//float bt,mt;
//mt=abs(round(m*1e3)/1e3);
//bt=abs(round(b*1e3)/1e3);
if(type=="mb"){
cout<<m<<endl<<b;
}
else if(type=="func"){
cout<<"m="<<m<<"b="<<b<<endl;
cout<<"y = ";
if(m==0&&b!=0) cout<<b;
else if(m==1) cout<<"x";
else if(m==-1) cout<<"-x";
else cout<<m<<"x";
if(b==0&&m==0) cout<<"0";
else if(b>0) cout<<" + "<<b;
else if(b<0) cout<<" - "<<-1*b;
}
} | # 0713, 2024-11-02 13:42:44, PPPPP-PPPPPPPPP--PPPP-PP (83%)
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
int n;
vector<float> x;
vector<float> y;
float xi,yi;
string type;
cin>>n>>type;
for(int i=0;i<n;i++){
cin>>xi>>yi;
x.push_back(xi);
y.push_back(yi);
}
float m,b;
float m1,m2,m3,m4=0;
for(int i=1;i<=n;i++){
m1+=(x[i-1]*y[i-1]);
m2+=x[i-1];
m3+=y[i-1];
m4+=(x[i-1]*x[i-1]);
}
m=((n*m1)-((m2)*(m3)))/((n*m4)-(m2*m2));
b=(m3-(m*m2))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(type=="mb"){
cout<<m<<endl<<b;
}
else if(type=="func"){
cout<<"y = ";
if(m==0&&b!=0) cout<<b;
else if(m==1) cout<<"x";
else if(m==-1) cout<<"-x";
else cout<<m<<"x";
if(b==0&&m==0) cout<<"0";
else if(b>0) cout<<" + "<<b;
else if(b<0) cout<<" - "<<-1*b;
}
} | # 0714, 2024-11-02 15:00:02, PPPPPPPPPP-------------- (41%)
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
int n;
vector<float> x;
vector<float> y;
float xi,yi;
string type;
cin>>n>>type;
for(int i=0;i<n;i++){
cin>>xi>>yi;
x.push_back(xi);
y.push_back(yi);
}
float m,b;
float m1,m2,m3,m4=0;
for(int i=1;i<=n;i++){
m1+=(x[i-1]*y[i-1]);
m2+=x[i-1];
m3+=y[i-1];
m4+=(x[i-1]*x[i-1]);
}
m=((n*m1)-((m2)*(m3)))/((n*m4)-(m2*m2));
b=(m3-(m*m2))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(type=="mb"){
if(m!=-0) cout<<m<<endl<<b;
else cout<<"0"<<endl<<b;
}
else if(type=="func"){
cout<<"m="<<m<<"b="<<b<<endl;
cout<<"y = ";
if(m==0&&b!=0) cout<<b;
else if(m==1) cout<<"x";
else if(m==-1) cout<<"-x";
else cout<<m<<"x";
if(b==0&&m==0) cout<<"0";
else if(b>0) cout<<" + "<<b;
else if(b<0) cout<<" - "<<-1*b;
}
} | # 0715, 2024-11-02 15:02:01, PPPPP-PPPPPPPPP--PPPP-PP (83%)
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
int n;
vector<float> x;
vector<float> y;
float xi,yi;
string type;
cin>>n>>type;
for(int i=0;i<n;i++){
cin>>xi>>yi;
x.push_back(xi);
y.push_back(yi);
}
float m,b;
float m1,m2,m3,m4=0;
for(int i=1;i<=n;i++){
m1+=(x[i-1]*y[i-1]);
m2+=x[i-1];
m3+=y[i-1];
m4+=(x[i-1]*x[i-1]);
}
m=((n*m1)-((m2)*(m3)))/((n*m4)-(m2*m2));
b=(m3-(m*m2))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(type=="mb"){
cout<<m<<endl<<b;
}
else if(type=="func"){
cout<<"y = ";
if(m==0&&b!=0) cout<<b;
else if(m==1) cout<<"x";
else if(m==-1) cout<<"-x";
else cout<<m<<"x";
if(b==0&&m==0) cout<<"0";
else if(b>0) cout<<" + "<<b;
else if(b<0) cout<<" - "<<-1*b;
}
} | # 0716, 2024-11-02 15:12:59, PPPPP-PPPPPPPPP--PPPP-PP (83%)
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
int n;
vector<float> x;
vector<float> y;
float xi,yi;
string type;
cin>>n>>type;
for(int i=0;i<n;i++){
cin>>xi>>yi;
x.push_back(xi);
y.push_back(yi);
}
float m,b;
float m1,m2,m3,m4=0;
for(int i=1;i<=n;i++){
m1+=(x[i-1]*y[i-1]);
m2+=x[i-1];
m3+=y[i-1];
m4+=(x[i-1]*x[i-1]);
}
m=((n*m1)-((m2)*(m3)))/((n*m4)-(m2*m2));
b=(m3-(m*m2))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(m==-0) m=0;
if(type=="mb"){
cout<<m<<endl<<b;
}
else if(type=="func"){
cout<<"y = ";
if(m==0&&b!=0) cout<<b;
else if(m==1) cout<<"x";
else if(m==-1) cout<<"-x";
else cout<<m<<"x";
if(b==0&&m==0) cout<<"0";
else if(b>0) cout<<" + "<<b;
else if(b<0) cout<<" - "<<-1*b;
}
} | # 0717, 2024-11-02 15:15:24, PPPPP-PPPPPPPPP--PPPP-PP (83%)
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
int n;
vector<float> x;
vector<float> y;
float xi,yi;
string type;
cin>>n>>type;
for(int i=0;i<n;i++){
cin>>xi>>yi;
x.push_back(xi);
y.push_back(yi);
}
float m,b;
float m1,m2,m3,m4=0;
for(int i=1;i<=n;i++){
m1+=(x[i-1]*y[i-1]);
m2+=x[i-1];
m3+=y[i-1];
m4+=(x[i-1]*x[i-1]);
}
m=((n*m1)-((m2)*(m3)))/((n*m4)-(m2*m2));
b=(m3-(m*m2))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
//if(m==-0) m=0;
if(type=="mb"){
cout<<m<<endl<<b;
}
else if(type=="func"){
cout<<"y = ";
if((abs(m)==0)&&b!=0) cout<<b;
else if(m==1) cout<<"x";
else if(m==-1) cout<<"-x";
else cout<<m<<"x";
if(b==0&&(abs(m)==0)) cout<<"0";
else if(b>0) cout<<" + "<<b;
else if(b<0) cout<<" - "<<-1*b;
}
} | # 0718, 2024-11-02 15:22:28, PPPPP-PPPPPPPPP-PPPPPPPP (91%)
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
int n;
vector<float> x;
vector<float> y;
float xi,yi;
string type;
cin>>n>>type;
for(int i=0;i<n;i++){
cin>>xi>>yi;
x.push_back(xi);
y.push_back(yi);
}
float m,b;
float m1,m2,m3,m4=0;
for(int i=1;i<=n;i++){
m1+=(x[i-1]*y[i-1]);
m2+=x[i-1];
m3+=y[i-1];
m4+=(x[i-1]*x[i-1]);
}
m=((n*m1)-((m2)*(m3)))/((n*m4)-(m2*m2));
b=(m3-(m*m2))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
//if(m==-0) m=0;
if(type=="mb"){
cout<<m<<endl<<b;
}
else if(type=="func"){
cout<<"y = ";
if((abs(m)==0)&&b!=0) cout<<b;
else if(m==1) cout<<"x";
else if(m==-1) cout<<"-x";
else cout<<m<<"x";
if(b==0&&(abs(m)==0)) cout<<"0";
else if(b>0&&(abs(m)!=0)) cout<<" + "<<b;
else if(b<0&&(abs(m)!=0)) cout<<" - "<<-1*b;
}
} | # 0719, 2024-11-02 15:26:30, PPPPP-PPPPPPPPP-PPPPPPPP (91%)
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
int n;
vector<float> x;
vector<float> y;
float xi,yi;
string type;
cin>>n>>type;
for(int i=0;i<n;i++){
cin>>xi>>yi;
x.push_back(xi);
y.push_back(yi);
}
float m,b;
float m1,m2,m3,m4=0;
for(int i=1;i<=n;i++){
m1+=(x[i-1]*y[i-1]);
m2+=x[i-1];
m3+=y[i-1];
m4+=(x[i-1]*x[i-1]);
}
m=((n*m1)-((m2)*(m3)))/((n*m4)-(m2*m2));
b=(m3-(m*m2))/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
//if(m==-0) m=0;
if(type=="mb"){
cout<<m<<endl<<b;
}
else if(type=="func"){
cout<<"y = ";
if((abs(m)==0)&& abs(b)!=0) cout<<b;
else if(m==1) cout<<"x";
else if(m==-1) cout<<"-x";
else cout<<m<<"x";
if(abs(b)==0&&(abs(m)==0)) cout<<"0";
else if(b>0&&(abs(m)!=0)) cout<<" + "<<b;
else if(b<0&&(abs(m)!=0)) cout<<" - "<<-1*b;
}
} |
# 0720, 2024-11-02 13:35:46, PxPPPPPPPP-x------------ (37%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main(){
float n;
string t;
cin >> n >> t;
vector<float> x(n,0);
vector<float> y(n,0);
for(int i = 1;i<=n;i++){
float xi,yi;
cin >> xi >> yi;
x[i] = xi;
y[i] = yi;
}
float m =0;
float b =0;
float p = 0;
float q = 0;
float r = 0;
float s = 0;
for(int i = 1;i<=n;i++){
p += x[i]*y[i];
q += x[i];
r += y[i];
s += x[i]*x[i];
}
m = (n*p-q*r) / (n*s-(q*q));
b = (r-(m*q)) / n;
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
} | # 0721, 2024-11-02 13:42:56, PxPPPPPPPP-x---P-----P-- (45%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main(){
float n;
string t;
cin >> n >> t;
vector<float> x(n,0);
vector<float> y(n,0);
for(int i = 1;i<=n;i++){
float xi,yi;
cin >> xi >> yi;
x[i] = xi;
y[i] = yi;
}
float m =0;
float b =0;
float p = 0;
float q = 0;
float r = 0;
float s = 0;
for(int i = 1;i<=n;i++){
p += x[i]*y[i];
q += x[i];
r += y[i];
s += x[i]*x[i];
}
m = (n*p-q*r) / (n*s-(q*q));
b = (r-(m*q)) / n;
if(t == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(t == "func"){
if(m == 0){
cout << "y = " << b;
}
else if(m == -1){
cout << "y = -x + " << b;
} else {
cout << "y = " << m << "x + " << b;
}
}
} | # 0722, 2024-11-02 13:55:25, PxPPPPPPPPPxP--PPPPPPP-- (75%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main(){
float n;
string t;
cin >> n >> t;
vector<float> x(n,0);
vector<float> y(n,0);
for(int i = 1;i<=n;i++){
float xi,yi;
cin >> xi >> yi;
x[i] = xi;
y[i] = yi;
}
float m =0;
float b =0;
float p = 0;
float q = 0;
float r = 0;
float s = 0;
for(int i = 1;i<=n;i++){
p += x[i]*y[i];
q += x[i];
r += y[i];
s += x[i]*x[i];
}
m = (n*p-q*r) / (n*s-(q*q));
b = (r-(m*q)) / n;
if(t == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(t == "func"){
if(round(m*1e3)/1e3 == 0){
cout << "y = " << round(b*1e3)/1e3 << endl;
}
else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 != 0){
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 == 0){
cout << "y = -x" << endl;
}else if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 != 0){
cout << "y = x + " << round(b*1e3)/1e3;
}else if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 == 0){
cout << "y = x" << endl;
}else{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3 << endl;
}
}
} | # 0723, 2024-11-02 14:00:16, PxPPPPPPPPPxP--PPPPPPP-- (75%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main(){
float n;
string t;
cin >> n >> t;
vector<float> x(n,0);
vector<float> y(n,0);
for(int i = 1;i<=n;i++){
float xi,yi;
cin >> xi >> yi;
x[i] = xi;
y[i] = yi;
}
float m =0;
float b =0;
float p = 0;
float q = 0;
float r = 0;
float s = 0;
for(int i = 1;i<=n;i++){
p += x[i]*y[i];
q += x[i];
r += y[i];
s += x[i]*x[i];
}
m = (n*p-q*r) / (n*s-(q*q));
b = (r-(m*q)) / n;
if(t == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(t == "func"){
if(round(m*1e3)/1e3 == 0){
cout << "y = " << round(b*1e3)/1e3 << endl;
} else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 < 0){
cout << "y = -x - " << round(b*1e3)/1e3 << endl;
}else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 > 0){
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 == 0){
cout << "y = -x" << endl;
}else if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 > 0){
cout << "y = x + " << round(b*1e3)/1e3;
}else if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 < 0){
cout << "y = x - " << round(b*1e3)/1e3;
}else if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 == 0){
cout << "y = x" << endl;
}else{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3 << endl;
}
}
} | # 0724, 2024-11-02 14:01:50, PxPPPPPPPPPxP--PPPPPPPPP (83%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main(){
float n;
string t;
cin >> n >> t;
vector<float> x(n,0);
vector<float> y(n,0);
for(int i = 1;i<=n;i++){
float xi,yi;
cin >> xi >> yi;
x[i] = xi;
y[i] = yi;
}
float m =0;
float b =0;
float p = 0;
float q = 0;
float r = 0;
float s = 0;
for(int i = 1;i<=n;i++){
p += x[i]*y[i];
q += x[i];
r += y[i];
s += x[i]*x[i];
}
m = (n*p-q*r) / (n*s-(q*q));
b = (r-(m*q)) / n;
if(t == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(t == "func"){
if(round(m*1e3)/1e3 == 0){
cout << "y = " << round(b*1e3)/1e3 << endl;
} else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 < 0){
cout << "y = -x - " << -round(b*1e3)/1e3 << endl;
}else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 > 0){
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 == 0){
cout << "y = -x" << endl;
}else if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 > 0){
cout << "y = x + " << round(b*1e3)/1e3;
}else if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 < 0){
cout << "y = x - " << -round(b*1e3)/1e3;
}else if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 == 0){
cout << "y = x" << endl;
}else{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3 << endl;
}
}
} | # 0725, 2024-11-02 14:09:16, PxPPPPPPPP-x------------ (37%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main(){
float n;
string t;
cin >> n >> t;
vector<float> x(n,0);
vector<float> y(n,0);
for(int i = 1;i<=n;i++){
float xi,yi;
cin >> xi >> yi;
x[i] = xi;
y[i] = yi;
}
float m =0;
float b =0;
float p = 0;
float q = 0;
float r = 0;
float s = 0;
for(int i = 1;i<=n;i++){
p += x[i]*y[i];
q += x[i];
r += y[i];
s += x[i]*x[i];
}
m = (n*p-q*r) / (n*s-(q*q));
b = (r-(m*q)) / n;
if(t == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(t == "func"){
if(round(m*1e3)/1e3 == 0){
cout << "y = " << round(b*1e3)/1e3 << endl;
cout << '1' << endl;
} else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 < 0){
cout << "y = -x - " << -round(b*1e3)/1e3 << endl;
cout << '2' << endl;
}else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 > 0){
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
cout << '3' << endl;
}else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 == 0){
cout << "y = -x" << endl;
cout << '4' << endl;
}else if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 > 0){
cout << "y = x + " << round(b*1e3)/1e3;
cout << '5' << endl;
}else if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 < 0){
cout << "y = x - " << -round(b*1e3)/1e3;
cout << '6' << endl;
}else if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 == 0){
cout << "y = x" << endl;
cout << '7' << endl;
} if(round(b*1e3)/1e3 < 0) {
cout << "y = " <<m<< "x - "<< -round(b*1e3)/1e3 << endl;
}else{
cout << "y = " <<m<< "x + "<< round(b*1e3)/1e3 << endl;
}
}
} | # 0726, 2024-11-02 14:10:17, PxPPPPPPPP-x------------ (37%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main(){
float n;
string t;
cin >> n >> t;
vector<float> x(n,0);
vector<float> y(n,0);
for(int i = 1;i<=n;i++){
float xi,yi;
cin >> xi >> yi;
x[i] = xi;
y[i] = yi;
}
float m =0;
float b =0;
float p = 0;
float q = 0;
float r = 0;
float s = 0;
for(int i = 1;i<=n;i++){
p += x[i]*y[i];
q += x[i];
r += y[i];
s += x[i]*x[i];
}
m = (n*p-q*r) / (n*s-(q*q));
b = (r-(m*q)) / n;
if(t == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(t == "func"){
if(round(m*1e3)/1e3 == 0){
cout << "y = " << round(b*1e3)/1e3 << endl;
// cout << '1' << endl;
} else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 < 0){
cout << "y = -x - " << -round(b*1e3)/1e3 << endl;
// cout << '2' << endl;
}else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 > 0){
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
// cout << '3' << endl;
}else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 == 0){
cout << "y = -x" << endl;
// cout << '4' << endl;
}else if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 > 0){
cout << "y = x + " << round(b*1e3)/1e3;
cout << '5' << endl;
}else if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 < 0){
cout << "y = x - " << -round(b*1e3)/1e3;
// cout << '6' << endl;
}else if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 == 0){
cout << "y = x" << endl;
// cout << '7' << endl;
} if(round(b*1e3)/1e3 < 0) {
cout << "y = " <<m<< "x - "<< -round(b*1e3)/1e3 << endl;
}else{
cout << "y = " <<m<< "x + "<< round(b*1e3)/1e3 << endl;
}
}
} | # 0727, 2024-11-02 14:11:03, PxPPPPPPPP-x---PP-PPP--- (58%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main(){
float n;
string t;
cin >> n >> t;
vector<float> x(n,0);
vector<float> y(n,0);
for(int i = 1;i<=n;i++){
float xi,yi;
cin >> xi >> yi;
x[i] = xi;
y[i] = yi;
}
float m =0;
float b =0;
float p = 0;
float q = 0;
float r = 0;
float s = 0;
for(int i = 1;i<=n;i++){
p += x[i]*y[i];
q += x[i];
r += y[i];
s += x[i]*x[i];
}
m = (n*p-q*r) / (n*s-(q*q));
b = (r-(m*q)) / n;
if(t == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(t == "func"){
if(round(m*1e3)/1e3 == 0){
cout << "y = " << round(b*1e3)/1e3 << endl;
// cout << '1' << endl;
} else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 < 0){
cout << "y = -x - " << -round(b*1e3)/1e3 << endl;
// cout << '2' << endl;
}else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 > 0){
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
// cout << '3' << endl;
}else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 == 0){
cout << "y = -x" << endl;
// cout << '4' << endl;
}else if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 > 0){
cout << "y = x + " << round(b*1e3)/1e3;
cout << '5' << endl;
}else if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 < 0){
cout << "y = x - " << -round(b*1e3)/1e3;
// cout << '6' << endl;
}else if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 == 0){
cout << "y = x" << endl;
// cout << '7' << endl;
} if(round(b*1e3)/1e3 < 0) {
cout << "y = " <<m<< "x - "<< -round(b*1e3)/1e3 << endl;
}
}
} | # 0728, 2024-11-02 14:17:15, PxPPPPPPPPPxPPPPPPPPPPPP (91%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main(){
float n;
string t;
cin >> n >> t;
vector<float> x(n,0);
vector<float> y(n,0);
for(int i = 1;i<=n;i++){
float xi,yi;
cin >> xi >> yi;
x[i] = xi;
y[i] = yi;
}
float m =0;
float b =0;
float p = 0;
float q = 0;
float r = 0;
float s = 0;
for(int i = 1;i<=n;i++){
p += x[i]*y[i];
q += x[i];
r += y[i];
s += x[i]*x[i];
}
m = (n*p-q*r) / (n*s-(q*q));
b = (r-(m*q)) / n;
if(t == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(t == "func"){
if(round(m*1e3)/1e3 == 0){
cout << "y = " << round(b*1e3)/1e3 << endl;
// cout << '1' << endl;
} else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 < 0){
cout << "y = -x - " << -round(b*1e3)/1e3 << endl;
// cout << '2' << endl;
}else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 > 0){
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
// cout << '3' << endl;
}else if(round(m*1e3)/1e3 == -1 && round(b*1e3)/1e3 == 0){
cout << "y = -x" << endl;
// cout << '4' << endl;
}else if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 > 0){
cout << "y = x + " << round(b*1e3)/1e3;
// cout << '5' << endl;
}else if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 < 0){
cout << "y = x - " << -round(b*1e3)/1e3;
// cout << '6' << endl;
}else if(round(m*1e3)/1e3 == 1 && round(b*1e3)/1e3 == 0){
cout << "y = x" << endl;
// cout << '7' << endl;
} else if(round(m*1e3)/1e3 != -1 && round(m*1e3)/1e3 != 1 && round(b*1e3)/1e3 > 0){
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3 << endl;
// cout << '8' << endl;
} else if(round(m*1e3)/1e3 != -1 && round(m*1e3)/1e3 != 1 && round(b*1e3)/1e3 < 0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << -round(b*1e3)/1e3 << endl;
// cout << '9' << endl;
}
}
} |
# 0729, 2024-11-02 10:01:25, -----PP-PP-------------- (16%)
// 200
#include<bits/stdc++.h>
using namespace std;
float zig_xP2(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += (val[i-1].first*val[i-1].first);
}
return sum;
}
float zig_x(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += val[i-1].first;
}
return sum;
}
float zig_y(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += val[i-1].second;
}
return sum;
}
float zig_xy(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += val[i-1].first*val[i-1].second;
}
return sum;
}
float m(int N, vector<pair<float, float>> &val){
float zX = zig_x(N, val);
float zY = zig_y(N, val);
float zXY = zig_xy(N, val);
float zX2 = zig_xP2(N, val);
return ( (N*zXY)-(zX*zY) )/ ( (N*zX2)-pow(zX, 2) );
}
float bF(int m, int N, vector<pair<float, float>> &val){
float zX = zig_x(N, val);
float zY = zig_y(N, val);
float zXY = zig_xy(N, val);
float zX2 = zig_xP2(N, val);
return (zY-(m*zX))/N;
}
int main(){
int N; cin >> N;
string func; cin >> func;
float a,b;
vector<pair<float, float>> dat;
for(int i=0; i<N; i++){
cin >> a >> b;
dat.push_back({a, b});
}
if(func == "mb"){
float r1 = m(N, dat);
float r2 = bF(r1, N, dat);
// float r2 = bF(N, dat);
cout << round(r1*1e3)/1e3 << endl;
cout << round(r2*1e3)/1e3 << endl;
}else if(func == "func"){
}else{
cout << "??";
}
return 0;
} | # 0730, 2024-11-02 10:07:29, PPPPPPP-PP-------------- (37%)
// 200
#include<bits/stdc++.h>
using namespace std;
float zig_xP2(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += (val[i-1].first*val[i-1].first);
}
return sum;
}
float zig_x(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += val[i-1].first;
}
return sum;
}
float zig_y(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += val[i-1].second;
}
return sum;
}
float zig_xy(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += val[i-1].first*val[i-1].second;
}
return sum;
}
float m(int N, vector<pair<float, float>> &val){
float zX = zig_x(N, val);
float zY = zig_y(N, val);
float zXY = zig_xy(N, val);
float zX2 = zig_xP2(N, val);
return ( (N*zXY)-(zX*zY) )/ ( (N*zX2)-pow(zX, 2) );
}
float bF(float m, int N, vector<pair<float, float>> &val){
float zX = zig_x(N, val);
float zY = zig_y(N, val);
float zXY = zig_xy(N, val);
float zX2 = zig_xP2(N, val);
return (zY-(m*zX))/N;
}
int main(){
int N; cin >> N;
string func; cin >> func;
float a,b;
vector<pair<float, float>> dat;
for(int i=0; i<N; i++){
cin >> a >> b;
dat.push_back({a, b});
}
if(func == "mb"){
float r1 = m(N, dat);
float r2 = bF(r1, N, dat);
// float r2 = bF(N, dat);
cout << round(r1*1e3)/1e3 << endl;
cout << round(r2*1e3)/1e3 << endl;
}else if(func == "func"){
}else{
cout << "??";
}
return 0;
} | # 0731, 2024-11-02 10:14:16, PPPPPPP-PPPPPPP--------- (58%)
// 200
#include<bits/stdc++.h>
using namespace std;
float zig_xP2(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += (val[i-1].first*val[i-1].first);
}
return sum;
}
float zig_x(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += val[i-1].first;
}
return sum;
}
float zig_y(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += val[i-1].second;
}
return sum;
}
float zig_xy(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += val[i-1].first*val[i-1].second;
}
return sum;
}
float m(int N, vector<pair<float, float>> &val){
float zX = zig_x(N, val);
float zY = zig_y(N, val);
float zXY = zig_xy(N, val);
float zX2 = zig_xP2(N, val);
return ( (N*zXY)-(zX*zY) )/ ( (N*zX2)-pow(zX, 2) );
}
float bF(float m, int N, vector<pair<float, float>> &val){
float zX = zig_x(N, val);
float zY = zig_y(N, val);
float zXY = zig_xy(N, val);
float zX2 = zig_xP2(N, val);
return (zY-(m*zX))/N;
}
int main(){
int N; cin >> N;
string func; cin >> func;
float a,b;
vector<pair<float, float>> dat;
for(int i=0; i<N; i++){
cin >> a >> b;
dat.push_back({a, b});
}
if(func == "mb"){
float r1 = m(N, dat);
float r2 = bF(r1, N, dat);
cout << round(r1*1e3)/1e3 << endl;
cout << round(r2*1e3)/1e3 << endl;
}else if(func == "func"){
float r1 = m(N, dat);
float r2 = bF(r1, N, dat);
cout << "y = ";
// show m
if(r1!=1 || r1!= -1){
cout << round(r1*1e3)/1e3 << "x ";
}else{
if(r1 == 1){
cout << "x ";
}else{
cout << "-x ";
}
}
// sign right
if(r2 > 0){
cout << "+ " << round(r2*1e3)/1e3;
}else{
cout << "- " << abs(round(r2*1e3)/1e3);
}
}else{
cout << "??";
}
return 0;
} | # 0732, 2024-11-02 10:24:10, PPPPPPP-PP-------PPPP-PP (62%)
// 200
#include<bits/stdc++.h>
using namespace std;
float zig_xP2(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += (val[i-1].first*val[i-1].first);
}
return sum;
}
float zig_x(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += val[i-1].first;
}
return sum;
}
float zig_y(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += val[i-1].second;
}
return sum;
}
float zig_xy(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += val[i-1].first*val[i-1].second;
}
return sum;
}
float m(int N, vector<pair<float, float>> &val){
float zX = zig_x(N, val);
float zY = zig_y(N, val);
float zXY = zig_xy(N, val);
float zX2 = zig_xP2(N, val);
return ( (N*zXY)-(zX*zY) )/ ( (N*zX2)-pow(zX, 2) );
}
float bF(float m, int N, vector<pair<float, float>> &val){
float zX = zig_x(N, val);
float zY = zig_y(N, val);
float zXY = zig_xy(N, val);
float zX2 = zig_xP2(N, val);
return (zY-(m*zX))/N;
}
int main(){
int N; cin >> N;
string func; cin >> func;
float a,b;
vector<pair<float, float>> dat;
for(int i=0; i<N; i++){
cin >> a >> b;
dat.push_back({a, b});
}
if(func == "mb"){
float r1 = m(N, dat);
float r2 = bF(r1, N, dat);
cout << round(r1*1e3)/1e3 << endl;
cout << round(r2*1e3)/1e3 << endl;
}else if(func == "func"){
float r1 = m(N, dat);
float r2 = bF(r1, N, dat);
cout << "y = ";
// show m
int r1_c = round(r1*1e3)/1e3;
if(!(r1_c!=1 || r1_c!= -1 || r1_c==0)){
cout << round(r1*1e3)/1e3 << "x ";
}else{
if(r1 > 0){
cout << "x ";
}else if(r1 < 0){
cout << "-x ";
}
}
// sign right
int r2_c = round(r2*1e3)/1e3;
if(r2_c==0){
cout << "";
}else{
if(r2 > 0){
cout << "+ "<< round(r2*1e3)/1e3;
}else if(r2 < 0){
cout << "- " << abs(round(r2*1e3)/1e3);
}
}
// if(r2 > 0){
// cout << "+ " << round(r2*1e3)/1e3;
// }else{
// cout << "- " << abs(round(r2*1e3)/1e3);
// }
}else{
cout << "??";
}
return 0;
} | # 0733, 2024-11-02 10:56:48, PPPPPPP-PP-----P-P--P-PP (58%)
// 200
#include<bits/stdc++.h>
using namespace std;
float zig_xP2(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += (val[i-1].first*val[i-1].first);
}
return sum;
}
float zig_x(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += val[i-1].first;
}
return sum;
}
float zig_y(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += val[i-1].second;
}
return sum;
}
float zig_xy(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += val[i-1].first*val[i-1].second;
}
return sum;
}
float m(int N, vector<pair<float, float>> &val){
float zX = zig_x(N, val);
float zY = zig_y(N, val);
float zXY = zig_xy(N, val);
float zX2 = zig_xP2(N, val);
return ( (N*zXY)-(zX*zY) )/ ( (N*zX2)-pow(zX, 2) );
}
float bF(float m, int N, vector<pair<float, float>> &val){
float zX = zig_x(N, val);
float zY = zig_y(N, val);
float zXY = zig_xy(N, val);
float zX2 = zig_xP2(N, val);
return (zY-(m*zX))/N;
}
int main(){
int N; cin >> N;
string func; cin >> func;
float a,b;
vector<pair<float, float>> dat;
for(int i=0; i<N; i++){
cin >> a >> b;
dat.push_back({a, b});
}
if(func == "mb"){
float r1 = m(N, dat);
float r2 = bF(r1, N, dat);
cout << round(r1*1e3)/1e3 << endl;
cout << round(r2*1e3)/1e3 << endl;
}else if(func == "func"){
float r1 = m(N, dat);
float r2 = bF(r1, N, dat);
cout << "y = ";
// show m
int r1_c = round(r1*1e3)/1e3;
if(!(r1_c!=1 || r1_c!= -1 || r1_c==0)){
cout << round(r1*1e3)/1e3 << "x ";
}else{
if(r1 > 0){
cout << "x ";
}else if(r1 < 0){
cout << "-x ";
}
}
// sign right
int r2_c = round(r2*1e3)/1e3;
if(r2_c==0){
cout << "0";
}else{
if(r2 > 0){
cout << "+ "<< round(r2*1e3)/1e3;
}else if(r2 < 0){
cout << "- " << abs(round(r2*1e3)/1e3);
}
}
// if(r2 > 0){
// cout << "+ " << round(r2*1e3)/1e3;
// }else{
// cout << "- " << abs(round(r2*1e3)/1e3);
// }
}else{
cout << "??";
}
return 0;
} | # 0734, 2024-11-02 10:56:58, PPPPPPP-PP-------PPPP-PP (62%)
// 200
#include<bits/stdc++.h>
using namespace std;
float zig_xP2(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += (val[i-1].first*val[i-1].first);
}
return sum;
}
float zig_x(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += val[i-1].first;
}
return sum;
}
float zig_y(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += val[i-1].second;
}
return sum;
}
float zig_xy(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += val[i-1].first*val[i-1].second;
}
return sum;
}
float m(int N, vector<pair<float, float>> &val){
float zX = zig_x(N, val);
float zY = zig_y(N, val);
float zXY = zig_xy(N, val);
float zX2 = zig_xP2(N, val);
return ( (N*zXY)-(zX*zY) )/ ( (N*zX2)-pow(zX, 2) );
}
float bF(float m, int N, vector<pair<float, float>> &val){
float zX = zig_x(N, val);
float zY = zig_y(N, val);
float zXY = zig_xy(N, val);
float zX2 = zig_xP2(N, val);
return (zY-(m*zX))/N;
}
int main(){
int N; cin >> N;
string func; cin >> func;
float a,b;
vector<pair<float, float>> dat;
for(int i=0; i<N; i++){
cin >> a >> b;
dat.push_back({a, b});
}
if(func == "mb"){
float r1 = m(N, dat);
float r2 = bF(r1, N, dat);
cout << round(r1*1e3)/1e3 << endl;
cout << round(r2*1e3)/1e3 << endl;
}else if(func == "func"){
float r1 = m(N, dat);
float r2 = bF(r1, N, dat);
cout << "y = ";
// show m
int r1_c = round(r1*1e3)/1e3;
if(!(r1_c!=1 || r1_c!= -1 || r1_c==0)){
cout << round(r1*1e3)/1e3 << "x ";
}else{
if(r1 > 0){
cout << "x ";
}else if(r1 < 0){
cout << "-x ";
}
}
// sign right
int r2_c = round(r2*1e3)/1e3;
if(r2_c==0){
cout << "";
}else{
if(r2 > 0){
cout << "+ "<< round(r2*1e3)/1e3;
}else if(r2 < 0){
cout << "- " << abs(round(r2*1e3)/1e3);
}
}
// if(r2 > 0){
// cout << "+ " << round(r2*1e3)/1e3;
// }else{
// cout << "- " << abs(round(r2*1e3)/1e3);
// }
}else{
cout << "??";
}
return 0;
} | # 0735, 2024-11-02 11:02:36, PPPPPPP-PPPPPPP--PPPP-PP (83%)
// 200
#include<bits/stdc++.h>
using namespace std;
float zig_xP2(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += (val[i-1].first*val[i-1].first);
}
return sum;
}
float zig_x(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += val[i-1].first;
}
return sum;
}
float zig_y(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += val[i-1].second;
}
return sum;
}
float zig_xy(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += val[i-1].first*val[i-1].second;
}
return sum;
}
float m(int N, vector<pair<float, float>> &val){
float zX = zig_x(N, val);
float zY = zig_y(N, val);
float zXY = zig_xy(N, val);
float zX2 = zig_xP2(N, val);
return ( (N*zXY)-(zX*zY) )/ ( (N*zX2)-pow(zX, 2) );
}
float bF(float m, int N, vector<pair<float, float>> &val){
float zX = zig_x(N, val);
float zY = zig_y(N, val);
float zXY = zig_xy(N, val);
float zX2 = zig_xP2(N, val);
return (zY-(m*zX))/N;
}
int main(){
int N; cin >> N;
string func; cin >> func;
float a,b;
vector<pair<float, float>> dat;
for(int i=0; i<N; i++){
cin >> a >> b;
dat.push_back({a, b});
}
if(func == "mb"){
float r1 = m(N, dat);
float r2 = bF(r1, N, dat);
cout << round(r1*1e3)/1e3 << endl;
cout << round(r2*1e3)/1e3 << endl;
}else if(func == "func"){
float r1 = m(N, dat);
float r2 = bF(r1, N, dat);
cout << "y = ";
// show m
int r1_c = round(r1*1e3)/1e3;
if(r1_c!=1 || r1_c!= -1 || r1_c==0){
if(r1_c == 1){
cout << "x ";
}else if(r1_c == -1){
cout << "-x ";
}else if(r1_c == 0){
cout << "";
}else{
cout << round(r1*1e3)/1e3 << "x ";
}
}else{
if(r1 > 0){
cout << "x ";
}else if(r1 < 0){
cout << "-x ";
}
}
// sign right
int r2_c = round(r2*1e3)/1e3;
if(r2_c==0){
cout << "";
}else{
if(r2 > 0){
cout << "+ "<< round(r2*1e3)/1e3;
}else if(r2 < 0){
cout << "- " << abs(round(r2*1e3)/1e3);
}
}
// if(r2 > 0){
// cout << "+ " << round(r2*1e3)/1e3;
// }else{
// cout << "- " << abs(round(r2*1e3)/1e3);
// }
}else{
cout << "??";
}
return 0;
} | # 0736, 2024-11-02 11:13:23, PPPPPPP-PPPPPPPP-PPPPPPP (91%)
// 200
#include<bits/stdc++.h>
using namespace std;
float zig_xP2(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += (val[i-1].first*val[i-1].first);
}
return sum;
}
float zig_x(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += val[i-1].first;
}
return sum;
}
float zig_y(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += val[i-1].second;
}
return sum;
}
float zig_xy(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += val[i-1].first*val[i-1].second;
}
return sum;
}
float m(int N, vector<pair<float, float>> &val){
float zX = zig_x(N, val);
float zY = zig_y(N, val);
float zXY = zig_xy(N, val);
float zX2 = zig_xP2(N, val);
return ( (N*zXY)-(zX*zY) )/ ( (N*zX2)-pow(zX, 2) );
}
float bF(float m, int N, vector<pair<float, float>> &val){
float zX = zig_x(N, val);
float zY = zig_y(N, val);
float zXY = zig_xy(N, val);
float zX2 = zig_xP2(N, val);
return (zY-(m*zX))/N;
}
int main(){
int N; cin >> N;
string func; cin >> func;
float a,b;
vector<pair<float, float>> dat;
for(int i=0; i<N; i++){
cin >> a >> b;
dat.push_back({a, b});
}
if(func == "mb"){
float r1 = m(N, dat);
float r2 = bF(r1, N, dat);
cout << round(r1*1e3)/1e3 << endl;
cout << round(r2*1e3)/1e3 << endl;
}else if(func == "func"){
float r1 = m(N, dat);
float r2 = bF(r1, N, dat);
cout << "y = ";
// show m
int r1_c = round(r1*1e3)/1e3;
bool m_nshow = false;
if(r1_c!=1 || r1_c!= -1 || r1_c==0){
if(r1_c == 1){
cout << "x ";
}else if(r1_c == -1){
cout << "-x ";
}else if(r1_c == 0){
cout << "";
m_nshow = true;
}else{
cout << round(r1*1e3)/1e3 << "x ";
}
}else{
if(r1 > 0){
cout << "x ";
}else if(r1 < 0){
cout << "-x ";
}
}
// sign right
int r2_c = round(r2*1e3)/1e3;
if(r2_c==0){
if(m_nshow){
cout << "0";
}
cout << "";
}else{
if(r2 > 0){
if(m_nshow){
cout << "+"<< round(r2*1e3)/1e3;
}else{
cout << "+ "<< round(r2*1e3)/1e3;
}
}else if(r2 < 0){
if(m_nshow){
cout << "-" << abs(round(r2*1e3)/1e3);
}else{
cout << "- " << abs(round(r2*1e3)/1e3);
}
}
}
// if(r2 > 0){
// cout << "+ " << round(r2*1e3)/1e3;
// }else{
// cout << "- " << abs(round(r2*1e3)/1e3);
// }
}else{
cout << "??";
}
return 0;
} | # 0737, 2024-11-02 11:50:12, PPPPPPP-PPPPPPPP-PPPPPPP (91%)
// 200
#include<bits/stdc++.h>
using namespace std;
float zig_xP2(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += (val[i-1].first*val[i-1].first);
}
return sum;
}
float zig_x(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += val[i-1].first;
}
return sum;
}
float zig_y(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += val[i-1].second;
}
return sum;
}
float zig_xy(int N, vector<pair<float, float>> &val){
float sum = 0;
for(int i=1; i<=N; i++){
sum += val[i-1].first*val[i-1].second;
}
return sum;
}
float m(int N, vector<pair<float, float>> &val){
float zX = zig_x(N, val);
float zY = zig_y(N, val);
float zXY = zig_xy(N, val);
float zX2 = zig_xP2(N, val);
return ( (N*zXY)-(zX*zY) )/ ( (N*zX2)-pow(zX, 2) );
}
float bF(float m, int N, vector<pair<float, float>> &val){
float zX = zig_x(N, val);
float zY = zig_y(N, val);
float zXY = zig_xy(N, val);
float zX2 = zig_xP2(N, val);
return (zY-(m*zX))/N;
}
int main(){
int N; cin >> N;
string func; cin >> func;
float a,b;
vector<pair<float, float>> dat;
for(int i=0; i<N; i++){
cin >> a >> b;
dat.push_back({a, b});
}
if(func == "mb"){
float r1 = m(N, dat);
float r2 = bF(r1, N, dat);
cout << round(r1*1e3)/1e3 << endl;
cout << round(r2*1e3)/1e3 << endl;
}else if(func == "func"){
float r1 = m(N, dat);
float r2 = bF(r1, N, dat);
cout << "y = ";
// show m
int r1_c = round(r1*1e3)/1e3;
bool m_nshow = false;
if(r1_c!=1 || r1_c!= -1 || r1_c==0){
if(r1_c == 1){
cout << "x ";
}else if(r1_c == -1){
cout << "-x ";
}else if(r1_c == 0){
cout << "";
m_nshow = true;
}else{
cout << round(r1*1e3)/1e3 << "x ";
}
}else{
if(r1 > 0){
cout << "x ";
}else if(r1 < 0){
cout << "-x ";
}
}
// sign right
int r2_c = round(r2*1e3)/1e3;
if(r2_c==0){
if(m_nshow){
cout << "0";
}
cout << "";
}else{
if(r2 > 0){
if(m_nshow){
cout << "+"<< round(r2*1e3)/1e3;
}else{
cout << "+ "<< round(r2*1e3)/1e3;
}
}else if(r2 < 0){
if(m_nshow){
cout << "-" << abs(round(r2*1e3)/1e3);
}else{
cout << "- " << abs(round(r2*1e3)/1e3);
}
}
}
// if(r2 > 0){
// cout << "+ " << round(r2*1e3)/1e3;
// }else{
// cout << "- " << abs(round(r2*1e3)/1e3);
// }
}else{
cout << "??";
}
return 0;
} |
# 0738, 2024-11-02 09:58:58, ------------------------ (0%)
#include<bits/stdc++.h>
using namespace std;
int main() {
int N;
string s;
float x,y;
vector<float> Vx,Vy;
cin >> N >> s;
while(N--) {
cin >> x >> y;
Vx.push_back(x);
Vy.push_back(y);
}
if(s=="mb") {
float sum1 = 0,sum2 = 0,sum3 = 0,sum4 = 0;
for(int i=0 ; i<N ; ++i) {
sum1 += Vx[i]*Vy[i];
sum2 += Vx[i];
sum3 += Vy[i];
sum4 += pow(Vx[i],2);
}
float m = ((N*sum1)-(sum2*sum3)) / ((N*sum4)-pow(sum2,2));
cout << m << endl;
cout << (sum3-(m*sum2)) / (N) << endl;
}
} | # 0739, 2024-11-02 10:05:26, PPPPPPPPPP-------------- (41%)
#include<bits/stdc++.h>
using namespace std;
int main() {
int N,amount;
string s;
float x,y;
vector<float> Vx,Vy;
cin >> N >> s;
amount = N;
while(N--) {
cin >> x >> y;
Vx.push_back(x);
Vy.push_back(y);
}
if(s=="mb") {
float sum1 = 0,sum2 = 0,sum3 = 0,sum4 = 0;
for(int i=0 ; i<amount ; ++i) {
sum1 += Vx[i]*Vy[i];
sum2 += Vx[i];
sum3 += Vy[i];
sum4 += pow(Vx[i],2);
}
float m = ((amount*sum1)-(sum2*sum3)) / ((amount*sum4)-pow(sum2,2));
float b = (sum3-(m*sum2)) / (amount);
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
} | # 0740, 2024-11-02 10:26:13, Compilation error (0%)
#include<bits/stdc++.h>
using namespace std;
int main() {
int N,amount;
string s;
float x,y;
vector<float> Vx,Vy;
cin >> N >> s;
amount = N;
while(N--) {
cin >> x >> y;
Vx.push_back(x);
Vy.push_back(y);
}
float sum1 = 0,sum2 = 0,sum3 = 0,sum4 = 0;
for(int i=0 ; i<amount ; ++i) {
sum1 += Vx[i]*Vy[i];
sum2 += Vx[i];
sum3 += Vy[i];
sum4 += pow(Vx[i],2);
}
float m = ((amount*sum1)-(sum2*sum3)) / ((amount*sum4)-pow(sum2,2));
float b = (sum3-(m*sum2)) / (amount);
if(s=="mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else {
cout << "y = ";
if(round(m*1e3)/1e3 == -1) {
cout << "-x ";
}else if(round(m*1e3)/1e3 < -1.00000 || round(m*1e3)/1e3 > 1.00000) {
cout << round(m*1e3)/1e3 << "x ";
}else if(round(m*1e3)/1e3 == 1) {
cout << "x ";
}
if(round(b*1e3)/1e3 < 0.00000) {
cout << "- " << -round(b*1e3)/1e3;
}else if(round(b*1e3)/1e3 > 0.00000) {
cout << "+ " << round(b*1e3)/1e3;
}
} | # 0741, 2024-11-02 10:27:15, PPPPPPPPPPPPPPP--PPPP-PP (87%)
#include<bits/stdc++.h>
using namespace std;
int main() {
int N,amount;
string s;
float x,y;
vector<float> Vx,Vy;
cin >> N >> s;
amount = N;
while(N--) {
cin >> x >> y;
Vx.push_back(x);
Vy.push_back(y);
}
float sum1 = 0,sum2 = 0,sum3 = 0,sum4 = 0;
for(int i=0 ; i<amount ; ++i) {
sum1 += Vx[i]*Vy[i];
sum2 += Vx[i];
sum3 += Vy[i];
sum4 += pow(Vx[i],2);
}
float m = ((amount*sum1)-(sum2*sum3)) / ((amount*sum4)-pow(sum2,2));
float b = (sum3-(m*sum2)) / (amount);
if(s=="mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else {
cout << "y = ";
if(round(m*1e3)/1e3 == -1) {
cout << "-x ";
}else if(round(m*1e3)/1e3 < -1.00000 || round(m*1e3)/1e3 > 1.00000) {
cout << round(m*1e3)/1e3 << "x ";
}else if(round(m*1e3)/1e3 == 1) {
cout << "x ";
}
if(round(b*1e3)/1e3 < 0.00000) {
cout << "- " << -round(b*1e3)/1e3;
}else if(round(b*1e3)/1e3 > 0.00000) {
cout << "+ " << round(b*1e3)/1e3;
}
}
} | # 0742, 2024-11-02 10:28:32, PPPPPPPPPPPPPPP--PPPP-PP (87%)
#include<bits/stdc++.h>
using namespace std;
int main() {
int N,amount;
string s;
float x,y;
vector<float> Vx,Vy;
cin >> N >> s;
amount = N;
while(N--) {
cin >> x >> y;
Vx.push_back(x);
Vy.push_back(y);
}
float sum1 = 0,sum2 = 0,sum3 = 0,sum4 = 0;
for(int i=0 ; i<amount ; ++i) {
sum1 += Vx[i]*Vy[i];
sum2 += Vx[i];
sum3 += Vy[i];
sum4 += pow(Vx[i],2);
}
float m = ((amount*sum1)-(sum2*sum3)) / ((amount*sum4)-pow(sum2,2));
float b = (sum3-(m*sum2)) / (amount);
if(s=="mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else {
cout << "y = ";
if(round(m*1e3)/1e3 == -1.0000) {
cout << "-x ";
}else if(round(m*1e3)/1e3 < -1.00000 || round(m*1e3)/1e3 > 1.00000) {
cout << round(m*1e3)/1e3 << "x ";
}else if(round(m*1e3)/1e3 == 1.0000) {
cout << "x ";
}
if(round(b*1e3)/1e3 < 0.00000) {
cout << "- " << -round(b*1e3)/1e3;
}else if(round(b*1e3)/1e3 > 0.00000) {
cout << "+ " << round(b*1e3)/1e3;
}
}
} | # 0743, 2024-11-02 10:33:46, PPPPPPPPPPPPPPPP-PPPP-PP (91%)
#include<bits/stdc++.h>
using namespace std;
int main() {
int N,amount;
string s;
float x,y;
vector<float> Vx,Vy;
cin >> N >> s;
amount = N;
while(N--) {
cin >> x >> y;
Vx.push_back(x);
Vy.push_back(y);
}
float sum1 = 0,sum2 = 0,sum3 = 0,sum4 = 0;
for(int i=0 ; i<amount ; ++i) {
sum1 += Vx[i]*Vy[i];
sum2 += Vx[i];
sum3 += Vy[i];
sum4 += pow(Vx[i],2);
}
float m = ((amount*sum1)-(sum2*sum3)) / ((amount*sum4)-pow(sum2,2));
float b = (sum3-(m*sum2)) / (amount);
if(s=="mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else {
cout << "y = ";
if(m==0 && b==0)cout << "0";
if(round(m*1e3)/1e3 == -1.0000) {
cout << "-x ";
}else if(round(m*1e3)/1e3 < -1.00000 || round(m*1e3)/1e3 > 1.00000) {
cout << round(m*1e3)/1e3 << "x ";
}else if(round(m*1e3)/1e3 == 1.0000) {
cout << "x ";
}
if(round(b*1e3)/1e3 < 0.00000) {
cout << "- " << -round(b*1e3)/1e3;
}else if(round(b*1e3)/1e3 > 0.00000) {
cout << "+ " << round(b*1e3)/1e3;
}
}
} | # 0744, 2024-11-02 10:35:26, PPPPPPPPPPPPPPP--PPPP-PP (87%)
#include<bits/stdc++.h>
using namespace std;
int main() {
int N,amount;
string s;
float x,y;
vector<float> Vx,Vy;
cin >> N >> s;
amount = N;
while(N--) {
cin >> x >> y;
Vx.push_back(x);
Vy.push_back(y);
}
float sum1 = 0,sum2 = 0,sum3 = 0,sum4 = 0;
for(int i=0 ; i<amount ; ++i) {
sum1 += Vx[i]*Vy[i];
sum2 += Vx[i];
sum3 += Vy[i];
sum4 += pow(Vx[i],2);
}
float m = ((amount*sum1)-(sum2*sum3)) / ((amount*sum4)-pow(sum2,2));
float b = (sum3-(m*sum2)) / (amount);
if(s=="mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else {
cout << "y = ";
if(m==0 && b==0)cout << "0";
if(round(m*1e3)/1e3 == -1.0000) {
cout << "-x ";
}else if(round(m*1e3)/1e3 < -1.00000 || round(m*1e3)/1e3 > 1.00000) {
cout << round(m*1e3)/1e3 << "x ";
}else if(round(m*1e3)/1e3 == 1.0000) {
cout << "x ";
}else {
cout << round(m*1e3)/1e3 << "x ";
}
if(round(b*1e3)/1e3 < 0.00000) {
cout << "- " << -round(b*1e3)/1e3;
}else if(round(b*1e3)/1e3 > 0.00000) {
cout << "+ " << round(b*1e3)/1e3;
}
}
} | # 0745, 2024-11-02 10:37:05, PPPPPPPPPPPPPPPP-PPPP-PP (91%)
#include<bits/stdc++.h>
using namespace std;
int main() {
int N,amount;
string s;
float x,y;
vector<float> Vx,Vy;
cin >> N >> s;
amount = N;
while(N--) {
cin >> x >> y;
Vx.push_back(x);
Vy.push_back(y);
}
float sum1 = 0,sum2 = 0,sum3 = 0,sum4 = 0;
for(int i=0 ; i<amount ; ++i) {
sum1 += Vx[i]*Vy[i];
sum2 += Vx[i];
sum3 += Vy[i];
sum4 += pow(Vx[i],2);
}
float m = ((amount*sum1)-(sum2*sum3)) / ((amount*sum4)-pow(sum2,2));
float b = (sum3-(m*sum2)) / (amount);
if(s=="mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else {
cout << "y = ";
if(m==0 && b==0)cout << "0";
if(round(m*1e3)/1e3 == -1.0000) {
cout << "-x ";
}else if(round(m*1e3)/1e3 < -1.00000 || round(m*1e3)/1e3 > 1.00000) {
cout << round(m*1e3)/1e3 << "x ";
}else if(round(m*1e3)/1e3 == 1.0000) {
cout << "x ";
}else if(round(m*1e3)/1e3 > 0.00000 && round(m*1e3)/1e3 < 1.00000) {
cout << round(m*1e3)/1e3 << "x ";
}
if(round(b*1e3)/1e3 < 0.00000) {
cout << "- " << -round(b*1e3)/1e3;
}else if(round(b*1e3)/1e3 > 0.00000) {
cout << "+ " << round(b*1e3)/1e3;
}
}
} |
# 0746, 2024-11-02 09:36:31, PPPPPPPPPP-------------- (41%)
#include<bits/stdc++.h>
using namespace std;
int main(){
//find m,b
int n;cin>>n;
string op;cin>>op;
float x,y;
vector<float> X;
vector<float> Y;
for(int i=0;i<n;i++){
cin>>x>>y;
X.push_back(x);
Y.push_back(y);
}
float sum_x=0,sum_y=0,sum_xy=0,sum_xsq =0;
for(int i=0;i<n;i++){
sum_x+=X[i];
sum_y+=Y[i];
sum_xy+=X[i]*Y[i];
sum_xsq+=X[i]*X[i];
}
float m = (n*sum_xy-sum_x*sum_y)/(n*sum_xsq-sum_x*sum_x);
float b = (sum_y-m*sum_x)/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(op=="mb"){
cout<<m<<endl;
cout<<b;
return 0;
}
} | # 0747, 2024-11-02 09:43:41, PPPPPPPPPP-----PPP--P-PP (66%)
#include<bits/stdc++.h>
using namespace std;
int main(){
//find m,b
int n;cin>>n;
string op;cin>>op;
float x,y;
vector<float> X;
vector<float> Y;
for(int i=0;i<n;i++){
cin>>x>>y;
X.push_back(x);
Y.push_back(y);
}
float sum_x=0,sum_y=0,sum_xy=0,sum_xsq =0;
for(int i=0;i<n;i++){
sum_x+=X[i];
sum_y+=Y[i];
sum_xy+=X[i]*Y[i];
sum_xsq+=X[i]*X[i];
}
float m = (n*sum_xy-sum_x*sum_y)/(n*sum_xsq-sum_x*sum_x);
float b = (sum_y-m*sum_x)/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(op=="mb"){
cout<<m<<endl;
cout<<b;
return 0;
}
else{
cout<<"y = ";
bool neg = false;
if(b<0){
neg = true;
}
bool passx = false;
if(m==0){
passx = true;
}
else if(m==-1){
cout<<"-";
}
if(!passx){
if(!neg){
cout<<"x + ";
}else{
cout<<"x - ";
}
}
if(b==0){
cout<<"0";
}else{
cout<<abs(b);
}
}
} | # 0748, 2024-11-02 09:46:54, PPPPPPPPPPPPPPPPP---P--P (79%)
#include<bits/stdc++.h>
using namespace std;
int main(){
//find m,b
int n;cin>>n;
string op;cin>>op;
float x,y;
vector<float> X;
vector<float> Y;
for(int i=0;i<n;i++){
cin>>x>>y;
X.push_back(x);
Y.push_back(y);
}
float sum_x=0,sum_y=0,sum_xy=0,sum_xsq =0;
for(int i=0;i<n;i++){
sum_x+=X[i];
sum_y+=Y[i];
sum_xy+=X[i]*Y[i];
sum_xsq+=X[i]*X[i];
}
float m = (n*sum_xy-sum_x*sum_y)/(n*sum_xsq-sum_x*sum_x);
float b = (sum_y-m*sum_x)/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(op=="mb"){
cout<<m<<endl;
cout<<b;
return 0;
}
else{
cout<<"y = ";
bool neg = false;
if(b<0){
neg = true;
}
bool passx = false;
if(m==0){
passx = true;
}
else if(m==-1){
cout<<"-";
}
else{
cout<<m;
}
if(!passx){
if(!neg){
cout<<"x + ";
}else{
cout<<"x - ";
}
}
if(b==0){
cout<<"0";
}else{
cout<<abs(b);
}
}
} | # 0749, 2024-11-02 09:49:50, PPPPPPPPPPPPPPPPPP--P-PP (87%)
#include<bits/stdc++.h>
using namespace std;
int main(){
//find m,b
int n;cin>>n;
string op;cin>>op;
float x,y;
vector<float> X;
vector<float> Y;
for(int i=0;i<n;i++){
cin>>x>>y;
X.push_back(x);
Y.push_back(y);
}
float sum_x=0,sum_y=0,sum_xy=0,sum_xsq =0;
for(int i=0;i<n;i++){
sum_x+=X[i];
sum_y+=Y[i];
sum_xy+=X[i]*Y[i];
sum_xsq+=X[i]*X[i];
}
float m = (n*sum_xy-sum_x*sum_y)/(n*sum_xsq-sum_x*sum_x);
float b = (sum_y-m*sum_x)/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(op=="mb"){
cout<<m<<endl;
cout<<b;
return 0;
}
else{
cout<<"y = ";
bool neg = false;
if(b<0){
neg = true;
}
bool passx = false;
if(m==0){
passx = true;
}
else if(m==-1){
cout<<"-";
}
else{
if(m!=1){
cout<<m;
}
}
if(!passx){
if(!neg){
cout<<"x + ";
}else{
cout<<"x - ";
}
}
if(b==0){
cout<<"0";
}else{
cout<<abs(b);
}
}
} | # 0750, 2024-11-02 09:52:21, PPPPPPPPPPPPPPP-PP--P-PP (83%)
#include<bits/stdc++.h>
using namespace std;
int main(){
//find m,b
int n;cin>>n;
string op;cin>>op;
float x,y;
vector<float> X;
vector<float> Y;
for(int i=0;i<n;i++){
cin>>x>>y;
X.push_back(x);
Y.push_back(y);
}
float sum_x=0,sum_y=0,sum_xy=0,sum_xsq =0;
for(int i=0;i<n;i++){
sum_x+=X[i];
sum_y+=Y[i];
sum_xy+=X[i]*Y[i];
sum_xsq+=X[i]*X[i];
}
float m = (n*sum_xy-sum_x*sum_y)/(n*sum_xsq-sum_x*sum_x);
float b = (sum_y-m*sum_x)/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(op=="mb"){
cout<<m<<endl;
cout<<b;
return 0;
}
else{
cout<<"y = ";
bool neg = false;
if(b<0){
neg = true;
}
bool passx = false;
if(m==0){
passx = true;
}
else if(m==-1){
cout<<"-";
}
else{
if(m!=1){
cout<<m;
}
}
if(!passx){
if(!neg){
cout<<"x + ";
}else{
cout<<"x - ";
}
}
if(b==0){
cout<<"";
}else{
cout<<abs(b);
}
}
} | # 0751, 2024-11-02 09:54:17, PPPPPPPPPPPPPPP-PP--P-PP (83%)
#include<bits/stdc++.h>
using namespace std;
int main(){
//find m,b
int n;cin>>n;
string op;cin>>op;
float x,y;
vector<float> X;
vector<float> Y;
for(int i=0;i<n;i++){
cin>>x>>y;
X.push_back(x);
Y.push_back(y);
}
float sum_x=0,sum_y=0,sum_xy=0,sum_xsq =0;
for(int i=0;i<n;i++){
sum_x+=X[i];
sum_y+=Y[i];
sum_xy+=X[i]*Y[i];
sum_xsq+=X[i]*X[i];
}
float m = (n*sum_xy-sum_x*sum_y)/(n*sum_xsq-sum_x*sum_x);
float b = (sum_y-m*sum_x)/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(op=="mb"){
cout<<m<<endl;
cout<<b;
return 0;
}
else{
cout<<"y = ";
bool neg = false;
if(b<0){
neg = true;
}
bool passx = false;
if(m==0){
passx = true;
}
else if(m==-1){
cout<<"-";
}
else{
if(m!=1){
cout<<m;
}
}
if(!passx){
if(!neg&&b!=0){
cout<<"x + ";
}else if(b!=0){
cout<<"x - ";
}else{
cout<<x;
}
}
if(b==0){
cout<<"";
}else{
cout<<abs(b);
}
}
} | # 0752, 2024-11-02 09:55:04, PPPPPPPPPPPPPPP-PPPPP-PP (91%)
#include<bits/stdc++.h>
using namespace std;
int main(){
//find m,b
int n;cin>>n;
string op;cin>>op;
float x,y;
vector<float> X;
vector<float> Y;
for(int i=0;i<n;i++){
cin>>x>>y;
X.push_back(x);
Y.push_back(y);
}
float sum_x=0,sum_y=0,sum_xy=0,sum_xsq =0;
for(int i=0;i<n;i++){
sum_x+=X[i];
sum_y+=Y[i];
sum_xy+=X[i]*Y[i];
sum_xsq+=X[i]*X[i];
}
float m = (n*sum_xy-sum_x*sum_y)/(n*sum_xsq-sum_x*sum_x);
float b = (sum_y-m*sum_x)/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(op=="mb"){
cout<<m<<endl;
cout<<b;
return 0;
}
else{
cout<<"y = ";
bool neg = false;
if(b<0){
neg = true;
}
bool passx = false;
if(m==0){
passx = true;
}
else if(m==-1){
cout<<"-";
}
else{
if(m!=1){
cout<<m;
}
}
if(!passx){
if(!neg&&b!=0){
cout<<"x + ";
}else if(b!=0){
cout<<"x - ";
}else{
cout<<"x";
}
}
if(b==0){
cout<<"";
}else{
cout<<abs(b);
}
}
} |
# 0753, 2024-11-02 14:21:39, ------------------------ (0%)
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
using namespace std;
int main() {
int pnts; string mode; cin >> pnts >> mode;
vector<pair<float,float>> testsample(pnts);
float xi, yi;
while(cin >> xi){
cin >> yi;
testsample.push_back(make_pair(xi, yi));
}
float sumXY = 0;
float sumX = 0;
float sumY = 0;
float sqrX = 0;
for(int i=0; i<pnts; i++){
sumX += testsample[i].first;
}
for(int i=0; i<pnts; i++){
sumY += testsample[i].second;
}
for(int i=0; i<pnts; i++){
sumXY += testsample[i].first * testsample[i].second;
}
for(int i=0; i<pnts; i++){
sqrX += testsample[i].first * testsample[i].first;
}
float m = pnts*sumXY - sumX*sumY; m/=(pnts*sqrX-sumX*sumX);
float b = sumY-m*sumX; b/=pnts;
if(mode == "mb"){
cout << round(m*1e3)/1e3 << '\n';
cout << round(b*1e3)/1e3 << '\n';
} else {
cout << "y = " << round(m*1e3)/1e3 << " + " << round(b*1e3)/1e3;
}
} | # 0754, 2024-11-02 14:31:30, ------------------------ (0%)
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
using namespace std;
int main() {
int pnts; string mode; cin >> pnts >> mode;
vector<pair<float,float>> testsample;
float xi, yi;
for(int i=0; i<pnts; i++){
cin >> xi >> yi;
testsample.push_back(make_pair(xi, yi));
}
cout << "\n------------------------------------------------------\n";
float sumXY = 0;
float sumX = 0;
float sumY = 0;
float sqrX = 0;
for(int i=0; i<pnts; i++){
sumX += testsample[i].first;
}
cout << sumX << '\n';
for(int i=0; i<pnts; i++){
sumY += testsample[i].second;
}
cout << sumY << '\n';
for(int i=0; i<pnts; i++){
sumXY += testsample[i].first * testsample[i].second;
}
cout << sumXY << '\n';
for(int i=0; i<pnts; i++){
sqrX += testsample[i].first * testsample[i].first;
}
cout << sqrX << '\n';
float m = pnts*sumXY - sumX*sumY; m/=(pnts*sqrX-sumX*sumX);
float b = sumY-m*sumX; b/=pnts;
if(mode == "mb"){
cout << round(m*1e3)/1e3 << '\n';
cout << round(b*1e3)/1e3 << '\n';
} else {
cout << "y = " << round(m*1e3)/1e3 << " + " << round(b*1e3)/1e3;
}
} | # 0755, 2024-11-02 14:32:48, PPPPPPPPPP-------------- (41%)
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
using namespace std;
int main() {
int pnts; string mode; cin >> pnts >> mode;
vector<pair<float,float>> testsample;
float xi, yi;
for(int i=0; i<pnts; i++){
cin >> xi >> yi;
testsample.push_back(make_pair(xi, yi));
}
//cout << "\n------------------------------------------------------\n";
float sumXY = 0;
float sumX = 0;
float sumY = 0;
float sqrX = 0;
for(int i=0; i<pnts; i++){
sumX += testsample[i].first;
}
//cout << sumX << '\n';
for(int i=0; i<pnts; i++){
sumY += testsample[i].second;
}
//cout << sumY << '\n';
for(int i=0; i<pnts; i++){
sumXY += testsample[i].first * testsample[i].second;
}
//cout << sumXY << '\n';
for(int i=0; i<pnts; i++){
sqrX += testsample[i].first * testsample[i].first;
}
//cout << sqrX << '\n';
float m = pnts*sumXY - sumX*sumY; m/=(pnts*sqrX-sumX*sumX);
float b = sumY-m*sumX; b/=pnts;
if(mode == "mb"){
cout << round(m*1e3)/1e3 << '\n';
cout << round(b*1e3)/1e3 << '\n';
} else {
cout << "y = " << round(m*1e3)/1e3 << " + " << round(b*1e3)/1e3;
}
} | # 0756, 2024-11-02 14:47:15, PPPPPPPPPPPPPPPPPP--PPPP (91%)
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
using namespace std;
int main() {
int pnts; string mode; cin >> pnts >> mode;
vector<pair<float,float>> testsample;
float xi, yi;
for(int i=0; i<pnts; i++){
cin >> xi >> yi;
testsample.push_back(make_pair(xi, yi));
}
//cout << "\n------------------------------------------------------\n";
float sumXY = 0;
float sumX = 0;
float sumY = 0;
float sqrX = 0;
for(int i=0; i<pnts; i++){
sumX += testsample[i].first;
}
//cout << sumX << '\n';
for(int i=0; i<pnts; i++){
sumY += testsample[i].second;
}
//cout << sumY << '\n';
for(int i=0; i<pnts; i++){
sumXY += testsample[i].first * testsample[i].second;
}
//cout << sumXY << '\n';
for(int i=0; i<pnts; i++){
sqrX += testsample[i].first * testsample[i].first;
}
//cout << sqrX << '\n';
float m = pnts*sumXY - sumX*sumY; m/=(pnts*sqrX-sumX*sumX);
float b = sumY-m*sumX; b/=pnts;
float finalm = round(m*1e3)/1e3;
float finalb = round(b*1e3)/1e3;
if(mode == "mb"){
cout << finalm << '\n';
cout << finalb << '\n';
} else if(mode == "func") {
if(finalm==0&&finalb==0){
cout << "y = 0";
} else if(finalm == 0 && finalb != 0){
cout << "y = " << finalb;
} else if(finalb == 0 && finalm != 0){
cout << "y = " << finalm;
} else if(finalm == -1){
if(finalb > 0){cout << "y = -x + " << finalb;}
else if(finalb < 0){cout << "y = -x - " << (-1)*finalb;}
} else if(finalm == 1){
if(finalb > 0){cout << "y = x + " << finalb;}
else if(finalb < 0){cout << "y = x - " << (-1)*finalb;}
} else {
if(finalb > 0){cout << "y = " << finalm <<"x + " << finalb;}
else if(finalb < 0){cout << "y = " << finalm <<"x - " << (-1)*finalb;}
}
}
} | # 0757, 2024-11-02 14:48:54, PPPPPPPPPPPPPPPPPP--PPPP (91%)
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
using namespace std;
int main() {
int pnts; string mode; cin >> pnts >> mode;
vector<pair<float,float>> testsample;
float xi, yi;
for(int i=0; i<pnts; i++){
cin >> xi >> yi;
testsample.push_back(make_pair(xi, yi));
}
//cout << "\n------------------------------------------------------\n";
float sumXY = 0;
float sumX = 0;
float sumY = 0;
float sqrX = 0;
for(int i=0; i<pnts; i++){
sumX += testsample[i].first;
}
//cout << sumX << '\n';
for(int i=0; i<pnts; i++){
sumY += testsample[i].second;
}
//cout << sumY << '\n';
for(int i=0; i<pnts; i++){
sumXY += testsample[i].first * testsample[i].second;
}
//cout << sumXY << '\n';
for(int i=0; i<pnts; i++){
sqrX += testsample[i].first * testsample[i].first;
}
//cout << sqrX << '\n';
float m = pnts*sumXY - sumX*sumY; m/=(pnts*sqrX-sumX*sumX);
float b = sumY-m*sumX; b/=pnts;
float finalm = round(m*1e3)/1e3;
float finalb = round(b*1e3)/1e3;
if(mode == "mb"){
cout << finalm << '\n';
cout << finalb << '\n';
} else if(mode == "func") {
if(finalm==0&&finalb==0){
cout << "y = 0";
} else if(finalm == 0 && finalb != 0){
cout << "y = " << finalb;
} else if(finalb == 0 && finalm != 0){
cout << "y = " << finalm << "x";
} else if(finalm == -1){
if(finalb > 0){cout << "y = -x + " << finalb;}
else if(finalb < 0){cout << "y = -x - " << (-1)*finalb;}
} else if(finalm == 1){
if(finalb > 0){cout << "y = x + " << finalb;}
else if(finalb < 0){cout << "y = x - " << (-1)*finalb;}
} else {
if(finalb > 0){cout << "y = " << finalm <<"x + " << finalb;}
else if(finalb < 0){cout << "y = " << finalm <<"x - " << (-1)*finalb;}
}
}
} | # 0758, 2024-11-02 14:49:34, PPPPPPPPPPPPPPPPPP--PPPP (91%)
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
using namespace std;
int main() {
int pnts; string mode; cin >> pnts >> mode;
vector<pair<float,float>> testsample;
float xi, yi;
for(int i=0; i<pnts; i++){
cin >> xi >> yi;
testsample.push_back(make_pair(xi, yi));
}
//cout << "\n------------------------------------------------------\n";
float sumXY = 0;
float sumX = 0;
float sumY = 0;
float sqrX = 0;
for(int i=0; i<pnts; i++){
sumX += testsample[i].first;
}
//cout << sumX << '\n';
for(int i=0; i<pnts; i++){
sumY += testsample[i].second;
}
//cout << sumY << '\n';
for(int i=0; i<pnts; i++){
sumXY += testsample[i].first * testsample[i].second;
}
//cout << sumXY << '\n';
for(int i=0; i<pnts; i++){
sqrX += testsample[i].first * testsample[i].first;
}
//cout << sqrX << '\n';
float m = pnts*sumXY - sumX*sumY; m/=(pnts*sqrX-sumX*sumX);
float b = sumY-m*sumX; b/=pnts;
float finalm = round(m*1e3)/1e3;
float finalb = round(b*1e3)/1e3;
if(mode == "mb"){
cout << finalm << '\n';
cout << finalb << '\n';
} else if(mode == "func") {
if(finalm==0&&finalb==0){
cout << "y = 0";
} else if(finalm == 0 && finalb != 0){
cout << "y = " << finalb;
} else if(finalb == 0 && finalm != 0){
cout << "y = " << finalm << "x";
} else if(finalm == -1){
if(finalb > 0){cout << "y = -x + " << finalb;}
else if(finalb < 0){cout << "y = -x - " << (-1)*finalb;}
} else if(finalm == 1){
if(finalb > 0){cout << "y = x + " << finalb;}
else if(finalb < 0){cout << "y = x - " << (-1)*finalb;}
} else {
if(finalb > 0){cout << "y = " << finalm <<"x + " << finalb;}
else if(finalb < 0){cout << "y = " << finalm <<"x - " << (-1)*finalb;}
}
}
} |
# 0759, 2024-11-02 09:49:49, PPPPPPPPPP-------------- (41%)
#include<bits/stdc++.h>
#include <cmath>
using namespace std;
int main(){
int n ;
cin >> n;
string com;
cin >> com;
float x,y;
map<int ,float> valuex;
map<int ,float> valuey;
for (int i = 1; i <= n ; ++i)
{
cin >> x>> y;
valuex[i] = x;
valuey[i] = y ;
}
float xyi = 0;
float xi = 0;
float yi = 0 ;
float x2 = 0;
for (int i = 1; i <= n; ++i)
{
xyi += valuex[i]*valuey[i];
xi += valuex[i];
yi += valuey[i] ;
x2 += valuex[i]*valuex[i];
}
float m = (n*xyi - (xi*yi))/(n*x2-(xi*xi));
float b = (yi - m*xi)/n;
if(com == "mb"){
cout << round(m*1e3)/1e3 <<endl;
cout << round(b*1e3)/1e3 <<endl;
}
} | # 0760, 2024-11-02 10:04:40, PPPPPPPPPPPPPPP--------- (62%)
#include<bits/stdc++.h>
#include <cmath>
using namespace std;
int main(){
int n ;
cin >> n;
string com;
cin >> com;
float x,y;
map<int ,float> valuex;
map<int ,float> valuey;
for (int i = 1; i <= n ; ++i)
{
cin >> x>> y;
valuex[i] = x;
valuey[i] = y ;
}
float xyi = 0;
float xi = 0;
float yi = 0 ;
float x2 = 0;
for (int i = 1; i <= n; ++i)
{
xyi += valuex[i]*valuey[i];
xi += valuex[i];
yi += valuey[i] ;
x2 += valuex[i]*valuex[i];
}
float m = (n*xyi - (xi*yi))/(n*x2-(xi*xi));
float b = (yi - m*xi)/n;
if(com == "mb"){
cout << round(m*1e3)/1e3 <<endl;
cout << round(b*1e3)/1e3 <<endl;
} else if(com == "func") {
float k,j;
string out ="";
if(b>= 0 ){
out += " + " ;
k = round(b*1e3)/1e3 ;
} else {
out += " - " ;
k = (round(b*1e3)/1e3)*-1;
}
string outx ="";
if(m == 1 ){
cout << "y = " << "x" <<out<< k<<endl;
} else if(m==-1){
cout << "y = " << "-x" <<out<< k<<endl;
}
else{
cout << "y = " << round(m*1e3)/1e3<<"x" <<out<< k<<endl;
}
}
} | # 0761, 2024-11-02 10:10:14, PPPPPPPPPPPPPPP------P-- (66%)
#include<bits/stdc++.h>
#include <cmath>
using namespace std;
int main(){
int n ;
cin >> n;
string com;
cin >> com;
float x,y;
map<int ,float> valuex;
map<int ,float> valuey;
for (int i = 1; i <= n ; ++i)
{
cin >> x>> y;
valuex[i] = x;
valuey[i] = y ;
}
float xyi = 0;
float xi = 0;
float yi = 0 ;
float x2 = 0;
for (int i = 1; i <= n; ++i)
{
xyi += valuex[i]*valuey[i];
xi += valuex[i];
yi += valuey[i] ;
x2 += valuex[i]*valuex[i];
}
float m = (n*xyi - (xi*yi))/(n*x2-(xi*xi));
float b = (yi - m*xi)/n;
if(com == "mb"){
cout << round(m*1e3)/1e3 <<endl;
cout << round(b*1e3)/1e3 <<endl;
} else if(com == "func") {
float k,j;
string out ="";
if(b> 0 ){
out += " + " ;
k = round(b*1e3)/1e3 ;
} else if (b==0){
cout << "y = " << round(m*1e3)/1e3<<"x";
}
else {
out += " - " ;
k = (round(b*1e3)/1e3)*-1;
}
string outx ="";
if(m == 1 ){
cout << "y = " << "x" <<out<< k<<endl;
} else if(m==-1){
cout << "y = " << "-x" <<out<< k<<endl;
} else if(m== 0 ){
cout <<"y = " << round(b*1e3)/1e3<<endl;
}
else{
cout << "y = " << round(m*1e3)/1e3<<"x" <<out<< k<<endl;
}
}
} | # 0762, 2024-11-02 11:12:37, PPPPPPPPPPPPPPP---PP---- (70%)
#include<bits/stdc++.h>
#include <cmath>
using namespace std;
int main(){
int n ;
cin >> n;
string com;
cin >> com;
float x,y;
map<int ,float> valuex;
map<int ,float> valuey;
for (int i = 1; i <= n ; ++i)
{
cin >> x>> y;
valuex[i] = x;
valuey[i] = y ;
}
float xyi = 0;
float xi = 0;
float yi = 0 ;
float x2 = 0;
for (int i = 1; i <= n; ++i)
{
xyi += valuex[i]*valuey[i];
xi += valuex[i];
yi += valuey[i] ;
x2 += valuex[i]*valuex[i];
}
float m = (n*xyi - (xi*yi))/(n*x2-(xi*xi));
float b = (yi - m*xi)/n;
if(com == "mb"){
cout << round(m*1e3)/1e3 <<endl;
cout << round(b*1e3)/1e3 <<endl;
} else if(com == "func") {
float k;
string out ="";
if(b> 0 ){
out += " + " ;
k = round(b*1e3)/1e3 ;
}
else {
out += " - " ;
k = (round(b*1e3)/1e3)*-1;
}
string outx ="";
if(m == 1 ){
if (b == 0){
cout << "y = " << "x" <<endl;
} else {
cout << "y = " << "x" <<out<< k<<endl;
}
} else if(m == -1 ){
if (b == 0){
cout << "y = " << "-x" <<endl;
} else {
cout << "y = " << "-x" <<out<< k<<endl;
}
}else {
if (b == 0){
cout << "y = " << round(m*1e3)/1e3<<"x" <<endl;
} else {
cout << "y = " << round(m*1e3)/1e3<<"x" <<out<< k<<endl;
}
}
}
} | # 0763, 2024-11-02 11:20:04, PPPPPPPPPPPPPPPP-PPPP-PP (91%)
#include<bits/stdc++.h>
#include <cmath>
using namespace std;
int main(){
int n ;
cin >> n;
string com;
cin >> com;
float x,y;
map<int ,float> valuex;
map<int ,float> valuey;
for (int i = 1; i <= n ; ++i)
{
cin >> x>> y;
valuex[i] = x;
valuey[i] = y ;
}
float xyi = 0;
float xi = 0;
float yi = 0 ;
float x2 = 0;
for (int i = 1; i <= n; ++i)
{
xyi += valuex[i]*valuey[i];
xi += valuex[i];
yi += valuey[i] ;
x2 += valuex[i]*valuex[i];
}
float m = (n*xyi - (xi*yi))/(n*x2-(xi*xi));
float b = (yi - m*xi)/n;
if(com == "mb"){
cout << round(m*1e3)/1e3 <<endl;
cout << round(b*1e3)/1e3 <<endl;
} else if(com == "func") {
float k;
string out ="";
if(b> 0 ){
out += " + " ;
k = round(b*1e3)/1e3 ;
}
else {
out += " - " ;
k = (round(b*1e3)/1e3)*-1;
}
string outx ="";
if(round(m*1e3)/1e3 == 1 ){
if (round(b*1e3)/1e3 == 0){
cout << "y = " << "x" <<endl;
} else {
cout << "y = " << "x" <<out<< k<<endl;
}
} else if(round(m*1e3)/1e3 == -1 ){
if (round(b*1e3)/1e3 == 0){
cout << "y = " << "-x" <<endl;
} else {
cout << "y = " << "-x" <<out<< k<<endl;
}
}
else if(round(m*1e3)/1e3 ==0){
if (round(b*1e3)/1e3 == 0){
cout << "y = " << "0" <<endl;
} else {
cout << "y =" <<out<< k<<endl;
}
}
else {
if (round(b*1e3)/1e3 == 0){
cout << "y = " << round(m*1e3)/1e3<<"x" <<endl;
} else {
cout << "y = " << round(m*1e3)/1e3<<"x" <<out<< k<<endl;
}
}
}
} |
# 0764, 2024-11-02 14:23:50, -----PPPPP------PPPPPPPP (54%)
#include <bits/stdc++.h>
using namespace std ;
float xiyi(vector<float> xi, vector<float> yi, int N) {
float result = 0 ;
for(int i = 0 ; i < N ; i++) {
result += xi[i] * yi[i] ;
}
return result ;
}
float sumxi(vector<float> xi, int N) {
float result = 0 ;
for(int i = 0 ; i < N ; i++) {
result += xi[i] ;
}
return result ;
}
float sumyi(vector<float> yi, int N) {
float result = 0 ;
for(int i = 0 ; i < N ; i++) {
result += yi[i] ;
}
return result ;
}
float xipow(vector<float> xi, int N) {
float result = 0 ;
for(int i = 0 ; i < N ; i++) {
result += xi[i] * xi[i] ;
}
return result ;
}
int main() {
int N ; cin >> N ;
string command ; cin >> command ;
vector<float> xi, yi ;
float temp, temp2 ;
for(int i = 0 ; i < N ; i++) {
cin >> temp ; xi.push_back(temp) ;
cin >> temp2 ; yi.push_back(temp2) ;
}
float m = round(((N * xiyi(xi, yi, N) - sumxi(xi, N) * sumyi(yi, N)) / (N * xipow(xi, N) - pow(sumxi(xi, N), 2))) * 1e3) / 1e3 ;
float b = round(((sumyi(yi, N) - m * sumxi(xi, N)) / N) * 1e3) / 1e3 ;
if(command == "mb") {
cout << m << endl ;
cout << b ;
}
else {
cout << "y = " ;
if(m == 0 && b == 0) {
cout << "y = 0" ;
return 0 ;
}
if(m != 0) {
if(m != 1) {
if(m == -1) {
cout << "-" ;
}
else {
cout << m ;
}
}
cout << "x" ;
}
if(m == 0) {
cout << b ;
return 0 ;
}
if(b != 0) {
if(b < 0) {
cout << " - " << b * -1 ;
}
else {
cout << " + " << b ;
}
return 0 ;
}
else {
return 0 ;
}
}
} | # 0765, 2024-11-02 14:25:21, PPPPPPP-PPPPPPP-PPPPPPPP (91%)
#include <bits/stdc++.h>
using namespace std ;
float xiyi(vector<float> xi, vector<float> yi, int N) {
float result = 0 ;
for(int i = 0 ; i < N ; i++) {
result += xi[i] * yi[i] ;
}
return result ;
}
float sumxi(vector<float> xi, int N) {
float result = 0 ;
for(int i = 0 ; i < N ; i++) {
result += xi[i] ;
}
return result ;
}
float sumyi(vector<float> yi, int N) {
float result = 0 ;
for(int i = 0 ; i < N ; i++) {
result += yi[i] ;
}
return result ;
}
float xipow(vector<float> xi, int N) {
float result = 0 ;
for(int i = 0 ; i < N ; i++) {
result += xi[i] * xi[i] ;
}
return result ;
}
int main() {
int N ; cin >> N ;
string command ; cin >> command ;
vector<float> xi, yi ;
float temp, temp2 ;
for(int i = 0 ; i < N ; i++) {
cin >> temp ; xi.push_back(temp) ;
cin >> temp2 ; yi.push_back(temp2) ;
}
float m = ((N * xiyi(xi, yi, N) - sumxi(xi, N) * sumyi(yi, N)) / (N * xipow(xi, N) - pow(sumxi(xi, N), 2))) ;
float b = round(((sumyi(yi, N) - m * sumxi(xi, N)) / N) * 1e3) / 1e3 ;
m = round(m * 1e3) / 1e3 ;
if(command == "mb") {
cout << m << endl ;
cout << b ;
}
else {
cout << "y = " ;
if(m == 0 && b == 0) {
cout << "y = 0" ;
return 0 ;
}
if(m != 0) {
if(m != 1) {
if(m == -1) {
cout << "-" ;
}
else {
cout << m ;
}
}
cout << "x" ;
}
if(m == 0) {
cout << b ;
return 0 ;
}
if(b != 0) {
if(b < 0) {
cout << " - " << b * -1 ;
}
else {
cout << " + " << b ;
}
return 0 ;
}
else {
return 0 ;
}
}
} | # 0766, 2024-11-02 14:26:09, PPPPPPP-PPPPPPP-PPPPPPPP (91%)
#include <bits/stdc++.h>
using namespace std ;
float xiyi(vector<float> xi, vector<float> yi, int N) {
float result = 0 ;
for(int i = 0 ; i < N ; i++) {
result += xi[i] * yi[i] ;
}
return result ;
}
float sumxi(vector<float> xi, int N) {
float result = 0 ;
for(int i = 0 ; i < N ; i++) {
result += xi[i] ;
}
return result ;
}
float sumyi(vector<float> yi, int N) {
float result = 0 ;
for(int i = 0 ; i < N ; i++) {
result += yi[i] ;
}
return result ;
}
float xipow(vector<float> xi, int N) {
float result = 0 ;
for(int i = 0 ; i < N ; i++) {
result += xi[i] * xi[i] ;
}
return result ;
}
int main() {
long long int N ; cin >> N ;
string command ; cin >> command ;
vector<float> xi, yi ;
float temp, temp2 ;
for(long long int i = 0 ; i < N ; i++) {
cin >> temp ; xi.push_back(temp) ;
cin >> temp2 ; yi.push_back(temp2) ;
}
float m = ((N * xiyi(xi, yi, N) - sumxi(xi, N) * sumyi(yi, N)) / (N * xipow(xi, N) - pow(sumxi(xi, N), 2))) ;
float b = round(((sumyi(yi, N) - m * sumxi(xi, N)) / N) * 1e3) / 1e3 ;
m = round(m * 1e3) / 1e3 ;
if(command == "mb") {
cout << m << endl ;
cout << b ;
}
else {
cout << "y = " ;
if(m == 0 && b == 0) {
cout << "y = 0" ;
return 0 ;
}
if(m != 0) {
if(m != 1) {
if(m == -1) {
cout << "-" ;
}
else {
cout << m ;
}
}
cout << "x" ;
}
if(m == 0) {
cout << b ;
return 0 ;
}
if(b != 0) {
if(b < 0) {
cout << " - " << b * -1 ;
}
else {
cout << " + " << b ;
}
return 0 ;
}
else {
return 0 ;
}
}
} |
# 0767, 2024-11-02 10:43:23, PPPPPPPPPPPPPPPPPP--PPPP (91%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
string k;
cin >> n >> k;
float x, y;
vector<float> X;
vector<float> Y;
for (int i = 0; i < n; i++)
{
cin >> x >> y;
X.push_back(x);
Y.push_back(y);
}
float a = 0;
float b = 0, c = 0, d = 0;
float N = n;
for (int i = 0; i < n; i++)
{
a += X[i]*Y[i];
b += X[i];
c += Y[i];
d += X[i]*X[i];
}
float M = (N*(a) - b*c) / (N*d - b*b);
float B = (c - M*b) / N;
M = round(M * 1e3)/1e3;
B = round(B * 1e3)/1e3;
float p = 0;
float q = 1;
if (k == "mb")
{
cout << M << endl;
cout << B;
} else if (k == "func")
{
cout << "y = ";
if (M == p && B == p)
{
cout << 0;
} else if (M == p && B != p)
{
cout << B;
} else if (M != p && B == p)
{
cout << M << 'x';
} else
{
if (M == q)
{
if (B > p)
cout << "x + " << B;
if (B < p)
cout << "x - " << abs(B);
} else if (M == -q)
{
if (B > p)
cout << "-x + " << B;
if (B < p)
cout << "-x - " << abs(B);
} else
{
if (B > p)
cout << M << "x + " << B;
if (B < p)
cout << M << "x - " << abs(B);
}
}
}
} | # 0768, 2024-11-02 10:48:32, PPPPPPPPPPPPPPPPPP--PPPP (91%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
string k;
cin >> n >> k;
float x, y;
vector<float> X;
vector<float> Y;
for (int i = 0; i < n; i++)
{
cin >> x >> y;
X.push_back(x);
Y.push_back(y);
}
float a = 0;
float b = 0, c = 0, d = 0;
float N = n;
for (int i = 0; i < n; i++)
{
a += X[i]*Y[i];
b += X[i];
c += Y[i];
d += X[i]*X[i];
}
float M = (N*(a) - b*c) / (N*d - b*b);
float B = (c - M*b) / N;
M = round(M * 1e3)/1e3;
B = round(B * 1e3)/1e3;
float p = 0;
float q = 1;
if (k == "mb")
{
cout << M << endl;
cout << B;
} else if (k == "func")
{
cout << "y = ";
if (M == p && B == p)
{
cout << p;
} else if (M == p && B != p)
{
cout << B;
} else if (M != p && B == p)
{
cout << M << 'x';
} else
{
if (M == q)
{
if (B > p)
cout << "x + " << B;
if (B < p)
cout << "x - " << abs(B);
} else if (M == -q)
{
if (B > p)
cout << "-x + " << B;
if (B < p)
cout << "-x - " << abs(B);
} else
{
if (B > p)
cout << M << "x + " << B;
if (B < p)
cout << M << "x - " << abs(B);
}
}
}
} |
# 0769, 2024-11-02 13:56:57, PPPPPPPPPPPPPPPP-PPPP-PP (91%)
#include<bits/stdc++.h>
using namespace std;
int main() {
vector<pair<float, float> > V;
int N;
float X, Y, M, B, All = 0, Xi = 0, Yi = 0, sade, soun, Xi2 = 0;
string S;
cin >> N >> S;
for(int i = 0; i < N; i++) {
cin >> X >> Y;
V.push_back(make_pair(X, Y));
}
for(int i = 0; i< N; i++) {
All += V[i].first*V[i].second;
}
for(int i = 0; i< N; i++) {
Xi += V[i].first;
Xi2 += (V[i].first*V[i].first);
Yi += V[i].second;
}
All = N*All;
sade = All-(Xi*Yi);
soun = (N*Xi2) - (Xi*Xi);
M = sade/soun;
B = (Yi -(M*Xi)) / N;
M = round(M*1e3)/1e3;
B = round(B*1e3)/1e3;
if(S == "mb") {
cout << M << endl;
cout << B << endl;
}
else {
cout << "y = ";
if(M == 0 && B == 0) cout << "0";
if(M != 0) {
if(M == -1) {
cout << "-x ";
}
else if(M == 1) cout << "x ";
else cout << M << "x ";
}
if(B != 0) {
if(B > 0) {
cout << "+ " << B;
}
else cout << "- " << abs(B);
}
}
return 0;
} |
# 0770, 2024-11-02 13:29:19, PPPPPPPPPPP----P-PP----- (58%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string f;
cin>>n>>f;
float s=n;
float x[n],y[n];
float m1=0,m2=0,m3=0,m4=0,m5=0,b1=0,b2=0,m=0,b=0;
for(int i=0 ;i<n;i++){
cin>>x[i]>>y[i];
}
for(int i=0 ;i<n;i++){
m1=m1+(x[i]*y[i]);
m2=m2+x[i];
m3=m3+y[i];
m4=m4+(x[i]*x[i]);
}
b1=m3;
m5=m2*m2;
m=((s*m1)-(m2*m3))/((s*m4)-m5);
b2=m*m2;
b=(b1-b2)/s;
m=round(m * 1e3)/1e3;
b=round(b * 1e3)/1e3;
if(f=="mb"){
cout<<m<<endl<<b;
}
if(f=="func"){
cout<<"y = ";
if(m==0){
if(b==0) cout<<b;
}
if(m==1){
if(b==0) cout<<"x";
if(b!=0) cout<<"x + "<<b;;
}
if(m>1){
if(b==0) cout<<m<<"x";
if(b!=0) cout<<m<<"x + "<<b;
}
}
} | # 0771, 2024-11-02 13:35:24, PPPPPPPPPPPP---P-PP---P- (66%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string f;
cin>>n>>f;
float s=n;
float x[n],y[n];
float m1=0,m2=0,m3=0,m4=0,m5=0,b1=0,b2=0,m=0,b=0;
for(int i=0 ;i<n;i++){
cin>>x[i]>>y[i];
}
for(int i=0 ;i<n;i++){
m1=m1+(x[i]*y[i]);
m2=m2+x[i];
m3=m3+y[i];
m4=m4+(x[i]*x[i]);
}
b1=m3;
m5=m2*m2;
m=((s*m1)-(m2*m3))/((s*m4)-m5);
b2=m*m2;
b=(b1-b2)/s;
m=round(m * 1e3)/1e3;
b=round(b * 1e3)/1e3;
if(f=="mb"){
cout<<m<<endl<<b;
}
if(f=="func"){
cout<<"y = ";
if(m==0){
if(b==0) cout<<b;
}
if(m==1){
if(b==0) cout<<"x";
if(b!=0) {cout<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}
}
}
if(m>1){
if(b==0) cout<<m<<"x";
if(b!=0) {cout<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}}
}
}
} | # 0772, 2024-11-02 13:42:01, PPPPPPPPPPPP---P---P---- (58%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string f;
cin>>n>>f;
float s=n;
float x[n],y[n];
float m1=0,m2=0,m3=0,m4=0,m5=0,b1=0,b2=0,m=0,b=0;
for(int i=0 ;i<n;i++){
cin>>x[i]>>y[i];
}
for(int i=0 ;i<n;i++){
m1=m1+(x[i]*y[i]);
m2=m2+x[i];
m3=m3+y[i];
m4=m4+(x[i]*x[i]);
}
b1=m3;
m5=m2*m2;
m=((s*m1)-(m2*m3))/((s*m4)-m5);
b2=m*m2;
b=(b1-b2)/s;
m=round(m * 1e3)/1e3;
b=round(b * 1e3)/1e3;
if(f=="mb"){
cout<<m<<endl<<b;
}
if(f=="func"){
cout<<"y = ";
if(m==0){
if(b==0) cout<<b;
}
if(m==1){
if(b==0) cout<<"x";
if(b!=0) {cout<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}
}
}
if(m>0){
if(b==0) cout<<m<<"x";
if(b!=0) {cout<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}}
}
if(m==-1) cout<<"-x";
if(m<-1){
if(b==0) cout<<"- "<<m<<"x";
if(b!=0) {cout<<"- "<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}}
}
}
} | # 0773, 2024-11-02 13:43:39, PPPPPPPPPPPP---P---PP--P (66%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string f;
cin>>n>>f;
float s=n;
float x[n],y[n];
float m1=0,m2=0,m3=0,m4=0,m5=0,b1=0,b2=0,m=0,b=0;
for(int i=0 ;i<n;i++){
cin>>x[i]>>y[i];
}
for(int i=0 ;i<n;i++){
m1=m1+(x[i]*y[i]);
m2=m2+x[i];
m3=m3+y[i];
m4=m4+(x[i]*x[i]);
}
b1=m3;
m5=m2*m2;
m=((s*m1)-(m2*m3))/((s*m4)-m5);
b2=m*m2;
b=(b1-b2)/s;
m=round(m * 1e3)/1e3;
b=round(b * 1e3)/1e3;
if(f=="mb"){
cout<<m<<endl<<b;
}
if(f=="func"){
cout<<"y = ";
if(m==0){
if(b==0) cout<<b;
}
if(m==1){
if(b==0) cout<<"x";
if(b!=0) {cout<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}
}
}
if(m>0){
if(b==0) cout<<m<<"x";
if(b!=0) {cout<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}}
}
if(m==-1){ if(b==0) cout<<"-x";
if(b!=0) {cout<<"-x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}}
}
if(m<-1){
if(b==0) cout<<"-"<<m<<"x";
if(b!=0) {cout<<"-"<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}}
}
}
} | # 0774, 2024-11-02 13:48:24, PPPPPPPPPPPP---PP--PPP-P (75%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string f;
cin>>n>>f;
float s=n;
float x[n],y[n];
float m1=0,m2=0,m3=0,m4=0,m5=0,b1=0,b2=0,m=0,b=0;
for(int i=0 ;i<n;i++){
cin>>x[i]>>y[i];
}
for(int i=0 ;i<n;i++){
m1=m1+(x[i]*y[i]);
m2=m2+x[i];
m3=m3+y[i];
m4=m4+(x[i]*x[i]);
}
b1=m3;
m5=m2*m2;
m=((s*m1)-(m2*m3))/((s*m4)-m5);
b2=m*m2;
b=(b1-b2)/s;
m=round(m * 1e3)/1e3;
b=round(b * 1e3)/1e3;
if(f=="mb"){
cout<<m<<endl<<b;
}
if(f=="func"){
cout<<"y = ";
if(m==0){
cout<<b;
}
if(m==1){
if(b==0) cout<<"x";
if(b!=0) {cout<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}
}
}
if(m>0){
if(b==0) cout<<m<<"x";
if(b!=0) {cout<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}}
}
if(m==-1){ if(b==0) cout<<"-x";
if(b!=0) {cout<<"-x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}}
}
if(m<-1){
if(b==0) cout<<"-"<<m<<"x";
if(b!=0) {cout<<"-"<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}}
}
}
} | # 0775, 2024-11-02 14:54:41, PPPPPPPPPPPP---PP----P-- (62%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string f;
cin>>n>>f;
float s=n;
float x[n],y[n];
float m1=0,m2=0,m3=0,m4=0,m5=0,b1=0,b2=0,m=0,b=0;
for(int i=0 ;i<n;i++){
cin>>x[i]>>y[i];
}
for(int i=0 ;i<n;i++){
m1=m1+(x[i]*y[i]);
m2=m2+x[i];
m3=m3+y[i];
m4=m4+(x[i]*x[i]);
}
m1=s*m1;
b1=m3;
m5=m2*m2;
m=((m1)-(m2*m3))/((s*m4)-m5);
b2=m*m2;
b=(b1-b2)/s;
m=round(m * 1e3)/1e3;
b=round(b * 1e3)/1e3;
if(f=="mb"){
cout<<m<<endl<<b;
}
if(f=="func"){
cout<<"y = ";
if(m==0){
cout<<b;
}
if(m==1){
if(b==0) cout<<"x";
if(b!=0) {cout<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}
}
}
if(m>0){
if(b==0) cout<<m<<"x";
if(b!=0) {cout<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}}
}
if(m==-1){ if(b==0) cout<<"-x";
if(b!=0) {cout<<"-x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}}
}
if(m<-0){
if(b==0) cout<<"-"<<m<<"x";
if(b!=0) {cout<<"-"<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}}
}
}
} | # 0776, 2024-11-02 14:55:00, PPPPPPPPPPPP---PP--PPP-P (75%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string f;
cin>>n>>f;
float s=n;
float x[n],y[n];
float m1=0,m2=0,m3=0,m4=0,m5=0,b1=0,b2=0,m=0,b=0;
for(int i=0 ;i<n;i++){
cin>>x[i]>>y[i];
}
for(int i=0 ;i<n;i++){
m1=m1+(x[i]*y[i]);
m2=m2+x[i];
m3=m3+y[i];
m4=m4+(x[i]*x[i]);
}
m1=s*m1;
b1=m3;
m5=m2*m2;
m=((m1)-(m2*m3))/((s*m4)-m5);
b2=m*m2;
b=(b1-b2)/s;
m=round(m * 1e3)/1e3;
b=round(b * 1e3)/1e3;
if(f=="mb"){
cout<<m<<endl<<b;
}
if(f=="func"){
cout<<"y = ";
if(m==0){
cout<<b;
}
if(m==1){
if(b==0) cout<<"x";
if(b!=0) {cout<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}
}
}
if(m>0){
if(b==0) cout<<m<<"x";
if(b!=0) {cout<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}}
}
if(m==-1){ if(b==0) cout<<"-x";
if(b!=0) {cout<<"-x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}}
}
if(m<-1){
if(b==0) cout<<"-"<<m<<"x";
if(b!=0) {cout<<"-"<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}}
}
}
} | # 0777, 2024-11-02 14:58:20, PPPPPPPPPPPP---PP----P-- (62%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string f;
cin>>n>>f;
float s=n;
float x[n],y[n];
float m1=0,m2=0,m3=0,m4=0,m5=0,b1=0,b2=0,m=0,b=0;
for(int i=0 ;i<n;i++){
cin>>x[i]>>y[i];
m1=m1+(x[i]*y[i]);
m2=m2+x[i];
m3=m3+y[i];
m4=m4+(x[i]*x[i]);
}
m1=s*m1;
b1=m3;
m5=m2*m2;
m=((m1)-(m2*m3))/((s*m4)-m5);
b2=m*m2;
b=(b1-b2)/s;
m=round(m * 1e3)/1e3;
b=round(b * 1e3)/1e3;
if(f=="mb"){
cout<<m<<endl<<b;
}
if(f=="func"){
cout<<"y = ";
if(m==0){
cout<<b;
}
if(m==1){
if(b==0) cout<<"x";
if(b!=0) {cout<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}
}
}
if(m>0){
if(b==0) cout<<m<<"x";
if(b!=0) {cout<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}}
}
if(m==-1){ if(b==0) cout<<"-x";
if(b!=0) {cout<<"-x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}}
}
if(m<-0){
if(b==0) cout<<"-"<<m<<"x";
if(b!=0) {cout<<"-"<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}}
}
}
} | # 0778, 2024-11-02 15:05:25, PPPPPPPPPPPP---PP--PPP-P (75%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string f;
cin>>n>>f;
float s=n;
float x[n],y[n];
float m1=0,m2=0,m3=0,m4=0,m5=0,b1=0,b2=0,m=0,b=0;
for(int i=0 ;i<n;i++){
cin>>x[i]>>y[i];
}
for(int i=0 ;i<n;i++){
m1=m1+(x[i]*y[i]);
m2=m2+x[i];
m3=m3+y[i];
m4=m4+(x[i]*x[i]);
}
m1=s*m1;
b1=m3;
m5=m2*m2;
m4=m4*s;
m=((m1)-(m2*m3))/(m4-m5);
b2=m*m2;
b=(b1-b2)/s;
m=round(m * 1e3)/1e3;
b=round(b * 1e3)/1e3;
if(f=="mb"){
cout<<m<<endl<<b;
}
if(f=="func"){
cout<<"y = ";
if(m==0){
cout<<b;
}
if(m==1){
if(b==0) cout<<"x";
if(b!=0) {cout<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}
}
}
if(m>0){
if(b==0) cout<<m<<"x";
if(b!=0) {cout<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}}
}
if(m==-1){ if(b==0) cout<<"-x";
if(b!=0) {cout<<"-x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}}
}
if(m<-1){
if(b==0) cout<<"-"<<m<<"x";
if(b!=0) {cout<<"-"<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}}
}
}
} | # 0779, 2024-11-02 15:07:50, PPPPPPPPPPPP---PP--PPP-P (75%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string f;
cin>>n>>f;
float s=n;
float x[n],y[n];
float m1=0.0,m2=0.0,m3=0.0,m4=0.0,m5=0.0,b1=0.0,b2=0.0,m=0.0,b=0.0;
for(int i=0 ;i<n;i++){
cin>>x[i]>>y[i];
}
for(int i=0 ;i<n;i++){
m1=m1+(x[i]*y[i]);
m2=m2+x[i];
m3=m3+y[i];
m4=m4+(x[i]*x[i]);
}
m1=s*m1;
b1=m3;
m5=m2*m2;
m4=m4*s;
m=((m1)-(m2*m3))/(m4-m5);
b2=m*m2;
b=(b1-b2)/s;
m=round(m * 1e3)/1e3;
b=round(b * 1e3)/1e3;
if(f=="mb"){
cout<<m<<endl<<b;
}
if(f=="func"){
cout<<"y = ";
if(m==0){
cout<<b;
}
if(m==1){
if(b==0) cout<<"x";
if(b!=0) {cout<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}
}
}
if(m>0){
if(b==0) cout<<m<<"x";
if(b!=0) {cout<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}}
}
if(m==-1){ if(b==0) cout<<"-x";
if(b!=0) {cout<<"-x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}}
}
if(m<-1){
if(b==0) cout<<"-"<<m<<"x";
if(b!=0) {cout<<"-"<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}}
}
}
} | # 0780, 2024-11-02 15:10:07, PPPPPPPPPPPP---PP--PPP-P (75%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string f;
cin>>n>>f;
float s=n;
float x[n],y[n];
float m1=0.0,m2=0.0,m3=0.0,m4=0.0,m5=0.0,b1=0.0,b2=0.0,m=0.0,b=0.0;
for(int i=0 ;i<n;i++){
cin>>x[i]>>y[i];
}
for(int i=0 ;i<n;i++){
m1=m1+(x[i]*y[i]);
m2=m2+x[i];
m3=m3+y[i];
m4=m4+pow(x[i],2);
}
m1=s*m1;
b1=m3;
m5=m2*m2;
m4=m4*s;
m=((m1)-(m2*m3))/(m4-m5);
b2=m*m2;
b=(b1-b2)/s;
m=round(m * 1e3)/1e3;
b=round(b * 1e3)/1e3;
if(f=="mb"){
cout<<m<<endl<<b;
}
if(f=="func"){
cout<<"y = ";
if(m==0){
cout<<b;
}
if(m==1){
if(b==0) cout<<"x";
if(b!=0) {cout<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}
}
}
if(m>0){
if(b==0) cout<<m<<"x";
if(b!=0) {cout<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}}
}
if(m==-1){ if(b==0) cout<<"-x";
if(b!=0) {cout<<"-x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}}
}
if(m<-1){
if(b==0) cout<<"-"<<m<<"x";
if(b!=0) {cout<<"-"<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}}
}
}
} | # 0781, 2024-11-02 15:11:26, PPPPPPPPPPPP---PP--PPP-P (75%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string f;
cin>>n>>f;
float s=n;
float x[n],y[n];
float m1=0.0,m2=0.0,m3=0.0,m4=0.0,m5=0.0,b1=0.0,b2=0.0,m=0.0,b=0.0;
for(int i=0 ;i<n;i++){
cin>>x[i]>>y[i];
}
for(int i=0 ;i<n;i++){
m1=m1+(x[i]*y[i]);
m2=m2+x[i];
m3=m3+y[i];
m4=m4+pow(x[i],2);
}
m1=s*m1;
b1=m3;
m5=pow(m2,2);
m4=m4*s;
m=((m1)-(m2*m3))/(m4-m5);
b2=m*m2;
b=(b1-b2)/s;
m=round(m * 1e3)/1e3;
b=round(b * 1e3)/1e3;
if(f=="mb"){
cout<<m<<endl<<b;
}
if(f=="func"){
cout<<"y = ";
if(m==0){
cout<<b;
}
if(m==1){
if(b==0) cout<<"x";
if(b!=0) {cout<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}
}
}
if(m>0){
if(b==0) cout<<m<<"x";
if(b!=0) {cout<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}}
}
if(m==-1){ if(b==0) cout<<"-x";
if(b!=0) {cout<<"-x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}}
}
if(m<-1){
if(b==0) cout<<"-"<<m<<"x";
if(b!=0) {cout<<"-"<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
b=b-2*b;cout<<" - "<<b;
}}
}
}
} | # 0782, 2024-11-02 15:14:10, PPPPPPPPPPPP---PP--PPP-P (75%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string f;
cin>>n>>f;
float s=n;
float x[n],y[n];
float m1=0.0,m2=0.0,m3=0.0,m4=0.0,m5=0.0,b1=0.0,b2=0.0,m=0.0,b=0.0;
for(int i=0 ;i<n;i++){
cin>>x[i]>>y[i];
}
for(int i=0 ;i<n;i++){
m1=m1+(x[i]*y[i]);
m2=m2+x[i];
m3=m3+y[i];
m4=m4+pow(x[i],2);
}
m1=s*m1;
b1=m3;
m5=pow(m2,2);
m4=m4*s;
m=((m1)-(m2*m3))/(m4-m5);
b2=m*m2;
b=(b1-b2)/s;
m=round(m * 1e3)/1e3;
b=round(b * 1e3)/1e3;
if(f=="mb"){
cout<<m<<endl<<b;
}
if(f=="func"){
cout<<"y = ";
if(m==0){
cout<<b;
}
if(m==1){
if(b==0) cout<<"x";
if(b!=0) {cout<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
cout<<" - "<<abs(b);
}
}
}
if(m>0){
if(b==0) cout<<m<<"x";
if(b!=0) {cout<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
cout<<" - "<<abs(b);
}}
}
if(m==-1){ if(b==0) cout<<"-x";
if(b!=0) {cout<<"-x";
if(b>0) cout<<" + "<<b;
if(b<0){
cout<<" - "<<abs(b);
}}
}
if(m<-1){
if(b==0) cout<<"-"<<m<<"x";
if(b!=0) {cout<<"-"<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
cout<<" - "<<abs(b);
}}
}
}
} | # 0783, 2024-11-02 15:14:53, PPPPPPPPPPPP---PP--PPP-P (75%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string f;
cin>>n>>f;
float s=n;
float x[n],y[n];
float m1=0.0,m2=0.0,m3=0.0,m4=0.0,m5=0.0,b1=0.0,b2=0.0,m=0.0,b=0.0;
for(int i=0 ;i<n;i++){
cin>>x[i]>>y[i];
}
for(int i=0 ;i<n;i++){
m1=m1+(x[i]*y[i]);
m2=m2+x[i];
m3=m3+y[i];
m4=m4+pow(x[i],2);
}
m1=s*m1;
b1=m3;
m5=pow(m2,2);
m4=m4*s;
m=((m1)-(m2*m3))/(m4-m5);
b2=m*m2;
b=(b1-b2)/s;
m=round(m * 1e3)/1e3;
b=round(b * 1e3)/1e3;
if(f=="mb"){
cout<<m<<endl<<b;
}
if(f=="func"){
cout<<"y = ";
if(m==0){
cout<<b;
}
if(m==1){
if(b==0) cout<<"x";
if(b!=0) {cout<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
cout<<" - "<<abs(b);
}
}
}
if(m>0){
if(b==0) cout<<m<<"x";
if(b!=0) {cout<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
cout<<" - "<<abs(b);
}}
}
if(m==-1){ if(b==0) cout<<"-x";
if(b!=0) {cout<<"-x";
if(b>0) cout<<" + "<<b;
if(b<0){
cout<<" - "<<abs(b);
}}
}
if(m<-1){
if(b==0) cout<<"-"<<m<<"x";
if(b!=0) {cout<<"-"<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
cout<<" -"<<abs(b);
}}
}
}
} | # 0784, 2024-11-02 15:18:39, PPPPPPPPPPPP---PP--PPP-- (70%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string f;
cin>>n>>f;
float s=n;
float x[n],y[n];
float m1=0.0,m2=0.0,m3=0.0,m4=0.0,m5=0.0,b1=0.0,b2=0.0,m=0.0,b=0.0;
for(int i=0 ;i<n;i++){
cin>>x[i]>>y[i];
}
for(int i=0 ;i<n;i++){
m1=m1+(x[i]*y[i]);
m2=m2+x[i];
m3=m3+y[i];
m4=m4+pow(x[i],2);
}
m1=s*m1;
b1=m3;
m5=pow(m2,2);
m4=m4*s;
m=((m1)-(m2*m3))/(m4-m5);
b2=m*m2;
b=(b1-b2)/s;
m=round(m * 1e3)/1e3;
b=round(b * 1e3)/1e3;
if(f=="mb"){
cout<<m<<endl<<b;
}
if(f=="func"){
cout<<"y = ";
if(m==0){
cout<<b;
}
if(m==1){
if(b==0) cout<<"x";
if(b!=0) {cout<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
cout<<" - "<<abs(b);
}
}
}
if(m>0){
if(b==0) cout<<m<<"x";
if(b!=0) {cout<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
cout<<" - "<<abs(b);
}}
}
if(m==-1){ if(b==0) cout<<"-x";
if(b!=0) {cout<<"-x";
if(b>0) cout<<" + "<<b;
if(b<0){
cout<<" -"<<abs(b);
}}
}
if(m<-1){
if(b==0) cout<<"-"<<m<<"x";
if(b!=0) {cout<<"-"<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
cout<<" -"<<abs(b);
}}
}
}
} | # 0785, 2024-11-02 15:18:51, PPPPPPPPPPPP---PP--PPP-P (75%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string f;
cin>>n>>f;
float s=n;
float x[n],y[n];
float m1=0.0,m2=0.0,m3=0.0,m4=0.0,m5=0.0,b1=0.0,b2=0.0,m=0.0,b=0.0;
for(int i=0 ;i<n;i++){
cin>>x[i]>>y[i];
}
for(int i=0 ;i<n;i++){
m1=m1+(x[i]*y[i]);
m2=m2+x[i];
m3=m3+y[i];
m4=m4+pow(x[i],2);
}
m1=s*m1;
b1=m3;
m5=pow(m2,2);
m4=m4*s;
m=((m1)-(m2*m3))/(m4-m5);
b2=m*m2;
b=(b1-b2)/s;
m=round(m * 1e3)/1e3;
b=round(b * 1e3)/1e3;
if(f=="mb"){
cout<<m<<endl<<b;
}
if(f=="func"){
cout<<"y = ";
if(m==0){
cout<<b;
}
if(m==1){
if(b==0) cout<<"x";
if(b!=0) {cout<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
cout<<" - "<<abs(b);
}
}
}
if(m>0){
if(b==0) cout<<m<<"x";
if(b!=0) {cout<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
cout<<" - "<<abs(b);
}}
}
if(m==-1){ if(b==0) cout<<"-x";
if(b!=0) {cout<<"-x";
if(b>0) cout<<" + "<<b;
if(b<0){
cout<<" - "<<abs(b);
}}
}
if(m<-1){
if(b==0) cout<<"-"<<m<<"x";
if(b!=0) {cout<<"-"<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
cout<<" - "<<abs(b);
}}
}
}
} | # 0786, 2024-11-02 15:18:58, PPPPPPPPPPPP---PP--PPP-P (75%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string f;
cin>>n>>f;
float s=n;
float x[n],y[n];
float m1=0.0,m2=0.0,m3=0.0,m4=0.0,m5=0.0,b1=0.0,b2=0.0,m=0.0,b=0.0;
for(int i=0 ;i<n;i++){
cin>>x[i]>>y[i];
}
for(int i=0 ;i<n;i++){
m1=m1+(x[i]*y[i]);
m2=m2+x[i];
m3=m3+y[i];
m4=m4+pow(x[i],2);
}
m1=s*m1;
b1=m3;
m5=pow(m2,2);
m4=m4*s;
m=((m1)-(m2*m3))/(m4-m5);
b2=m*m2;
b=(b1-b2)/s;
m=round(m * 1e3)/1e3;
b=round(b * 1e3)/1e3;
if(f=="mb"){
cout<<m<<endl<<b;
}
if(f=="func"){
cout<<"y = ";
if(m==0){
cout<<b;
}
if(m==1){
if(b==0) cout<<"x";
if(b!=0) {cout<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
cout<<" - "<<abs(b);
}
}
}
if(m>0){
if(b==0) cout<<m<<"x";
if(b!=0) {cout<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
cout<<" - "<<abs(b);
}}
}
if(m==-1){ if(b==0) cout<<"-x";
if(b!=0) {cout<<"-x";
if(b>0) cout<<" + "<<b;
if(b<0){
cout<<" - "<<abs(b);
}}
}
if(m<-1){
if(b==0) cout<<"-"<<m<<"x";
if(b!=0) {cout<<"-"<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
cout<<" - "<<abs(b);
}}
}
}
} | # 0787, 2024-11-02 15:22:40, PPPPPPPPPPPP---PPPPPPPPP (87%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string f;
cin>>n>>f;
float s=n;
float x[n],y[n];
float m1=0.0,m2=0.0,m3=0.0,m4=0.0,m5=0.0,b1=0.0,b2=0.0,m=0.0,b=0.0;
for(int i=0 ;i<n;i++){
cin>>x[i]>>y[i];
}
for(int i=0 ;i<n;i++){
m1=m1+(x[i]*y[i]);
m2=m2+x[i];
m3=m3+y[i];
m4=m4+pow(x[i],2);
}
m1=s*m1;
b1=m3;
m5=pow(m2,2);
m4=m4*s;
m=((m1)-(m2*m3))/(m4-m5);
b2=m*m2;
b=(b1-b2)/s;
m=round(m * 1e3)/1e3;
b=round(b * 1e3)/1e3;
if(f=="mb"){
cout<<m<<endl<<b;
}
if(f=="func"){
cout<<"y = ";
if(m==0){
cout<<b;
}
if(m==1){
if(b==0) cout<<"x";
if(b!=0) {cout<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
cout<<" - "<<abs(b);
}
}
}
if(m>1){
if(b==0) cout<<m<<"x";
if(b!=0) {cout<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
cout<<" - "<<abs(b);
}}
}
if(m==-1){ if(b==0) cout<<"-x";
if(b!=0) {cout<<"-x";
if(b>0) cout<<" + "<<b;
if(b<0){
cout<<" - "<<abs(b);
}}
}
if(m<-1){
if(b==0) cout<<"-"<<m<<"x";
if(b!=0) {cout<<"-"<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
cout<<" - "<<abs(b);
}}
}
}
} | # 0788, 2024-11-02 15:23:19, PPPPPPPPPPPP---PPPPPPPPP (87%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string f;
cin>>n>>f;
float s=n;
float x[n],y[n];
float m1=0.0,m2=0.0,m3=0.0,m4=0.0,m5=0.0,b1=0.0,b2=0.0,m=0.0,b=0.0;
for(int i=0 ;i<n;i++){
cin>>x[i]>>y[i];
}
for(int i=0 ;i<n;i++){
m1=m1+(x[i]*y[i]);
m2=m2+x[i];
m3=m3+y[i];
m4=m4+pow(x[i],2);
}
m1=s*m1;
b1=m3;
m5=pow(m2,2);
m4=m4*s;
m=((m1)-(m2*m3))/(m4-m5);
b2=m*m2;
b=(b1-b2)/s;
m=round(m * 1e3)/1e3;
b=round(b * 1e3)/1e3;
if(f=="mb"){
cout<<m<<endl<<b;
}
if(f=="func"){
cout<<"y = ";
if(m==0){
cout<<b;
}
else if(m==1){
if(b==0) cout<<"x";
if(b!=0) {cout<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
cout<<" - "<<abs(b);
}
}
}
else if(m==-1){ if(b==0) cout<<"-x";
if(b!=0) {cout<<"-x";
if(b>0) cout<<" + "<<b;
if(b<0){
cout<<" - "<<abs(b);
}}
}
else if(m>1){
if(b==0) cout<<m<<"x";
if(b!=0) {cout<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
cout<<" - "<<abs(b);
}}
}
else if(m<-1){
if(b==0) cout<<"-"<<m<<"x";
if(b!=0) {cout<<"-"<<m<<"x";
if(b>0) cout<<" + "<<b;
if(b<0){
cout<<" - "<<abs(b);
}}
}
}
} |
# 0789, 2024-11-02 09:47:43, -----PPP---------------- (12%)
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
void mb(const vector<float> &x ,const vector<float> &y ,const int &n ){
float m=0 , b=0;
float a=0 , q=0 ,c=0,d=0 ,e=0 ,f=0,g=0;
for(int i=1;i<=n;++i ){
a+=(x[i]*y[i]);
q+=x[i];
c+=y[i];
d+=pow(x[i],2);
}
a=a*n;
d=d*n;
e=pow(q,2);
m=(a-(q*c))/(d-e);
std::cout << m << endl;
f=c;
g=m*q;
b=(f-g)/n;
std::cout << b << endl;
}
void func(const vector<float> &x ,const vector<float> &y ,const int &n ){
float m=0 , b=0;
float a=0 , q=0 ,c=0,d=0 ,e=0 ,f=0,g=0;
for(int i=1;i<=n;++i ){
a+=(x[i]*y[i]);
q+=x[i];
c+=y[i];
d+=pow(x[i],2);
}
a=a*n;
d=d*n;
e=pow(q,2);
m=(a-(q*c))/(d-e);
std::cout << m << endl;
f=c;
g=m*q;
b=(f-g)/n;
std::cout << b << endl;
}
int main(){
int n;
std::cin >> n;
string f ;
std::cin >> f ;
float a , b;
std::vector<float> x , y ;
for(int i=0; i<n ; ++i){
std::cin >> a >> b ;
x.push_back(a);
y.push_back(b);
}
if(f=="mb"){
mb(x,y,n);
}
if(f=="func"){
func(x,y,n);
}
} | # 0790, 2024-11-02 10:19:01, PPPPPPPPPP-----P--P----- (50%)
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
void mb(const vector<float> &x ,const vector<float> &y ,const int &n ){
float m=0 , b=0;
float a=0 , q=0 ,c=0,d=0 ,e=0 ,f=0,g=0;
for(int i=1;i<=n;++i ){
a+=(x[i]*y[i]);
q+=x[i];
c+=y[i];
d+=pow(x[i],2);
}
a=a*n;
d=d*n;
e=pow(q,2);
m=(a-(q*c))/(d-e);
std::cout << round(m*1e3)/1e3 << endl;
f=c;
g=m*q;
b=(f-g)/n;
std::cout << round(b*1e3)/1e3 << endl;
}
void func(const vector<float> &x ,const vector<float> &y ,const int &n ){
float m=0 , b=0;
float a=0 , q=0 ,c=0,d=0 ,e=0 ,f=0,g=0;
for(int i=1;i<=n;++i ){
a+=(x[i]*y[i]);
q+=x[i];
c+=y[i];
d+=pow(x[i],2);
}
a=a*n;
d=d*n;
e=pow(q,2);
m=(a-(q*c))/(d-e);//m
f=c;
g=m*q;
b=(f-g)/n;//b
if(m==0 && b==0){
std::cout << "y = 0" ;
}else if (m==-1 &&b==0){
std::cout << "y = - x" ;
}
else if (m==1 &&b==0){
std::cout << "y = x" ;
}else if (m==-1 && b<0){
std::cout << "y = -x - " << -round(b*1e3)/1e3 ;
}
else if (b<0){
std::cout << "y = "<< round(m*1e3)/1e3 <<" - " << -round(b*1e3)/1e3 ;
}
else if (m==0){
std::cout << "y = " << round(b*1e3)/1e3 ;
}
else if (b==0){
std::cout << "y = " << round(m*1e3)/1e3 << "x" ;
}
else if (m==1){
std::cout << "y = x + " << round(b*1e3)/1e3 ;
}
else if (m==-1){
std::cout << "y = -x + " << round(b*1e3)/1e3 ;
}
}
int main(){
int n;
std::cin >> n;
string f ;
std::cin >> f ;
float a , b;
std::vector<float> x , y ;
x.push_back(0);
y.push_back(0);
for(int i=0; i<n ; ++i){
std::cin >> a >> b ;
x.push_back(a);
y.push_back(b);
}
if(f=="mb"){
mb(x,y,n);
}
if(f=="func"){
func(x,y,n);
}
} | # 0791, 2024-11-02 10:20:07, PPPPPPPPPP-P-PPP--P----- (62%)
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
void mb(const vector<float> &x ,const vector<float> &y ,const int &n ){
float m=0 , b=0;
float a=0 , q=0 ,c=0,d=0 ,e=0 ,f=0,g=0;
for(int i=1;i<=n;++i ){
a+=(x[i]*y[i]);
q+=x[i];
c+=y[i];
d+=pow(x[i],2);
}
a=a*n;
d=d*n;
e=pow(q,2);
m=(a-(q*c))/(d-e);
std::cout << round(m*1e3)/1e3 << endl;
f=c;
g=m*q;
b=(f-g)/n;
std::cout << round(b*1e3)/1e3 << endl;
}
void func(const vector<float> &x ,const vector<float> &y ,const int &n ){
float m=0 , b=0;
float a=0 , q=0 ,c=0,d=0 ,e=0 ,f=0,g=0;
for(int i=1;i<=n;++i ){
a+=(x[i]*y[i]);
q+=x[i];
c+=y[i];
d+=pow(x[i],2);
}
a=a*n;
d=d*n;
e=pow(q,2);
m=(a-(q*c))/(d-e);//m
f=c;
g=m*q;
b=(f-g)/n;//b
if(m==0 && b==0){
std::cout << "y = 0" ;
}else if (m==-1 &&b==0){
std::cout << "y = - x" ;
}
else if (m==1 &&b==0){
std::cout << "y = x" ;
}else if (m==-1 && b<0){
std::cout << "y = -x - " << -round(b*1e3)/1e3 ;
}
else if (b<0){
std::cout << "y = "<< round(m*1e3)/1e3 <<"x - " << -round(b*1e3)/1e3 ;
}
else if (m==0){
std::cout << "y = " << round(b*1e3)/1e3 ;
}
else if (b==0){
std::cout << "y = " << round(m*1e3)/1e3 << "x" ;
}
else if (m==1){
std::cout << "y = x + " << round(b*1e3)/1e3 ;
}
else if (m==-1){
std::cout << "y = -x + " << round(b*1e3)/1e3 ;
}
}
int main(){
int n;
std::cin >> n;
string f ;
std::cin >> f ;
float a , b;
std::vector<float> x , y ;
x.push_back(0);
y.push_back(0);
for(int i=0; i<n ; ++i){
std::cin >> a >> b ;
x.push_back(a);
y.push_back(b);
}
if(f=="mb"){
mb(x,y,n);
}
if(f=="func"){
func(x,y,n);
}
} | # 0792, 2024-11-02 10:28:28, PPPPPPPPPP-P-PPP--P--P-- (66%)
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
void mb(const vector<float> &x ,const vector<float> &y ,const int &n ){
float m=0 , b=0;
float a=0 , q=0 ,c=0,d=0 ,e=0 ,f=0,g=0;
for(int i=1;i<=n;++i ){
a+=(x[i]*y[i]);
q+=x[i];
c+=y[i];
d+=pow(x[i],2);
}
a=a*n;
d=d*n;
e=pow(q,2);
m=(a-(q*c))/(d-e);
std::cout << round(m*1e3)/1e3 << endl;
f=c;
g=m*q;
b=(f-g)/n;
std::cout << round(b*1e3)/1e3 << endl;
}
void func(const vector<float> &x ,const vector<float> &y ,const int &n ){
float m=0 , b=0;
float a=0 , q=0 ,c=0,d=0 ,e=0 ,f=0,g=0;
for(int i=1;i<=n;++i ){
a+=(x[i]*y[i]);
q+=x[i];
c+=y[i];
d+=pow(x[i],2);
}
a=a*n;
d=d*n;
e=pow(q,2);
m=(a-(q*c))/(d-e);//m
f=c;
g=m*q;
b=(f-g)/n;//b
if(m==0 && b==0){
std::cout << "y = 0" ;
}else if (m==-1 &&b==0){
std::cout << "y = - x" ;
}
else if (m==0 &&b<0){
std::cout << "y = " << round(b*1e3)/1e3 ;
}
else if (m==1 &&b==0){
std::cout << "y = x" ;
}else if (m==-1 && b<0){
std::cout << "y = -x - " << -round(b*1e3)/1e3 ;
}
else if (b<0){
std::cout << "y = "<< round(m*1e3)/1e3 <<"x - " << -round(b*1e3)/1e3 ;
}
else if (m==0){
std::cout << "y = " << round(b*1e3)/1e3 ;
}
else if (b==0){
std::cout << "y = " << round(m*1e3)/1e3 << "x" ;
}
else if (m==1){
std::cout << "y = x + " << round(b*1e3)/1e3 ;
}
else if (m==-1){
std::cout << "y = -x + " << round(b*1e3)/1e3 ;
}
}
int main(){
int n;
std::cin >> n;
string f ;
std::cin >> f ;
float a , b;
std::vector<float> x , y ;
x.push_back(0);
y.push_back(0);
for(int i=0; i<n ; ++i){
std::cin >> a >> b ;
x.push_back(a);
y.push_back(b);
}
if(f=="mb"){
mb(x,y,n);
}
if(f=="func"){
func(x,y,n);
}
} | # 0793, 2024-11-02 10:37:06, PPPPPPPPPP-P-PPP--P----- (62%)
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
void mb(const vector<float> &x ,const vector<float> &y ,const int &n ){
float m=0 , b=0;
float a=0 , q=0 ,c=0,d=0 ,e=0 ,f=0,g=0;
for(int i=1;i<=n;++i ){
a+=(x[i]*y[i]);
q+=x[i];
c+=y[i];
d+=pow(x[i],2);
}
a=a*n;
d=d*n;
e=pow(q,2);
m=(a-(q*c))/(d-e);
if(m==0){
m=0;
}
std::cout << round(m*1e3)/1e3 << endl;
f=c;
g=m*q;
b=(f-g)/n;
std::cout << round(b*1e3)/1e3 << endl;
}
void func(const vector<float> &x ,const vector<float> &y ,const int &n ){
float m=0 , b=0;
float a=0 , q=0 ,c=0,d=0 ,e=0 ,f=0,g=0;
for(int i=1;i<=n;++i ){
a+=(x[i]*y[i]);
q+=x[i];
c+=y[i];
d+=pow(x[i],2);
}
a=a*n;
d=d*n;
e=pow(q,2);
m=(a-(q*c))/(d-e);//m
if(m==-0){
m=0;
}
f=c;
g=m*q;
b=(f-g)/n;//b
if(m==0 && b==0){
std::cout << "y = 0" ;
}else if (m==-1 &&b==0){
std::cout << "y = - x" ;
}
else if (m==1 &&b==0){
std::cout << "y = x" ;
}else if (m==-1 && b<0){
std::cout << "y = -x - " << -round(b*1e3)/1e3 ;
}
else if (b<0){
std::cout << "y = "<< round(m*1e3)/1e3 <<"x - " << -round(b*1e3)/1e3 ;
}
else if (m==0){
std::cout << "y = " << round(b*1e3)/1e3 ;
}
else if (b==0){
std::cout << "y = " << round(m*1e3)/1e3 << "x" ;
}
else if (m==1){
std::cout << "y = x + " << round(b*1e3)/1e3 ;
}
else if (m==-1){
std::cout << "y = -x + " << round(b*1e3)/1e3 ;
}
}
int main(){
int n;
std::cin >> n;
string f ;
std::cin >> f ;
float a , b;
std::vector<float> x , y ;
x.push_back(0);
y.push_back(0);
for(int i=0; i<n ; ++i){
std::cin >> a >> b ;
x.push_back(a);
y.push_back(b);
}
if(f=="mb"){
mb(x,y,n);
}
if(f=="func"){
func(x,y,n);
}
} | # 0794, 2024-11-02 10:41:40, -----PPPPP-----P-------- (25%)
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
void mb(const vector<float> &x ,const vector<float> &y ,const int &n ){
float m=0 , b=0;
float a=0 , q=0 ,c=0,d=0 ,e=0 ,f=0,g=0;
for(int i=1;i<=n;++i ){
a+=(x[i]*y[i]);
q+=x[i];
c+=y[i];
d+=pow(x[i],2);
}
a=a*n;
d=d*n;
e=pow(q,2);
m=(a-(q*c))/(d-e);
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
std::cout << m << endl;
f=c;
g=m*q;
b=(f-g)/n;
std::cout << b << endl;
}
void func(const vector<float> &x ,const vector<float> &y ,const int &n ){
float m=0 , b=0;
float a=0 , q=0 ,c=0,d=0 ,e=0 ,f=0,g=0;
for(int i=1;i<=n;++i ){
a+=(x[i]*y[i]);
q+=x[i];
c+=y[i];
d+=pow(x[i],2);
}
a=a*n;
d=d*n;
e=pow(q,2);
m=(a-(q*c))/(d-e);//m
if(m==-0){
m=0;
}
f=c;
g=m*q;
b=(f-g)/n;//b
m=round(m*1e3)/1e3;
b=round(m*1e3)/1e3;
if(m==0 && b==0){
std::cout << "y = 0" ;
}else if (m==-1 &&b==0){
std::cout << "y = - x" ;
}
else if (m==1 &&b==0){
std::cout << "y = x" ;
}else if (m==-1 && b<0){
std::cout << "y = -x - " << -b ;
}
else if (b<0){
std::cout << "y = "<< m <<"x - " << -b ;
}
else if (m==0){
std::cout << "y = " << b ;
}
else if (b==0){
std::cout << "y = " << m << "x" ;
}
else if (m==1){
std::cout << "y = x + " << b ;
}
else if (m==-1){
std::cout << "y = -x + " << b ;
}
}
int main(){
int n;
std::cin >> n;
string f ;
std::cin >> f ;
float a , b;
std::vector<float> x , y ;
x.push_back(0);
y.push_back(0);
for(int i=0; i<n ; ++i){
std::cin >> a >> b ;
x.push_back(a);
y.push_back(b);
}
if(f=="mb"){
mb(x,y,n);
}
if(f=="func"){
func(x,y,n);
}
} | # 0795, 2024-11-02 10:42:20, PPPPPPPPPP-----P-------- (45%)
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
void mb(const vector<float> &x ,const vector<float> &y ,const int &n ){
float m=0 , b=0;
float a=0 , q=0 ,c=0,d=0 ,e=0 ,f=0,g=0;
for(int i=1;i<=n;++i ){
a+=(x[i]*y[i]);
q+=x[i];
c+=y[i];
d+=pow(x[i],2);
}
a=a*n;
d=d*n;
e=pow(q,2);
m=(a-(q*c))/(d-e);
f=c;
g=m*q;
b=(f-g)/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
std::cout << m << endl;
std::cout << b << endl;
}
void func(const vector<float> &x ,const vector<float> &y ,const int &n ){
float m=0 , b=0;
float a=0 , q=0 ,c=0,d=0 ,e=0 ,f=0,g=0;
for(int i=1;i<=n;++i ){
a+=(x[i]*y[i]);
q+=x[i];
c+=y[i];
d+=pow(x[i],2);
}
a=a*n;
d=d*n;
e=pow(q,2);
m=(a-(q*c))/(d-e);//m
if(m==-0){
m=0;
}
f=c;
g=m*q;
b=(f-g)/n;//b
m=round(m*1e3)/1e3;
b=round(m*1e3)/1e3;
if(m==0 && b==0){
std::cout << "y = 0" ;
}else if (m==-1 &&b==0){
std::cout << "y = - x" ;
}
else if (m==1 &&b==0){
std::cout << "y = x" ;
}else if (m==-1 && b<0){
std::cout << "y = -x - " << -b ;
}
else if (b<0){
std::cout << "y = "<< m <<"x - " << -b ;
}
else if (m==0){
std::cout << "y = " << b ;
}
else if (b==0){
std::cout << "y = " << m << "x" ;
}
else if (m==1){
std::cout << "y = x + " << b ;
}
else if (m==-1){
std::cout << "y = -x + " << b ;
}
}
int main(){
int n;
std::cin >> n;
string f ;
std::cin >> f ;
float a , b;
std::vector<float> x , y ;
x.push_back(0);
y.push_back(0);
for(int i=0; i<n ; ++i){
std::cin >> a >> b ;
x.push_back(a);
y.push_back(b);
}
if(f=="mb"){
mb(x,y,n);
}
if(f=="func"){
func(x,y,n);
}
} | # 0796, 2024-11-02 10:48:37, PPPPPPPPPP-P-PPPPPPPP--P (83%)
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
void mb(const vector<float> &x ,const vector<float> &y ,const int &n ){
float m=0 , b=0;
float a=0 , q=0 ,c=0,d=0 ,e=0 ,f=0,g=0;
for(int i=1;i<=n;++i ){
a+=(x[i]*y[i]);
q+=x[i];
c+=y[i];
d+=pow(x[i],2);
}
a=a*n;
d=d*n;
e=pow(q,2);
m=(a-(q*c))/(d-e);
f=c;
g=m*q;
b=(f-g)/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
std::cout << m << endl;
std::cout << b << endl;
}
void func(const vector<float> &x ,const vector<float> &y ,const int &n ){
float m=0 , b=0;
float a=0 , q=0 ,c=0,d=0 ,e=0 ,f=0,g=0;
for(int i=1;i<=n;++i ){
a+=(x[i]*y[i]);
q+=x[i];
c+=y[i];
d+=pow(x[i],2);
}
a=a*n;
d=d*n;
e=pow(q,2);
m=(a-(q*c))/(d-e);
f=c;
g=m*q;
b=(f-g)/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(m==0 && b==0){
std::cout << "y = 0" ;
}else if (m==-1 &&b==0){
std::cout << "y = -x" ;
}
else if (m==1 &&b==0){
std::cout << "y = x" ;
}else if (m==-1 && b<0){
std::cout << "y = -x - " << -b ;
}
else if (b<0){
std::cout << "y = "<< m <<"x - " << -b ;
}
else if (m==0){
std::cout << "y = " << b ;
}
else if (b==0){
std::cout << "y = " << m << "x" ;
}
else if (m==1){
std::cout << "y = x + " << b ;
}
else if (m==-1){
std::cout << "y = -x + " << b ;
}
}
int main(){
int n;
std::cin >> n;
string f ;
std::cin >> f ;
float a , b;
std::vector<float> x , y ;
x.push_back(0);
y.push_back(0);
for(int i=0; i<n ; ++i){
std::cin >> a >> b ;
x.push_back(a);
y.push_back(b);
}
if(f=="mb"){
mb(x,y,n);
}
if(f=="func"){
func(x,y,n);
}
} | # 0797, 2024-11-02 10:51:02, PPPPPPPPPP-P-PPPPPPPPP-P (87%)
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
void mb(const vector<float> &x ,const vector<float> &y ,const int &n ){
float m=0 , b=0;
float a=0 , q=0 ,c=0,d=0 ,e=0 ,f=0,g=0;
for(int i=1;i<=n;++i ){
a+=(x[i]*y[i]);
q+=x[i];
c+=y[i];
d+=pow(x[i],2);
}
a=a*n;
d=d*n;
e=pow(q,2);
m=(a-(q*c))/(d-e);
f=c;
g=m*q;
b=(f-g)/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
std::cout << m << endl;
std::cout << b << endl;
}
void func(const vector<float> &x ,const vector<float> &y ,const int &n ){
float m=0 , b=0;
float a=0 , q=0 ,c=0,d=0 ,e=0 ,f=0,g=0;
for(int i=1;i<=n;++i ){
a+=(x[i]*y[i]);
q+=x[i];
c+=y[i];
d+=pow(x[i],2);
}
a=a*n;
d=d*n;
e=pow(q,2);
m=(a-(q*c))/(d-e);
f=c;
g=m*q;
b=(f-g)/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(m==0 && b==0){
std::cout << "y = 0" ;
}else if (m==-1 &&b==0){
std::cout << "y = -x" ;
}
else if (m==0 &&b<0){
std::cout << "y = " << b ;
}
else if (m==1 &&b==0){
std::cout << "y = x" ;
}else if (m==-1 && b<0){
std::cout << "y = -x - " << -b ;
}
else if (b<0){
std::cout << "y = "<< m <<"x - " << -b ;
}
else if (m==0){
std::cout << "y = " << b ;
}
else if (b==0){
std::cout << "y = " << m << "x" ;
}
else if (m==1){
std::cout << "y = x + " << b ;
}
else if (m==-1){
std::cout << "y = -x + " << b ;
}
}
int main(){
int n;
std::cin >> n;
string f ;
std::cin >> f ;
float a , b;
std::vector<float> x , y ;
x.push_back(0);
y.push_back(0);
for(int i=0; i<n ; ++i){
std::cin >> a >> b ;
x.push_back(a);
y.push_back(b);
}
if(f=="mb"){
mb(x,y,n);
}
if(f=="func"){
func(x,y,n);
}
} | # 0798, 2024-11-02 10:54:13, Compilation error (0%)
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
void mb(const vector<float> &x ,const vector<float> &y ,const int &n ){
float m=0 , b=0;
float a=0 , q=0 ,c=0,d=0 ,e=0 ,f=0,g=0;
for(int i=1;i<=n;++i ){
a+=(x[i]*y[i]);
q+=x[i];
c+=y[i];
d+=pow(x[i],2);
}
a=a*n;
d=d*n;
e=pow(q,2);
m=(a-(q*c))/(d-e);
f=c;
g=m*q;
b=(f-g)/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
std::cout << m << endl;
std::cout << b << endl;
}
void func(const vector<float> &x ,const vector<float> &y ,const int &n ){
float m=0 , b=0;
float a=0 , q=0 ,c=0,d=0 ,e=0 ,f=0,g=0;
for(int i=1;i<=n;++i ){
a+=(x[i]*y[i]);
q+=x[i];
c+=y[i];
d+=pow(x[i],2);
}
a=a*n;
d=d*n;
e=pow(q,2);
m=(a-(q*c))/(d-e);
f=c;
g=m*q;
b=(f-g)/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(m==0 && b==0){
std::cout << "y = 0" ;
}else if (m==-1 &&b==0){
std::cout << "y = -x" ;
}
else if (m==0 &&b<0){
std::cout << "y = " << b ;
}
else if (m==1 &&b==0){
std::cout << "y = x" ;
}else if (m==-1 && b<0){
std::cout << "y = -x - " << -b ;
}
else if (b<0){
std::cout << "y = "<< m <<"x - " << -b ;
}
else if (m==0){
std::cout << "y = " << b ;
}
else if (b==0){
std::cout << "y = " << m << "x" ;
}
else if (m==1){
std::cout << "y = x + " << b ;
}
else if (m==-1){
std::cout << "y = -x + " << b ;
}
}
int main(){
int n;
std::cin >> n;
string f ;
std::cin >> f ;
float a , b;
std::vector<float> x , y ;
x.push_back(0);
y.push_back(0);
for(int i=0; i<n ; ++i){
std::cin >> a >> b ;
x.push_back(a);
y.push_back(b);
}
if(f=="mb"){
mb(x,y,n);
}
if(f=="func"){
func(x,y,n);
}
}#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
void mb(const vector<float> &x ,const vector<float> &y ,const int &n ){
float m=0 , b=0;
float a=0 , q=0 ,c=0,d=0 ,e=0 ,f=0,g=0;
for(int i=1;i<=n;++i ){
a+=(x[i]*y[i]);
q+=x[i];
c+=y[i];
d+=pow(x[i],2);
}
a=a*n;
d=d*n;
e=pow(q,2);
m=(a-(q*c))/(d-e);
f=c;
g=m*q;
b=(f-g)/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
std::cout << m << endl;
std::cout << b << endl;
}
void func(const vector<float> &x ,const vector<float> &y ,const int &n ){
float m=0 , b=0;
float a=0 , q=0 ,c=0,d=0 ,e=0 ,f=0,g=0;
for(int i=1;i<=n;++i ){
a+=(x[i]*y[i]);
q+=x[i];
c+=y[i];
d+=pow(x[i],2);
}
a=a*n;
d=d*n;
e=pow(q,2);
m=(a-(q*c))/(d-e);
f=c;
g=m*q;
b=(f-g)/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(m==0 && b==0){
std::cout << "y = 0" ;
}else if (m==-1 &&b==0){
std::cout << "y = -x" ;
}
else if (m==0 &&b<0){
std::cout << "y = " << b ;
}
else if (m==1 &&b==0){
std::cout << "y = x" ;
}else if (m==-1 && b<0){
std::cout << "y = -x - " << -b ;
}
else if (b<0){
std::cout << "y = "<< m <<"x - " << -b ;
}
else if (m==0){
std::cout << "y = " << b ;
}
else if (b==0){
std::cout << "y = " << m << "x" ;
}
else if (m==1){
std::cout << "y = x + " << b ;
}
else if (m==-1){
std::cout << "y = -x + " << b ;
}
}
int main(){
int n;
std::cin >> n;
string f ;
std::cin >> f ;
float a , b;
std::vector<float> x , y ;
x.push_back(0);
y.push_back(0);
for(int i=0; i<n ; ++i){
std::cin >> a >> b ;
x.push_back(a);
y.push_back(b);
}
if(f=="mb"){
mb(x,y,n);
}
if(f=="func"){
func(x,y,n);
}
} | # 0799, 2024-11-02 10:54:26, PPPPPPPPPP-P-PPPPPPPPP-P (87%)
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
void mb(const vector<float> &x ,const vector<float> &y ,const int &n ){
float m=0 , b=0;
float a=0 , q=0 ,c=0,d=0 ,e=0 ,f=0,g=0;
for(int i=1;i<=n;++i ){
a+=(x[i]*y[i]);
q+=x[i];
c+=y[i];
d+=pow(x[i],2);
}
a=a*n;
d=d*n;
e=pow(q,2);
m=(a-(q*c))/(d-e);
f=c;
g=m*q;
b=(f-g)/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
std::cout << m << endl;
std::cout << b << endl;
}
void func(const vector<float> &x ,const vector<float> &y ,const int &n ){
float m=0 , b=0;
float a=0 , q=0 ,c=0,d=0 ,e=0 ,f=0,g=0;
for(int i=1;i<=n;++i ){
a+=(x[i]*y[i]);
q+=x[i];
c+=y[i];
d+=pow(x[i],2);
}
a=a*n;
d=d*n;
e=pow(q,2);
m=(a-(q*c))/(d-e);
f=c;
g=m*q;
b=(f-g)/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(m==0 && b==0){
std::cout << "y = 0" ;
}else if (m==-1 &&b==0){
std::cout << "y = -x" ;
}
else if (m==0 &&b<0){
std::cout << "y = " << b ;
}
else if (m==1 &&b==0){
std::cout << "y = x" ;
}else if (m==-1 && b<0){
std::cout << "y = -x - " << -b ;
}
else if (b<0){
std::cout << "y = "<< m <<"x - " << -b ;
}
else if (m==0){
std::cout << "y = " << b ;
}
else if (b==0){
std::cout << "y = " << m << "x" ;
}
else if (m==1){
std::cout << "y = x + " << b ;
}
else if (m==-1){
std::cout << "y = -x + " << b ;
}
}
int main(){
int n;
std::cin >> n;
string f ;
std::cin >> f ;
float a , b;
std::vector<float> x , y ;
x.push_back(0);
y.push_back(0);
for(int i=0; i<n ; ++i){
std::cin >> a >> b ;
x.push_back(a);
y.push_back(b);
}
if(f=="mb"){
mb(x,y,n);
}
if(f=="func"){
func(x,y,n);
}
} | # 0800, 2024-11-02 10:56:22, PPPPPPPPPP-P-PPPPPPPPP-P (87%)
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
void mb(const vector<float> &x ,const vector<float> &y ,const int &n ){
float m=0 , b=0;
float a=0 , q=0 ,c=0,d=0 ,e=0 ,f=0,g=0;
for(int i=1;i<=n;++i ){
a+=(x[i]*y[i]);
q+=x[i];
c+=y[i];
d+=pow(x[i],2);
}
a=a*n;
d=d*n;
e=pow(q,2);
m=(a-(q*c))/(d-e);
f=c;
g=m*q;
b=(f-g)/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
std::cout << m << endl;
std::cout << b << endl;
}
void func(const vector<float> &x ,const vector<float> &y ,const int &n ){
float m=0 , b=0;
float a=0 , q=0 ,c=0,d=0 ,e=0 ,f=0,g=0;
for(int i=1;i<=n;++i ){
a+=(x[i]*y[i]);
q+=x[i];
c+=y[i];
d+=pow(x[i],2);
}
a=a*n;
d=d*n;
e=pow(q,2);
m=(a-(q*c))/(d-e);
f=c;
g=m*q;
b=(f-g)/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(m==0 && b==0){
std::cout << "y = 0" ;
}else if (m==-1 &&b==0){
std::cout << "y = -x" ;
}
else if (m==0 &&b<0){
std::cout << "y = " << b ;
}
else if (m==1 &&b==0){
std::cout << "y = x" ;
}else if (m==-1 && b<0){
std::cout << "y = -x - " << -b ;
}
else if (b<0){
std::cout << "y = "<< m <<"x - " << -b ;
}
else if (m==0){
std::cout << "y = " << b ;
}
else if (b==0){
std::cout << "y = " << m << "x" ;
}
else if (m==1){
std::cout << "y = x + " << b ;
}
else if (m==-1){
std::cout << "y = -x + " << b ;
}
}
int main(){
int n=0;
std::cin >> n;
string f ;
std::cin >> f ;
float a=0 , b=0;
std::vector<float> x , y ;
x.push_back(0);
y.push_back(0);
for(int i=0; i<n ; ++i){
std::cin >> a >> b ;
x.push_back(a);
y.push_back(b);
}
if(f=="mb"){
mb(x,y,n);
}
if(f=="func"){
func(x,y,n);
}
} | # 0801, 2024-11-02 10:59:26, PPPPPPPPPP-P-PPPPPPPPP-P (87%)
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
void mb(const vector<float> &x ,const vector<float> &y ,const long long &n ){
float m=0 , b=0;
float a=0 , q=0 ,c=0,d=0 ,e=0 ,f=0,g=0;
for(int i=1;i<=n;++i ){
a+=(x[i]*y[i]);
q+=x[i];
c+=y[i];
d+=pow(x[i],2);
}
a=a*n;
d=d*n;
e=pow(q,2);
m=(a-(q*c))/(d-e);
f=c;
g=m*q;
b=(f-g)/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
std::cout << m << endl;
std::cout << b << endl;
}
void func(const vector<float> &x ,const vector<float> &y ,const long long &n ){
float m=0 , b=0;
float a=0 , q=0 ,c=0,d=0 ,e=0 ,f=0,g=0;
for(int i=1;i<=n;++i ){
a+=(x[i]*y[i]);
q+=x[i];
c+=y[i];
d+=pow(x[i],2);
}
a=a*n;
d=d*n;
e=pow(q,2);
m=(a-(q*c))/(d-e);
f=c;
g=m*q;
b=(f-g)/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(m==0 && b==0){
std::cout << "y = 0" ;
}else if (m==-1 &&b==0){
std::cout << "y = -x" ;
}
else if (m==0 &&b<0){
std::cout << "y = " << b ;
}
else if (m==1 &&b==0){
std::cout << "y = x" ;
}else if (m==-1 && b<0){
std::cout << "y = -x - " << -b ;
}
else if (b<0){
std::cout << "y = "<< m <<"x - " << -b ;
}
else if (m==0){
std::cout << "y = " << b ;
}
else if (b==0){
std::cout << "y = " << m << "x" ;
}
else if (m==1){
std::cout << "y = x + " << b ;
}
else if (m==-1){
std::cout << "y = -x + " << b ;
}
}
int main(){
long long n=0;
std::cin >> n;
string f ;
std::cin >> f ;
float a=0 , b=0;
std::vector<float> x , y ;
x.push_back(0);
y.push_back(0);
for(int i=0; i<n ; ++i){
std::cin >> a >> b ;
x.push_back(a);
y.push_back(b);
}
if(f=="mb"){
mb(x,y,n);
}
if(f=="func"){
func(x,y,n);
}
} | # 0802, 2024-11-02 11:03:28, PPPPPPPPPP-P-PPPPPPPPP-P (87%)
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
void mb(const vector<float> &x ,const vector<float> &y ,const long long &n ){
float m=0 , b=0;
float a=0 , q=0 ,c=0,d=0 ,e=0 ,f=0,g=0;
for(long long i=1;i<=n;++i ){
a+=(x[i]*y[i]);
q+=x[i];
c+=y[i];
d+=pow(x[i],2);
}
a=a*n;
d=d*n;
e=pow(q,2);
m=(a-(q*c))/(d-e);
f=c;
g=m*q;
b=(f-g)/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
std::cout << m << endl;
std::cout << b << endl;
}
void func(const vector<float> &x ,const vector<float> &y ,const long long &n ){
float m=0 , b=0;
float a=0 , q=0 ,c=0,d=0 ,e=0 ,f=0,g=0;
for(long long i=1;i<=n;++i ){
a+=(x[i]*y[i]);
q+=x[i];
c+=y[i];
d+=pow(x[i],2);
}
a=a*n;
d=d*n;
e=pow(q,2);
m=(a-(q*c))/(d-e);
f=c;
g=m*q;
b=(f-g)/n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if(m==0 && b==0){
std::cout << "y = 0" ;
}else if (m==-1 &&b==0){
std::cout << "y = -x" ;
}
else if (m==0 &&b<0){
std::cout << "y = " << b ;
}
else if (m==1 &&b==0){
std::cout << "y = x" ;
}else if (m==-1 && b<0){
std::cout << "y = -x - " << -b ;
}
else if (b<0){
std::cout << "y = "<< m <<"x - " << -b ;
}
else if (m==0){
std::cout << "y = " << b ;
}
else if (b==0){
std::cout << "y = " << m << "x" ;
}
else if (m==1){
std::cout << "y = x + " << b ;
}
else if (m==-1){
std::cout << "y = -x + " << b ;
}
}
int main(){
long long n=0;
std::cin >> n;
string f ;
std::cin >> f ;
float a=0 , b=0;
std::vector<float> x , y ;
x.push_back(0);
y.push_back(0);
for(long long i=0; i<n ; ++i){
std::cin >> a >> b ;
x.push_back(a);
y.push_back(b);
}
if(f=="mb"){
mb(x,y,n);
}
if(f=="func"){
func(x,y,n);
}
} |
# 0803, 2024-11-02 10:08:38, PPPPPPPPPP-------------- (41%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; string out;
cin>>n>>out;
double xx,yy; vector<double> x; vector<double> y;
for(int i=0;i<n;i++){
cin>>xx>>yy;
x.push_back(xx); y.push_back(yy);
}
double m,q=0,w=0,e=0,r=0;
for(int i=0;i<n;i++){q+=x[i]*y[i]; w+=x[i]; e+=y[i]; r+=pow(x[i],2);}
m=((n*q)-(w*e))/((n*r)-pow(w,2));
double b=(e-(m*w))/n;
if(out=="mb"){cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;}
// else{
// }
} | # 0804, 2024-11-02 10:26:53, PPPPPPPPPPPPPPPP-PPP-P-- (83%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; string out;
cin>>n>>out;
double xx,yy; vector<double> x; vector<double> y;
for(int i=0;i<n;i++){
cin>>xx>>yy;
x.push_back(xx); y.push_back(yy);
}
double m,q=0,w=0,e=0,r=0;
for(int i=0;i<n;i++){q+=x[i]*y[i]; w+=x[i]; e+=y[i]; r+=pow(x[i],2);}
m=((n*q)-(w*e))/((n*r)-pow(w,2));
double b=(e-(m*w))/n;
if(out=="mb"){cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;}
else{
if(m==0){cout<<"y = "<<b;}
else{
if(m==-1){
if(b==0)cout<<"y = -x";
else if(b<0) cout<<"y = -x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = -x +"<<round(b*1e3)/1e3;
}
else if(m==1){
if(b==0) cout<<"y = x";
else if(b<0) cout<<"y = x - "<<round(b*-1*1e3)/1e3;
else if(b>0) cout<<"y = x + "<<round(b*1e3)/1e3;
}
else{
if(b==0) cout<<"y = "<<round(m*1e3)/1e3<<'x';
else if(b<0) cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
}
}
} | # 0805, 2024-11-02 10:30:38, PPPPPPPPPPPPPPPP-PPP-P-- (83%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; string out;
cin>>n>>out;
double xx,yy; vector<double> x; vector<double> y;
for(int i=0;i<n;i++){
cin>>xx>>yy;
x.push_back(xx); y.push_back(yy);
}
double m,q=0,w=0,e=0,r=0;
for(int i=0;i<n;i++){q+=x[i]*y[i]; w+=x[i]; e+=y[i]; r+=pow(x[i],2);}
m=((n*q)-(w*e))/((n*r)-pow(w,2));
double b=(e-(m*w))/n;
if(out=="mb"){cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;}
else{
if(m==0){
if(b>0)cout<<"y = "<<round(b*1e3)/1e3;
else if(b<0)cout<<"y = -"<<round(b*-1*1e3)/1e3;
else if(b==0)cout<<"y = 0";}
else{
if(m==-1){
if(b==0)cout<<"y = -x";
else if(b<0) cout<<"y = -x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = -x +"<<round(b*1e3)/1e3;
}
else if(m==1){
if(b==0) cout<<"y = x";
else if(b<0) cout<<"y = x - "<<round(b*-1*1e3)/1e3;
else if(b>0) cout<<"y = x + "<<round(b*1e3)/1e3;
}
else{
if(b==0) cout<<"y = "<<round(m*1e3)/1e3<<'x';
else if(b<0) cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
}
}
} | # 0806, 2024-11-02 10:33:12, Compilation error (0%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; string out;
cin>>n>>out;
double xx,yy; vector<double> x; vector<double> y;
for(int i=0;i<n;i++){
cin>>xx>>yy;
x.push_back(xx); y.push_back(yy);
}
double m,q=0,w=0,e=0,r=0;
for(int i=0;i<n;i++){q+=x[i]*y[i]; w+=x[i]; e+=y[i]; r+=pow(x[i],2);}
m=((n*q)-(w*e))/((n*r)-pow(w,2));
double b=(e-(m*w))/n;
if(out=="mb"){cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;}
else{
if(m==0){
if(b>0)cout<<"y = "<<round(b*1e3)/1e3;
else if(b<0)cout<<"y = -"<<round(b*-1*1e3)/1e3;
else if(b==0)cout<<"y = 0";}
else{
if(m==-1){
if(b==0)cout<<"y = -x";
else if(b<0) cout<<"y = -x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = -x +"<<round(b*1e3)/1e3;
}
else if(m==1){
if(b==0) cout<<"y = x";
else if(b<0) cout<<"y = x - "<<round(b*-1*1e3)/1e3;
else if(b>0) cout<<"y = x + "<<round(b*1e3)/1e3;
}
else{
if(m>0){
if(b==0) cout<<"y = "<<round(m*1e3)/1e3<<'x';
else if(b<0) cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
else if (m<0){
if(m>0){
if(b==0) cout<<"y = -"<<round(m*-1*1e3)/1e3<<'x';
else if(b<0) cout<<"y = -"<<round(m*-1*1e3)/1e3<<"x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = -"<<round(m*-1*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
}
}
}
} | # 0807, 2024-11-02 10:34:24, PPPPPPPPPPPP---P-PPP-P-- (70%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; string out;
cin>>n>>out;
double xx,yy; vector<double> x; vector<double> y;
for(int i=0;i<n;i++){
cin>>xx>>yy;
x.push_back(xx); y.push_back(yy);
}
double m,q=0,w=0,e=0,r=0;
for(int i=0;i<n;i++){q+=x[i]*y[i]; w+=x[i]; e+=y[i]; r+=pow(x[i],2);}
m=((n*q)-(w*e))/((n*r)-pow(w,2));
double b=(e-(m*w))/n;
if(out=="mb"){cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;}
else{
if(m==0){
if(b>0)cout<<"y = "<<round(b*1e3)/1e3;
else if(b<0)cout<<"y = -"<<round(b*-1*1e3)/1e3;
else if(b==0)cout<<"y = 0";}
else{
if(m==-1){
if(b==0)cout<<"y = -x";
else if(b<0) cout<<"y = -x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = -x +"<<round(b*1e3)/1e3;
}
else if(m==1){
if(b==0) cout<<"y = x";
else if(b<0) cout<<"y = x - "<<round(b*-1*1e3)/1e3;
else if(b>0) cout<<"y = x + "<<round(b*1e3)/1e3;
}
else{
if(m>0){
if(b==0) cout<<"y = "<<round(m*1e3)/1e3<<'x';
else if(b<0) cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
else if (m<0){
if(m>0){
if(b==0) cout<<"y = -"<<round(m*-1*1e3)/1e3<<'x';
else if(b<0) cout<<"y = -"<<round(m*-1*1e3)/1e3<<"x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = -"<<round(m*-1*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
}
}
}
}} | # 0808, 2024-11-02 10:35:02, PPPPPPPPPPPPPPPP-PPP-P-- (83%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; string out;
cin>>n>>out;
double xx,yy; vector<double> x; vector<double> y;
for(int i=0;i<n;i++){
cin>>xx>>yy;
x.push_back(xx); y.push_back(yy);
}
double m,q=0,w=0,e=0,r=0;
for(int i=0;i<n;i++){q+=x[i]*y[i]; w+=x[i]; e+=y[i]; r+=pow(x[i],2);}
m=((n*q)-(w*e))/((n*r)-pow(w,2));
double b=(e-(m*w))/n;
if(out=="mb"){cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;}
else{
if(m==0){
if(b>0)cout<<"y = "<<round(b*1e3)/1e3;
else if(b<0)cout<<"y = -"<<round(b*-1*1e3)/1e3;
else if(b==0)cout<<"y = 0";}
else{
if(m==-1){
if(b==0)cout<<"y = -x";
else if(b<0) cout<<"y = -x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = -x +"<<round(b*1e3)/1e3;
}
else if(m==1){
if(b==0) cout<<"y = x";
else if(b<0) cout<<"y = x - "<<round(b*-1*1e3)/1e3;
else if(b>0) cout<<"y = x + "<<round(b*1e3)/1e3;
}
else{
if(b==0) cout<<"y = "<<round(m*1e3)/1e3<<'x';
else if(b<0) cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
}
}
} | # 0809, 2024-11-02 10:38:35, PPPPPPPPPPPPPPPP-PPP-P-- (83%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; string out;
cin>>n>>out;
double xx,yy; vector<double> x; vector<double> y;
for(int i=0;i<n;i++){
cin>>xx>>yy;
x.push_back(xx); y.push_back(yy);
}
double m,q=0,w=0,e=0,r=0;
for(int i=0;i<n;i++){q+=x[i]*y[i]; w+=x[i]; e+=y[i]; r+=pow(x[i],2);}
m=((n*q)-(w*e))/((n*r)-pow(w,2));
double b=(e-(m*w))/n;
if(out=="mb"){cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;}
else{
if(m==0){
if(b>0)cout<<"y = "<<round(b*1e3)/1e3;
else if(b<0)cout<<"y = -"<<round(b*-1*1e3)/1e3;
else if(b==0)cout<<"y = 0";}
else{
if(m==-1){
if(b==0)cout<<"y = -x";
else if(b<0) cout<<"y = -x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = -x +"<<round(b*1e3)/1e3;
}
else if(m==1){
if(b==0) cout<<"y = x";
else if(b<0) cout<<"y = x - "<<round(b*-1*1e3)/1e3;
else if(b>0) cout<<"y = x + "<<round(b*1e3)/1e3;
}
else{
if(m>1){
if(b==0) cout<<"y = "<<round(m*1e3)/1e3<<'x';
else if(b<0) cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
else if(m<-1){
if(b==0) cout<<"y = -"<<round(m*-1*1e3)/1e3<<'x';
else if(b<0) cout<<"y = -"<<round(m*-1*1e3)/1e3<<"x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = -"<<round(m*-1*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
}
}
}
} | # 0810, 2024-11-02 10:40:09, PPPPPPPPPPPPPPPP-PPP-P-- (83%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; string out;
cin>>n>>out;
double xx,yy; vector<double> x; vector<double> y;
for(int i=0;i<n;i++){
cin>>xx>>yy;
x.push_back(xx); y.push_back(yy);
}
double m,q=0,w=0,e=0,r=0;
for(int i=0;i<n;i++){q+=x[i]*y[i]; w+=x[i]; e+=y[i]; r+=pow(x[i],2);}
m=((n*q)-(w*e))/((n*r)-pow(w,2));
double b=(e-(m*w))/n;
if(out=="mb"){cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;}
else{
if(m==0){
if(b>0)cout<<"y = "<<round(b*1e3)/1e3;
else if(b<0)cout<<"y = "<<round(b*1e3)/1e3;
else if(b==0)cout<<"y = 0";}
else{
if(m==-1){
if(b==0)cout<<"y = -x";
else if(b<0) cout<<"y = -x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = -x +"<<round(b*1e3)/1e3;
}
else if(m==1){
if(b==0) cout<<"y = x";
else if(b<0) cout<<"y = x - "<<round(b*-1*1e3)/1e3;
else if(b>0) cout<<"y = x + "<<round(b*1e3)/1e3;
}
else{
if(m>1){
if(b==0) cout<<"y = "<<round(m*1e3)/1e3<<'x';
else if(b<0) cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
else if(m<-1){
if(b==0) cout<<"y = -"<<round(m*-1*1e3)/1e3<<'x';
else if(b<0) cout<<"y = -"<<round(m*-1*1e3)/1e3<<"x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = -"<<round(m*-1*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
}
}
}
} | # 0811, 2024-11-02 10:42:08, Compilation error (0%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; string out;
cin>>n>>out;
double xx,yy; vector<double> x; vector<double> y;
for(int i=0;i<n;i++){
cin>>xx>>yy;
x.push_back(xx); y.push_back(yy);
}
double m,q=0,w=0,e=0,r=0;
for(int i=0;i<n;i++){q+=x[i]*y[i]; w+=x[i]; e+=y[i]; r+=pow(x[i],2);}
m=((n*q)-(w*e))/((n*r)-pow(w,2));
double b=(e-(m*w))/n;
if(out=="mb"){cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;}
else if(cout=="func"){
if(m==0){
if(b>0)cout<<"y = "<<round(b*1e3)/1e3;
else if(b<0)cout<<"y = "<<round(b*1e3)/1e3;
else if(b==0)cout<<"y = 0";}
else{
if(m==-1){
if(b==0)cout<<"y = -x";
else if(b<0) cout<<"y = -x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = -x +"<<round(b*1e3)/1e3;
}
else if(m==1){
if(b==0) cout<<"y = x";
else if(b<0) cout<<"y = x - "<<round(b*-1*1e3)/1e3;
else if(b>0) cout<<"y = x + "<<round(b*1e3)/1e3;
}
else{
if(m>1){
if(b==0) cout<<"y = "<<round(m*1e3)/1e3<<'x';
else if(b<0) cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
else if(m<-1){
if(b==0) cout<<"y = -"<<round(m*-1*1e3)/1e3<<'x';
else if(b<0) cout<<"y = -"<<round(m*-1*1e3)/1e3<<"x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = -"<<round(m*-1*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
}
}
}
} | # 0812, 2024-11-02 10:42:25, PPPPPPPPPPPPPPPP-PPP-P-- (83%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; string out;
cin>>n>>out;
double xx,yy; vector<double> x; vector<double> y;
for(int i=0;i<n;i++){
cin>>xx>>yy;
x.push_back(xx); y.push_back(yy);
}
double m,q=0,w=0,e=0,r=0;
for(int i=0;i<n;i++){q+=x[i]*y[i]; w+=x[i]; e+=y[i]; r+=pow(x[i],2);}
m=((n*q)-(w*e))/((n*r)-pow(w,2));
double b=(e-(m*w))/n;
if(out=="mb"){cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;}
else if(out=="func"){
if(m==0){
if(b>0)cout<<"y = "<<round(b*1e3)/1e3;
else if(b<0)cout<<"y = "<<round(b*1e3)/1e3;
else if(b==0)cout<<"y = 0";}
else{
if(m==-1){
if(b==0)cout<<"y = -x";
else if(b<0) cout<<"y = -x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = -x +"<<round(b*1e3)/1e3;
}
else if(m==1){
if(b==0) cout<<"y = x";
else if(b<0) cout<<"y = x - "<<round(b*-1*1e3)/1e3;
else if(b>0) cout<<"y = x + "<<round(b*1e3)/1e3;
}
else{
if(m>1){
if(b==0) cout<<"y = "<<round(m*1e3)/1e3<<'x';
else if(b<0) cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
else if(m<-1){
if(b==0) cout<<"y = -"<<round(m*-1*1e3)/1e3<<'x';
else if(b<0) cout<<"y = -"<<round(m*-1*1e3)/1e3<<"x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = -"<<round(m*-1*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
}
}
}
} | # 0813, 2024-11-02 10:42:58, ----------PPPPPP-PPP-P-- (41%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; string out;
cin>>n>>out;
double xx,yy; vector<double> x; vector<double> y;
for(int i=0;i<n;i++){
cin>>xx>>yy;
x.push_back(xx); y.push_back(yy);
}
double m,q=0,w=0,e=0,r=0;
for(int i=0;i<n;i++){q+=x[i]*y[i]; w+=x[i]; e+=y[i]; r+=pow(x[i],2);}
m=((n*q)-(w*e))/((n*r)-pow(w,2));
double b=(e-(m*w))/n;
if(out=="func"){
if(m==0){
if(b>0)cout<<"y = "<<round(b*1e3)/1e3;
else if(b<0)cout<<"y = "<<round(b*1e3)/1e3;
else if(b==0)cout<<"y = 0";}
else{
if(m==-1){
if(b==0)cout<<"y = -x";
else if(b<0) cout<<"y = -x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = -x +"<<round(b*1e3)/1e3;
}
else if(m==1){
if(b==0) cout<<"y = x";
else if(b<0) cout<<"y = x - "<<round(b*-1*1e3)/1e3;
else if(b>0) cout<<"y = x + "<<round(b*1e3)/1e3;
}
else{
if(m>1){
if(b==0) cout<<"y = "<<round(m*1e3)/1e3<<'x';
else if(b<0) cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
else if(m<-1){
if(b==0) cout<<"y = -"<<round(m*-1*1e3)/1e3<<'x';
else if(b<0) cout<<"y = -"<<round(m*-1*1e3)/1e3<<"x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = -"<<round(m*-1*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
}
}
}
} | # 0814, 2024-11-02 10:43:53, PPPPPPPPPPPPPPPP-PPP-P-- (83%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; string out;
cin>>n>>out;
double xx,yy; vector<double> x; vector<double> y;
for(int i=0;i<n;i++){
cin>>xx>>yy;
x.push_back(xx); y.push_back(yy);
}
double m,q=0,w=0,e=0,r=0;
for(int i=0;i<n;i++){q+=x[i]*y[i]; w+=x[i]; e+=y[i]; r+=pow(x[i],2);}
m=((n*q)-(w*e))/((n*r)-pow(w,2));
double b=(e-(m*w))/n;
if(out=="mb"){cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;}
else if(out=="func"){
if(m==0){
if(b>0)cout<<"y = "<<round(b*1e3)/1e3;
else if(b<0)cout<<"y = "<<round(b*1e3)/1e3;
else if(b==0)cout<<"y = 0";}
else{
if(m==-1){
if(b==0)cout<<"y = -x";
else if(b<0) cout<<"y = -x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = -x +"<<round(b*1e3)/1e3;
}
else if(m==1){
if(b==0) cout<<"y = x";
else if(b<0) cout<<"y = x - "<<round(b*-1*1e3)/1e3;
else if(b>0) cout<<"y = x + "<<round(b*1e3)/1e3;
}
else{
if(m>1){
if(b==0) cout<<"y = "<<round(m*1e3)/1e3<<'x';
else if(b<0) cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
else if(m<-1){
if(b==0) cout<<"y = -"<<round(m*-1*1e3)/1e3<<'x';
else if(b<0) cout<<"y = -"<<round(m*-1*1e3)/1e3<<"x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = -"<<round(m*-1*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
}
}
}
} | # 0815, 2024-11-02 11:25:02, PPPPPPPPPPPPPPPP-PPPPP-- (87%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; string out;
cin>>n>>out;
double xx,yy; vector<double> x; vector<double> y;
for(int i=0;i<n;i++){
cin>>xx>>yy;
x.push_back(xx); y.push_back(yy);
}
double m,q=0,w=0,e=0,r=0;
for(int i=0;i<n;i++){q+=x[i]*y[i]; w+=x[i]; e+=y[i]; r+=pow(x[i],2);}
m=((n*q)-(w*e))/((n*r)-pow(w,2));
double b=(e-(m*w))/n;
if(out=="mb"){cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;}
else if(out=="func"){
if(m==0){
if(b>0)cout<<"y = "<<round(b*1e3)/1e3;
else if(b<0)cout<<"y = "<<round(b*1e3)/1e3;
else if(b==0)cout<<"y = 0";}
else{
if(m==-1){
if(b==0)cout<<"y = -x";
else if(b<0) cout<<"y = -x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = -x + "<<round(b*1e3)/1e3;
}
else if(m==1){
if(b==0) cout<<"y = x";
else if(b<0) cout<<"y = x - "<<round(b*-1*1e3)/1e3;
else if(b>0) cout<<"y = x + "<<round(b*1e3)/1e3;
}
else{
if(m>1){
if(b==0) cout<<"y = "<<round(m*1e3)/1e3<<'x';
else if(b<0) cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
else if(m<-1){
if(b==0) cout<<"y = -"<<round(m*-1*1e3)/1e3<<'x';
else if(b<0) cout<<"y = -"<<round(m*-1*1e3)/1e3<<"x - "<<round(b*-1*1e3)/1e3;
else if(b>0)cout<<"y = -"<<round(m*-1*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
}
}
}
} |
# 0816, 2024-11-02 13:00:57, PPPPPPPPPPP-P----P--P--- (58%)
#include<bits/stdc++.h>
using namespace std;
float all(vector<float> x,vector<float> y , int n){
float sum = 0;
for(int i = 0; i < n; i++){
sum += x[i]*y[i];
}
return sum;
}
float solo(vector<float> x, int n){
float sum = 0;
for(int i = 0; i < n; i++){
sum += x[i];
}
return sum;
}
int main(){
int num;
float val1,val2,m,m1,m2,b;
string order;
vector<float> x;
vector<float> y;
cin >> num >> order;
for(int i = 0; i < num; i++){
cin >> val1 >> val2;
x.push_back(val1);
y.push_back(val2);
}
m1 = (num*all(x,y,num)) - (solo(x,num)*solo(y,num));
m2 = (num*all(x,x,num)) - (solo(x,num)*solo(x,num));
m = m1/m2;
b = (solo(y,num) - m*(solo(x,num)))/num;
if(order == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
}else if(order == "func"){
if(round(m*1e3)/1e3 != 1 && round(m*1e3)/1e3 != -1)
cout << "y = "<< round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
else if(round(m*1e3)/1e3 == 1)
cout << "y = "<< "x + " << round(b*1e3)/1e3;
else if(round(m*1e3)/1e3 == -1)
cout << "y = "<< "-x + " << round(b*1e3)/1e3;
}
} | # 0817, 2024-11-02 13:13:28, PPPPPPPPPPPPP--PPPPPP-PP (87%)
#include<bits/stdc++.h>
using namespace std;
float all(vector<float> x,vector<float> y , int n){
float sum = 0;
for(int i = 0; i < n; i++){
sum += x[i]*y[i];
}
return sum;
}
float solo(vector<float> x, int n){
float sum = 0;
for(int i = 0; i < n; i++){
sum += x[i];
}
return sum;
}
void check(float b){
if(round(b*1e3)/1e3 > 0) cout << " + " << round(b*1e3)/1e3;
else if(round(b*1e3)/1e3 == 0);
else if(round(b*1e3)/1e3 < 0) cout << " - " << -1*round(b*1e3)/1e3;
}
int main(){
int num;
float val1,val2,m,m1,m2,b;
string order;
vector<float> x;
vector<float> y;
cin >> num >> order;
for(int i = 0; i < num; i++){
cin >> val1 >> val2;
x.push_back(val1);
y.push_back(val2);
}
m1 = (num*all(x,y,num)) - (solo(x,num)*solo(y,num));
m2 = (num*all(x,x,num)) - (solo(x,num)*solo(x,num));
m = m1/m2;
b = (solo(y,num) - m*(solo(x,num)))/num;
if(order == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
}else if(order == "func"){
if(round(m*1e3)/1e3 != 1 && round(m*1e3)/1e3 != -1 && round(b*1e3)/1e3 > 0 && round(m*1e3)/1e3 != 0)
cout << "y = "<< round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
else if(round(m*1e3)/1e3 == 1 ){
cout << "y = x";
check(b);
}
else if(round(m*1e3)/1e3 == -1 ){
cout << "y = -x";
check(b);
}
else if(round(m*1e3)/1e3 == 0 ){
cout << "y = ";
if(round(b*1e3)/1e3 > 0) cout << round(b*1e3)/1e3;
else if(round(b*1e3)/1e3 == 0) cout << 0;
else if(round(b*1e3)/1e3 < 0) cout << -1*round(b*1e3)/1e3;
}else if(round(m*1e3)/1e3 > 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
check(b);
}
}
} | # 0818, 2024-11-02 15:15:14, ------------------------ (0%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int num;
set<long long>q1,q2,q3,q4;
set<long long>yq1,yq2,yq3,yq4;
cin >> num;
long long x,y;
for(int i = 0; i < num; i++){
cin >> x >> y;
if(x > 0 && y > 0){
q1.insert(x);
yq1.insert(y);
}
if(x < 0 && y > 0){
q2.insert(x);
yq2.insert(y);
}
if(x < 0 && y < 0){
q3.insert(x);
yq3.insert(y);
}
if(x > 0 && y < 0){
q4.insert(x);
yq4.insert(y);
}
}
bool max = true;
if(q1.size() > 0){
max = false;
long long area = abs(*(q1.begin()) - *(--q1.end()))* abs(*(yq1.begin()) - *(--yq1.end()));
cout << "Q1: (" << *(q1.begin())<< ", " << *(yq1.begin()) << ") (" << *(--q1.end()) << ", " << *(--yq1.end()) << ") " << area << endl;
}if(q2.size() > 0){
max = false;
long long area = abs(*(q2.begin()) - *(--q2.end()))* abs(*(yq2.begin()) - *(--yq2.end()));
cout << "Q2: (" << *(q2.begin())<< ", " << *(yq2.begin()) << ") (" << *(--q2.end()) << ", " << *(--yq2.end()) << ") " << area << endl;
}if(q3.size() > 0){
max = false;
long long area = abs(*(q3.begin()) - *(--q3.end()))* abs(*(yq3.begin()) - *(--yq3.end()));
cout << "Q3: (" << *(q3.begin())<< ", " << *(yq3.begin()) << ") (" << *(--q3.end()) << ", " << *(--yq3.end()) << ") " << area << endl;
}if(q4.size() > 0){
max = false;
long long area = abs(*(q4.begin()) - *(--q4.end()))* abs(*(yq4.begin()) - *(--yq4.end()));
cout << "Q4: (" << *(q4.begin())<< ", " << *(yq4.begin()) << ") (" << *(--q4.end()) << ", " << *(--yq4.end()) << ") " << area << endl;
}
if(max)
cout << "No polong long in any quadrant";
} | # 0819, 2024-11-02 15:15:46, PPPPPPPPPPPPP--PPPPPP-PP (87%)
#include<bits/stdc++.h>
using namespace std;
float all(vector<float> x,vector<float> y , int n){
float sum = 0;
for(int i = 0; i < n; i++){
sum += x[i]*y[i];
}
return sum;
}
float solo(vector<float> x, int n){
float sum = 0;
for(int i = 0; i < n; i++){
sum += x[i];
}
return sum;
}
void check(float b){
if(round(b*1e3)/1e3 > 0) cout << " + " << round(b*1e3)/1e3;
else if(round(b*1e3)/1e3 == 0);
else if(round(b*1e3)/1e3 < 0) cout << " - " << -1*round(b*1e3)/1e3;
}
int main(){
int num;
float val1,val2,m,m1,m2,b;
string order;
vector<float> x;
vector<float> y;
cin >> num >> order;
for(int i = 0; i < num; i++){
cin >> val1 >> val2;
x.push_back(val1);
y.push_back(val2);
}
m1 = (num*all(x,y,num)) - (solo(x,num)*solo(y,num));
m2 = (num*all(x,x,num)) - (solo(x,num)*solo(x,num));
m = m1/m2;
b = (solo(y,num) - m*(solo(x,num)))/num;
if(order == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
}else if(order == "func"){
if(round(m*1e3)/1e3 != 1 && round(m*1e3)/1e3 != -1 && round(b*1e3)/1e3 > 0 && round(m*1e3)/1e3 != 0)
cout << "y = "<< round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
else if(round(m*1e3)/1e3 == 1 ){
cout << "y = x";
check(b);
}
else if(round(m*1e3)/1e3 == -1 ){
cout << "y = -x";
check(b);
}
else if(round(m*1e3)/1e3 == 0 ){
cout << "y = ";
if(round(b*1e3)/1e3 > 0) cout << round(b*1e3)/1e3;
else if(round(b*1e3)/1e3 == 0) cout << 0;
else if(round(b*1e3)/1e3 < 0) cout << -1*round(b*1e3)/1e3;
}else if(round(m*1e3)/1e3 > 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
check(b);
}
}
} | # 0820, 2024-11-02 15:19:35, PPPPPPPPPPPP---PPPPPP-PP (83%)
#include<bits/stdc++.h>
using namespace std;
float all(vector<float> x,vector<float> y , int n){
float sum = 0;
for(int i = 0; i < n; i++){
sum += x[i]*y[i];
}
return sum;
}
float solo(vector<float> x, int n){
float sum = 0;
for(int i = 0; i < n; i++){
sum += x[i];
}
return sum;
}
void check(float b){
if(round(b*1e3)/1e3 > 0) cout << " + " << round(b*1e3)/1e3;
else if(round(b*1e3)/1e3 == 0);
else if(round(b*1e3)/1e3 < 0) cout << " - " << -1*round(b*1e3)/1e3;
}
int main(){
int num;
float val1,val2,m,m1,m2,b;
string order;
vector<float> x;
vector<float> y;
cin >> num >> order;
for(int i = 0; i < num; i++){
cin >> val1 >> val2;
x.push_back(val1);
y.push_back(val2);
}
m1 = (num*all(x,y,num)) - (solo(x,num)*solo(y,num));
m2 = (num*all(x,x,num)) - (solo(x,num)*solo(x,num));
m = m1/m2;
b = (solo(y,num) - m*(solo(x,num)))/num;
if(order == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
}else if(order == "func"){
if(round(m*1e3)/1e3 == 1 ){
cout << "y = x";
check(b);
}
else if(round(m*1e3)/1e3 == -1 ){
cout << "y = -x";
check(b);
}
else if(round(m*1e3)/1e3 == 0 ){
cout << "y = ";
if(round(b*1e3)/1e3 > 0) cout << round(b*1e3)/1e3;
else if(round(b*1e3)/1e3 == 0) cout << 0;
else if(round(b*1e3)/1e3 < 0) cout << -1*round(b*1e3)/1e3;
}else if(round(m*1e3)/1e3 > 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
check(b);
}
}
} | # 0821, 2024-11-02 15:24:33, PPPPPPPPPPPP-----PPPP-PP (75%)
#include<bits/stdc++.h>
using namespace std;
float all(vector<float> x,vector<float> y , int n){
float sum = 0;
for(int i = 0; i < n; i++){
sum += x[i]*y[i];
}
return sum;
}
float solo(vector<float> x, int n){
float sum = 0;
for(int i = 0; i < n; i++){
sum += x[i];
}
return sum;
}
void check(float b){
if(round(b*1e3)/1e3 > 0) cout << " + " << round(b*1e3)/1e3;
else if(round(b*1e3)/1e3 == 0);
else if(round(b*1e3)/1e3 < 0) cout << " - " << -1*round(b*1e3)/1e3;
}
int main(){
int num;
float val1,val2,m,m1,m2,b;
string order;
vector<float> x;
vector<float> y;
cin >> num >> order;
for(int i = 0; i < num; i++){
cin >> val1 >> val2;
x.push_back(val1);
y.push_back(val2);
}
m1 = (num*all(x,y,num)) - (solo(x,num)*solo(y,num));
m2 = (num*all(x,x,num)) - (solo(x,num)*solo(x,num));
m = m1/m2;
b = (solo(y,num) - m*(solo(x,num)))/num;
if(order == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
}else if(order == "func"){
if(round(m*1e3)/1e3 == 1 ){
cout << "y = x";
check(b);
}
else if(round(m*1e3)/1e3 == -1 ){
cout << "y = -x";
check(b);
}
else if(round(m*1e3)/1e3 == 0 ){
if(round(b*1e3)/1e3 > 0) cout << round(b*1e3)/1e3;
else if(round(b*1e3)/1e3 == 0) cout << 0;
else if(round(b*1e3)/1e3 < 0) cout << -1*round(b*1e3)/1e3;
}else if(round(m*1e3)/1e3 > 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
check(b);
}
}
} | # 0822, 2024-11-02 15:24:49, PPPPPPPPPPPP-----PPPP-PP (75%)
#include<bits/stdc++.h>
using namespace std;
float all(vector<float> x,vector<float> y , int n){
float sum = 0;
for(int i = 0; i < n; i++){
sum += x[i]*y[i];
}
return sum;
}
float solo(vector<float> x, int n){
float sum = 0;
for(int i = 0; i < n; i++){
sum += x[i];
}
return sum;
}
void check(float b){
if(round(b*1e3)/1e3 > 0) cout << " + " << round(b*1e3)/1e3;
else if(round(b*1e3)/1e3 == 0);
else if(round(b*1e3)/1e3 < 0) cout << " - " << -1*round(b*1e3)/1e3;
}
int main(){
int num;
float val1,val2,m,m1,m2,b;
string order;
vector<float> x;
vector<float> y;
cin >> num >> order;
for(int i = 0; i < num; i++){
cin >> val1 >> val2;
x.push_back(val1);
y.push_back(val2);
}
m1 = (num*all(x,y,num)) - (solo(x,num)*solo(y,num));
m2 = (num*all(x,x,num)) - (solo(x,num)*solo(x,num));
m = m1/m2;
b = (solo(y,num) - m*(solo(x,num)))/num;
if(order == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
}else if(order == "func"){
if(round(m*1e3)/1e3 == 1 ){
cout << "y = x";
check(b);
}
else if(round(m*1e3)/1e3 == -1 ){
cout << "y = -x";
check(b);
}
else if(round(m*1e3)/1e3 == 0 ){
if(round(b*1e3)/1e3 > 0) cout << round(b*1e3)/1e3;
else if(round(b*1e3)/1e3 == 0) cout << 0;
else if(round(b*1e3)/1e3 < 0) cout << -1*round(b*1e3)/1e3;
}else if(round(m*1e3)/1e3 > 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
check(b);
}
}
} | # 0823, 2024-11-02 15:24:57, PPPPPPPPPPPP-----PPPP-PP (75%)
#include<bits/stdc++.h>
using namespace std;
float all(vector<float> x,vector<float> y , int n){
float sum = 0;
for(int i = 0; i < n; i++){
sum += x[i]*y[i];
}
return sum;
}
float solo(vector<float> x, int n){
float sum = 0;
for(int i = 0; i < n; i++){
sum += x[i];
}
return sum;
}
void check(float b){
if(round(b*1e3)/1e3 > 0) cout << " + " << round(b*1e3)/1e3;
else if(round(b*1e3)/1e3 == 0);
else if(round(b*1e3)/1e3 < 0) cout << " - " << -1*round(b*1e3)/1e3;
}
int main(){
int num;
float val1,val2,m,m1,m2,b;
string order;
vector<float> x;
vector<float> y;
cin >> num >> order;
for(int i = 0; i < num; i++){
cin >> val1 >> val2;
x.push_back(val1);
y.push_back(val2);
}
m1 = (num*all(x,y,num)) - (solo(x,num)*solo(y,num));
m2 = (num*all(x,x,num)) - (solo(x,num)*solo(x,num));
m = m1/m2;
b = (solo(y,num) - m*(solo(x,num)))/num;
if(order == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
}else if(order == "func"){
if(round(m*1e3)/1e3 == 1 ){
cout << "y = x";
check(b);
}
else if(round(m*1e3)/1e3 == -1 ){
cout << "y = -x";
check(b);
}
else if(round(m*1e3)/1e3 == 0 ){
if(round(b*1e3)/1e3 > 0) cout << round(b*1e3)/1e3;
else if(round(b*1e3)/1e3 == 0) cout << 0;
else if(round(b*1e3)/1e3 < 0) cout << -1*round(b*1e3)/1e3;
}else if(round(m*1e3)/1e3 > 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
check(b);
}
}
} | # 0824, 2024-11-02 15:25:20, PPPPPPPPPPPPP--PPPPPP-PP (87%)
#include<bits/stdc++.h>
using namespace std;
float all(vector<float> x,vector<float> y , int n){
float sum = 0;
for(int i = 0; i < n; i++){
sum += x[i]*y[i];
}
return sum;
}
float solo(vector<float> x, int n){
float sum = 0;
for(int i = 0; i < n; i++){
sum += x[i];
}
return sum;
}
void check(float b){
if(round(b*1e3)/1e3 > 0) cout << " + " << round(b*1e3)/1e3;
else if(round(b*1e3)/1e3 == 0);
else if(round(b*1e3)/1e3 < 0) cout << " - " << -1*round(b*1e3)/1e3;
}
int main(){
int num;
float val1,val2,m,m1,m2,b;
string order;
vector<float> x;
vector<float> y;
cin >> num >> order;
for(int i = 0; i < num; i++){
cin >> val1 >> val2;
x.push_back(val1);
y.push_back(val2);
}
m1 = (num*all(x,y,num)) - (solo(x,num)*solo(y,num));
m2 = (num*all(x,x,num)) - (solo(x,num)*solo(x,num));
m = m1/m2;
b = (solo(y,num) - m*(solo(x,num)))/num;
if(order == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
}else if(order == "func"){
if(round(m*1e3)/1e3 != 1 && round(m*1e3)/1e3 != -1 && round(b*1e3)/1e3 > 0 && round(m*1e3)/1e3 != 0)
cout << "y = "<< round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
else if(round(m*1e3)/1e3 == 1 ){
cout << "y = x";
check(b);
}
else if(round(m*1e3)/1e3 == -1 ){
cout << "y = -x";
check(b);
}
else if(round(m*1e3)/1e3 == 0 ){
cout << "y = ";
if(round(b*1e3)/1e3 > 0) cout << round(b*1e3)/1e3;
else if(round(b*1e3)/1e3 == 0) cout << 0;
else if(round(b*1e3)/1e3 < 0) cout << -1*round(b*1e3)/1e3;
}else if(round(m*1e3)/1e3 > 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
check(b);
}
}
} | # 0825, 2024-11-02 15:27:21, PPPPPPPPPP-----PPPPPP-PP (75%)
#include<bits/stdc++.h>
using namespace std;
float all(vector<float> x,vector<float> y , int n){
float sum = 0;
for(int i = 0; i < n; i++){
sum += x[i]*y[i];
}
return sum;
}
float solo(vector<float> x, int n){
float sum = 0;
for(int i = 0; i < n; i++){
sum += x[i];
}
return sum;
}
void check(float b){
if(round(b*1e3)/1e3 > 0) cout << " + " << round(b*1e3)/1e3;
else if(round(b*1e3)/1e3 == 0);
else if(round(b*1e3)/1e3 < 0) cout << " - " << -1*round(b*1e3)/1e3;
}
int main(){
int num;
float val1,val2,m,m1,m2,b;
string order;
vector<float> x;
vector<float> y;
cin >> num >> order;
for(int i = 0; i < num; i++){
cin >> val1 >> val2;
x.push_back(val1);
y.push_back(val2);
}
m1 = (num*all(x,y,num)) - (solo(x,num)*solo(y,num));
m2 = (num*all(x,x,num)) - (solo(x,num)*solo(x,num));
m = m1/m2;
b = (solo(y,num) - m*(solo(x,num)))/num;
if(order == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
}else if(order == "func"){
if(round(m*1e3)/1e3 != 1 && round(m*1e3)/1e3 != -1 && round(b*1e3)/1e3 > 0 && round(m*1e3)/1e3 != 0){
cout << "y = ";
check(b);
}
else if(round(m*1e3)/1e3 == 1 ){
cout << "y = x";
check(b);
}
else if(round(m*1e3)/1e3 == -1 ){
cout << "y = -x";
check(b);
}
else if(round(m*1e3)/1e3 == 0 ){
cout << "y = ";
if(round(b*1e3)/1e3 > 0) cout << round(b*1e3)/1e3;
else if(round(b*1e3)/1e3 == 0) cout << 0;
else if(round(b*1e3)/1e3 < 0) cout << -1*round(b*1e3)/1e3;
}
}
} | # 0826, 2024-11-02 15:29:47, PPPPPPPPPPP-P--PPPPPP-PP (83%)
#include<bits/stdc++.h>
using namespace std;
float all(vector<float> x,vector<float> y , int n){
float sum = 0;
for(int i = 0; i < n; i++){
sum += x[i]*y[i];
}
return sum;
}
float solo(vector<float> x, int n){
float sum = 0;
for(int i = 0; i < n; i++){
sum += x[i];
}
return sum;
}
void check(float b){
if(round(b*1e3)/1e3 > 0) cout << " + " << round(b*1e3)/1e3;
else if(round(b*1e3)/1e3 == 0);
else if(round(b*1e3)/1e3 < 0) cout << " - " << -1*round(b*1e3)/1e3;
}
int main(){
int num;
float val1,val2,m,m1,m2,b;
string order;
vector<float> x;
vector<float> y;
cin >> num >> order;
for(int i = 0; i < num; i++){
cin >> val1 >> val2;
x.push_back(val1);
y.push_back(val2);
}
m1 = (num*all(x,y,num)) - (solo(x,num)*solo(y,num));
m2 = (num*all(x,x,num)) - (solo(x,num)*solo(x,num));
m = m1/m2;
b = (solo(y,num) - m*(solo(x,num)))/num;
if(order == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
}else if(order == "func"){
if(round(m*1e3)/1e3 != 1 && round(m*1e3)/1e3 != -1 && round(b*1e3)/1e3 > 0 && round(m*1e3)/1e3 != 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
check(b);
}
else if(round(m*1e3)/1e3 == 1 ){
cout << "y = x";
check(b);
}
else if(round(m*1e3)/1e3 == -1 ){
cout << "y = -x";
check(b);
}
else if(round(m*1e3)/1e3 == 0 ){
cout << "y = ";
if(round(b*1e3)/1e3 > 0) cout << round(b*1e3)/1e3;
else if(round(b*1e3)/1e3 == 0) cout << 0;
else if(round(b*1e3)/1e3 < 0) cout << -1*round(b*1e3)/1e3;
}
}
} | # 0827, 2024-11-02 15:30:08, PPPPPPPPPPPPP--PPPPPP-PP (87%)
#include<bits/stdc++.h>
using namespace std;
float all(vector<float> x,vector<float> y , int n){
float sum = 0;
for(int i = 0; i < n; i++){
sum += x[i]*y[i];
}
return sum;
}
float solo(vector<float> x, int n){
float sum = 0;
for(int i = 0; i < n; i++){
sum += x[i];
}
return sum;
}
void check(float b){
if(round(b*1e3)/1e3 > 0) cout << " + " << round(b*1e3)/1e3;
else if(round(b*1e3)/1e3 == 0);
else if(round(b*1e3)/1e3 < 0) cout << " - " << -1*round(b*1e3)/1e3;
}
int main(){
int num;
float val1,val2,m,m1,m2,b;
string order;
vector<float> x;
vector<float> y;
cin >> num >> order;
for(int i = 0; i < num; i++){
cin >> val1 >> val2;
x.push_back(val1);
y.push_back(val2);
}
m1 = (num*all(x,y,num)) - (solo(x,num)*solo(y,num));
m2 = (num*all(x,x,num)) - (solo(x,num)*solo(x,num));
m = m1/m2;
b = (solo(y,num) - m*(solo(x,num)))/num;
if(order == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
}else if(order == "func"){
if(round(m*1e3)/1e3 != 1 && round(m*1e3)/1e3 != -1 && round(b*1e3)/1e3 > 0 && round(m*1e3)/1e3 != 0)
cout << "y = "<< round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
else if(round(m*1e3)/1e3 == 1 ){
cout << "y = x";
check(b);
}
else if(round(m*1e3)/1e3 == -1 ){
cout << "y = -x";
check(b);
}
else if(round(m*1e3)/1e3 == 0 ){
cout << "y = ";
if(round(b*1e3)/1e3 > 0) cout << round(b*1e3)/1e3;
else if(round(b*1e3)/1e3 == 0) cout << 0;
else if(round(b*1e3)/1e3 < 0) cout << -1*round(b*1e3)/1e3;
}else if(round(m*1e3)/1e3 > 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
check(b);
}
}
} |
# 0828, 2024-11-02 10:35:22, PPPPPPPPPP-------------- (41%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string c;
cin>>n>>c;
int N = n;
map<float,float> w;
vector<pair<float,float>> j = {make_pair(0.0,0.0)};
while(n--){
float x = 0.0,y =0.0;
cin>>x>>y;
j.push_back(make_pair(x,y));
}
float m = 0.0,b = 0.0;
float a1 = 0.0,a2 = 0.0,a3 = 0.0,b1 = 0.0,b2 = 0.0;
for(int i=1;i<=N;i++){
a1 += (j[i].first*j[i].second);
}
for(int i=1;i<=N;i++){
a2 += (j[i].first);
}
for(int i=1;i<=N;i++){
a3 += (j[i].second);
}
for(int i=1;i<=N;i++){
b1 += pow(j[i].first,2);
}
for(int i=1;i<=N;i++){
b2 += j[i].first;
}
m = ((N*a1)-((a2)*(a3)))/((N*b1)-(pow(b2,2)));
b = (a3-(m*a2))/N;
if(c == "mb"){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3;
}
} | # 0829, 2024-11-02 10:55:02, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string c;
cin>>n>>c;
int N = n;
map<float,float> w;
vector<pair<float,float>> j = {make_pair(0.0,0.0)};
while(n--){
float x = 0.0,y =0.0;
cin>>x>>y;
j.push_back(make_pair(x,y));
}
float m = 0.0,b = 0.0;
float a1 = 0.0,a2 = 0.0,a3 = 0.0,b1 = 0.0,b2 = 0.0;
for(int i=1;i<=N;i++){
a1 += (j[i].first*j[i].second);
}
for(int i=1;i<=N;i++){
a2 += (j[i].first);
}
for(int i=1;i<=N;i++){
a3 += (j[i].second);
}
for(int i=1;i<=N;i++){
b1 += pow(j[i].first,2);
}
for(int i=1;i<=N;i++){
b2 += j[i].first;
}
m = ((N*a1)-((a2)*(a3)))/((N*b1)-(pow(b2,2)));
b = (a3-(m*a2))/N;
if(c == "mb"){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3;
}
if(c == "func"){
cout<<"y = ";
if(m == 1&& b>0){
cout<<"x + "<<b;
}else if(m == 0 && b == 0){
cout<<0;
}else if(m == 1&&b ==0){
cout<<"x";
}else if(m == -1&b == 0){
cout<<"-x";
}else if(m == -1& b>=1){
cout<<"-x + "<<b;
}else if(m ==-1& b<=-1){
cout<<"-x "<<b;
}else if(m == 0){
cout<<b;
}else if(m != 0& b<0){
cout<<round(m*1e3)/1e3<<"x "<<"- "<<-round(b*1e3)/1e3;
}else{
cout<<round(m*1e3)/1e3<<"x "<<"+ "<<round(b*1e3)/1e3;
}
}
} | # 0830, 2024-11-02 11:07:32, PPPPPPPPPPPPPPPP---P-P-- (75%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string c;
cin>>n>>c;
int N = n;
map<float,float> w;
vector<pair<float,float>> j = {make_pair(0.0,0.0)};
while(n--){
float x = 0.0,y =0.0;
cin>>x>>y;
j.push_back(make_pair(x,y));
}
float m = 0.0,b = 0.0;
float a1 = 0.0,a2 = 0.0,a3 = 0.0,b1 = 0.0,b2 = 0.0;
for(int i=1;i<=N;i++){
a1 += (j[i].first*j[i].second);
}
for(int i=1;i<=N;i++){
a2 += (j[i].first);
}
for(int i=1;i<=N;i++){
a3 += (j[i].second);
}
for(int i=1;i<=N;i++){
b1 += pow(j[i].first,2);
}
for(int i=1;i<=N;i++){
b2 += j[i].first;
}
m = ((N*a1)-((a2)*(a3)))/((N*b1)-(pow(b2,2)));
b = (a3-(m*a2))/N;
if(c == "mb"){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3;
}
if(c == "func"){
cout<<"y = ";
if(m == 1&& b>0){
cout<<"x + "<<b;
}else if((m == 0||m== -0) && b == 0){
cout<<0;
}else if((m == 0||m == -0)&&b ==0){
cout<<"x";
}else if(m == -1&b == 0){
cout<<"-x";
}else if(m == -1& b>=1){
cout<<"-x + "<<b;
}else if(m ==-1& b<=-1){
cout<<"-x "<<b;
}else if(m == 0){
cout<<b;
}else if((m != 0||m != -0)& b<0){
cout<<round(m*1e3)/1e3<<"x "<<"- "<<-round(b*1e3)/1e3;
}else{
cout<<round(m*1e3)/1e3<<"x "<<"+ "<<round(b*1e3)/1e3;
}
}
} | # 0831, 2024-11-02 11:13:33, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string c;
cin>>n>>c;
int N = n;
map<float,float> w;
vector<pair<float,float>> j = {make_pair(0.0,0.0)};
while(n--){
float x = 0.0,y =0.0;
cin>>x>>y;
j.push_back(make_pair(x,y));
}
float m = 0.0,b = 0.0;
float a1 = 0.0,a2 = 0.0,a3 = 0.0,b1 = 0.0,b2 = 0.0;
for(int i=1;i<=N;i++){
a1 += (j[i].first*j[i].second);
}
for(int i=1;i<=N;i++){
a2 += (j[i].first);
}
for(int i=1;i<=N;i++){
a3 += (j[i].second);
}
for(int i=1;i<=N;i++){
b1 += pow(j[i].first,2);
}
for(int i=1;i<=N;i++){
b2 += j[i].first;
}
m = ((N*a1)-((a2)*(a3)))/((N*b1)-(pow(b2,2)));
b = (a3-(m*a2))/N;
if(c == "mb"){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3;
}
if(c == "func"){
cout<<"y = ";
if(m == 1&& b>0){
cout<<"x + "<<round(b*1e3)/1e3;
}else if(m == 0 && b == 0){
cout<<0;
}else if(m == 1&&b ==0){
cout<<"x";
}else if(m == -1&b == 0){
cout<<"-x";
}else if(m == -1& b>=1){
cout<<"-x + "<<round(b*1e3)/1e3;
}else if(m ==-1& b<=-1){
cout<<"-x "<<"- "<<-round(b*1e3)/1e3;
}else if(m == 0){
cout<<round(b*1e3)/1e3;
}else if(m != 0& b<0){
cout<<round(m*1e3)/1e3<<"x "<<"- "<<-round(b*1e3)/1e3;
}else if(m== -0){
cout<<b;
}else{
cout<<round(m*1e3)/1e3<<"x "<<"+ "<<round(b*1e3)/1e3;
}
}
} | # 0832, 2024-11-02 11:24:59, ------------------------ (0%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string c;
cin>>n>>c;
int N = n;
map<float,float> w;
vector<pair<float,float>> j = {make_pair(0.0,0.0)};
while(n--){
float x = 0.0,y =0.0;
cin>>x>>y;
j.push_back(make_pair(x,y));
}
float m = 0.0,b = 0.0;
float a1 = 0.0,a2 = 0.0,a3 = 0.0,b1 = 0.0,b2 = 0.0;
for(int i=1;i<=N;i++){
a1 += (j[i].first*j[i].second);
}
for(int i=1;i<=N;i++){
a2 += (j[i].first);
}
for(int i=1;i<=N;i++){
a3 += (j[i].second);
}
for(int i=1;i<=N;i++){
b1 += pow(j[i].first,2);
}
for(int i=1;i<=N;i++){
b2 += j[i].first;
}
cout<<a1<<" "<<a2<<" "<<a3<<" "<<b1<<" "<<b2<<endl;
m = ((N*a1)-((a2)*(a3)))/((N*b1)-(pow(b2,2)));
for(int i =1;i<N;i++){
if(j[i].second == j[i-1].second){
m=0;
}
}
b = (a3-(m*a2))/N;
if(c == "mb"){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3;
}
if(c == "func"){
cout<<"y = ";
if(m == 1&& b>0){
cout<<"x + "<<round(b*1e3)/1e3;
}else if(m == 0 && b == 0){
cout<<0;
}else if(m == 1&&b ==0){
cout<<"x";
}else if(m == -1&b == 0){
cout<<"-x";
}else if(m == -1& b>=1){
cout<<"-x + "<<round(b*1e3)/1e3;
}else if(m ==-1& b<=-1){
cout<<"-x "<<"- "<<-round(b*1e3)/1e3;
}else if(m == 0){
cout<<round(b*1e3)/1e3;
}else if(m != 0& b<0){
cout<<round(m*1e3)/1e3<<"x "<<"- "<<-round(b*1e3)/1e3;
}else if(m== -0){
cout<<b;
}else{
cout<<round(m*1e3)/1e3<<"x "<<"+ "<<round(b*1e3)/1e3;
}
}
} | # 0833, 2024-11-02 11:25:47, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string c;
cin>>n>>c;
int N = n;
map<float,float> w;
vector<pair<float,float>> j = {make_pair(0.0,0.0)};
while(n--){
float x = 0.0,y =0.0;
cin>>x>>y;
j.push_back(make_pair(x,y));
}
float m = 0.0,b = 0.0;
float a1 = 0.0,a2 = 0.0,a3 = 0.0,b1 = 0.0,b2 = 0.0;
for(int i=1;i<=N;i++){
a1 += (j[i].first*j[i].second);
}
for(int i=1;i<=N;i++){
a2 += (j[i].first);
}
for(int i=1;i<=N;i++){
a3 += (j[i].second);
}
for(int i=1;i<=N;i++){
b1 += pow(j[i].first,2);
}
for(int i=1;i<=N;i++){
b2 += j[i].first;
}
m = ((N*a1)-((a2)*(a3)))/((N*b1)-(pow(b2,2)));
for(int i =1;i<N;i++){
if(j[i].second == j[i-1].second){
m=0;
}
}
b = (a3-(m*a2))/N;
if(c == "mb"){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3;
}
if(c == "func"){
cout<<"y = ";
if(m == 1&& b>0){
cout<<"x + "<<round(b*1e3)/1e3;
}else if(m == 0 && b == 0){
cout<<0;
}else if(m == 1&&b ==0){
cout<<"x";
}else if(m == -1&b == 0){
cout<<"-x";
}else if(m == -1& b>=1){
cout<<"-x + "<<round(b*1e3)/1e3;
}else if(m ==-1& b<=-1){
cout<<"-x "<<"- "<<-round(b*1e3)/1e3;
}else if(m == 0){
cout<<round(b*1e3)/1e3;
}else if(m != 0& b<0){
cout<<round(m*1e3)/1e3<<"x "<<"- "<<-round(b*1e3)/1e3;
}else if(m== -0){
cout<<b;
}else{
cout<<round(m*1e3)/1e3<<"x "<<"+ "<<round(b*1e3)/1e3;
}
}
} | # 0834, 2024-11-02 11:31:01, PPPPPPPPPPPPP--PP-PP-PP- (79%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string c;
cin>>n>>c;
int N = n;
map<float,float> w;
vector<pair<float,float>> j = {make_pair(0.0,0.0)};
while(n--){
float x = 0.0,y =0.0;
cin>>x>>y;
j.push_back(make_pair(x,y));
}
float m = 0.0,b = 0.0;
float a1 = 0.0,a2 = 0.0,a3 = 0.0,b1 = 0.0,b2 = 0.0;
for(int i=1;i<=N;i++){
a1 += (j[i].first*j[i].second);
}
for(int i=1;i<=N;i++){
a2 += (j[i].first);
}
for(int i=1;i<=N;i++){
a3 += (j[i].second);
}
for(int i=1;i<=N;i++){
b1 += pow(j[i].first,2);
}
for(int i=1;i<=N;i++){
b2 += j[i].first;
}
m = ((N*a1)-((a2)*(a3)))/((N*b1)-(pow(b2,2)));
for(int i =1;i<N;i++){
if(j[i].second == j[i-1].second){
m=0;
}
}
b = (a3-(m*a2))/N;
if(c == "mb"){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3;
}
if(c == "func"){
cout<<"y = ";
if(m == 1&& b>0){
cout<<"x + "<<round(b*1e3)/1e3;
}else if(m == 1&&b<0){
cout<<"x - "<<-round(b*1e3)/1e3;
}else if(m == 0 && b == 0){
cout<<0;
}else if(m == 1&&b ==0){
cout<<"x";
}else if(m == -1&b == 0){
cout<<"-x";
}else if(m == -1& b>=1){
cout<<"-x + "<<round(b*1e3)/1e3;
}else if(m ==-1& b<=-1){
cout<<"-x "<<"- "<<-round(b*1e3)/1e3;
}else if(m == 0){
cout<<round(b*1e3)/1e3;
}else if(m >= 0& b<0){
cout<<round(m*1e3)/1e3<<"x "<<"- "<<-round(b*1e3)/1e3;
}else{
cout<<round(m*1e3)/1e3<<"x "<<"+ "<<round(b*1e3)/1e3;
}
}
} | # 0835, 2024-11-02 11:31:29, PPPPPPPPPPPPPPPPP-PP-PP- (87%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string c;
cin>>n>>c;
int N = n;
map<float,float> w;
vector<pair<float,float>> j = {make_pair(0.0,0.0)};
while(n--){
float x = 0.0,y =0.0;
cin>>x>>y;
j.push_back(make_pair(x,y));
}
float m = 0.0,b = 0.0;
float a1 = 0.0,a2 = 0.0,a3 = 0.0,b1 = 0.0,b2 = 0.0;
for(int i=1;i<=N;i++){
a1 += (j[i].first*j[i].second);
}
for(int i=1;i<=N;i++){
a2 += (j[i].first);
}
for(int i=1;i<=N;i++){
a3 += (j[i].second);
}
for(int i=1;i<=N;i++){
b1 += pow(j[i].first,2);
}
for(int i=1;i<=N;i++){
b2 += j[i].first;
}
m = ((N*a1)-((a2)*(a3)))/((N*b1)-(pow(b2,2)));
for(int i =1;i<N;i++){
if(j[i].second == j[i-1].second){
m=0;
}
}
b = (a3-(m*a2))/N;
if(c == "mb"){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3;
}
if(c == "func"){
cout<<"y = ";
if(m == 1&& b>0){
cout<<"x + "<<round(b*1e3)/1e3;
}else if(m == 1&&b<0){
cout<<"x - "<<-round(b*1e3)/1e3;
}else if(m == 0 && b == 0){
cout<<0;
}else if(m == 1&&b ==0){
cout<<"x";
}else if(m == -1&b == 0){
cout<<"-x";
}else if(m == -1& b>=1){
cout<<"-x + "<<round(b*1e3)/1e3;
}else if(m ==-1& b<=-1){
cout<<"-x "<<"- "<<-round(b*1e3)/1e3;
}else if(m == 0){
cout<<round(b*1e3)/1e3;
}else if(m != 0& b<0){
cout<<round(m*1e3)/1e3<<"x "<<"- "<<-round(b*1e3)/1e3;
}else{
cout<<round(m*1e3)/1e3<<"x "<<"+ "<<round(b*1e3)/1e3;
}
}
} | # 0836, 2024-11-02 11:45:28, PPPPPPPPPPPPPPPPP-PP-PP- (87%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string c;
cin>>n>>c;
int N = n;
map<float,float> w;
vector<pair<float,float>> j = {make_pair(0.0,0.0)};
while(n--){
float x = 0.0,y =0.0;
cin>>x>>y;
j.push_back(make_pair(x,y));
}
float m = 0.0,b = 0.0;
float a1 = 0.0,a2 = 0.0,a3 = 0.0,b1 = 0.0,b2 = 0.0;
for(int i=1;i<=N;i++){
a1 += (j[i].first*j[i].second);
}
for(int i=1;i<=N;i++){
a2 += (j[i].first);
}
for(int i=1;i<=N;i++){
a3 += (j[i].second);
}
for(int i=1;i<=N;i++){
b1 += pow(j[i].first,2);
}
for(int i=1;i<=N;i++){
b2 += j[i].first;
}
m = ((N*a1)-((a2)*(a3)))/((N*b1)-(pow(b2,2)));
for(int i =1;i<N;i++){
if(j[i].second == j[i-1].second){
m=0;
}
}
b = (a3-(m*a2))/N;
if(c == "mb"){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3;
}
if(c == "func"){
cout<<"y = ";
if(m == 1){
if(b >0){
cout<<"x + "<<round(b*1e3)/1e3;
}else if(b <0){
cout<<"x - "<<-round(b*1e3)/1e3;
}else{
cout<<"x";
}
}else if(m == 0){
if(b == 0){
cout<<"0";
}else if(b>0){
cout<<round(b*1e3)/1e3;
}else{
cout<<round(b*1e3)/1e3;
}
}else if(m ==-1){
if(b == 0){
cout<<"-x";
}else if(b>0){
cout<<"-x + "<<round(b*1e3)/1e3;
}else if(b<0){
cout<<"-x - "<<-round(b*1e3)/1e3;
}
}else if(m>0 && m!=1){
if(b == 0){
cout<<round(m*1e3)/1e3<<"x";
}else if( b >0){
cout<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}else{
cout<<round(m*1e3)/1e3<<"x - "<<-round(b*1e3)/1e3;
}
}else if(m<0 && m!=1){
if(b == 0){
cout<<round(m*1e3)/1e3<<"x";
}else if( b >0){
cout<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}else{
cout<<round(m*1e3)/1e3<<"x - "<<-round(b*1e3)/1e3;
}
}
}
} |
# 0837, 2024-11-02 13:34:17, -----P--PP-----PP----P-- (25%)
#include<bits/stdc++.h>
using namespace std ;
int main () {
float n,x,y ;
string out ;
vector<float> vecx;
vector<float> vecy ;
cin>>n>>out;
for (int i=0;i<n;i++) {
cin>>x>>y ;
vecx.push_back(x) ;
vecy.push_back(y) ;
}
//find m first term
float sum1 = 0;
for (int i=1;i<=n;i++) {
sum1+=vecx[i-1]*vecy[i-1] ;
}
sum1*=n;
//cout<<sum1<<endl;
//m term2
float s1=0,s2=0 ;
for (int i=1;i<=n;i++) {
s1+=vecx[i-1] ;
}
for (int i=1;i<=n;i++) {
s2+=vecy[i-1] ;
}
float sum2=s1*s2;
//cout<<sum2<<endl ;
//m term3
float s3=0,s4=0 ;
for (int i=1;i<n;i++) {
s3+=vecx[i-1]*vecx[i-1] ;
}
s3*=n;
//cout<<s3<<endl ;
for (int i=1;i<n;i++) {
s4+=vecx[i-1] ;
}
s4*=s4;
//cout<<s4<<endl;
float m=(sum1-sum2)/(s3-s4) ;
float b=(s2-(m*s1))/n ;
if (out=="mb") {
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
}
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if (out=="func") {
string first="" ;
if (m==1) {
first = "x" ;
}
else if (m==-1) {
first="-x" ;
}
else if (m==0) {
first="" ;
}
else {
first=to_string(m) ;
first+=x;
}
cout<<"y = "<<first ;
if (first!=""&&b!=0) cout<<" + ";
if (b!=0) cout<<b;
if (first==""&&b==0) cout<<b;
}
//cout<<(sum1-sum2)/(s3-s4)<<endl;
//cout<<sum1<<"-"<<sum2<<"/"<<s3<<"-"<<s4<<endl;
} | # 0838, 2024-11-02 13:41:25, -----P--PP-----P-------- (16%)
#include<bits/stdc++.h>
using namespace std ;
int main () {
float n,x,y ;
string out ;
vector<float> vecx;
vector<float> vecy ;
cin>>n>>out;
for (int i=0;i<n;i++) {
cin>>x>>y ;
vecx.push_back(x) ;
vecy.push_back(y) ;
}
//find m first term
float sum1 = 0;
for (int i=1;i<=n;i++) {
sum1+=vecx[i-1]*vecy[i-1] ;
}
sum1*=n;
//cout<<sum1<<endl;
//m term2
float s1=0,s2=0 ;
for (int i=1;i<=n;i++) {
s1+=vecx[i-1] ;
}
for (int i=1;i<=n;i++) {
s2+=vecy[i-1] ;
}
float sum2=s1*s2;
//cout<<sum2<<endl ;
//m term3
float s3=0,s4=0 ;
for (int i=1;i<n;i++) {
s3+=vecx[i-1]*vecx[i-1] ;
}
s3*=n;
//cout<<s3<<endl ;
for (int i=1;i<n;i++) {
s4+=vecx[i-1] ;
}
s4*=s4;
//cout<<s4<<endl;
float m=(sum1-sum2)/(s3-s4) ;
float b=(s2-(m*s1))/n ;
if (out=="mb") {
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
}
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if (out=="func") {
string first="" ;
if (m==1) {
first = "x" ;
}
else if (m==-1) {
first="-x" ;
}
else if (m==0) {
first="" ;
}
else {
first=to_string(m) ;
first+=x;
}
string second="" ;
if (b>0 ) {
second=" + "+to_string(b);
}
if (b<0) {
second=" - "+to_string((-1)*b);
}
if (b==0) {
if (first=="") second="0" ;
else second=" + 0";
}
cout<<"y = " ;
cout<<first<<second;
}
//cout<<(sum1-sum2)/(s3-s4)<<endl;
//cout<<sum1<<"-"<<sum2<<"/"<<s3<<"-"<<s4<<endl;
} | # 0839, 2024-11-02 13:47:04, PPPPPPPPPP-------------- (41%)
#include<bits/stdc++.h>
using namespace std ;
int main () {
float n,x,y ;
string out ;
vector<float> vecx;
vector<float> vecy ;
cin>>n>>out;
for (int i=0;i<n;i++) {
cin>>x>>y ;
vecx.push_back(x) ;
vecy.push_back(y) ;
}
/*cout<<"******"<<endl;
for (int i=0;i<n;i++) {
cout<<vecx[i]<<" "<<vecy[i]<<endl ;
}*/
//find m first term
float sum1 = 0;
for (int i=1;i<=n;i++) {
sum1+=vecx[i-1]*vecy[i-1] ;
}
sum1*=n;
//m term2
float s1=0,s2=0 ;
for (int i=1;i<=n;i++) {
s1+=vecx[i-1] ;
}
for (int i=1;i<=n;i++) {
s2+=vecy[i-1] ;
}
float sum2=s1*s2;
//m term3
float s3=0,s4=0 ;
for (int i=1;i<=n;i++) {
s3+=vecx[i-1]*vecx[i-1] ;
}
s3*=n;
for (int i=1;i<=n;i++) {
s4+=vecx[i-1] ;
}
s4*=s4;
float m=(sum1-sum2)/(s3-s4) ;
float b=(s2-(m*s1))/n ;
if (out=="mb") {
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
}
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if (out=="func") {
string first="" ;
if (m==1) {
first = "x" ;
}
else if (m==-1) {
first="-x" ;
}
else if (m==0) {
first="" ;
}
else {
first=to_string(m) ;
first+=x;
}
//cout<<"y = "<<first ;
}
//cout<<(sum1-sum2)/(s3-s4)<<endl;
//cout<<sum1<<"-"<<sum2<<"/"<<s3<<"-"<<s4<<endl;
} | # 0840, 2024-11-02 13:51:15, Compilation error (0%)
#include<bits/stdc++.h>
using namespace std ;
int main () {
float n,x,y ;
string out ;
vector<float> vecx;
vector<float> vecy ;
cin>>n>>out;
for (int i=0;i<n;i++) {
cin>>x>>y ;
vecx.push_back(x) ;
vecy.push_back(y) ;
}
/*cout<<"******"<<endl;
for (int i=0;i<n;i++) {
cout<<vecx[i]<<" "<<vecy[i]<<endl ;
}*/
//find m first term
float sum1 = 0;
for (int i=1;i<=n;i++) {
sum1+=vecx[i-1]*vecy[i-1] ;
}
sum1*=n;
//m term2
float s1=0,s2=0 ;
for (int i=1;i<=n;i++) {
s1+=vecx[i-1] ;
}
for (int i=1;i<=n;i++) {
s2+=vecy[i-1] ;
}
float sum2=s1*s2;
//m term3
float s3=0,s4=0 ;
for (int i=1;i<=n;i++) {
s3+=vecx[i-1]*vecx[i-1] ;
}
s3*=n;
for (int i=1;i<=n;i++) {
s4+=vecx[i-1] ;
}
s4*=s4;
float m=(sum1-sum2)/(s3-s4) ;
float b=(s2-(m*s1))/n ;
if (out=="mb") {
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
}
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if (out=="func") {
string first="" ;
if (m==1) {
first = "x" ;
}
else if (m==-1) {
first="-x" ;
}
else if (m==0) {
first="" ;
}
else {
first=to_string(round(m*1e3)/1e3) ;
first+=x;
}
cout<<"y = "<<first ;
if (first!="") {
if (b>=0) cout<<" + " ;
else if (b<0) cout<<" - ";
}
if (b>=0) cout<<b ;
else if (b<0) {
cout<<(b)*(-1);
} | # 0841, 2024-11-02 13:51:53, PPPPPPPPPP-----PPP--P-PP (66%)
#include<bits/stdc++.h>
using namespace std ;
int main () {
float n,x,y ;
string out ;
vector<float> vecx;
vector<float> vecy ;
cin>>n>>out;
for (int i=0;i<n;i++) {
cin>>x>>y ;
vecx.push_back(x) ;
vecy.push_back(y) ;
}
/*cout<<"******"<<endl;
for (int i=0;i<n;i++) {
cout<<vecx[i]<<" "<<vecy[i]<<endl ;
}*/
//find m first term
float sum1 = 0;
for (int i=1;i<=n;i++) {
sum1+=vecx[i-1]*vecy[i-1] ;
}
sum1*=n;
//m term2
float s1=0,s2=0 ;
for (int i=1;i<=n;i++) {
s1+=vecx[i-1] ;
}
for (int i=1;i<=n;i++) {
s2+=vecy[i-1] ;
}
float sum2=s1*s2;
//m term3
float s3=0,s4=0 ;
for (int i=1;i<=n;i++) {
s3+=vecx[i-1]*vecx[i-1] ;
}
s3*=n;
for (int i=1;i<=n;i++) {
s4+=vecx[i-1] ;
}
s4*=s4;
float m=(sum1-sum2)/(s3-s4) ;
float b=(s2-(m*s1))/n ;
if (out=="mb") {
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
}
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if (out=="func") {
string first="" ;
if (m==1) {
first = "x" ;
}
else if (m==-1) {
first="-x" ;
}
else if (m==0) {
first="" ;
}
else {
first=to_string(round(m*1e3)/1e3) ;
first+=x;
}
cout<<"y = "<<first ;
if (first!="") {
if (b>=0) cout<<" + " ;
else if (b<0) cout<<" - ";
}
if (b>=0) cout<<b ;
else if (b<0) {
cout<<(b)*(-1);
}
}
} | # 0842, 2024-11-02 13:57:00, PPPPPPPPPPPPPPPPPP--P-PP (87%)
#include<bits/stdc++.h>
using namespace std ;
int main () {
float n,x,y ;
string out ;
vector<float> vecx;
vector<float> vecy ;
cin>>n>>out;
for (int i=0;i<n;i++) {
cin>>x>>y ;
vecx.push_back(x) ;
vecy.push_back(y) ;
}
/*cout<<"******"<<endl;
for (int i=0;i<n;i++) {
cout<<vecx[i]<<" "<<vecy[i]<<endl ;
}*/
//find m first term
float sum1 = 0;
for (int i=1;i<=n;i++) {
sum1+=vecx[i-1]*vecy[i-1] ;
}
sum1*=n;
//m term2
float s1=0,s2=0 ;
for (int i=1;i<=n;i++) {
s1+=vecx[i-1] ;
}
for (int i=1;i<=n;i++) {
s2+=vecy[i-1] ;
}
float sum2=s1*s2;
//m term3
float s3=0,s4=0 ;
for (int i=1;i<=n;i++) {
s3+=vecx[i-1]*vecx[i-1] ;
}
s3*=n;
for (int i=1;i<=n;i++) {
s4+=vecx[i-1] ;
}
s4*=s4;
float m=(sum1-sum2)/(s3-s4) ;
float b=(s2-(m*s1))/n ;
if (out=="mb") {
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
}
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if (out=="func") {
string first="" ;
if (m==1) {
first = "x" ;
}
else if (m==-1) {
first="-x" ;
}
else if (m==0) {
first="" ;
}
else {
string ms = to_string(m) ;
first=to_string(round(m*1e3)/1e3) ;
first+=x;
}
cout<<"y = ";
if (m==1) {
first = "x" ;
cout<<"x";
}
else if (m==-1) {
first="-x" ;
cout<<"-x";
}
else if (m==0) {
first="" ;
}
else {
cout<<round(m*1e3)/1e3<<"x" ;
}
if (first!="") {
if (b>=0) cout<<" + " ;
else if (b<0) cout<<" - ";
}
if (b>=0) cout<<b ;
else if (b<0) {
cout<<(b)*(-1);
}
}
//cout<<(sum1-sum2)/(s3-s4)<<endl;
//cout<<sum1<<"-"<<sum2<<"/"<<s3<<"-"<<s4<<endl;
} | # 0843, 2024-11-02 14:55:25, PPPPPPPPPP-------------- (41%)
#include<bits/stdc++.h>
using namespace std ;
int main () {
float n,x,y ;
string out ;
vector<float> vecx;
vector<float> vecy ;
cin>>n>>out;
for (int i=0;i<n;i++) {
cin>>x>>y ;
vecx.push_back(x) ;
vecy.push_back(y) ;
}
/*cout<<"******"<<endl;
for (int i=0;i<n;i++) {
cout<<vecx[i]<<" "<<vecy[i]<<endl ;
}*/
//find m first term
float sum1 = 0;
for (int i=1;i<=n;i++) {
sum1+=vecx[i-1]*vecy[i-1] ;
}
sum1*=n;
//m term2
float s1=0,s2=0 ;
for (int i=1;i<=n;i++) {
s1+=vecx[i-1] ;
}
for (int i=1;i<=n;i++) {
s2+=vecy[i-1] ;
}
float sum2=s1*s2;
//m term3
float s3=0,s4=0 ;
for (int i=1;i<=n;i++) {
s3+=vecx[i-1]*vecx[i-1] ;
}
s3*=n;
for (int i=1;i<=n;i++) {
s4+=vecx[i-1] ;
}
s4*=s4;
float m=(sum1-sum2)/(s3-s4) ;
float b=(s2-(m*s1))/n ;
if (out=="mb") {
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
}
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
m=-56663.444422557 ;
b=-243556 ;
if (out=="func") {
string first="" ;
if (m==1) {
first = "x" ;
}
else if (m==-1) {
first="-x" ;
}
else if (m==0) {
first="" ;
}
else {
string ms = to_string(m) ;
first=to_string(round(m*1e3)/1e3) ;
first+=x;
}
cout<<"y = ";
if (m==1) {
first = "x" ;
cout<<"x";
}
else if (m==-1) {
first="-x" ;
cout<<"-x";
}
else if (m==0) {
first="" ;
}
else {
cout<<round(m*1e3)/1e3<<"x" ;
}
if (first!="") {
if (b>=0) cout<<" + " ;
else if (b<0) cout<<" - ";
}
if (b>=0) cout<<round(b*1e3)/1e3 ;
else if (b<0) {
cout<<round(b*(-1)*1e3)/1e3 ;
}
}
//cout<<(sum1-sum2)/(s3-s4)<<endl;
//cout<<sum1<<"-"<<sum2<<"/"<<s3<<"-"<<s4<<endl;
} | # 0844, 2024-11-02 14:56:43, PPPPPPPPPPPPPPPPPP--P-PP (87%)
#include<bits/stdc++.h>
using namespace std ;
int main () {
float n,x,y ;
string out ;
vector<float> vecx;
vector<float> vecy ;
cin>>n>>out;
for (int i=0;i<n;i++) {
cin>>x>>y ;
vecx.push_back(x) ;
vecy.push_back(y) ;
}
/*cout<<"******"<<endl;
for (int i=0;i<n;i++) {
cout<<vecx[i]<<" "<<vecy[i]<<endl ;
}*/
//find m first term
float sum1 = 0;
for (int i=1;i<=n;i++) {
sum1+=vecx[i-1]*vecy[i-1] ;
}
sum1*=n;
//m term2
float s1=0,s2=0 ;
for (int i=1;i<=n;i++) {
s1+=vecx[i-1] ;
}
for (int i=1;i<=n;i++) {
s2+=vecy[i-1] ;
}
float sum2=s1*s2;
//m term3
float s3=0,s4=0 ;
for (int i=1;i<=n;i++) {
s3+=vecx[i-1]*vecx[i-1] ;
}
s3*=n;
for (int i=1;i<=n;i++) {
s4+=vecx[i-1] ;
}
s4*=s4;
float m=(sum1-sum2)/(s3-s4) ;
float b=(s2-(m*s1))/n ;
if (out=="mb") {
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
}
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if (out=="func") {
string first="" ;
if (m==1) {
first = "x" ;
}
else if (m==-1) {
first="-x" ;
}
else if (m==0) {
first="" ;
}
else {
string ms = to_string(m) ;
first=to_string(round(m*1e3)/1e3) ;
first+=x;
}
cout<<"y = ";
if (m==1) {
first = "x" ;
cout<<"x";
}
else if (m==-1) {
first="-x" ;
cout<<"-x";
}
else if (m==0) {
first="" ;
}
else {
cout<<round(m*1e3)/1e3<<"x" ;
}
if (first!="") {
if (b>=0) cout<<" + " ;
else if (b<0) cout<<" - ";
}
if (b>=0) cout<<round(b*1e3)/1e3 ;
else if (b<0) {
cout<<round(b*(-1)*1e3)/1e3 ;
}
}
//cout<<(sum1-sum2)/(s3-s4)<<endl;
//cout<<sum1<<"-"<<sum2<<"/"<<s3<<"-"<<s4<<endl;
} |
# 0845, 2024-11-02 13:26:31, PPPPPPPPP--------PPPP-PP (62%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
float table[n][2];
string mode ; cin >> mode;
for(int i = 0 ; i < n ; i++){
cin >> table[i][0] >> table[i][1];
}
float m,b;
float sum1 = 0 ,sum2 = 0 ,sum3 = 0 ,sum4 = 0;
for(int i = 0 ; i < n ; i++){
sum1 += n * table[i][0]*table[i][1];
sum2 += table[i][0];
sum3 += table[i][1];
sum4 += n * table[i][0] * table[i][0];
}
m = (sum1 - sum2*sum3)/(sum4-sum2*sum2);
float sumb = 0;
for(int i = 0 ; i < n ; i++){
sumb += m * table[i][0];
}
b = (sum3-sumb)/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(mode == "mb"){
cout << m << endl << b;
}
else{
if(m!=0){
if(m==1){
cout << "y = x ";
if(b > 0) cout << "+ " << b;
if(b < 0) cout << "- " << abs(b);
}
if(m==-1){
cout << "y = -x ";
if(b > 0) cout << "+ " << b;
if(b < 0) cout << "- " << abs(b);
}
}
}
} | # 0846, 2024-11-02 13:29:11, PPPPPPPPP-PPPPPPPPP--PP- (83%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
float table[n][2];
string mode ; cin >> mode;
for(int i = 0 ; i < n ; i++){
cin >> table[i][0] >> table[i][1];
}
float m,b;
float sum1 = 0 ,sum2 = 0 ,sum3 = 0 ,sum4 = 0;
for(int i = 0 ; i < n ; i++){
sum1 += n * table[i][0]*table[i][1];
sum2 += table[i][0];
sum3 += table[i][1];
sum4 += n * table[i][0] * table[i][0];
}
m = (sum1 - sum2*sum3)/(sum4-sum2*sum2);
float sumb = 0;
for(int i = 0 ; i < n ; i++){
sumb += m * table[i][0];
}
b = (sum3-sumb)/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(mode == "mb"){
cout << m << endl << b;
}
else{
if(m!=0){
if(m==1){
cout << "y = x ";
if(b > 0) cout << "+ " << b;
if(b < 0) cout << "- " << abs(b);
}
if(m==-1){
cout << "y = -x ";
if(b > 0) cout << "+ " << b;
if(b < 0) cout << "- " << abs(b);
}
if(m > 1){
cout << "y = " << m << "x ";
if(b > 0) cout << "+ " << b;
if(b < 0) cout << "- " << abs(b);
}
if(m < 1){
cout << "y = " << m << "x ";
if(b > 0) cout << "+ " << b;
if(b < 0) cout << "- " << abs(b);
}
}
if(m==0){
cout << "y = " << b;
}
}
} | # 0847, 2024-11-02 13:31:19, PPPPPPPPP-PP---PPPP--PP- (70%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
float table[n][2];
string mode ; cin >> mode;
for(int i = 0 ; i < n ; i++){
cin >> table[i][0] >> table[i][1];
}
float m,b;
float sum1 = 0 ,sum2 = 0 ,sum3 = 0 ,sum4 = 0;
for(int i = 0 ; i < n ; i++){
sum1 += n * table[i][0]*table[i][1];
sum2 += table[i][0];
sum3 += table[i][1];
sum4 += n * table[i][0] * table[i][0];
}
m = (sum1 - sum2*sum3)/(sum4-sum2*sum2);
float sumb = 0;
for(int i = 0 ; i < n ; i++){
sumb += m * table[i][0];
}
b = (sum3-sumb)/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(mode == "mb"){
cout << m << endl << b;
}
else{
if(m!=0){
if(m==1){
cout << "y = x";
if(b > 0) cout << " + " << b;
if(b < 0) cout << " - " << abs(b);
}
if(m==-1){
cout << "y = -x";
if(b > 0) cout << " + " << b;
if(b < 0) cout << " - " << abs(b);
}
if(m > 1){
cout << "y = " << m << "x";
if(b > 0) cout << " + " << b;
if(b < 0) cout << " - " << abs(b);
}
if(m < 1){
cout << "y = " << m << " x";
if(b > 0) cout << " +" << b;
if(b < 0) cout << " -" << abs(b);
}
}
if(m==0){
cout << "y = " << b;
}
}
} | # 0848, 2024-11-02 13:38:54, PPPPPPPPPPPPPPPPPPP--PP- (87%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
float table[n][2];
string mode ; cin >> mode;
for(int i = 0 ; i < n ; i++){
cin >> table[i][0] >> table[i][1];
}
float m,b;
float sum1 = 0 ,sum2 = 0 ,sum3 = 0 ,sum4 = 0;
for(int i = 0 ; i < n ; i++){
sum1 += table[i][0]*table[i][1];
sum2 += table[i][0];
sum3 += table[i][1];
sum4 += table[i][0] * table[i][0];
}
m = (n*sum1 - sum2*sum3)/(n*sum4-sum2*sum2);
float sumb = 0;
for(int i = 0 ; i < n ; i++){
sumb += table[i][0];
}
b = (sum3-m*sumb)/n;
//cout << m << ' ' << b << endl;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(mode == "mb"){
cout << m << endl << b;
}
else{
if(m!=0){
if(m==1){
cout << "y = x ";
if(b > 0) cout << "+ " << b;
if(b < 0) cout << "- " << abs(b);
}
if(m==-1){
cout << "y = -x ";
if(b > 0) cout << "+ " << b;
if(b < 0) cout << "- " << abs(b);
}
if(m > 1){
cout << "y = " << m << "x ";
if(b > 0) cout << "+ " << b;
if(b < 0) cout << "- " << abs(b);
}
if(m < 1){
cout << "y = " << m << "x ";
if(b > 0) cout << "+ " << b;
if(b < 0) cout << "- " << abs(b);
}
}
if(m==0){
cout << "y = " << b;
}
}
} |
# 0849, 2024-11-02 09:57:12, PPPPPPPPPPPPPPPP--PP---- (75%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int N;
string cmd;
cin >> N >> cmd;
float sumxi = 0, sumyi = 0, sumxy = 0, sumx2 = 0;
for (int i = 0; i < N; i++)
{
float xi, yi;
cin >> xi >> yi;
sumxi += xi;
sumyi += yi;
sumxy += xi * yi;
sumx2 += xi * xi;
}
float m = ((N * sumxy) - (sumxi * sumyi)) / ((N * sumx2) - (sumxi * sumxi));
float b = (sumyi - (m * sumxi)) / N;
if (cmd == "mb")
{
cout << round(m * 1e3) / 1e3 << "\n";
cout << round(b * 1e3) / 1e3;
}
else
{
string signM = "", signB = "+";
if (m < 0)
{
signM = "-";
m *= -1;
}
if (b < 0)
{
signB = "-";
b *= -1;
}
if (m == 0)
{
cout << "y = 0";
}
else if (m == 1 || m == -1)
{
cout << "y = " << signM << "x";
}
else
{
cout << "y = " << signM << round(m * 1e3) / 1e3 << "x";
}
if (b == 0)
{
return 0;
}
else
{
cout << " " << signB << " " << round(b * 1e3) / 1e3;
}
}
return 0;
} | # 0850, 2024-11-02 10:06:01, PPPPPPPPPPPPPPPP-P--PPPP (87%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int N;
string cmd;
cin >> N >> cmd;
float sumxi = 0, sumyi = 0, sumxy = 0, sumx2 = 0;
for (int i = 0; i < N; i++)
{
float xi, yi;
cin >> xi >> yi;
sumxi += xi;
sumyi += yi;
sumxy += xi * yi;
sumx2 += xi * xi;
}
float m = ((N * sumxy) - (sumxi * sumyi)) / ((N * sumx2) - (sumxi * sumxi));
float b = (sumyi - (m * sumxi)) / N;
if (cmd == "mb")
{
cout << round(m * 1e3) / 1e3 << "\n";
cout << round(b * 1e3) / 1e3;
}
else
{
string signM = "", signB = "+";
if (m < 0)
{
signM = "-";
m *= -1;
}
if (b < 0)
{
signB = "-";
b *= -1;
}
m = round(m * 1e3) / 1e3;
b = round(b * 1e3) / 1e3;
if (m == 0 && b == 0)
{
cout << "y = 0";
}
else if (m == 0 && b != 0)
{
cout << "y = " << signB << b;
}
else if (m == 1 || m == -1)
{
cout << "y = " << signM << "x";
cout << " " << signB << " " << b;
}
else
{
cout << "y = " << signM << m << "x";
cout << " " << signB << " " << b;
}
}
return 0;
} |
# 0851, 2024-11-02 13:41:33, PPPPPPPPPPPPPPPPP-PP-PP- (87%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string in;
cin >> n >> in;
vector<pair<float, float>> vp (n, {0, 0});
for (int i = 0; i < n; i++)
{
float a, b;
cin >> a >> b;
vp[i] = {a, b};
}
/*for(int i=0; i<n; i++)
{
cout << vp[i].first << " " << vp[i].second << endl;
}
cout << n << endl;*/
float sum1=0, sum2=0, sum3=0, sum4=0;
for (int i = 0; i < n; i++)
{
sum1 += vp[i].first * vp[i].second;
}
for (int i = 0; i < n; i++)
{
sum2 += vp[i].first;
}
for (int i = 0; i < n; i++)
{
sum3 += vp[i].second;
}
for (int i = 0; i < n; i++)
{
sum4 += pow(vp[i].first, 2.0);
}
float m = ((n*sum1) - (sum2*sum3)) / ((n * sum4) - pow(sum2, 2.0));
float b = (sum3 - (m * sum2)) / n;
if (in == "mb")
{
if(m == -0 || m == 0)
{
cout << "0" << endl;
}
else
{
cout << round(m*1e3)/1e3 << endl;
}
if(b == -0 || b == 0)
{
cout << "0" << endl;
}
else
{
cout << round(b*1e3)/1e3 << endl;
}
}
else
{
//cout << round(m*1e3)/1e3 << endl;
//cout << round(m*1e3)/1e3 << " " << round(b*1e3)/1e3 << endl;
cout << "y = " ;
if(m == 0 && (b == 0 || b == -0))
{
cout << "0" << endl;
return 0;
}
if(m == 0 || round(m*1e3)/1e3 == -0)
{
cout << round(b*1e3)/1e3 << endl;
return 0;
}
else if(m == 1)
{
cout << "x ";
}
else if(m == -1)
{
cout << "-x ";
}
else
{
cout << round(m*1e3)/1e3 << "x ";
}
if(b == 0 || b == -0)
{
cout << endl;
return 0;
}
else if(b > 0)
{
cout << "+ " << abs(round(b*1e3)/1e3) << endl;
}
else if(b < 0)
{
cout << "- " << abs(round(b*1e3)/1e3) << endl;
}
}
return 0;
} | # 0852, 2024-11-02 13:43:30, PPPPPPPPPPPPPPPPP-PP-PP- (87%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string in;
cin >> n >> in;
vector<pair<float, float>> vp (n, {0, 0});
for (int i = 0; i < n; i++)
{
float a, b;
cin >> a >> b;
vp[i] = {a, b};
}
/*for(int i=0; i<n; i++)
{
cout << vp[i].first << " " << vp[i].second << endl;
}
cout << n << endl;*/
float sum1=0, sum2=0, sum3=0, sum4=0;
for (int i = 0; i < n; i++)
{
sum1 += vp[i].first * vp[i].second;
}
for (int i = 0; i < n; i++)
{
sum2 += vp[i].first;
}
for (int i = 0; i < n; i++)
{
sum3 += vp[i].second;
}
for (int i = 0; i < n; i++)
{
sum4 += pow(vp[i].first, 2.0);
}
float m = ((n*sum1) - (sum2*sum3)) / ((n * sum4) - pow(sum2, 2.0));
float b = (sum3 - (m * sum2)) / n;
if (in == "mb")
{
if(round(m*1e3)/1e3 == -0 || m == 0)
{
cout << "0" << endl;
}
else
{
cout << round(m*1e3)/1e3 << endl;
}
if(b == -0 || b == 0)
{
cout << "0" << endl;
}
else
{
cout << round(b*1e3)/1e3 << endl;
}
}
else
{
//cout << round(m*1e3)/1e3 << endl;
//cout << round(m*1e3)/1e3 << " " << round(b*1e3)/1e3 << endl;
cout << "y = " ;
if(m == 0 && (b == 0 || round(b*1e3)/1e3 == -0))
{
cout << "0" << endl;
return 0;
}
if(m == 0 || round(m*1e3)/1e3 == -0)
{
cout << round(b*1e3)/1e3 << endl;
return 0;
}
else if(m == 1)
{
cout << "x ";
}
else if(m == -1)
{
cout << "-x ";
}
else
{
cout << round(m*1e3)/1e3 << "x ";
}
if(b == 0 || round(b*1e3)/1e3 == -0)
{
cout << endl;
return 0;
}
else if(b > 0)
{
cout << "+ " << abs(round(b*1e3)/1e3) << endl;
}
else if(b < 0)
{
cout << "- " << abs(round(b*1e3)/1e3) << endl;
}
}
return 0;
} |
# 0853, 2024-11-02 09:50:21, -----P------------------ (4%)
#include <bits/stdc++.h>
using namespace std;
int main(){
// concept: mb --> keep x and y in vector, func --> show y = mx+b;
int n;
float x,y;
string cmd;
vector<float> xi, yi;
cin >> n >> cmd;
for(int i=0; i<n; i++){
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
if(cmd == "mb"){
float m,b1;
// find m
// first
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
for(int i=1; i<=n; i++){
sumXY += xi[i] * yi[i];
}
a = n * sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i] * xi[i];
}
c = n * sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
f = m * sumX;
b1 = (e-f)/n;
cout << round(m*1e3)/1e3 << endl;
cout << round(b1*1e3)/1e3 << endl;
}
} | # 0854, 2024-11-02 09:57:07, -----P------------------ (4%)
#include <bits/stdc++.h>
using namespace std;
int main(){
// concept: mb --> keep x and y in vector, func --> show y = mx+b;
int n;
float x,y;
string cmd;
vector<float> xi, yi;
cin >> n >> cmd;
for(int i=0; i<n; i++){
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// for(auto v:xi){
// cout << v << " ";
// }
// cout << endl;
// for(auto v: yi){
// cout << v << " ";
// }
if(cmd == "mb"){
float m,b1;
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=1; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
cout << round(m*1e3)/1e3 << endl;
cout << round(b1*1e3)/1e3 << endl;
}
} | # 0855, 2024-11-02 09:58:49, PPPPPPPPP--------------- (37%)
#include <bits/stdc++.h>
using namespace std;
int main(){
// concept: mb --> keep x and y in vector, func --> show y = mx+b;
int n;
float x,y;
string cmd;
vector<float> xi, yi;
cin >> n >> cmd;
for(int i=0; i<n; i++){
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// for(auto v:xi){
// cout << v << " ";
// }
// cout << endl;
// for(auto v: yi){
// cout << v << " ";
// }
if(cmd == "mb"){
float m,b1;
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
cout << round(m*1e3)/1e3 << endl;
cout << round(b1*1e3)/1e3 << endl;
}
} | # 0856, 2024-11-02 10:01:39, PPPPPPPPP--------------- (37%)
#include <bits/stdc++.h>
using namespace std;
int main(){
// concept: mb --> keep x and y in vector, func --> show y = mx+b;
int n;
float x,y;
string cmd;
vector<float> xi, yi;
cin >> n >> cmd;
for(int i=0; i<n; i++){
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// for(auto v:xi){
// cout << v << " ";
// }
// cout << endl;
// for(auto v: yi){
// cout << v << " ";
// }
float m,b1;
if(cmd == "mb"){
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
cout << round(m*1e3)/1e3 << endl;
cout << round(b1*1e3)/1e3 << endl;
}
if(cmd == "func"){
cout << "y = " << m << "x + " << b1;
}
} | # 0857, 2024-11-02 10:07:15, PPPPPPPPP--------------- (37%)
#include <bits/stdc++.h>
using namespace std;
int main(){
// concept: mb --> keep x and y in vector, func --> show y = mx+b;
int n;
float x,y;
string cmd;
vector<float> xi, yi;
cin >> n >> cmd;
for(int i=0; i<n; i++){
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// for(auto v:xi){
// cout << v << " ";
// }
// cout << endl;
// for(auto v: yi){
// cout << v << " ";
// }
float m,b1;
if(cmd == "mb"){
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
cout << round(m*1e3)/1e3 << endl;
cout << round(b1*1e3)/1e3 << endl;
}
if(cmd == "func"){
// cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b1*1e3)/1e3;
if(m != 0 && b1 != 0){
if(b1 > 0){
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b1*1e3)/1e3;
}
}
}
} | # 0858, 2024-11-02 10:11:22, PPPPPPPPP-PPPPP--------- (58%)
#include <bits/stdc++.h>
using namespace std;
int main(){
// concept: mb --> keep x and y in vector, func --> show y = mx+b;
int n;
float x,y;
string cmd;
vector<float> xi, yi;
cin >> n >> cmd;
for(int i=0; i<n; i++){
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// for(auto v:xi){
// cout << v << " ";
// }
// cout << endl;
// for(auto v: yi){
// cout << v << " ";
// }
float m,b1;
if(cmd == "mb"){
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
cout << round(m*1e3)/1e3 << endl;
cout << round(b1*1e3)/1e3 << endl;
}
if(cmd == "func"){
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
if(m != 0 && b1 != 0){
if(b1 > 0){
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << fabs(round(b1*1e3)/1e3);
}
}
}
} | # 0859, 2024-11-02 10:18:47, PPPPPPPPP-PPPPP------P-- (62%)
#include <bits/stdc++.h>
using namespace std;
int main(){
// concept: mb --> keep x and y in vector, func --> show y = mx+b;
int n;
float x,y;
string cmd;
vector<float> xi, yi;
cin >> n >> cmd;
for(int i=0; i<n; i++){
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// for(auto v:xi){
// cout << v << " ";
// }
// cout << endl;
// for(auto v: yi){
// cout << v << " ";
// }
float m,b1;
if(cmd == "mb"){
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
cout << round(m*1e3)/1e3 << endl;
cout << round(b1*1e3)/1e3 << endl;
}
if(cmd == "func"){
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
if(m != 0 && b1 != 0){
if(b1 > 0){
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m == 1 && b1 != 0){
if(b1 > 0){
cout << "y = " << "x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << "x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m == -1 && b1 != 0){
if(b1 > 0){
cout << "y = " << "-x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << "-x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m != 0 && b1 == 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
}
if(m == 1 && b1 == 0){
cout << "y = x";
}
if(m == -1 && b1 == 0){
cout << "y = -x";
}
if(m == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}
}
} | # 0860, 2024-11-02 11:19:06, PPPPPPPPP-PPPPP-----PP-- (66%)
#include <bits/stdc++.h>
using namespace std;
int main(){
// concept: mb --> keep x and y in vector, func --> show y = mx+b;
int n;
float x,y;
string cmd;
vector<float> xi, yi;
cin >> n >> cmd;
for(int i=0; i<n; i++){
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// for(auto v:xi){
// cout << v << " ";
// }
// cout << endl;
// for(auto v: yi){
// cout << v << " ";
// }
float m,b1;
if(cmd == "mb"){
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
cout << round(m*1e3)/1e3 << endl;
cout << round(b1*1e3)/1e3 << endl;
}
if(cmd == "func"){
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
if(m != 0 && m!= 1 && m!= -1 && b1 != 0){
if(b1 > 0){
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m == 1 && b1 != 0){
if(b1 > 0){
cout << "y = " << "x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << "x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m == -1 && b1 != 0){
if(b1 > 0){
cout << "y = " << "-x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << "-x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m != 0 && b1 == 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
}
if(m == 1 && b1 == 0){
cout << "y = x";
}
if(m == -1 && b1 == 0){
cout << "y = -x";
}
if(m == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}
}
} | # 0861, 2024-11-02 11:21:12, PPPPPPPPP---------PPP--- (50%)
#include <bits/stdc++.h>
using namespace std;
int main(){
// concept: mb --> keep x and y in vector, func --> show y = mx+b;
int n;
float x,y;
string cmd;
vector<float> xi, yi;
cin >> n >> cmd;
for(int i=0; i<n; i++){
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// for(auto v:xi){
// cout << v << " ";
// }
// cout << endl;
// for(auto v: yi){
// cout << v << " ";
// }
float m,b1;
if(cmd == "mb"){
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
cout << round(m*1e3)/1e3 << endl;
cout << round(b1*1e3)/1e3 << endl;
}
if(cmd == "func"){
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
if(m != 0 && m!= 1 && m!= -1 && b1 != 0){
if(b1 > 0){
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m == 1 && b1 != 0){
if(b1 > 0){
cout << "y = " << "x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << "x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m == -1 && b1 != 0){
if(b1 > 0){
cout << "y = " << "-x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << "-x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m != 0 && m!= 1 && m!= -1 && b1 == 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
}
if(m == 1 && b1 == 0){
cout << "y = x";
}
if(m == -1 && b1 == 0){
cout << "y = -x";
}
if(m != 0 && m!= 1 && m!= -1 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}
}
} | # 0862, 2024-11-02 11:21:47, PPPPPPPPP-PPPPP---PPPP-- (75%)
#include <bits/stdc++.h>
using namespace std;
int main(){
// concept: mb --> keep x and y in vector, func --> show y = mx+b;
int n;
float x,y;
string cmd;
vector<float> xi, yi;
cin >> n >> cmd;
for(int i=0; i<n; i++){
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// for(auto v:xi){
// cout << v << " ";
// }
// cout << endl;
// for(auto v: yi){
// cout << v << " ";
// }
float m,b1;
if(cmd == "mb"){
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
cout << round(m*1e3)/1e3 << endl;
cout << round(b1*1e3)/1e3 << endl;
}
if(cmd == "func"){
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
if(m != 0 && m!= 1 && m!= -1 && b1 != 0){
if(b1 > 0){
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m == 1 && b1 != 0){
if(b1 > 0){
cout << "y = " << "x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << "x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m == -1 && b1 != 0){
if(b1 > 0){
cout << "y = " << "-x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << "-x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m != 0 && m!= 1 && m!= -1 && b1 == 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
}
if(m == 1 && b1 == 0){
cout << "y = x";
}
if(m == -1 && b1 == 0){
cout << "y = -x";
}
if(m == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}
}
} | # 0863, 2024-11-02 11:30:43, PPPPPPPPP-PPPPPP--PP-P-- (75%)
#include <bits/stdc++.h>
using namespace std;
int main(){
// concept: mb --> keep x and y in vector, func --> show y = mx+b;
int n;
float x,y;
string cmd;
vector<float> xi, yi;
cin >> n >> cmd;
for(int i=0; i<n; i++){
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// for(auto v:xi){
// cout << v << " ";
// }
// cout << endl;
// for(auto v: yi){
// cout << v << " ";
// }
float m,b1;
if(cmd == "mb"){
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
cout << round(m*1e3)/1e3 << endl;
cout << round(b1*1e3)/1e3 << endl;
}
if(cmd == "func"){
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
// string output="";
if (m==0 && b==0){
cout << "y = 0";
}
if(m != 0 && b1 != 0){
if(b1 > 0){
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << fabs(round(b1*1e3)/1e3);
}
// cout << endl;
// cout << m;
}
if(m == 1 && b1 != 0){
if(b1 > 0){
cout << "y = " << "x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << "x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m == -1 && b1 != 0){
if(b1 > 0){
cout << "y = " << "-x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << "-x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m != 0 && m!= 1 && m!= -1 && b1 == 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
}
if(m == 1 && b1 == 0){
cout << "y = x";
}
if(m == -1 && b1 == 0){
cout << "y = -x";
}
if(m == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}
}
} | # 0864, 2024-11-02 11:40:07, PPPPPPPPP-PPPPPP--PP---- (70%)
#include <bits/stdc++.h>
using namespace std;
int main(){
// concept: mb --> keep x and y in vector, func --> show y = mx+b;
int n;
float x,y;
string cmd;
vector<float> xi, yi;
cin >> n >> cmd;
for(int i=0; i<n; i++){
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// for(auto v:xi){
// cout << v << " ";
// }
// cout << endl;
// for(auto v: yi){
// cout << v << " ";
// }
float m,b1;
if(cmd == "mb"){
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
cout << round(m*1e3)/1e3 << endl;
cout << round(b1*1e3)/1e3 << endl;
}
if(cmd == "func"){
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
// string output="";
if (m==0 && b==0){
cout << "y = 0";
}
if(round(m*1e3)/1e3 != -0 && round(m*1e3)/1e3 != 0 && m != 0 && b1 != 0){
if(b1 > 0){
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b1*1e3)/1e3;
// output + "y = " + to_string(round(m*1e3)/1e3) + "x + " + to_string(round(b1*1e3)/1e3);
}
else if(b1 < 0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << fabs(round(b1*1e3)/1e3);
// output + "y = " + to_string(round(m*1e3)/1e3) + "x - " + to_string(round(b1*1e3)/1e3);
}
// cout << endl;
// cout << m;
//cout << output;
}
if(round(m*1e3)/1e3 == -0 || round(m*1e3)/1e3 == 0 && b1 != 0){
if(b1 > 0){
cout << "y = " << "x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << "x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m == 1 && b1 != 0){
if(b1 > 0){
cout << "y = " << "x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << "x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m == -1 && b1 != 0){
if(b1 > 0){
cout << "y = " << "-x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << "-x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m != 0 && m!= 1 && m!= -1 && b1 == 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
}
if(m == 1 && b1 == 0){
cout << "y = x";
}
if(m == -1 && b1 == 0){
cout << "y = -x";
}
if(m == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}
}
} | # 0865, 2024-11-02 11:41:15, PPPPPPPPP-PPPPPP--PP---- (70%)
#include <bits/stdc++.h>
using namespace std;
int main(){
// concept: mb --> keep x and y in vector, func --> show y = mx+b;
int n;
float x,y;
string cmd;
vector<float> xi, yi;
cin >> n >> cmd;
for(int i=0; i<n; i++){
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// for(auto v:xi){
// cout << v << " ";
// }
// cout << endl;
// for(auto v: yi){
// cout << v << " ";
// }
float m,b1;
if(cmd == "mb"){
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
cout << round(m*1e3)/1e3 << endl;
cout << round(b1*1e3)/1e3 << endl;
}
if(cmd == "func"){
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
// string output="";
if (m==0 && b==0){
cout << "y = 0";
}
if(round(m*1e3)/1e3 != -0 && round(m*1e3)/1e3 != 0 && m != 0 && b1 != 0){
if(b1 > 0){
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b1*1e3)/1e3;
// output + "y = " + to_string(round(m*1e3)/1e3) + "x + " + to_string(round(b1*1e3)/1e3);
}
else if(b1 < 0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << fabs(round(b1*1e3)/1e3);
// output + "y = " + to_string(round(m*1e3)/1e3) + "x - " + to_string(round(b1*1e3)/1e3);
}
// cout << endl;
// cout << m;
//cout << output;
}
if((round(m*1e3)/1e3 == -0 || round(m*1e3)/1e3 == 0) && b1 != 0){
if(b1 > 0){
cout << "y = " << "x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << "x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m == 1 && b1 != 0){
if(b1 > 0){
cout << "y = " << "x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << "x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m == -1 && b1 != 0){
if(b1 > 0){
cout << "y = " << "-x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << "-x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m != 0 && m!= 1 && m!= -1 && b1 == 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
}
if(m == 1 && b1 == 0){
cout << "y = x";
}
if(m == -1 && b1 == 0){
cout << "y = -x";
}
if(m == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}
}
} | # 0866, 2024-11-02 11:45:53, PPPPPPPPP-PPPPPP--PPPP-- (79%)
#include <bits/stdc++.h>
using namespace std;
int main(){
// concept: mb --> keep x and y in vector, func --> show y = mx+b;
int n;
float x,y;
string cmd;
vector<float> xi, yi;
cin >> n >> cmd;
for(int i=0; i<n; i++){
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// for(auto v:xi){
// cout << v << " ";
// }
// cout << endl;
// for(auto v: yi){
// cout << v << " ";
// }
float m,b1;
if(cmd == "mb"){
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
cout << round(m*1e3)/1e3 << endl;
cout << round(b1*1e3)/1e3 << endl;
}
if(cmd == "func"){
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
// string output="";
if (m==0 && b==0){
cout << "y = 0";
}
if(m != 0 && m!=1 && m!=-1 && b1 != 0){
if(b1 > 0){
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << fabs(round(b1*1e3)/1e3);
}
// cout << endl;
// cout << m;
}
if(m == 1 && b1 != 0){
if(b1 > 0){
cout << "y = " << "x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << "x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m == -1 && b1 != 0){
if(b1 > 0){
cout << "y = " << "-x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << "-x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m != 0 && m!= 1 && m!= -1 && b1 == 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
}
if(m == 1 && b1 == 0){
cout << "y = x";
}
if(m == -1 && b1 == 0){
cout << "y = -x";
}
if(m == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}
}
} | # 0867, 2024-11-02 11:49:16, PPPPPPPPP-PPPPP-P-PPP--- (75%)
#include <bits/stdc++.h>
using namespace std;
int main(){
// concept: mb --> keep x and y in vector, func --> show y = mx+b;
int n;
float x,y;
string cmd;
vector<float> xi, yi;
cin >> n >> cmd;
for(int i=0; i<n; i++){
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// for(auto v:xi){
// cout << v << " ";
// }
// cout << endl;
// for(auto v: yi){
// cout << v << " ";
// }
float m,b1;
if(cmd == "mb"){
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
cout << round(m*1e3)/1e3 << endl;
cout << round(b1*1e3)/1e3 << endl;
}
if(cmd == "func"){
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
// string output="";
if(fabs(round(m*1e3)/1e3) == 0){
cout << "y = " << round(b1*1e3)/1e3;
}
if (m==0 && b==0){
cout << "y = 0";
}
if(fabs(round(m*1e3)/1e3) != 0 && m != 0 && m!=1 && m!=-1 && b1 != 0){
if(b1 > 0){
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << fabs(round(b1*1e3)/1e3);
}
// cout << endl;
// cout << m;
}
if(m == 1 && b1 != 0){
if(b1 > 0){
cout << "y = " << "x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << "x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m == -1 && b1 != 0){
if(b1 > 0){
cout << "y = " << "-x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << "-x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m != 0 && m!= 1 && m!= -1 && b1 == 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
}
if(m == 1 && b1 == 0){
cout << "y = x";
}
if(m == -1 && b1 == 0){
cout << "y = -x";
}
if(m == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}
}
} | # 0868, 2024-11-02 11:49:54, PPPPPPPPP-PPPPP---PPP--- (70%)
#include <bits/stdc++.h>
using namespace std;
int main(){
// concept: mb --> keep x and y in vector, func --> show y = mx+b;
int n;
float x,y;
string cmd;
vector<float> xi, yi;
cin >> n >> cmd;
for(int i=0; i<n; i++){
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// for(auto v:xi){
// cout << v << " ";
// }
// cout << endl;
// for(auto v: yi){
// cout << v << " ";
// }
float m,b1;
if(cmd == "mb"){
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
cout << round(m*1e3)/1e3 << endl;
cout << round(b1*1e3)/1e3 << endl;
}
if(cmd == "func"){
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
// string output="";
if(fabs(round(m*1e3)/1e3) == 0){
cout << "y = " << round(b1*1e3)/1e3;
}
if (m==0 && b==0){
cout << "y = 0";
}
if(m != 0 && m!=1 && m!=-1 && b1 != 0){
if(b1 > 0){
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << fabs(round(b1*1e3)/1e3);
}
// cout << endl;
// cout << m;
}
if(m == 1 && b1 != 0){
if(b1 > 0){
cout << "y = " << "x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << "x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m == -1 && b1 != 0){
if(b1 > 0){
cout << "y = " << "-x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << "-x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m != 0 && m!= 1 && m!= -1 && b1 == 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
}
if(m == 1 && b1 == 0){
cout << "y = x";
}
if(m == -1 && b1 == 0){
cout << "y = -x";
}
if(m == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}
}
} | # 0869, 2024-11-02 11:50:41, PPPPPPPPP-PPPPPP--PPPP-- (79%)
#include <bits/stdc++.h>
using namespace std;
int main(){
// concept: mb --> keep x and y in vector, func --> show y = mx+b;
int n;
float x,y;
string cmd;
vector<float> xi, yi;
cin >> n >> cmd;
for(int i=0; i<n; i++){
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// for(auto v:xi){
// cout << v << " ";
// }
// cout << endl;
// for(auto v: yi){
// cout << v << " ";
// }
float m,b1;
if(cmd == "mb"){
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
cout << round(m*1e3)/1e3 << endl;
cout << round(b1*1e3)/1e3 << endl;
}
if(cmd == "func"){
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
// string output="";
if (m==0 && b==0){
cout << "y = 0";
}
if(m != 0 && m!=1 && m!=-1 && b1 != 0){
if(b1 > 0){
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << fabs(round(b1*1e3)/1e3);
}
// cout << endl;
// cout << m;
}
if(m == 1 && b1 != 0){
if(b1 > 0){
cout << "y = " << "x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << "x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m == -1 && b1 != 0){
if(b1 > 0){
cout << "y = " << "-x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << "-x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m != 0 && m!= 1 && m!= -1 && b1 == 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
}
if(m == 1 && b1 == 0){
cout << "y = x";
}
if(m == -1 && b1 == 0){
cout << "y = -x";
}
if(m == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}
}
} | # 0870, 2024-11-02 11:54:36, PPPPPPPPP-PPPPPPP-PPPP-- (83%)
#include <bits/stdc++.h>
using namespace std;
int main(){
// concept: mb --> keep x and y in vector, func --> show y = mx+b;
int n;
float x,y;
string cmd;
vector<float> xi, yi;
cin >> n >> cmd;
for(int i=0; i<n; i++){
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// for(auto v:xi){
// cout << v << " ";
// }
// cout << endl;
// for(auto v: yi){
// cout << v << " ";
// }
float m,b1;
if(cmd == "mb"){
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
cout << round(m*1e3)/1e3 << endl;
cout << round(b1*1e3)/1e3 << endl;
}
if(cmd == "func"){
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
// string output="";
// if(fabs(round(m*1e3)/1e3) == 0){
// cout << "y = " << round(b1*1e3)/1e3;
// }
if (m==0 && b==0){
cout << "y = 0";
}
if(fabs(round(m*1e3)/1e3) != 0 && m != 0 && m!=1 && m!=-1 && b1 != 0){
if(b1 > 0){
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << fabs(round(b1*1e3)/1e3);
}
// cout << endl;
// cout << m;
}
if(m == 1 && b1 != 0){
if(b1 > 0){
cout << "y = " << "x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << "x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m == -1 && b1 != 0){
if(b1 > 0){
cout << "y = " << "-x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << "-x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m != 0 && m!= 1 && m!= -1 && b1 == 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
}
if(m == 1 && b1 == 0){
cout << "y = x";
}
if(m == -1 && b1 == 0){
cout << "y = -x";
}
if(fabs(round(m*1e3)/1e3) == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}
}
} | # 0871, 2024-11-02 12:04:27, PPPPPPPPP-PPPPPPP-PPPP-- (83%)
#include <bits/stdc++.h>
using namespace std;
int main(){
// concept: mb --> keep x and y in vector, func --> show y = mx+b;
int n;
float x,y;
string cmd;
vector<float> xi, yi;
cin >> n >> cmd;
for(int i=0; i<n; i++){
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// for(auto v:xi){
// cout << v << " ";
// }
// cout << endl;
// for(auto v: yi){
// cout << v << " ";
// }
float m,b1;
if(cmd == "mb"){
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
cout << round(m*1e3)/1e3 << endl;
cout << round(b1*1e3)/1e3 << endl;
}
if(cmd == "func"){
// find m
float sumXY = 0.0, sumX = 0.0, sumY = 0.0;
float a,b,c,d,e,f;
// first
for(int i=0; i<=n; i++){
sumXY += n * (xi[i] * yi[i]) ;
}
a = sumXY;
// second
for(int i=0; i<=n; i++){
sumX += xi[i];
}
for(int i=0; i<=n; i++){
sumY += yi[i];
}
b = sumX * sumY;
// third
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += n * (xi[i] * xi[i]);
}
c = sumX;
// forth
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += xi[i];
}
d = sumX * sumX;
m = (a-b)/(c-d);
// "-----------------------------------------------"
// find b
// first
sumY = 0.0;
for(int i=0; i<=n; i++){
sumY += yi[i];
}
e = sumY;
// second
sumX = 0.0;
for(int i=0; i<=n; i++){
sumX += m * xi[i];
}
f = sumX;
b1 = (e-f)/n;
if (m==0 && b==0){
cout << "y = 0";
}
if(fabs(round(m*1e3)/1e3) != 0 && m != 0 && m!=1 && m!=-1 && b1 != 0){
if(b1 > 0){
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m == 1 && b1 != 0){
if(b1 > 0){
cout << "y = " << "x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << "x - " << fabs(round(b1*1e3)/1e3);
}
cout << "test";
}
if(m == -1 && b1 != 0){
if(b1 > 0){
cout << "y = " << "-x + " << round(b1*1e3)/1e3;
}
else if(b1 < 0){
cout << "y = " << "-x - " << fabs(round(b1*1e3)/1e3);
}
}
if(m != 0 && m!= 1 && m!= -1 && b1 == 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
}
if(m == 1 && b1 == 0){
cout << "y = x";
}
if(m == -1 && b1 == 0){
cout << "y = -x";
}
if(fabs(round(m*1e3)/1e3) == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}
}
} |
# 0872, 2024-11-02 13:05:04, -----PPP---------------- (12%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string m_f;
cin >> n >> m_f;
pair<float, float> xy[n];
for (int i = 0; i < n; ++i)
{
cin >> xy[i].first >> xy[i].second;
}
if (m_f == "mb")
{
float m, b, S1 = 0, S2 = 0, S3 = 0, S4 = 0, S5 = 0;
for (int i = 1; i < n; ++i)
{
S1 += xy[i].first * xy[i].second;
S2 += xy[i].first;
S3 += xy[i].second;
S4 += pow(xy[i].first, 2);
}
S5 = pow(S2, 2);
m = ((n * S1) - (S2 * S3)) / ((n * S4) - S5);
b = (S3 - (m*S2))/n;
cout<<m<<endl<<b;
}
} | # 0873, 2024-11-02 13:06:22, -----PPP---------------- (12%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string m_f;
cin >> n >> m_f;
pair<float, float> xy[n];
for (int i = 0; i < n; ++i)
{
cin >> xy[i].first >> xy[i].second;
}
if (m_f == "mb")
{
float m, b, S1 = 0, S2 = 0, S3 = 0, S4 = 0, S5 = 0;
for (int i = 1; i < n; ++i)
{
S1 += xy[i].first * xy[i].second;
S2 += xy[i].first;
S3 += xy[i].second;
S4 += pow(xy[i].first, 2);
}
S5 = pow(S2, 2);
m = ((n * S1) - (S2 * S3)) / ((n * S4) - S5);
b = (S3 - (m*S2))/n;
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
} | # 0874, 2024-11-02 13:08:48, PPPPPPPPPP-------------- (41%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string m_f;
cin >> n >> m_f;
pair<float, float> xy[n];
for (int i = 0; i < n; ++i)
{
cin >> xy[i].first >> xy[i].second;
}
if (m_f == "mb")
{
float m, b, S1 = 0, S2 = 0, S3 = 0, S4 = 0, S5 = 0;
for (int i = 0; i < n; ++i)
{
S1 += xy[i].first * xy[i].second;
S2 += xy[i].first;
S3 += xy[i].second;
S4 += pow(xy[i].first, 2);
}
S5 = pow(S2, 2);
m = ((n * S1) - (S2 * S3)) / ((n * S4) - S5);
b = (S3 - (m*S2))/n;
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
} | # 0875, 2024-11-02 13:16:00, Compilation error (0%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string m_f;
cin >> n >> m_f;
pair<float, float> xy[n];
for (int i = 0; i < n; ++i)
{
cin >> xy[i].first >> xy[i].second;
}
float m, b, S1 = 0, S2 = 0, S3 = 0, S4 = 0, S5 = 0;
for (int i = 0; i < n; ++i)
{
S1 += xy[i].first * xy[i].second;
S2 += xy[i].first;
S3 += xy[i].second;
S4 += pow(xy[i].first, 2);
}
S5 = pow(S2, 2);
m = ((n * S1) - (S2 * S3)) / ((n * S4) - S5);
b = (S3 - (m * S2)) / n;
if (m_f == "mb")
{
cout << round(m * 1e3) / 1e3 << endl
<< round(b * 1e3) / 1e3;
}
if (m_f == "fucn")
{
if(m==1){
if(b==0){
cout<<"y = x";
}
cout<<"y = x + "<<round(b * 1e3) / 1e3;
}
if(m==-1){
if(b==0){
cout<<"y = -x";
}
cout<<"y = -x + "<<round(b * 1e3) / 1e3;
}
if(m==0&&b==0){
out<<"y = 0";
}
}
} | # 0876, 2024-11-02 13:16:16, PPPPPPPPPP-------------- (41%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string m_f;
cin >> n >> m_f;
pair<float, float> xy[n];
for (int i = 0; i < n; ++i)
{
cin >> xy[i].first >> xy[i].second;
}
float m, b, S1 = 0, S2 = 0, S3 = 0, S4 = 0, S5 = 0;
for (int i = 0; i < n; ++i)
{
S1 += xy[i].first * xy[i].second;
S2 += xy[i].first;
S3 += xy[i].second;
S4 += pow(xy[i].first, 2);
}
S5 = pow(S2, 2);
m = ((n * S1) - (S2 * S3)) / ((n * S4) - S5);
b = (S3 - (m * S2)) / n;
if (m_f == "mb")
{
cout << round(m * 1e3) / 1e3 << endl
<< round(b * 1e3) / 1e3;
}
if (m_f == "fucn")
{
if(m==1){
if(b==0){
cout<<"y = x";
}
cout<<"y = x + "<<round(b * 1e3) / 1e3;
}
if(m==-1){
if(b==0){
cout<<"y = -x";
}
cout<<"y = -x + "<<round(b * 1e3) / 1e3;
}
if(m==0&&b==0){
cout<<"y = 0";
}
}
} | # 0877, 2024-11-02 13:17:31, PPPPPPPPPP-----P-------- (45%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string m_f;
cin >> n >> m_f;
pair<float, float> xy[n];
for (int i = 0; i < n; ++i)
{
cin >> xy[i].first >> xy[i].second;
}
float m, b, S1 = 0, S2 = 0, S3 = 0, S4 = 0, S5 = 0;
for (int i = 0; i < n; ++i)
{
S1 += xy[i].first * xy[i].second;
S2 += xy[i].first;
S3 += xy[i].second;
S4 += pow(xy[i].first, 2);
}
S5 = pow(S2, 2);
m = ((n * S1) - (S2 * S3)) / ((n * S4) - S5);
b = (S3 - (m * S2)) / n;
if (m_f == "mb")
{
cout << round(m * 1e3) / 1e3 << endl
<< round(b * 1e3) / 1e3;
}
if (m_f == "func")
{
if(m==1){
if(b==0){
cout<<"y = x";
}
cout<<"y = x + "<<round(b * 1e3) / 1e3;
}
if(m==-1){
if(b==0){
cout<<"y = -x";
}
cout<<"y = -x + "<<round(b * 1e3) / 1e3;
}
if(m==0&&b==0){
cout<<"y = 0";
}
}
} | # 0878, 2024-11-02 13:25:49, PPPPPPPPPP-----P--PP-P-- (58%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string m_f;
cin >> n >> m_f;
pair<float, float> xy[n];
for (int i = 0; i < n; ++i)
{
cin >> xy[i].first >> xy[i].second;
}
float m, b, S1 = 0, S2 = 0, S3 = 0, S4 = 0, S5 = 0;
for (int i = 0; i < n; ++i)
{
S1 += xy[i].first * xy[i].second;
S2 += xy[i].first;
S3 += xy[i].second;
S4 += pow(xy[i].first, 2);
}
S5 = pow(S2, 2);
m = ((n * S1) - (S2 * S3)) / ((n * S4) - S5);
b = (S3 - (m * S2)) / n;
if (m_f == "mb")
{
cout << round(m * 1e3) / 1e3 << endl
<< round(b * 1e3) / 1e3;
}
if (m_f == "func")
{
if(m==1){
if(b==0){
cout<<"y = x";
return 0;
}
cout<<"y = x + "<<round(b * 1e3) / 1e3;
return 0;
}
if(m==-1){
if(b==0){
cout<<"y = -x";
return 0;
}
cout<<"y = -x + "<<round(b * 1e3) / 1e3;
return 0;
}
if(m==0&&b==0){
cout<<"y = 0";
return 0;
}
if(m==0&&b!=0){
cout<<"y = "<<round(b * 1e3) / 1e3;
return 0;
}
if(b!=0){
char op;
if(b>=0){
op ='+';
}
else op = '-';
cout<<"y = "<<round(m * 1e3) / 1e3<<"x "+op<<" "<<b;
return 0;
}
}
} | # 0879, 2024-11-02 13:29:22, PPPPPPPPPP-----PP-PP-P-- (62%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string m_f;
cin >> n >> m_f;
pair<float, float> xy[n];
for (int i = 0; i < n; ++i)
{
cin >> xy[i].first >> xy[i].second;
}
float m, b, S1 = 0, S2 = 0, S3 = 0, S4 = 0, S5 = 0;
for (int i = 0; i < n; ++i)
{
S1 += xy[i].first * xy[i].second;
S2 += xy[i].first;
S3 += xy[i].second;
S4 += pow(xy[i].first, 2);
}
S5 = pow(S2, 2);
m = ((n * S1) - (S2 * S3)) / ((n * S4) - S5);
b = (S3 - (m * S2)) / n;
if (m_f == "mb")
{
cout << round(m * 1e3) / 1e3 << endl
<< round(b * 1e3) / 1e3;
}
if (m_f == "func")
{
if(m==1){
if(b==0){
cout<<"y = x";
return 0;
}
cout<<"y = x + "<<round(b * 1e3) / 1e3;
return 0;
}
if(m==-1){
if(b==0){
cout<<"y = -x";
return 0;
}
cout<<"y = -x + "<<round(b * 1e3) / 1e3;
return 0;
}
if(m==0&&b==0){
cout<<"y = 0";
return 0;
}
if(b!=0){
cout<<"y = "<<round(b * 1e3) / 1e3;
return 0;
}
if(b!=0){
char op;
if(b>=0){
op ='+';
}
else op = '-';
cout<<"y = "<<round(m * 1e3) / 1e3<<"x "+op<<" "<<b;
return 0;
}
}
} | # 0880, 2024-11-02 13:36:32, PPPPPPPPPP-----PP-PP-P-- (62%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string m_f;
cin >> n >> m_f;
pair<float, float> xy[n];
for (int i = 0; i < n; ++i)
{
cin >> xy[i].first >> xy[i].second;
}
float m, b, S1 = 0, S2 = 0, S3 = 0, S4 = 0, S5 = 0;
for (int i = 0; i < n; ++i)
{
S1 += xy[i].first * xy[i].second;
S2 += xy[i].first;
S3 += xy[i].second;
S4 += pow(xy[i].first, 2);
}
S5 = pow(S2, 2);
m = ((n * S1) - (S2 * S3)) / ((n * S4) - S5);
b = (S3 - (m * S2)) / n;
if (m_f == "mb")
{
cout << round(m * 1e3) / 1e3 << endl
<< round(b * 1e3) / 1e3;
}
if (m_f == "func")
{
if(m==1){
if(b==0){
cout<<"y = x";
return 0;
}
cout<<"y = x + "<<round(b * 1e3) / 1e3;
return 0;
}
if(m==-1){
if(b==0){
cout<<"y = -x";
return 0;
}
cout<<"y = -x + "<<round(b * 1e3) / 1e3;
return 0;
}
if(m==0&&b==0){
cout<<"y = 0";
return 0;
}
if(b!=0){
cout<<"y = "<<round(b * 1e3) / 1e3;
return 0;
}
if(b!=0){
char op;
if(b>=0){
op ='+';
}
else op = '-';
cout<<"y = "<<round(m * 1e3) / 1e3<<"x "+op<<" "<<round(b * 1e3) / 1e3;
return 0;
}
}
} | # 0881, 2024-11-02 13:39:29, PPPPPPPPPP-----PP-PP-P-- (62%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string m_f;
cin >> n >> m_f;
pair<float, float> xy[n];
for (int i = 0; i < n; ++i)
{
cin >> xy[i].first >> xy[i].second;
}
float m, b, S1 = 0, S2 = 0, S3 = 0, S4 = 0, S5 = 0;
for (int i = 0; i < n; ++i)
{
S1 += xy[i].first * xy[i].second;
S2 += xy[i].first;
S3 += xy[i].second;
S4 += pow(xy[i].first, 2);
}
S5 = pow(S2, 2);
m = ((n * S1) - (S2 * S3)) / ((n * S4) - S5);
b = (S3 - (m * S2)) / n;
if (m_f == "mb")
{
cout << round(m * 1e3) / 1e3 << endl
<< round(b * 1e3) / 1e3;
}
if (m_f == "func")
{
char op;
if(b>=0){
op ='+';
}
else op = '-';
if(m==1){
if(b==0){
cout<<"y = x";
return 0;
}
cout<<"y = x "<<op<<" "<<round(b * 1e3) / 1e3;
return 0;
}
if(m==-1){
if(b==0){
cout<<"y = -x";
return 0;
}
cout<<"y = -x "<<"op"<<" "<<round(b * 1e3) / 1e3;
return 0;
}
if(m==0&&b==0){
cout<<"y = 0";
return 0;
}
if(b!=0){
cout<<"y = "<<round(b * 1e3) / 1e3;
return 0;
}
if(b!=0){
cout<<"y = "<<round(m * 1e3) / 1e3<<"x "+op<<" "<<round(b * 1e3) / 1e3;
return 0;
}
}
} | # 0882, 2024-11-02 13:40:14, PPPPPPPPPP-----PP-PP-P-- (62%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string m_f;
cin >> n >> m_f;
pair<float, float> xy[n];
for (int i = 0; i < n; ++i)
{
cin >> xy[i].first >> xy[i].second;
}
float m, b, S1 = 0, S2 = 0, S3 = 0, S4 = 0, S5 = 0;
for (int i = 0; i < n; ++i)
{
S1 += xy[i].first * xy[i].second;
S2 += xy[i].first;
S3 += xy[i].second;
S4 += pow(xy[i].first, 2);
}
S5 = pow(S2, 2);
m = ((n * S1) - (S2 * S3)) / ((n * S4) - S5);
b = (S3 - (m * S2)) / n;
if (m_f == "mb")
{
cout << round(m * 1e3) / 1e3 << endl
<< round(b * 1e3) / 1e3;
}
if (m_f == "func")
{
char op;
if(b>=0){
op ='+';
}
else op = '-';
if(m==1){
if(b==0){
cout<<"y = x";
return 0;
}
cout<<"y = x "<<op<<" "<<round(b * 1e3) / 1e3;
return 0;
}
if(m==-1){
if(b==0){
cout<<"y = -x";
return 0;
}
cout<<"y = -x "<<op<<" "<<round(b * 1e3) / 1e3;
return 0;
}
if(m==0&&b==0){
cout<<"y = 0";
return 0;
}
if(b!=0){
cout<<"y = "<<round(b * 1e3) / 1e3;
return 0;
}
if(b!=0){
cout<<"y = "<<round(m * 1e3) / 1e3<<"x "+op<<" "<<round(b * 1e3) / 1e3;
return 0;
}
}
} | # 0883, 2024-11-02 13:41:40, PPPPPPPPPP-----PP-PP-P-- (62%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string m_f;
cin >> n >> m_f;
pair<float, float> xy[n];
for (int i = 0; i < n; ++i)
{
cin >> xy[i].first >> xy[i].second;
}
float m, b, S1 = 0, S2 = 0, S3 = 0, S4 = 0, S5 = 0;
for (int i = 0; i < n; ++i)
{
S1 += xy[i].first * xy[i].second;
S2 += xy[i].first;
S3 += xy[i].second;
S4 += pow(xy[i].first, 2);
}
S5 = pow(S2, 2);
m = ((n * S1) - (S2 * S3)) / ((n * S4) - S5);
b = (S3 - (m * S2)) / n;
if (m_f == "mb")
{
cout << round(m * 1e3) / 1e3 << endl
<< round(b * 1e3) / 1e3;
}
if (m_f == "func")
{
char op;
if(b>=0){
op ='+';
}
else op = '-';
if(m==1){
if(b==0){
cout<<"y = x";
return 0;
}
cout<<"y = x "<<op<<" "<<round(abs(b) * 1e3) / 1e3;
return 0;
}
if(m==-1){
if(b==0){
cout<<"y = -x";
return 0;
}
cout<<"y = -x "<<op<<" "<<round(abs(b) * 1e3) / 1e3;
return 0;
}
if(m==0&&b==0){
cout<<"y = 0";
return 0;
}
if(b!=0){
cout<<"y = "<<round(b * 1e3) / 1e3;
return 0;
}
if(b!=0){
cout<<"y = "<<round(m * 1e3) / 1e3<<"x "+op<<" "<<round(b * 1e3) / 1e3;
return 0;
}
}
} | # 0884, 2024-11-02 13:43:58, PPPPPPPPPP-----P--PP-P-- (58%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string m_f;
cin >> n >> m_f;
pair<float, float> xy[n];
for (int i = 0; i < n; ++i)
{
cin >> xy[i].first >> xy[i].second;
}
float m, b, S1 = 0, S2 = 0, S3 = 0, S4 = 0, S5 = 0;
for (int i = 0; i < n; ++i)
{
S1 += xy[i].first * xy[i].second;
S2 += xy[i].first;
S3 += xy[i].second;
S4 += pow(xy[i].first, 2);
}
S5 = pow(S2, 2);
m = ((n * S1) - (S2 * S3)) / ((n * S4) - S5);
b = (S3 - (m * S2)) / n;
if (m_f == "mb")
{
cout << round(m * 1e3) / 1e3 << endl
<< round(b * 1e3) / 1e3;
}
if (m_f == "func")
{
char op;
if (b >= 0)
{
op = '+';
}
else
op = '-';
if (m == 1)
{
if (b == 0)
{
cout << "y = x";
return 0;
}
cout << "y = x " << op << " " << round(abs(b) * 1e3) / 1e3;
return 0;
}
if (m == -1)
{
if (b == 0)
{
cout << "y = -x";
return 0;
}
cout << "y = -x " << op << " " << round(abs(b) * 1e3) / 1e3;
return 0;
}
if (m == 0 && b == 0)
{
cout << "y = 0";
return 0;
}
if (m == 0 && b != 0)
{
cout << "y = " << round(b * 1e3) / 1e3;
return 0;
}
cout << "y = " << round(m * 1e3) / 1e3 << "x " + op << " " << round(b * 1e3) / 1e3;
return 0;
}
} | # 0885, 2024-11-02 13:46:41, PPPPPPPPPP-----P--PP-P-- (58%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string m_f;
cin >> n >> m_f;
pair<float, float> xy[n];
for (int i = 0; i < n; ++i)
{
cin >> xy[i].first >> xy[i].second;
}
float m, b, S1 = 0, S2 = 0, S3 = 0, S4 = 0, S5 = 0;
for (int i = 0; i < n; ++i)
{
S1 += xy[i].first * xy[i].second;
S2 += xy[i].first;
S3 += xy[i].second;
S4 += pow(xy[i].first, 2);
}
S5 = pow(S2, 2);
m = ((n * S1) - (S2 * S3)) / ((n * S4) - S5);
b = (S3 - (m * S2)) / n;
if (m_f == "mb")
{
cout << round(m * 1e3) / 1e3 << endl
<< round(b * 1e3) / 1e3;
}
if (m_f == "func")
{
char op;
if(b>=0){
op ='+';
}
else op = '-';
if(m==1){
if(b==0){
cout<<"y = x";
return 0;
}
cout<<"y = x "<<op<<" "<<round(abs(b) * 1e3) / 1e3;
return 0;
}
if(m==-1){
if(b==0){
cout<<"y = -x";
return 0;
}
cout<<"y = -x "<<op<<" "<<round(abs(b) * 1e3) / 1e3;
return 0;
}
if(m==0){
cout<<"y = "<<round(b * 1e3) / 1e3;
return 0;
}
if(b!=0){
cout<<"y = "<<round(m * 1e3) / 1e3<<"x "+op<<" "<<round(b * 1e3) / 1e3;
return 0;
}
}
} | # 0886, 2024-11-02 13:48:52, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string m_f;
cin >> n >> m_f;
pair<float, float> xy[n];
for (int i = 0; i < n; ++i)
{
cin >> xy[i].first >> xy[i].second;
}
float m, b, S1 = 0, S2 = 0, S3 = 0, S4 = 0, S5 = 0;
for (int i = 0; i < n; ++i)
{
S1 += xy[i].first * xy[i].second;
S2 += xy[i].first;
S3 += xy[i].second;
S4 += pow(xy[i].first, 2);
}
S5 = pow(S2, 2);
m = ((n * S1) - (S2 * S3)) / ((n * S4) - S5);
b = (S3 - (m * S2)) / n;
if (m_f == "mb")
{
cout << round(m * 1e3) / 1e3 << endl
<< round(b * 1e3) / 1e3;
}
if (m_f == "func")
{
char op;
if(b>=0){
op ='+';
}
else op = '-';
if(m==1){
if(b==0){
cout<<"y = x";
return 0;
}
cout<<"y = x "<<op<<" "<<round(abs(b) * 1e3) / 1e3;
return 0;
}
if(m==-1){
if(b==0){
cout<<"y = -x";
return 0;
}
cout<<"y = -x "<<op<<" "<<round(abs(b) * 1e3) / 1e3;
return 0;
}
if(m==0){
cout<<"y = "<<round(b * 1e3) / 1e3;
return 0;
}
if(b!=0){
cout<<"y = "<<round(m * 1e3) / 1e3<<"x "<<op<<" "<<round(abs(b) * 1e3) / 1e3;
return 0;
}
}
} | # 0887, 2024-11-02 13:52:14, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string m_f;
cin >> n >> m_f;
pair<float, float> xy[n];
for (int i = 0; i < n; ++i)
{
cin >> xy[i].first >> xy[i].second;
}
float m, b, S1 = 0, S2 = 0, S3 = 0, S4 = 0, S5 = 0;
for (int i = 0; i < n; ++i)
{
S1 += xy[i].first * xy[i].second;
S2 += xy[i].first;
S3 += xy[i].second;
S4 += pow(xy[i].first, 2);
}
S5 = pow(S2, 2);
m = ((n * S1) - (S2 * S3)) / ((n * S4) - S5);
b = (S3 - (m * S2)) / n;
if (m_f == "mb")
{
cout << round(m * 1e3) / 1e3 << endl
<< round(b * 1e3) / 1e3;
}
if (m_f == "func")
{
char op;
if(b>=0){
op ='+';
}
else op = '-';
if(m==1){
if(b==0){
cout<<"y = x";
return 0;
}
cout<<"y = x "<<op<<" "<<round(abs(b) * 1e3) / 1e3;
return 0;
}
if(m==-1){
if(b==0){
cout<<"y = -x";
return 0;
}
cout<<"y = -x "<<op<<" "<<round(abs(b) * 1e3) / 1e3;
return 0;
}
if(m==0.0){
cout<<"y = "<<round(b * 1e3) / 1e3;
return 0;
}
if(b!=0){
cout<<"y = "<<round(m * 1e3) / 1e3<<"x "<<op<<" "<<round(abs(b) * 1e3) / 1e3;
return 0;
}
}
} | # 0888, 2024-11-02 13:54:01, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string m_f;
cin >> n >> m_f;
pair<float, float> xy[n];
for (int i = 0; i < n; ++i)
{
cin >> xy[i].first >> xy[i].second;
}
float m, b, S1 = 0, S2 = 0, S3 = 0, S4 = 0, S5 = 0;
for (int i = 0; i < n; ++i)
{
S1 += xy[i].first * xy[i].second;
S2 += xy[i].first;
S3 += xy[i].second;
S4 += pow(xy[i].first, 2);
}
S5 = pow(S2, 2);
m = ((n * S1) - (S2 * S3)) / ((n * S4) - S5);
b = (S3 - (m * S2)) / n;
if (m_f == "mb")
{
cout << round(m * 1e3) / 1e3 << endl
<< round(b * 1e3) / 1e3;
}
if (m_f == "func")
{
char op;
if(b>=0){
op ='+';
}
else op = '-';
if(m==1){
if(b==0){
cout<<"y = x";
return 0;
}
cout<<"y = x "<<op<<" "<<round(abs(b) * 1e3) / 1e3;
return 0;
}
if(m==-1){
if(b==0){
cout<<"y = -x";
return 0;
}
cout<<"y = -x "<<op<<" "<<round(abs(b) * 1e3) / 1e3;
return 0;
}
if(m==0||round(m * 1e3) / 1e3 ==0){
cout<<"y = "<<round(b * 1e3) / 1e3;
return 0;
}
if(b!=0){
cout<<"y = "<<round(m * 1e3) / 1e3<<"x "<<op<<" "<<round(abs(b) * 1e3) / 1e3;
return 0;
}
}
} | # 0889, 2024-11-02 13:56:06, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string m_f;
cin >> n >> m_f;
pair<float, float> xy[n];
for (int i = 0; i < n; ++i)
{
cin >> xy[i].first >> xy[i].second;
}
float m, b, S1 = 0, S2 = 0, S3 = 0, S4 = 0, S5 = 0;
for (int i = 0; i < n; ++i)
{
S1 += xy[i].first * xy[i].second;
S2 += xy[i].first;
S3 += xy[i].second;
S4 += pow(xy[i].first, 2);
}
S5 = pow(S2, 2);
m = ((n * S1) - (S2 * S3)) / ((n * S4) - S5);
b = (S3 - (m * S2)) / n;
if (m_f == "mb")
{
cout << round(m * 1e3) / 1e3 << endl
<< round(b * 1e3) / 1e3;
}
if (m_f == "func")
{
char op;
if(b>=0){
op ='+';
}
else op = '-';
if(m==1){
if(b==0){
cout<<"y = x";
return 0;
}
cout<<"y = x "<<op<<" "<<round(abs(b) * 1e3) / 1e3;
return 0;
}
if(m==-1){
if(b==0){
cout<<"y = -x";
return 0;
}
cout<<"y = -x "<<op<<" "<<round(abs(b) * 1e3) / 1e3;
return 0;
}
if(m==0){
cout<<"y = "<<round(b * 1e3) / 1e3;
return 0;
}
if(b!=0){
if(round(m * 1e3) / 1e3 ==0){
cout<<"y = "<<op<<round(abs(b) * 1e3) / 1e3;
return 0;
}
cout<<"y = "<<round(m * 1e3) / 1e3<<"x "<<op<<" "<<round(abs(b) * 1e3) / 1e3;
return 0;
}
}
} | # 0890, 2024-11-02 13:58:13, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string m_f;
cin >> n >> m_f;
pair<float, float> xy[n];
for (int i = 0; i < n; ++i)
{
cin >> xy[i].first >> xy[i].second;
}
float m, b, S1 = 0, S2 = 0, S3 = 0, S4 = 0, S5 = 0;
for (int i = 0; i < n; ++i)
{
S1 += xy[i].first * xy[i].second;
S2 += xy[i].first;
S3 += xy[i].second;
S4 += pow(xy[i].first, 2);
}
S5 = pow(S2, 2);
m = ((n * S1) - (S2 * S3)) / ((n * S4) - S5);
b = (S3 - (m * S2)) / n;
if (m_f == "mb")
{
cout << round(m * 1e3) / 1e3 << endl
<< round(b * 1e3) / 1e3;
}
if (m_f == "func")
{
char op;
if(b>=0){
op ='+';
}
else op = '-';
if(m==0&&b==0){
cout<<"y = 0";
return 0;
}
if(m==1){
if(b==0){
cout<<"y = x";
return 0;
}
cout<<"y = x "<<op<<" "<<round(abs(b) * 1e3) / 1e3;
return 0;
}
if(m==-1){
if(b==0){
cout<<"y = -x";
return 0;
}
cout<<"y = -x "<<op<<" "<<round(abs(b) * 1e3) / 1e3;
return 0;
}
if(m==0||round(m * 1e3) / 1e3 ==0){
cout<<"y = "<<round(b * 1e3) / 1e3;
return 0;
}
if(b!=0){
cout<<"y = "<<round(m * 1e3) / 1e3<<"x "<<op<<" "<<round(abs(b) * 1e3) / 1e3;
return 0;
}
}
} |
# 0891, 2024-11-02 11:08:32, PPPPPPPPPPPPPPPP--PP--P- (79%)
#include<bits/stdc++.h>
using namespace std;
int main(){
string type;
int n;
float tempa,tempb,m=0,b=0;
map<float,float> info;
cin >> n >> type;
int time = n;
while(time--){
cin >> tempa >> tempb;
info[tempa] = tempb;
}
float temp1 = 0,temp2 = 0,temp3 =0,temp4 =0;
for(auto i = info.begin() ; i!= info.end() ; i++){
temp1+= i->first*i->second;//keep xy
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp2+= i->first;//keep x
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp3+= i->second;// keep y
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp4+= pow(i->first,2);//keep xpow2
}
m = ((n*temp1)-(temp2*temp3))/((n*temp4)-pow(temp2,2));
b = (temp3-m*temp2)/n;
if(type=="mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else if(type=="func"){
if(m==0&&b==0){
cout << "y = 0" << endl;
}else if(m==-1&&b==0){
cout << "y = -x" << endl;
}else if(m==-1&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = -x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==1&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==1&b==0){
cout << "y = x" << endl;
}else{
if(b<=0){
b = abs(b);
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3 << endl;
}
}
}
} | # 0892, 2024-11-02 11:12:30, PPPPPPPPPPPPPPPP--PP--P- (79%)
#include<bits/stdc++.h>
using namespace std;
int main(){
string type;
int n;
float tempa,tempb,m=0,b=0;
map<float,float> info;
cin >> n >> type;
int time = n;
while(time--){
cin >> tempa >> tempb;
info[tempa] = tempb;
}
float temp1 = 0,temp2 = 0,temp3 =0,temp4 =0;
for(auto i = info.begin() ; i!= info.end() ; i++){
temp1+= i->first*i->second;//keep xy
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp2+= i->first;//keep x
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp3+= i->second;// keep y
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp4+= pow(i->first,2);//keep xpow2
}
m = ((n*temp1)-(temp2*temp3))/((n*temp4)-pow(temp2,2));
b = (temp3-m*temp2)/n;
if(type=="mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else if(type=="func"){
if(m==0&&b==0){
cout << "y = 0" << endl;
}else if(m==-1&&b==0){
cout << "y = -x" << endl;
}else if(m==-1&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = -x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==1&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==1&b==0){
cout << "y = x" << endl;
}else{
if(b<=0){
b = abs(b);
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3 << endl;
}
}
}
} | # 0893, 2024-11-02 11:13:52, PPPPPPPPPPPPPPPP--PP--P- (79%)
#include<bits/stdc++.h>
using namespace std;
int main(){
string type;
int n;
float tempa,tempb,m=0,b=0;
map<float,float> info;
cin >> n >> type;
int time = n;
while(time--){
cin >> tempa >> tempb;
info[tempa] = tempb;
}
float temp1 = 0,temp2 = 0,temp3 =0,temp4 =0;
for(auto i = info.begin() ; i!= info.end() ; i++){
temp1+= i->first*i->second;//keep xy
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp2+= i->first;//keep x
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp3+= i->second;// keep y
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp4+= pow(i->first,2);//keep xpow2
}
m = ((n*temp1)-(temp2*temp3))/((n*temp4)-pow(temp2,2));
b = (temp3-m*temp2)/n;
if(type=="mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else if(type=="func"){
if(m==0&&b==0){
cout << "y = 0" << endl;
}else if(m==-1&&b==0){
cout << "y = -x" << endl;
}else if(m==-1&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = -x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==1&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==1&b==0){
cout << "y = x" << endl;
}else if(m!=0&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3 << endl;
}
}
}
} | # 0894, 2024-11-02 11:16:52, PPPPPPPPPPPPPPPP-PPPP--- (83%)
#include<bits/stdc++.h>
using namespace std;
int main(){
string type;
int n;
double tempa,tempb,m=0,b=0;
map<double,double> info;
cin >> n >> type;
int time = n;
while(time--){
cin >> tempa >> tempb;
info[tempa] = tempb;
}
double temp1 = 0,temp2 = 0,temp3 =0,temp4 =0;
for(auto i = info.begin() ; i!= info.end() ; i++){
temp1+= i->first*i->second;//keep xy
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp2+= i->first;//keep x
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp3+= i->second;// keep y
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp4+= pow(i->first,2);//keep xpow2
}
m = ((n*temp1)-(temp2*temp3))/((n*temp4)-pow(temp2,2));
b = (temp3-m*temp2)/n;
if(type=="mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else if(type=="func"){
if(m==0&&b==0){
cout << "y = 0" << endl;
}else if(m==-1&&b==0){
cout << "y = -x" << endl;
}else if(m==-1&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = -x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==1&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==1&b==0){
cout << "y = x" << endl;
}else if(m!=0&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3 << endl;
}
}
}
} | # 0895, 2024-11-02 11:17:52, PPPPPPPPPPPPPPPP--PP--P- (79%)
#include<bits/stdc++.h>
using namespace std;
int main(){
string type;
float n;
float tempa,tempb,m=0,b=0;
map<float,float> info;
cin >> n >> type;
int time = n;
while(time--){
cin >> tempa >> tempb;
info[tempa] = tempb;
}
float temp1 = 0,temp2 = 0,temp3 =0,temp4 =0;
for(auto i = info.begin() ; i!= info.end() ; i++){
temp1+= i->first*i->second;//keep xy
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp2+= i->first;//keep x
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp3+= i->second;// keep y
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp4+= pow(i->first,2);//keep xpow2
}
m = ((n*temp1)-(temp2*temp3))/((n*temp4)-pow(temp2,2));
b = (temp3-m*temp2)/n;
if(type=="mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else if(type=="func"){
if(m==0&&b==0){
cout << "y = 0" << endl;
}else if(m==-1&&b==0){
cout << "y = -x" << endl;
}else if(m==-1&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = -x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==1&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==1&b==0){
cout << "y = x" << endl;
}else if(m!=0&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3 << endl;
}
}
}
} | # 0896, 2024-11-02 11:18:51, PPPPPPPPPPPPPPPP--PP--P- (79%)
#include<bits/stdc++.h>
using namespace std;
int main(){
string type;
float n;
float tempa,tempb,m=0,b=0;
map<float,float> info;
cin >> n >> type;
float time = n;
while(time--){
cin >> tempa >> tempb;
info[tempa] = tempb;
}
float temp1 = 0,temp2 = 0,temp3 =0,temp4 =0;
for(auto i = info.begin() ; i!= info.end() ; i++){
temp1+= i->first*i->second;//keep xy
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp2+= i->first;//keep x
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp3+= i->second;// keep y
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp4+= pow(i->first,2);//keep xpow2
}
m = ((n*temp1)-(temp2*temp3))/((n*temp4)-pow(temp2,2));
b = (temp3-m*temp2)/n;
if(type=="mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else if(type=="func"){
if(m==0&&b==0){
cout << "y = 0" << endl;
}else if(m==-1&&b==0){
cout << "y = -x" << endl;
}else if(m==-1&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = -x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==1&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==1&b==0){
cout << "y = x" << endl;
}else if(m!=0&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3 << endl;
}
}
}
} | # 0897, 2024-11-02 11:20:58, PPPPPP-PP-PPPPPP-------- (58%)
#include<bits/stdc++.h>
using namespace std;
int main(){
string type;
double n;
double tempa,tempb,m=0,b=0;
map<double,double> info;
cin >> n >> type;
double time = n;
while(time--){
cin >> tempa >> tempb;
info[tempa] = tempb;
}
float temp1 = 0,temp2 = 0,temp3 =0,temp4 =0;
for(auto i = info.begin() ; i!= info.end() ; i++){
temp1+= i->first*i->second;//keep xy
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp2+= i->first;//keep x
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp3+= i->second;// keep y
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp4+= pow(i->first,2);//keep xpow2
}
m = ((n*temp1)-(temp2*temp3))/((n*temp4)-pow(temp2,2));
b = (temp3-m*temp2)/n;
if(type=="mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else if(type=="func"){
if(m==0&&b==0){
cout << "y = 0" << endl;
}else if(m==-1&&b==0){
cout << "y = -x" << endl;
}else if(m==-1&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = -x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==1&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==1&b==0){
cout << "y = x" << endl;
}else if(m!=0&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3 << endl;
}
}
}
} | # 0898, 2024-11-02 11:21:17, PPPPPP-PPPPPPPPP-------- (62%)
#include<bits/stdc++.h>
using namespace std;
int main(){
string type;
int n;
double tempa,tempb,m=0,b=0;
map<double,double> info;
cin >> n >> type;
double time = n;
while(time--){
cin >> tempa >> tempb;
info[tempa] = tempb;
}
float temp1 = 0,temp2 = 0,temp3 =0,temp4 =0;
for(auto i = info.begin() ; i!= info.end() ; i++){
temp1+= i->first*i->second;//keep xy
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp2+= i->first;//keep x
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp3+= i->second;// keep y
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp4+= pow(i->first,2);//keep xpow2
}
m = ((n*temp1)-(temp2*temp3))/((n*temp4)-pow(temp2,2));
b = (temp3-m*temp2)/n;
if(type=="mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else if(type=="func"){
if(m==0&&b==0){
cout << "y = 0" << endl;
}else if(m==-1&&b==0){
cout << "y = -x" << endl;
}else if(m==-1&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = -x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==1&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==1&b==0){
cout << "y = x" << endl;
}else if(m!=0&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3 << endl;
}
}
}
} | # 0899, 2024-11-02 11:24:16, PPPPPPPPPPPPPPPP-PPPP--- (83%)
#include<bits/stdc++.h>
using namespace std;
int main(){
string type;
int n;
double tempa,tempb,m=0,b=0;
map<double,double> info;
cin >> n >> type;
int time = n;
while(time--){
cin >> tempa >> tempb;
info[tempa] = tempb;
}
double temp1 = 0,temp2 = 0,temp3 =0,temp4 =0;
for(auto i = info.begin() ; i!= info.end() ; i++){
temp1+= i->first*i->second;//keep xy
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp2+= i->first;//keep x
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp3+= i->second;// keep y
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp4+= pow(i->first,2);//keep xpow2
}
m = ((n*temp1)-(temp2*temp3))/((n*temp4)-pow(temp2,2));
b = (temp3-m*temp2)/n;
if(type=="mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else if(type=="func"){
if(m==0&&b==0){
cout << "y = 0" << endl;
}else if(m==-1&&b==0){
cout << "y = -x" << endl;
}else if(m==-1&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = -x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==1&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==1&b==0){
cout << "y = x" << endl;
}else if(m!=0&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3 << endl;
}
}
}
} | # 0900, 2024-11-02 11:28:03, PPPPPPPPPP-----P--PP--P- (58%)
#include<bits/stdc++.h>
using namespace std;
int main(){
string type;
int n;
float tempa,tempb,m=0,b=0;
map<float,float> info;
cin >> n >> type;
int time = n;
while(time--){
cin >> tempa >> tempb;
info[tempa] = tempb;
}
float temp1 = 0,temp2 = 0,temp3 =0,temp4 =0;
for(auto i = info.begin() ; i!= info.end() ; i++){
temp1+= i->first*i->second;//keep xy
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp2+= i->first;//keep x
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp3+= i->second;// keep y
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp4+= pow(i->first,2);//keep xpow2
}
m = ((n*temp1)-(temp2*temp3))/((n*temp4)-pow(temp2,2));
b = (temp3-m*temp2)/n;
if(type=="mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else if(type=="func"){
if(m==0&&b==0){
cout << "y = 0" << endl;
}else if(m==-1&&b==0){
cout << "y = -x" << endl;
}else if(m==-1&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = -x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==1&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==1&b==0){
cout << "y = x" << endl;
}else if(m!=0&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = " << round(b*1e3)/1e3 << "x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = " << round(b*1e3)/1e3 << "x + " << round(b*1e3)/1e3 << endl;
}
}
}
} | # 0901, 2024-11-02 11:28:29, PPPPPPPPPPPPPPPP--PP--P- (79%)
#include<bits/stdc++.h>
using namespace std;
int main(){
string type;
int n;
float tempa,tempb,m=0,b=0;
map<float,float> info;
cin >> n >> type;
int time = n;
while(time--){
cin >> tempa >> tempb;
info[tempa] = tempb;
}
float temp1 = 0,temp2 = 0,temp3 =0,temp4 =0;
for(auto i = info.begin() ; i!= info.end() ; i++){
temp1+= i->first*i->second;//keep xy
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp2+= i->first;//keep x
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp3+= i->second;// keep y
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp4+= pow(i->first,2);//keep xpow2
}
m = ((n*temp1)-(temp2*temp3))/((n*temp4)-pow(temp2,2));
b = (temp3-m*temp2)/n;
if(type=="mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else if(type=="func"){
if(m==0&&b==0){
cout << "y = 0" << endl;
}else if(m==-1&&b==0){
cout << "y = -x" << endl;
}else if(m==-1&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = -x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==1&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==1&b==0){
cout << "y = x" << endl;
}else if(m!=0&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3 << endl;
}
}
}
} | # 0902, 2024-11-02 11:29:49, PPPPPPPPPPPPPPPP--PP-PP- (83%)
#include<bits/stdc++.h>
using namespace std;
int main(){
string type;
int n;
float tempa,tempb,m=0,b=0;
map<float,float> info;
cin >> n >> type;
int time = n;
while(time--){
cin >> tempa >> tempb;
info[tempa] = tempb;
}
float temp1 = 0,temp2 = 0,temp3 =0,temp4 =0;
for(auto i = info.begin() ; i!= info.end() ; i++){
temp1+= i->first*i->second;//keep xy
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp2+= i->first;//keep x
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp3+= i->second;// keep y
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp4+= pow(i->first,2);//keep xpow2
}
m = ((n*temp1)-(temp2*temp3))/((n*temp4)-pow(temp2,2));
b = (temp3-m*temp2)/n;
if(type=="mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else if(type=="func"){
if(m==0&&b==0){
cout << "y = 0" << endl;
}else if(m==-1&&b==0){
cout << "y = -x" << endl;
}else if(m==-1&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = -x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==1&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==1&b==0){
cout << "y = x" << endl;
}else if(m==0&b!=0){
cout << "y = " << round(b*1e3)/1e3 << endl;
}else if(m!=0&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3 << endl;
}
}
}
} | # 0903, 2024-11-02 11:36:56, PPPPPPPPPPPPPPPP--PP---- (75%)
#include<bits/stdc++.h>
using namespace std;
int main(){
string type;
int n;
float tempa,tempb,m=0,b=0;
map<float,float> info;
cin >> n >> type;
int time = n;
while(time--){
cin >> tempa >> tempb;
info[tempa] = tempb;
}
float temp1 = 0,temp2 = 0,temp3 =0,temp4 =0;
for(auto i = info.begin() ; i!= info.end() ; i++){
temp1+= i->first*i->second;//keep xy
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp2+= i->first;//keep x
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp3+= i->second;// keep y
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp4+= pow(i->first,2);//keep xpow2
}
m = ((n*temp1)-(temp2*temp3))/((n*temp4)-pow(temp2,2));
b = (temp3-m*temp2)/n;
if(type=="mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else if(type=="func"){
if(m==0&&b==0){
cout << "y = 0" << endl;
}else if(m==0&b!=0){
if(b<=0){
b = abs(b);
cout << "y = - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = " << round(b*1e3)/1e3 << endl;
}
}else if(m!=0&&b==0){
if(m==1){
cout << "y = x" << endl;
}else if(m==-1){
cout << "y = -x" << endl;
}else{
cout << "y = " << round(m*1e3)/1e3 << 'x' << endl;
}
}else if(m!=0&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3 << endl;
}
}
/*else if(m==-1&&b==0){
cout << "y = -x" << endl;
}else if(m==-1&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = -x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==1&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==1&b==0){
cout << "y = x" << endl;
}else if(m==0&b!=0){
cout << "y = " << round(b*1e3)/1e3 << endl;
}else if(m!=0&&b==0){
}
else if(m!=0&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3 << endl;
}
}*/
}
} | # 0904, 2024-11-02 11:39:43, PPPPPPPPPPPPPPPP--PP--P- (79%)
#include<bits/stdc++.h>
using namespace std;
int main(){
string type;
int n;
float tempa,tempb,m=0,b=0;
map<float,float> info;
cin >> n >> type;
int time = n;
while(time--){
cin >> tempa >> tempb;
info[tempa] = tempb;
}
float temp1 = 0,temp2 = 0,temp3 =0,temp4 =0;
for(auto i = info.begin() ; i!= info.end() ; i++){
temp1+= i->first*i->second;//keep xy
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp2+= i->first;//keep x
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp3+= i->second;// keep y
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp4+= pow(i->first,2);//keep xpow2
}
m = ((n*temp1)-(temp2*temp3))/((n*temp4)-pow(temp2,2));
b = (temp3-m*temp2)/n;
if(type=="mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else if(type=="func"){
if(m==0&&b==0){
cout << "y = 0" << endl;
}else if(m==0&b!=0){
if(b<=0){
b = abs(b);
cout << "y = - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = " << round(b*1e3)/1e3 << endl;
}
}else if(m!=0&&b==0){
if(m==1){
cout << "y = x" << endl;
}else if(m==-1){
cout << "y = -x" << endl;
}else{
cout << "y = " << round(m*1e3)/1e3 << 'x' << endl;
}
}else if(m!=0&&b!=0){
if(m==1){
if(b<=0){
b = abs(b);
cout << "y = x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==-1){
if(b<=0){
b = abs(b);
cout << "y = -x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}
}else{
if(b<=0){
b = abs(b);
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3 << endl;
}
}
}
/*else if(m==-1&&b==0){
cout << "y = -x" << endl;
}else if(m==-1&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = -x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==1&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==1&b==0){
cout << "y = x" << endl;
}else if(m==0&b!=0){
cout << "y = " << round(b*1e3)/1e3 << endl;
}else if(m!=0&&b==0){
}
else if(m!=0&&b!=0){
if(b<=0){
b = abs(b);
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3 << endl;
}
}*/
}
} | # 0905, 2024-11-02 11:44:23, PPPPPPPPPPPPPPPP-PPPP--- (83%)
#include<bits/stdc++.h>
using namespace std;
int main(){
string type;
long n;
double tempa,tempb,m=0,b=0;
map<double,double> info;
cin >> n >> type;
double time = n;
while(time--){
cin >> tempa >> tempb;
info[tempa] = tempb;
}
double temp1 = 0,temp2 = 0,temp3 =0,temp4 =0;
for(auto i = info.begin() ; i!= info.end() ; i++){
temp1+= i->first*i->second;//keep xy
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp2+= i->first;//keep x
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp3+= i->second;// keep y
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp4+= pow(i->first,2);//keep xpow2
}
m = ((n*temp1)-(temp2*temp3))/((n*temp4)-pow(temp2,2));
b = (temp3-m*temp2)/n;
if(type=="mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else if(type=="func"){
if(m==0&&b==0){
cout << "y = 0" << endl;
}else if(m==0&b!=0){
if(b<=0){
b = abs(b);
cout << "y = - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = " << round(b*1e3)/1e3 << endl;
}
}else if(m!=0&&b==0){
if(m==1){
cout << "y = x" << endl;
}else if(m==-1){
cout << "y = -x" << endl;
}else{
cout << "y = " << round(m*1e3)/1e3 << 'x' << endl;
}
}else if(m!=0&&b!=0){
if(m==1){
if(b<=0){
b = abs(b);
cout << "y = x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==-1){
if(b<=0){
b = abs(b);
cout << "y = -x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}
}else{
if(b<=0){
b = abs(b);
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3 << endl;
}
}
}
}
} | # 0906, 2024-11-02 12:02:16, PPPPPP-PPPPPPPPP-------- (62%)
#include<bits/stdc++.h>
using namespace std;
int main(){
string type;
long n;
double tempa,tempb,m=0,b=0;
map<double,double> info;
cin >> n >> type;
double time = n;
while(time--){
cin >> tempa >> tempb;
info[tempa] = tempb;
}
float temp1 = 0,temp2 = 0,temp3 =0,temp4 =0;
for(auto i = info.begin() ; i!= info.end() ; i++){
temp1+= i->first*i->second;//keep xy
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp2+= i->first;//keep x
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp3+= i->second;// keep y
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp4+= pow(i->first,2);//keep xpow2
}
m = ((n*temp1)-(temp2*temp3))/((n*temp4)-pow(temp2,2));
b = (temp3-m*temp2)/n;
if(type=="mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else if(type=="func"){
if(m==0&&b==0){
cout << "y = 0" << endl;
}else if(m==0&b!=0){
if(b<=0){
b = abs(b);
cout << "y = - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = " << round(b*1e3)/1e3 << endl;
}
}else if(m!=0&&b==0){
if(m==1){
cout << "y = x" << endl;
}else if(m==-1){
cout << "y = -x" << endl;
}else{
cout << "y = " << round(m*1e3)/1e3 << 'x' << endl;
}
}else if(m!=0&&b!=0){
if(m==1){
if(b<=0){
b = abs(b);
cout << "y = x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==-1){
if(b<=0){
b = abs(b);
cout << "y = -x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}
}else{
if(b<=0){
b = abs(b);
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3 << endl;
}
}
}
}
} | # 0907, 2024-11-02 12:02:53, PPPPPPPPPPPPPPPP--PP--P- (79%)
#include<bits/stdc++.h>
using namespace std;
int main(){
string type;
long n;
float tempa,tempb,m=0,b=0;
map<float,float> info;
cin >> n >> type;
double time = n;
while(time--){
cin >> tempa >> tempb;
info[tempa] = tempb;
}
float temp1 = 0,temp2 = 0,temp3 =0,temp4 =0;
for(auto i = info.begin() ; i!= info.end() ; i++){
temp1+= i->first*i->second;//keep xy
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp2+= i->first;//keep x
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp3+= i->second;// keep y
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp4+= pow(i->first,2);//keep xpow2
}
m = ((n*temp1)-(temp2*temp3))/((n*temp4)-pow(temp2,2));
b = (temp3-m*temp2)/n;
if(type=="mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else if(type=="func"){
if(m==0&&b==0){
cout << "y = 0" << endl;
}else if(m==0&b!=0){
if(b<=0){
b = abs(b);
cout << "y = - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = " << round(b*1e3)/1e3 << endl;
}
}else if(m!=0&&b==0){
if(m==1){
cout << "y = x" << endl;
}else if(m==-1){
cout << "y = -x" << endl;
}else{
cout << "y = " << round(m*1e3)/1e3 << 'x' << endl;
}
}else if(m!=0&&b!=0){
if(m==1){
if(b<=0){
b = abs(b);
cout << "y = x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==-1){
if(b<=0){
b = abs(b);
cout << "y = -x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}
}else{
if(b<=0){
b = abs(b);
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3 << endl;
}
}
}
}
} | # 0908, 2024-11-02 12:07:23, PPPPPPPPPPPPPPPP-PPPP--- (83%)
#include<bits/stdc++.h>
using namespace std;
int main(){
string type;
long n;
double tempa,tempb,m=0,b=0;
map<double,double> info;
cin >> n >> type;
double time = n;
while(time--){
cin >> tempa >> tempb;
info[tempa] = tempb;
}
double temp1 = 0,temp2 = 0,temp3 =0,temp4 =0;
for(auto i = info.begin() ; i!= info.end() ; i++){
temp1+= i->first*i->second;//keep xy
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp2+= i->first;//keep x
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp3+= i->second;// keep y
}
for(auto i = info.begin() ; i!= info.end() ; i++){
temp4+= pow(i->first,2);//keep xpow2
}
m = ((n*temp1)-(temp2*temp3))/((n*temp4)-pow(temp2,2));
b = (temp3-m*temp2)/n;
if(type=="mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else if(type=="func"){
if(m==0&&b==0){
cout << "y = 0" << endl;
}else if(m==0&b!=0){
if(b<=0){
b = abs(b);
cout << "y = - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = " << round(b*1e3)/1e3 << endl;
}
}else if(m!=0&&b==0){
if(m==1){
cout << "y = x" << endl;
}else if(m==-1){
cout << "y = -x" << endl;
}else{
cout << "y = " << round(m*1e3)/1e3 << 'x' << endl;
}
}else if(m!=0&&b!=0){
if(m==1){
if(b<=0){
b = abs(b);
cout << "y = x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = x + " << round(b*1e3)/1e3 << endl;
}
}else if(m==-1){
if(b<=0){
b = abs(b);
cout << "y = -x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = -x + " << round(b*1e3)/1e3 << endl;
}
}else{
if(b<=0){
b = abs(b);
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3 << endl;
}else{
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3 << endl;
}
}
}
}
} |
# 0909, 2024-11-02 13:28:32, ------------------------ (0%)
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
float n;
string s;
double x,y;
cin>>n>>s;
vector<double> X;
vector<double> Y;
for(int i=0;i<n;i++){
cin>>x>>y;
X.push_back(x);
Y.push_back(y);
}
float sumby=0;
float sumbx=0;
for(int i=1;i<=n;i++){
sumby+=Y[i-1];
}
for(int i=1;i<=n;i++){
sumbx+=X[i-1];
}
//m
float m=0;
float sumxy=0;
for(int i=0;i<n;i++){
sumxy+=X[i]*Y[i];
}
float sumxx=0;
for(int i=0;i<n;i++){
sumxx+=X[i]*X[i];
}
m=((n*sumxy)-((sumbx)*(sumby)))/((n*sumxx)-((sumbx)*(sumbx)));
//b
float b=0;
b=(sumby-sumbx)/n;
cout<<m<<" "<<b<<endl;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3<<endl;
}else if(s=="func"){
if(m==0&&b==0){
cout<<"y = 0";
}
if(m==0){
cout<<"y =";
}else if(m==1){
cout<<"y = "<<"x";
}else if(m==-1){
cout<<"y = "<<"-x";
}else{
cout<<"y = "<<m<<"x";
}
if(b==0){
}else if(b>0){
cout<<" + "<<b;
}else if(b<0){
cout<<" - "<<b;
}
}
} | # 0910, 2024-11-02 13:29:12, ------P-----------P----- (8%)
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
float n;
string s;
double x,y;
cin>>n>>s;
vector<double> X;
vector<double> Y;
for(int i=0;i<n;i++){
cin>>x>>y;
X.push_back(x);
Y.push_back(y);
}
float sumby=0;
float sumbx=0;
for(int i=1;i<=n;i++){
sumby+=Y[i-1];
}
for(int i=1;i<=n;i++){
sumbx+=X[i-1];
}
//m
float m=0;
float sumxy=0;
for(int i=0;i<n;i++){
sumxy+=X[i]*Y[i];
}
float sumxx=0;
for(int i=0;i<n;i++){
sumxx+=X[i]*X[i];
}
m=((n*sumxy)-((sumbx)*(sumby)))/((n*sumxx)-((sumbx)*(sumbx)));
//b
float b=0;
b=(sumby-sumbx)/n;
//cout<<m<<" "<<b<<endl;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3<<endl;
}else if(s=="func"){
if(m==0&&b==0){
cout<<"y = 0";
}
if(m==0){
cout<<"y =";
}else if(m==1){
cout<<"y = "<<"x";
}else if(m==-1){
cout<<"y = "<<"-x";
}else{
cout<<"y = "<<m<<"x";
}
if(b==0){
}else if(b>0){
cout<<" + "<<b;
}else if(b<0){
cout<<" - "<<b;
}
}
} | # 0911, 2024-11-02 13:30:19, ------P-----------P----- (8%)
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
float n;
string s;
double x,y;
cin>>n>>s;
vector<double> X;
vector<double> Y;
for(int i=0;i<n;i++){
cin>>x>>y;
X.push_back(x);
Y.push_back(y);
}
float sumby=0;
float sumbx=0;
for(int i=1;i<=n;i++){
sumby+=Y[i-1];
}
for(int i=1;i<=n;i++){
sumbx+=X[i-1];
}
//m
float m=0;
float sumxy=0;
for(int i=0;i<n;i++){
sumxy+=X[i]*Y[i];
}
float sumxx=0;
for(int i=0;i<n;i++){
sumxx+=X[i]*X[i];
}
m=((n*sumxy)-((sumbx)*(sumby)))/((n*sumxx)-((sumbx)*(sumbx)));
//b
float b=0;
b=(sumby-sumbx)/n;
//cout<<m<<" "<<b<<endl;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3<<endl;
}else if(s=="func"){
if(m==0&&b==0){
cout<<"y = 0";
}
if(m==0){
cout<<"y =";
}else if(m==1){
cout<<"y = "<<"x";
}else if(m==-1){
cout<<"y = "<<"-x";
}else{
cout<<"y = "<<round(m*1e3)/1e3<<"x";
}
if(b==0){
}else if(b>0){
cout<<" + "<<round(b*1e3)/1e3;
}else if(b<0){
cout<<" - "<<round(b*1e3)/1e3;
}
}
} | # 0912, 2024-11-02 13:32:05, ------------------------ (0%)
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
float n;
string s;
double x,y;
cin>>n>>s;
vector<double> X;
vector<double> Y;
for(int i=0;i<n;i++){
cin>>x>>y;
X.push_back(x);
Y.push_back(y);
}
float sumby=0;
float sumbx=0;
for(int i=1;i<=n;i++){
sumby+=Y[i-1];
}
for(int i=1;i<=n;i++){
sumbx+=X[i-1];
}
//m
float m=0;
float sumxy=0;
for(int i=0;i<n;i++){
sumxy+=X[i]*Y[i];
}
float sumxx=0;
for(int i=0;i<n;i++){
sumxx+=X[i]*X[i];
}
m=((n*sumxy)-((sumbx)*(sumby)))/((n*sumxx)-((sumbx)*(sumbx)));
//b
float b=0;
b=(sumby-sumbx)/n;
cout<<m<<" "<<b<<endl;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else if(s=="func"){
if(m==0&&b==0){
cout<<"y = 0";
}
if(m==0){
cout<<"y =";
}else if(m==1){
cout<<"y = "<<"x";
}else if(m==-1){
cout<<"y = "<<"-x";
}else{
cout<<"y = "<<round(m*1e3)/1e3<<"x";
}
if(b==0){
}else if(b>0){
cout<<" + "<<round(b*1e3)/1e3;
}else if(b<0){
cout<<" - "<<round(b*1e3)/1e3;
}
}
} | # 0913, 2024-11-02 13:32:14, ------P-----------P----- (8%)
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
float n;
string s;
double x,y;
cin>>n>>s;
vector<double> X;
vector<double> Y;
for(int i=0;i<n;i++){
cin>>x>>y;
X.push_back(x);
Y.push_back(y);
}
float sumby=0;
float sumbx=0;
for(int i=1;i<=n;i++){
sumby+=Y[i-1];
}
for(int i=1;i<=n;i++){
sumbx+=X[i-1];
}
//m
float m=0;
float sumxy=0;
for(int i=0;i<n;i++){
sumxy+=X[i]*Y[i];
}
float sumxx=0;
for(int i=0;i<n;i++){
sumxx+=X[i]*X[i];
}
m=((n*sumxy)-((sumbx)*(sumby)))/((n*sumxx)-((sumbx)*(sumbx)));
//b
float b=0;
b=(sumby-sumbx)/n;
//cout<<m<<" "<<b<<endl;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else if(s=="func"){
if(m==0&&b==0){
cout<<"y = 0";
}
if(m==0){
cout<<"y =";
}else if(m==1){
cout<<"y = "<<"x";
}else if(m==-1){
cout<<"y = "<<"-x";
}else{
cout<<"y = "<<round(m*1e3)/1e3<<"x";
}
if(b==0){
}else if(b>0){
cout<<" + "<<round(b*1e3)/1e3;
}else if(b<0){
cout<<" - "<<round(b*1e3)/1e3;
}
}
} | # 0914, 2024-11-02 13:40:45, ------------------------ (0%)
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
float n;
string s;
double x,y;
float A,B;
cin>>n>>s;
vector<float> X;
vector<float> Y;
for(int i=0;i<n;i++){
cin>>x>>y;
A=x;
B=y;
X.push_back(A);
Y.push_back(B);
}
float sumby=0;
float sumbx=0;
for(int i=1;i<=n;i++){
sumby+=Y[i-1];
}
for(int i=1;i<=n;i++){
sumbx+=X[i-1];
}
//m
float m=0;
float sumxy=0;
for(int i=0;i<n;i++){
sumxy+=X[i]*Y[i];
}
float sumxx=0;
for(int i=0;i<n;i++){
sumxx+=X[i]*X[i];
}
m=((n*sumxy)-((sumbx)*(sumby)))/((n*sumxx)-((sumbx)*(sumbx)));
//b
float b=0;
b=(sumby-(m*sumbx))/n;
cout<<m<<" "<<b<<endl;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else if(s=="func"){
if(m==0&&b==0){
cout<<"y = 0";
}
if(m==0){
cout<<"y =";
}else if(m==1){
cout<<"y = "<<"x";
}else if(m==-1){
cout<<"y = "<<"-x";
}else{
cout<<"y = "<<round(m*1e3)/1e3<<"x";
}
if(b==0){
}else if(b>0){
cout<<" + "<<round(b*1e3)/1e3;
}else if(b<0){
cout<<" - "<<round(((-1)*b)*1e3)/1e3;
}
}
} | # 0915, 2024-11-02 13:40:54, PPPPPPPPPPPPPPP---PP---- (70%)
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
float n;
string s;
double x,y;
float A,B;
cin>>n>>s;
vector<float> X;
vector<float> Y;
for(int i=0;i<n;i++){
cin>>x>>y;
A=x;
B=y;
X.push_back(A);
Y.push_back(B);
}
float sumby=0;
float sumbx=0;
for(int i=1;i<=n;i++){
sumby+=Y[i-1];
}
for(int i=1;i<=n;i++){
sumbx+=X[i-1];
}
//m
float m=0;
float sumxy=0;
for(int i=0;i<n;i++){
sumxy+=X[i]*Y[i];
}
float sumxx=0;
for(int i=0;i<n;i++){
sumxx+=X[i]*X[i];
}
m=((n*sumxy)-((sumbx)*(sumby)))/((n*sumxx)-((sumbx)*(sumbx)));
//b
float b=0;
b=(sumby-(m*sumbx))/n;
//cout<<m<<" "<<b<<endl;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else if(s=="func"){
if(m==0&&b==0){
cout<<"y = 0";
}
if(m==0){
cout<<"y =";
}else if(m==1){
cout<<"y = "<<"x";
}else if(m==-1){
cout<<"y = "<<"-x";
}else{
cout<<"y = "<<round(m*1e3)/1e3<<"x";
}
if(b==0){
}else if(b>0){
cout<<" + "<<round(b*1e3)/1e3;
}else if(b<0){
cout<<" - "<<round(((-1)*b)*1e3)/1e3;
}
}
} | # 0916, 2024-11-02 13:47:19, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
float n;
string s;
double x,y;
float A,B;
cin>>n>>s;
vector<float> X;
vector<float> Y;
for(int i=0;i<n;i++){
cin>>x>>y;
A=x;
B=y;
X.push_back(A);
Y.push_back(B);
}
float sumby=0;
float sumbx=0;
for(int i=1;i<=n;i++){
sumby+=Y[i-1];
}
for(int i=1;i<=n;i++){
sumbx+=X[i-1];
}
//m
float m=0;
float sumxy=0;
for(int i=0;i<n;i++){
sumxy+=X[i]*Y[i];
}
float sumxx=0;
for(int i=0;i<n;i++){
sumxx+=X[i]*X[i];
}
m=((n*sumxy)-((sumbx)*(sumby)))/((n*sumxx)-((sumbx)*(sumbx)));
//b
float b=0;
b=(sumby-(m*sumbx))/n;
//cout<<m<<" "<<b<<endl;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else if(s=="func"){
if(m==0&&b==0){
cout<<"y = 0";
}else if(m==0&& b!=0){
cout<<"y = "<<round(b*1e3)/1e3;
}else{
if(m==0){
cout<<"y =";
}else if(m==1){
cout<<"y = "<<"x";
}else if(m==-1){
cout<<"y = "<<"-x";
}else{
cout<<"y = "<<round(m*1e3)/1e3<<"x";
}
if(b==0){
}else if(b>0){
cout<<" + "<<round(b*1e3)/1e3;
}else if(b<0){
cout<<" - "<<round(((-1)*b)*1e3)/1e3;
}
}
}
} | # 0917, 2024-11-02 13:50:07, PPPPPPPPPPPPPPPP-----P-- (70%)
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
float n;
string s;
float x,y;
float A,B;
cin>>n>>s;
vector<float> X;
vector<float> Y;
for(int i=0;i<n;i++){
cin>>x>>y;
A=x;
B=y;
X.push_back(x);
Y.push_back(y);
}
float sumby=0;
float sumbx=0;
for(int i=1;i<=n;i++){
sumby+=Y[i-1];
}
for(int i=1;i<=n;i++){
sumbx+=X[i-1];
}
//m
float m=0;
float sumxy=0;
for(int i=0;i<n;i++){
sumxy+=X[i]*Y[i];
}
float sumxx=0;
for(int i=0;i<n;i++){
sumxx+=X[i]*X[i];
}
m=((n*sumxy)-((sumbx)*(sumby)))/((n*sumxx)-((sumbx)*(sumbx)));
//b
float b=0;
b=(sumby-(m*sumbx))/n;
//cout<<m<<" "<<b<<endl;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else if(s=="func"){
if(m==0&&b==0){
cout<<"y = 0";
}else if(m==0&& b!=0){
cout<<"y = "<<round(b*1e3)/1e3;
}else{
if(m==0){
cout<<"y =";
}else if(m==1){
cout<<"y = "<<"x";
}else if(m==-1){
cout<<"y = "<<"-x";
}else{
cout<<"y = "<<round(m*1e3)/1e3<<"x";
}
if(b==0){
cout<<" "<<round(b*1e3)/1e3;
}else if(b>0){
cout<<" + "<<round(b*1e3)/1e3;
}else if(b<0){
cout<<" - "<<round(((-1)*b)*1e3)/1e3;
}
}
}
} | # 0918, 2024-11-02 13:50:57, PPPPPPPPPPPPPPPP-----P-- (70%)
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
float n;
string s;
double x,y;
float A,B;
cin>>n>>s;
vector<float> X;
vector<float> Y;
for(int i=0;i<n;i++){
cin>>x>>y;
A=x;
B=y;
X.push_back(A);
Y.push_back(B);
}
float sumby=0;
float sumbx=0;
for(int i=1;i<=n;i++){
sumby+=Y[i-1];
}
for(int i=1;i<=n;i++){
sumbx+=X[i-1];
}
//m
float m=0;
float sumxy=0;
for(int i=0;i<n;i++){
sumxy+=X[i]*Y[i];
}
float sumxx=0;
for(int i=0;i<n;i++){
sumxx+=X[i]*X[i];
}
m=((n*sumxy)-((sumbx)*(sumby)))/((n*sumxx)-((sumbx)*(sumbx)));
//b
float b=0;
b=(sumby-(m*sumbx))/n;
//cout<<m<<" "<<b<<endl;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else if(s=="func"){
if(m==0&&b==0){
cout<<"y = 0";
}else if(m==0&& b!=0){
cout<<"y = "<<round(b*1e3)/1e3;
}else{
if(m==0){
cout<<"y =";
}else if(m==1){
cout<<"y = "<<"x";
}else if(m==-1){
cout<<"y = "<<"-x";
}else{
cout<<"y = "<<round(m*1e3)/1e3<<"x";
}
if(b==0){
cout<<" "<<round(b*1e3)/1e3;
}else if(b>0){
cout<<" + "<<round(b*1e3)/1e3;
}else if(b<0){
cout<<" - "<<round(((-1)*b)*1e3)/1e3;
}
}
}
} | # 0919, 2024-11-02 13:51:24, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
float n;
string s;
double x,y;
float A,B;
cin>>n>>s;
vector<float> X;
vector<float> Y;
for(int i=0;i<n;i++){
cin>>x>>y;
A=x;
B=y;
X.push_back(A);
Y.push_back(B);
}
float sumby=0;
float sumbx=0;
for(int i=1;i<=n;i++){
sumby+=Y[i-1];
}
for(int i=1;i<=n;i++){
sumbx+=X[i-1];
}
//m
float m=0;
float sumxy=0;
for(int i=0;i<n;i++){
sumxy+=X[i]*Y[i];
}
float sumxx=0;
for(int i=0;i<n;i++){
sumxx+=X[i]*X[i];
}
m=((n*sumxy)-((sumbx)*(sumby)))/((n*sumxx)-((sumbx)*(sumbx)));
//b
float b=0;
b=(sumby-(m*sumbx))/n;
//cout<<m<<" "<<b<<endl;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else if(s=="func"){
if(m==0&&b==0){
cout<<"y = 0";
}else if(m==0&& b!=0){
cout<<"y = "<<round(b*1e3)/1e3;
}else{
if(m==0){
cout<<"y =";
}else if(m==1){
cout<<"y = "<<"x";
}else if(m==-1){
cout<<"y = "<<"-x";
}else{
cout<<"y = "<<round(m*1e3)/1e3<<"x";
}
if(b==0){
}else if(b>0){
cout<<" + "<<round(b*1e3)/1e3;
}else if(b<0){
cout<<" - "<<round(((-1)*b)*1e3)/1e3;
}
}
}
} | # 0920, 2024-11-02 13:51:47, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
float n;
string s;
float x,y;
float A,B;
cin>>n>>s;
vector<float> X;
vector<float> Y;
for(int i=0;i<n;i++){
cin>>x>>y;
A=x;
B=y;
X.push_back(x);
Y.push_back(y);
}
float sumby=0;
float sumbx=0;
for(int i=1;i<=n;i++){
sumby+=Y[i-1];
}
for(int i=1;i<=n;i++){
sumbx+=X[i-1];
}
//m
float m=0;
float sumxy=0;
for(int i=0;i<n;i++){
sumxy+=X[i]*Y[i];
}
float sumxx=0;
for(int i=0;i<n;i++){
sumxx+=X[i]*X[i];
}
m=((n*sumxy)-((sumbx)*(sumby)))/((n*sumxx)-((sumbx)*(sumbx)));
//b
float b=0;
b=(sumby-(m*sumbx))/n;
//cout<<m<<" "<<b<<endl;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else if(s=="func"){
if(m==0&&b==0){
cout<<"y = 0";
}else if(m==0&& b!=0){
cout<<"y = "<<round(b*1e3)/1e3;
}else{
if(m==0){
cout<<"y =";
}else if(m==1){
cout<<"y = "<<"x";
}else if(m==-1){
cout<<"y = "<<"-x";
}else{
cout<<"y = "<<round(m*1e3)/1e3<<"x";
}
if(b==0){
}else if(b>0){
cout<<" + "<<round(b*1e3)/1e3;
}else if(b<0){
cout<<" - "<<round(((-1)*b)*1e3)/1e3;
}
}
}
} | # 0921, 2024-11-02 14:07:16, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
float n;
string s;
double x,y;
float A,B;
cin>>n>>s;
vector<float> X;
vector<float> Y;
for(int i=0;i<n;i++){
cin>>x>>y;
A=x;
B=y;
X.push_back(A);
Y.push_back(B);
}
float sumby=0;
float sumbx=0;
for(int i=1;i<=n;i++){
sumby+=Y[i-1];
}
for(int i=1;i<=n;i++){
sumbx+=X[i-1];
}
//m
float m=0;
float sumxy=0;
for(int i=0;i<n;i++){
sumxy+=X[i]*Y[i];
}
float sumxx=0;
for(int i=0;i<n;i++){
sumxx+=X[i]*X[i];
}
m=((n*sumxy)-((sumbx)*(sumby)))/((n*sumxx)-((sumbx)*(sumbx)));
//b
float b=0;
b=(sumby-(m*sumbx))/n;
//cout<<m<<" "<<b<<endl;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else if(s=="func"){
if((round(m*1e3)/1e3==0)&&b==0){
cout<<"y = 0";
}else if((round(m*1e3)/1e3)==0&& b!=0){
cout<<"y = "<<round(b*1e3)/1e3;
}else{
if(m==0){
cout<<"y =";
}else if(m==1){
cout<<"y = "<<"x";
}else if(m==-1){
cout<<"y = "<<"-x";
}else{
cout<<"y = "<<round(m*1e3)/1e3<<"x";
}
if(b==0){
}else if(b>0){
cout<<" + "<<round(b*1e3)/1e3;
}else if(b<0){
cout<<" - "<<round(((-1)*b)*1e3)/1e3;
}
}
}
} | # 0922, 2024-11-02 15:19:49, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
float n;
string s;
double x,y;
float A,B;
cin>>n>>s;
vector<float> X;
vector<float> Y;
for(int i=0;i<n;i++){
cin>>x>>y;
A=x;
B=y;
X.push_back(A);
Y.push_back(B);
}
float sumby=0;
float sumbx=0;
for(int i=0;i<n;i++){
sumby+=Y[i];
}
for(int i=0;i<n;i++){
sumbx+=X[i];
}
//m
float m=0;
float sumxy=0;
for(int i=0;i<n;i++){
sumxy+=X[i]*Y[i];
}
float sumxx=0;
for(int i=0;i<n;i++){
sumxx+=X[i]*X[i];
}
m=((n*sumxy)-((sumbx)*(sumby)))/((n*sumxx)-((sumbx)*(sumbx)));
//b
float b=0;
b=(sumby-(m*sumbx))/n;
//cout<<m<<" "<<b<<endl;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else if(s=="func"){
if((round(m*1e3)/1e3==0)&&b==0){
cout<<"y = 0";
}else if((round(m*1e3)/1e3)==0&& b!=0){
cout<<"y = "<<round(b*1e3)/1e3;
}else{
if(m==0){
cout<<"y =";
}else if(m==1){
cout<<"y = "<<"x";
}else if(m==-1){
cout<<"y = "<<"-x";
}else{
cout<<"y = "<<round(m*1e3)/1e3<<"x";
}
if(b==0){
}else if(b>0){
cout<<" + "<<round(b*1e3)/1e3;
}else if(b<0){
cout<<" - "<<round(((-1)*b)*1e3)/1e3;
}
}
}
} | # 0923, 2024-11-02 15:20:36, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
float n;
string s;
double x,y;
float A,B;
cin>>n>>s;
vector<double> X;
vector<double> Y;
for(int i=0;i<n;i++){
cin>>x>>y;
A=x;
B=y;
X.push_back(x);
Y.push_back(y);
}
float sumby=0;
float sumbx=0;
for(int i=0;i<n;i++){
sumby+=Y[i];
}
for(int i=0;i<n;i++){
sumbx+=X[i];
}
//m
float m=0;
float sumxy=0;
for(int i=0;i<n;i++){
sumxy+=X[i]*Y[i];
}
float sumxx=0;
for(int i=0;i<n;i++){
sumxx+=X[i]*X[i];
}
m=((n*sumxy)-((sumbx)*(sumby)))/((n*sumxx)-((sumbx)*(sumbx)));
//b
float b=0;
b=(sumby-(m*sumbx))/n;
//cout<<m<<" "<<b<<endl;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else if(s=="func"){
if((round(m*1e3)/1e3==0)&&b==0){
cout<<"y = 0";
}else if((round(m*1e3)/1e3)==0&& b!=0){
cout<<"y = "<<round(b*1e3)/1e3;
}else{
if(m==0){
cout<<"y =";
}else if(m==1){
cout<<"y = "<<"x";
}else if(m==-1){
cout<<"y = "<<"-x";
}else{
cout<<"y = "<<round(m*1e3)/1e3<<"x";
}
if(b==0){
}else if(b>0){
cout<<" + "<<round(b*1e3)/1e3;
}else if(b<0){
cout<<" - "<<round(((-1)*b)*1e3)/1e3;
}
}
}
} |
# 0924, 2024-11-02 10:28:54, PPPPPPPPPP-----P-------- (45%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
float x,y;
vector<float> xi;
vector<float> yi;
string indicator;
cin >> N >> indicator;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// find m
float m, mtop1 = 0, mtop2 = 0, mbtm1 = 0, mbtm2;
float mtop2x = 0, mtop2y = 0;
for (int i = 0; i < N; i++)
{
mtop1 += (xi[i] * yi[i]);
mtop2x += xi[i];
mtop2y += yi[i];
mbtm1 += pow(xi[i],2);
}
mtop1 = N * (mtop1);
mtop2 = mtop2x * mtop2y;
mbtm1 = N * (mbtm1);
mbtm2 = mtop2x * mtop2x;
m = (mtop1 - mtop2) / (mbtm1 - mbtm2);
//find b
float b;
b = ((mtop2y) - (m * (mtop2x))) / N;
if(indicator == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
} else {
if(m == 0 && b == 0){
cout << "y = 0";
} else if (m == 1){
cout << "y = x + " << b;
} else if (m == -1){
cout << "y = -x + " << b;
} else {
cout << "y = " << m << "x + " << b;
}
}
} | # 0925, 2024-11-02 10:32:59, PPPPPPPPPPPPPPPP-------- (66%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
float x,y;
vector<float> xi;
vector<float> yi;
string indicator;
cin >> N >> indicator;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// find m
float m, mtop1 = 0, mtop2 = 0, mbtm1 = 0, mbtm2;
float mtop2x = 0, mtop2y = 0;
for (int i = 0; i < N; i++)
{
mtop1 += (xi[i] * yi[i]);
mtop2x += xi[i];
mtop2y += yi[i];
mbtm1 += pow(xi[i],2);
}
mtop1 = N * (mtop1);
mtop2 = mtop2x * mtop2y;
mbtm1 = N * (mbtm1);
mbtm2 = mtop2x * mtop2x;
m = (mtop1 - mtop2) / (mbtm1 - mbtm2);
//find b
float b;
b = ((mtop2y) - (m * (mtop2x))) / N;
if(indicator == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
} else {
if(m == 0 && b == 0){
cout << "y = 0";
} else if (m == 1){
cout << "y = x + " << b;
} else if (m == -1){
cout << "y = -x + " << b;
} else if (b > 0){
cout << "y = " << round(m * 1000) / 1000 << "x + " << round(b * 1000) / 1000;
} else {
cout << "y = " << round(m * 1000) / 1000 << "x - " << abs( round(b * 1000) / 1000 );
}
}
} | # 0926, 2024-11-02 10:34:42, PPPPPPPPPPPPPPPP-------- (66%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
float x,y;
vector<float> xi;
vector<float> yi;
string indicator;
cin >> N >> indicator;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// find m
float m, mtop1 = 0, mtop2 = 0, mbtm1 = 0, mbtm2;
float mtop2x = 0, mtop2y = 0;
for (int i = 0; i < N; i++)
{
mtop1 += (xi[i] * yi[i]);
mtop2x += xi[i];
mtop2y += yi[i];
mbtm1 += pow(xi[i],2);
}
mtop1 = N * (mtop1);
mtop2 = mtop2x * mtop2y;
mbtm1 = N * (mbtm1);
mbtm2 = mtop2x * mtop2x;
m = (mtop1 - mtop2) / (mbtm1 - mbtm2);
//find b
float b;
b = ((mtop2y) - (m * (mtop2x))) / N;
if(indicator == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
} else {
if(m == 0 && b == 0){
cout << "y = 0";
} else if (m == 1){
cout << "y = x + " << round(b * 1000) / 1000;
} else if (m == 1 && b < 0){
cout << "y = x - " << abs( round(b * 1000) / 1000 );
} else if (m == -1){
cout << "y = -x + " << round(b * 1000) / 1000;
} else if (m == -1 && b < 0){
cout << "y = -x - " << abs( round(b * 1000) / 1000 );
} else if (b > 0){
cout << "y = " << round(m * 1000) / 1000 << "x + " << round(b * 1000) / 1000;
} else {
cout << "y = " << round(m * 1000) / 1000 << "x - " << abs( round(b * 1000) / 1000 );
}
}
} | # 0927, 2024-11-02 10:43:30, PPPPPPPPPPPPPPPP-------- (66%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
float x,y;
vector<float> xi;
vector<float> yi;
string indicator;
cin >> N >> indicator;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// find m
float m = 0, mtop1 = 0, mtop2 = 0, mbtm1 = 0, mbtm2 = 0;
float mtop2x = 0, mtop2y = 0;
for (int i = 0; i < N; i++)
{
mtop1 += (xi[i] * yi[i]);
mtop2x += xi[i];
mtop2y += yi[i];
mbtm1 += pow(xi[i],2);
}
mtop1 = N * (mtop1);
mtop2 = mtop2x * mtop2y;
mbtm1 = N * (mbtm1);
mbtm2 = mtop2x * mtop2x;
m = (mtop1 - mtop2) / (mbtm1 - mbtm2);
//find b
float b = 0;
b = ((mtop2y) - (m * (mtop2x))) / N;
if(indicator == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
} else {
if(m == 0 && b == 0){
cout << "y = 0";
} else if (m == 1){
cout << "y = x + " << round(b * 1000) / 1000;
} else if (m == 1 && b < 0){
cout << "y = x - " << abs( round(b * 1000) / 1000 );
} else if (m == -1){
cout << "y = -x + " << round(b * 1000) / 1000;
} else if (m == -1 && b < 0){
cout << "y = -x - " << abs( round(b * 1000) / 1000 );
} else if (b > 0){
cout << "y = " << round(m * 1000) / 1000 << "x + " << round(b * 1000) / 1000;
} else {
cout << "y = " << round(m * 1000) / 1000 << "x - " << abs( round(b * 1000) / 1000 );
}
}
} | # 0928, 2024-11-02 11:38:03, PPPPPPPPPPPPPPPP-------- (66%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
float x,y;
vector<float> xi;
vector<float> yi;
string indicator;
cin >> N >> indicator;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// find m
float m = 0, mtop1 = 0, mtop2 = 0, mbtm1 = 0, mbtm2 = 0;
float mtop2x = 0, mtop2y = 0;
for (int i = 0; i < N; i++)
{
mtop1 += (xi[i] * yi[i]);
mtop2x += xi[i];
mtop2y += yi[i];
mbtm1 += pow(xi[i],2);
}
mtop1 = N * (mtop1);
mtop2 = mtop2x * mtop2y;
mbtm1 = N * (mbtm1);
mbtm2 = mtop2x * mtop2x;
m = (mtop1 - mtop2) / (mbtm1 - mbtm2);
//find b
float b = 0;
b = ((mtop2y) - (m * (mtop2x))) / N;
if(indicator == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
} else {
if(m == 0 && b == 0){
cout << "y = 0";
} else if (m == 1){
if(b < 0){
cout << "y = x - " << abs( round(b * 1000) / 1000 );
} else {
cout << "y = x + " << round(b * 1000) / 1000;
}
} else if (m == -1){
if(b < 0){
cout << "y = -x - " << abs( round(b * 1000) / 1000 );
} else {
cout << "y = -x + " << round(b * 1000) / 1000;
}
} else if (b > 0){
cout << "y = " << round(m * 1000) / 1000 << "x + " << round(b * 1000) / 1000;
} else {
cout << "y = " << round(m * 1000) / 1000 << "x - " << abs( round(b * 1000) / 1000 );
}
}
} | # 0929, 2024-11-02 11:39:52, PPPPPPPPPPPPPPPP-------- (66%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
float x,y;
vector<float> xi;
vector<float> yi;
string indicator;
cin >> N >> indicator;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// find m
float m = 0, mtop1 = 0, mtop2 = 0, mbtm1 = 0, mbtm2 = 0;
float mtop2x = 0, mtop2y = 0;
for (int i = 0; i < N; i++)
{
mtop1 += (xi[i] * yi[i]);
mtop2x += xi[i];
mtop2y += yi[i];
mbtm1 += pow(xi[i],2);
}
mtop1 = N * (mtop1);
mtop2 = mtop2x * mtop2y;
mbtm1 = N * (mbtm1);
mbtm2 = mtop2x * mtop2x;
m = (mtop1 - mtop2) / (mbtm1 - mbtm2);
//find b
float b = 0;
b = ((mtop2y) - (m * (mtop2x))) / N;
if(indicator == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
} else {
if(m == 0 && b == 0){
cout << "y = 0";
} else if (m == 1){
if(b < 0){
cout << "y = x - " << abs( round(b * 1000) / 1000 );
} else {
cout << "y = x + " << round(b * 1000) / 1000;
}
} else if (m == -1){
if(b < 0){
cout << "y = -x - " << abs( round(b * 1000) / 1000 );
} else {
cout << "y = -x + " << round(b * 1000) / 1000;
}
} else if (b > 0){
cout << "y = " << round(m * 1000) / 1000 << "x + " << round(b * 1000) / 1000;
} else {
cout << "y = " << round(m * 1000) / 1000 << "x - " << abs( round(b * 1000) / 1000 );
}
}
} | # 0930, 2024-11-02 11:57:14, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
float x,y;
vector<float> xi;
vector<float> yi;
string indicator;
cin >> N >> indicator;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// find m
float m = 0, mtop1 = 0, mtop2 = 0, mbtm1 = 0, mbtm2 = 0;
float mtop2x = 0, mtop2y = 0;
for (int i = 0; i < N; i++)
{
mtop1 += (xi[i] * yi[i]);
mtop2x += xi[i];
mtop2y += yi[i];
mbtm1 += pow(xi[i],2);
}
mtop1 = N * (mtop1);
mtop2 = mtop2x * mtop2y;
mbtm1 = N * (mbtm1);
mbtm2 = mtop2x * mtop2x;
m = (mtop1 - mtop2) / (mbtm1 - mbtm2);
//find b
float b = 0;
b = ((mtop2y) - (m * (mtop2x))) / N;
if(indicator == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
} else {
if(m == 0 && b == 0){
cout << "y = 0";
} else if (m == 1){
if(b < 0){
cout << "y = x - " << abs( round(b * 1000) / 1000 );
} else if (b == 0){
cout << "y = x";
} else {
cout << "y = x + " << round(b * 1000) / 1000;
}
} else if (m == -1){
if(b < 0){
cout << "y = -x - " << abs( round(b * 1000) / 1000 );
} else if (b == 0){
cout << "y = -x";
} else {
cout << "y = -x + " << round(b * 1000) / 1000;
}
} else if (b > 0){
if(round(m * 1) / 1 == 0){
cout << "y = " << round(b * 1000) / 1000;
} else {
cout << "y = " << round(m * 1000) / 1000 << "x + " << round(b * 1000) / 1000;
}
} else if (b < 0){
if (round(m * 1) / 1 == 0){
cout << "y = " << round(b * 1000) / 1000;
} else {
cout << "y = " << round(m * 1000) / 1000 << "x - " << abs( round(b * 1000) / 1000 );
}
} else if (b == 0){
cout << "y = " << round(m * 1000) / 1000 << "x";
} else {
cout << "y = " << round(b * 1000) / 1000;
}
}
} | # 0931, 2024-11-02 11:58:46, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
float x,y;
vector<float> xi;
vector<float> yi;
string indicator;
cin >> N >> indicator;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// find m
float m = 0, mtop1 = 0, mtop2 = 0, mbtm1 = 0, mbtm2 = 0;
float mtop2x = 0, mtop2y = 0;
for (int i = 0; i < N; i++)
{
mtop1 += (xi[i] * yi[i]);
mtop2x += xi[i];
mtop2y += yi[i];
mbtm1 += pow(xi[i],2);
}
mtop1 = N * (mtop1);
mtop2 = mtop2x * mtop2y;
mbtm1 = N * (mbtm1);
mbtm2 = mtop2x * mtop2x;
m = (mtop1 - mtop2) / (mbtm1 - mbtm2);
//find b
float b = 0;
b = ((mtop2y) - (m * (mtop2x))) / N;
if(indicator == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
} else {
if(round(m * 1) / 1 == 0 && b == 0){
cout << "y = 0";
} else if (m == 1){
if(b < 0){
cout << "y = x - " << abs( round(b * 1000) / 1000 );
} else if (b == 0){
cout << "y = x";
} else {
cout << "y = x + " << round(b * 1000) / 1000;
}
} else if (m == -1){
if(b < 0){
cout << "y = -x - " << abs( round(b * 1000) / 1000 );
} else if (b == 0){
cout << "y = -x";
} else {
cout << "y = -x + " << round(b * 1000) / 1000;
}
} else if (b > 0){
if(round(m * 1) / 1 == 0){
cout << "y = " << round(b * 1000) / 1000;
} else {
cout << "y = " << round(m * 1000) / 1000 << "x + " << round(b * 1000) / 1000;
}
} else if (b < 0){
if (round(m * 1) / 1 == 0){
cout << "y = " << round(b * 1000) / 1000;
} else {
cout << "y = " << round(m * 1000) / 1000 << "x - " << abs( round(b * 1000) / 1000 );
}
} else if (round(b * 1) / 1 == 0){
cout << "y = " << round(m * 1000) / 1000 << "x";
} else {
cout << "y = " << round(b * 1000) / 1000;
}
}
} | # 0932, 2024-11-02 11:59:53, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
float x,y;
vector<float> xi;
vector<float> yi;
string indicator;
cin >> N >> indicator;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// find m
float m = 0, mtop1 = 0, mtop2 = 0, mbtm1 = 0, mbtm2 = 0;
float mtop2x = 0, mtop2y = 0;
for (int i = 0; i < N; i++)
{
mtop1 += (xi[i] * yi[i]);
mtop2x += xi[i];
mtop2y += yi[i];
mbtm1 += pow(xi[i],2);
}
mtop1 = N * (mtop1);
mtop2 = mtop2x * mtop2y;
mbtm1 = N * (mbtm1);
mbtm2 = mtop2x * mtop2x;
m = (mtop1 - mtop2) / (mbtm1 - mbtm2);
//find b
float b = 0;
b = ((mtop2y) - (m * (mtop2x))) / N;
if(indicator == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
} else {
if(round(m * 1) / 1 == 0 && round(b * 1) / 1 == 0){
cout << "y = 0";
} else if (m == 1){
if(b < 0){
cout << "y = x - " << abs( round(b * 1000) / 1000 );
} else if (b == 0){
cout << "y = x";
} else {
cout << "y = x + " << round(b * 1000) / 1000;
}
} else if (m == -1){
if(b < 0){
cout << "y = -x - " << abs( round(b * 1000) / 1000 );
} else if (b == 0){
cout << "y = -x";
} else {
cout << "y = -x + " << round(b * 1000) / 1000;
}
} else if (b > 0){
if(round(m * 1) / 1 == 0){
cout << "y = " << round(b * 1000) / 1000;
} else {
cout << "y = " << round(m * 1000) / 1000 << "x + " << round(b * 1000) / 1000;
}
} else if (b < 0){
if (round(m * 1) / 1 == 0){
cout << "y = " << round(b * 1000) / 1000;
} else {
cout << "y = " << round(m * 1000) / 1000 << "x - " << abs( round(b * 1000) / 1000 );
}
} else if (round(b * 1) / 1 == 0){
cout << "y = " << round(m * 1000) / 1000 << "x";
} else {
cout << "y = " << round(b * 1000) / 1000;
}
}
} | # 0933, 2024-11-02 12:00:39, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
float x,y;
vector<float> xi;
vector<float> yi;
string indicator;
cin >> N >> indicator;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// find m
float m = 0, mtop1 = 0, mtop2 = 0, mbtm1 = 0, mbtm2 = 0;
float mtop2x = 0, mtop2y = 0;
for (int i = 0; i < N; i++)
{
mtop1 += (xi[i] * yi[i]);
mtop2x += xi[i];
mtop2y += yi[i];
mbtm1 += pow(xi[i],2);
}
mtop1 = N * (mtop1);
mtop2 = mtop2x * mtop2y;
mbtm1 = N * (mbtm1);
mbtm2 = mtop2x * mtop2x;
m = (mtop1 - mtop2) / (mbtm1 - mbtm2);
//find b
float b = 0;
b = ((mtop2y) - (m * (mtop2x))) / N;
if(indicator == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
} else {
if(round(m * 1) / 1 == 0 && round(b * 1) / 1 == 0){
cout << "y = 0";
} else if (m == 1){
if(b < 0){
cout << "y = x - " << abs( round(b * 1000) / 1000 );
} else if (round(b * 1) / 1 == 0){
cout << "y = x";
} else {
cout << "y = x + " << round(b * 1000) / 1000;
}
} else if (m == -1){
if(b < 0){
cout << "y = -x - " << abs( round(b * 1000) / 1000 );
} else if (round(b * 1) / 1 == 0){
cout << "y = -x";
} else {
cout << "y = -x + " << round(b * 1000) / 1000;
}
} else if (b > 0){
if(round(m * 1) / 1 == 0){
cout << "y = " << round(b * 1000) / 1000;
} else {
cout << "y = " << round(m * 1000) / 1000 << "x + " << round(b * 1000) / 1000;
}
} else if (b < 0){
if (round(m * 1) / 1 == 0){
cout << "y = " << round(b * 1000) / 1000;
} else {
cout << "y = " << round(m * 1000) / 1000 << "x - " << abs( round(b * 1000) / 1000 );
}
} else if (round(b * 1) / 1 == 0){
cout << "y = " << round(m * 1000) / 1000 << "x";
} else {
cout << "y = " << round(b * 1000) / 1000;
}
}
} | # 0934, 2024-11-02 12:10:24, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
float x,y;
vector<float> xi;
vector<float> yi;
string indicator;
cin >> N >> indicator;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
xi.push_back(x);
yi.push_back(y);
}
// find m
float m = 0, mtop1 = 0, mtop2 = 0, mbtm1 = 0, mbtm2 = 0;
float mtop2x = 0, mtop2y = 0;
for (int i = 0; i < N; i++)
{
mtop1 += (xi[i] * yi[i]);
mtop2x += xi[i];
mtop2y += yi[i];
mbtm1 += pow(xi[i],2);
}
mtop1 = N * (mtop1);
mtop2 = mtop2x * mtop2y;
mbtm1 = N * (mbtm1);
mbtm2 = mtop2x * mtop2x;
m = (mtop1 - mtop2) / (mbtm1 - mbtm2);
//find b
float b = 0;
b = ((mtop2y) - (m * (mtop2x))) / N;
if(indicator == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
} else {
if(round(m * 1) / 1 == 0 && round(b * 1) / 1 == 0){
cout << "y = 0";
} else if (m == 1){
if(b < 0){
cout << "y = x - " << abs( round(b * 1000) / 1000 );
} else if (round(b * 1) / 1 == 0){
cout << "y = x";
} else {
cout << "y = x + " << round(b * 1000) / 1000;
}
} else if (m == -1){
if(b < 0){
cout << "y = -x - " << abs( round(b * 1000) / 1000 );
} else if (round(b * 1) / 1 == 0){
cout << "y = -x";
} else {
cout << "y = -x + " << round(b * 1000) / 1000;
}
} else if (round(m * 1) / 1 == 0){
if(b > 0){
cout << "y = " << round(b * 1000) / 1000;
} else if (b < 0){
cout << "y = " << round(b * 1000) / 1000;
} else {
cout << "y = 0";
}
} else {
if (b > 0){
cout << "y = " << round(m * 1000) / 1000 << "x + " << round(b * 1000) / 1000;
} else if (b < 0){
cout << "y = " << round(m * 1000) / 1000 << "x - " << abs( round(b * 1000) / 1000 );
} else if (b == 0){
cout << "y = " << round(m * 1000) / 1000 << "x";
}
}
}
} |
# 0935, 2024-11-02 13:54:51, ------------------------ (0%)
#include <bits/stdc++.h>
using namespace std;
int d()
{
return 5;
}
int main()
{
int n;
string type;
cin >> n;
cin >> type;
cout << n << " " << type << endl;
vector<float> x, y;
for (int i = 0; i < n; i++)
{
float xx, yy;
cin >> xx >> yy;
x.push_back(xx);
y.push_back(yy);
}
for (int i = 0; i < n; i++)
{
cout << x[i] << " " << y[i] << endl;
}
float m = 0.0, b = 0.0;
float mx = 0.0;
for (int i = 0; i < n; i++)
{
mx += x[i];
}
float my = 0.0;
for (int i = 0; i < n; i++)
{
my += y[i];
}
float mxy = 0.0;
for (int i = 0; i < n; i++)
{
mxy += x[i] * y[i];
}
cout << "mxy " << mxy << " mx " << mx << " my " << my << endl;
float mx2 = 0.0;
for (int i = 0; i < n; i++)
{
mx2 += pow(x[i], 2);
}
m = (n * mxy) - (mx * my);
cout << "Up: " << m << endl;
float md = (n * mx2) - pow(mx, 2);
cout << "Down: " << m << endl;
m = m / md;
b = (my - m * mx) / n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if (type == "func")
{
cout << "Output: " << m << " " << b << endl;
if (m == -1 && b < 0) cout << "y = -x - " << abs(b) << endl;
else if (m == -1 && b == 0) cout << "y = -x" << endl;
else if (m == -1) cout << "y = -x + " << b << endl;
else if (m == 1 && b < 0) cout << "y = x - " << abs(b) << endl;
else if (m == 1 && b == 0) cout << "y = x" << endl;
else if (m == 1) cout << "y = x + " << b << endl;
else if (m == 0 && b == 0) cout << "y = 0" << endl;
else if (m > -1 && m <= 0) cout << "y = " << b << endl;
else if (m > 1 && b < 0) cout << "y = " << m << "x - " << abs(b) << endl;
}
} | # 0936, 2024-11-02 13:55:45, -----------P---PPPPPPPPP (41%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string type;
cin >> n;
cin >> type;
// cout << n << " " << type << endl;
vector<float> x, y;
for (int i = 0; i < n; i++)
{
float xx, yy;
cin >> xx >> yy;
x.push_back(xx);
y.push_back(yy);
}
// for (int i = 0; i < n; i++)
// {
// cout << x[i] << " " << y[i] << endl;
// }
float m = 0.0, b = 0.0;
float mx = 0.0;
for (int i = 0; i < n; i++)
{
mx += x[i];
}
float my = 0.0;
for (int i = 0; i < n; i++)
{
my += y[i];
}
float mxy = 0.0;
for (int i = 0; i < n; i++)
{
mxy += x[i] * y[i];
}
// cout << "mxy " << mxy << " mx " << mx << " my " << my << endl;
float mx2 = 0.0;
for (int i = 0; i < n; i++)
{
mx2 += pow(x[i], 2);
}
m = (n * mxy) - (mx * my);
// cout << "Up: " << m << endl;
float md = (n * mx2) - pow(mx, 2);
// cout << "Down: " << m << endl;
m = m / md;
b = (my - m * mx) / n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if (type == "func")
{
// cout << "Output: " << m << " " << b << endl;
if (m == -1 && b < 0) cout << "y = -x - " << abs(b) << endl;
else if (m == -1 && b == 0) cout << "y = -x" << endl;
else if (m == -1) cout << "y = -x + " << b << endl;
else if (m == 1 && b < 0) cout << "y = x - " << abs(b) << endl;
else if (m == 1 && b == 0) cout << "y = x" << endl;
else if (m == 1) cout << "y = x + " << b << endl;
else if (m == 0 && b == 0) cout << "y = 0" << endl;
else if (m > -1 && m <= 0) cout << "y = " << b << endl;
else if (m > 1 && b < 0) cout << "y = " << m << "x - " << abs(b) << endl;
}
} | # 0937, 2024-11-02 13:56:58, -----------P---PPPPPPPPP (41%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string type;
cin >> n;
cin >> type;
// cout << n << " " << type << endl;
vector<float> x, y;
for (int i = 0; i < n; i++)
{
float xx, yy;
cin >> xx >> yy;
x.push_back(xx);
y.push_back(yy);
}
// for (int i = 0; i < n; i++)
// {
// cout << x[i] << " " << y[i] << endl;
// }
float m = 0.0, b = 0.0;
float mx = 0.0;
for (int i = 0; i < n; i++)
{
mx += x[i];
}
float my = 0.0;
for (int i = 0; i < n; i++)
{
my += y[i];
}
float mxy = 0.0;
for (int i = 0; i < n; i++)
{
mxy += x[i] * y[i];
}
// cout << "mxy " << mxy << " mx " << mx << " my " << my << endl;
float mx2 = 0.0;
for (int i = 0; i < n; i++)
{
mx2 += pow(x[i], 2);
}
m = (n * mxy) - (mx * my);
// cout << "Up: " << m << endl;
float md = (n * mx2) - pow(mx, 2);
// cout << "Down: " << m << endl;
m = m / md;
b = (my - m * mx) / n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if (type == "func")
{
// cout << "Output: " << m << " " << b << endl;
if (m == -1 && b < 0) cout << "y = -x - " << abs(b) << endl;
else if (m == -1 && b == 0) cout << "y = -x" << endl;
else if (m == -1) cout << "y = -x + " << b << endl;
else if (m == 1 && b < 0) cout << "y = x - " << abs(b) << endl;
else if (m == 1 && b == 0) cout << "y = x" << endl; //
else if (m == 1) cout << "y = x + " << b << endl;
else if (m == 0 && b == 0) cout << "y = 0" << endl;
else if (m > -1 && m <= 0) cout << "y = " << b << endl;
else if (m > 1 && b < 0) cout << "y = " << m << "x - " << abs(b) << endl;
else if (m > 1 && b == 0) cout << "y = " << m << "x" << endl;
}
} | # 0938, 2024-11-02 13:58:09, ----------PP---PPPPPPPPP (45%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string type;
cin >> n;
cin >> type;
// cout << n << " " << type << endl;
vector<float> x, y;
for (int i = 0; i < n; i++)
{
float xx, yy;
cin >> xx >> yy;
x.push_back(xx);
y.push_back(yy);
}
// for (int i = 0; i < n; i++)
// {
// cout << x[i] << " " << y[i] << endl;
// }
float m = 0.0, b = 0.0;
float mx = 0.0;
for (int i = 0; i < n; i++)
{
mx += x[i];
}
float my = 0.0;
for (int i = 0; i < n; i++)
{
my += y[i];
}
float mxy = 0.0;
for (int i = 0; i < n; i++)
{
mxy += x[i] * y[i];
}
// cout << "mxy " << mxy << " mx " << mx << " my " << my << endl;
float mx2 = 0.0;
for (int i = 0; i < n; i++)
{
mx2 += pow(x[i], 2);
}
m = (n * mxy) - (mx * my);
// cout << "Up: " << m << endl;
float md = (n * mx2) - pow(mx, 2);
// cout << "Down: " << m << endl;
m = m / md;
b = (my - m * mx) / n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
if (type == "func")
{
// cout << "Output: " << m << " " << b << endl;
if (m == -1 && b < 0) cout << "y = -x - " << abs(b) << endl;
else if (m == -1 && b == 0) cout << "y = -x" << endl;
else if (m == -1) cout << "y = -x + " << b << endl;
else if (m == 1 && b < 0) cout << "y = x - " << abs(b) << endl;
else if (m == 1 && b == 0) cout << "y = x" << endl; //
else if (m == 1) cout << "y = x + " << b << endl;
else if (m == 0 && b == 0) cout << "y = 0" << endl;
else if (m > -1 && m <= 0) cout << "y = " << b << endl;
else if (m > 1 && b < 0) cout << "y = " << m << "x - " << abs(b) << endl;
else if (m > 1 && b > 1) cout << "y = " << m << "x + " << b << endl;
}
} | # 0939, 2024-11-02 14:02:02, ------------------------ (0%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string type;
cin >> n;
cin >> type;
// cout << n << " " << type << endl;
vector<float> x, y;
for (int i = 0; i < n; i++)
{
float xx, yy;
cin >> xx >> yy;
x.push_back(xx);
y.push_back(yy);
}
// for (int i = 0; i < n; i++)
// {
// cout << x[i] << " " << y[i] << endl;
// }
float m = 0.0, b = 0.0;
float mx = 0.0;
for (int i = 0; i < n; i++)
{
mx += x[i];
}
float my = 0.0;
for (int i = 0; i < n; i++)
{
my += y[i];
}
float mxy = 0.0;
for (int i = 0; i < n; i++)
{
mxy += x[i] * y[i];
}
// cout << "mxy " << mxy << " mx " << mx << " my " << my << endl;
float mx2 = 0.0;
for (int i = 0; i < n; i++)
{
mx2 += pow(x[i], 2);
}
m = (n * mxy) - (mx * my);
// cout << "Up: " << m << endl;
float md = (n * mx2) - pow(mx, 2);
// cout << "Down: " << m << endl;
m = m / md;
b = (my - m * mx) / n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
m = 55, b = 0;
if (type == "func")
{
// cout << "Output: " << m << " " << b << endl;
if (m == -1 && b < 0) cout << "y = -x - " << abs(b) << endl;
else if (m == -1 && b == 0) cout << "y = -x" << endl;
else if (m == -1) cout << "y = -x + " << b << endl;
else if (m == 1 && b < 0) cout << "y = x - " << abs(b) << endl;
else if (m == 1 && b == 0) cout << "y = x" << endl;
else if (m == 1) cout << "y = x + " << b << endl;
else if (m == 0 && b == 0) cout << "y = 0" << endl;
else if (m > -1 && m <= 0) cout << "y = " << b << endl;
else if (m > 1 && b < 0) cout << "y = " << m << "x - " << abs(b) << endl;
else if (m > 1 && b > 1) cout << "y = " << m << "x + " << b << endl;
else if (m > 1 && b == 0) cout << "y = " << m << "x" << endl;
}
} | # 0940, 2024-11-02 14:02:16, ----------PP---PPPPPPPPP (45%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string type;
cin >> n;
cin >> type;
// cout << n << " " << type << endl;
vector<float> x, y;
for (int i = 0; i < n; i++)
{
float xx, yy;
cin >> xx >> yy;
x.push_back(xx);
y.push_back(yy);
}
// for (int i = 0; i < n; i++)
// {
// cout << x[i] << " " << y[i] << endl;
// }
float m = 0.0, b = 0.0;
float mx = 0.0;
for (int i = 0; i < n; i++)
{
mx += x[i];
}
float my = 0.0;
for (int i = 0; i < n; i++)
{
my += y[i];
}
float mxy = 0.0;
for (int i = 0; i < n; i++)
{
mxy += x[i] * y[i];
}
// cout << "mxy " << mxy << " mx " << mx << " my " << my << endl;
float mx2 = 0.0;
for (int i = 0; i < n; i++)
{
mx2 += pow(x[i], 2);
}
m = (n * mxy) - (mx * my);
// cout << "Up: " << m << endl;
float md = (n * mx2) - pow(mx, 2);
// cout << "Down: " << m << endl;
m = m / md;
b = (my - m * mx) / n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
//m = 55, b = 0;
if (type == "func")
{
// cout << "Output: " << m << " " << b << endl;
if (m == -1 && b < 0) cout << "y = -x - " << abs(b) << endl;
else if (m == -1 && b == 0) cout << "y = -x" << endl;
else if (m == -1) cout << "y = -x + " << b << endl;
else if (m == 1 && b < 0) cout << "y = x - " << abs(b) << endl;
else if (m == 1 && b == 0) cout << "y = x" << endl;
else if (m == 1) cout << "y = x + " << b << endl;
else if (m == 0 && b == 0) cout << "y = 0" << endl;
else if (m > -1 && m <= 0) cout << "y = " << b << endl;
else if (m > 1 && b < 0) cout << "y = " << m << "x - " << abs(b) << endl;
else if (m > 1 && b > 1) cout << "y = " << m << "x + " << b << endl;
else if (m > 1 && b == 0) cout << "y = " << m << "x" << endl;
}
} | # 0941, 2024-11-02 14:06:20, ------------------------ (0%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string type;
cin >> n;
cin >> type;
// cout << n << " " << type << endl;
vector<float> x, y;
for (int i = 0; i < n; i++)
{
float xx, yy;
cin >> xx >> yy;
x.push_back(xx);
y.push_back(yy);
}
// for (int i = 0; i < n; i++)
// {
// cout << x[i] << " " << y[i] << endl;
// }
float m = 0.0, b = 0.0;
float mx = 0.0;
for (int i = 0; i < n; i++)
{
mx += x[i];
}
float my = 0.0;
for (int i = 0; i < n; i++)
{
my += y[i];
}
float mxy = 0.0;
for (int i = 0; i < n; i++)
{
mxy += x[i] * y[i];
}
// cout << "mxy " << mxy << " mx " << mx << " my " << my << endl;
float mx2 = 0.0;
for (int i = 0; i < n; i++)
{
mx2 += pow(x[i], 2);
}
m = (n * mxy) - (mx * my);
// cout << "Up: " << m << endl;
float md = (n * mx2) - pow(mx, 2);
// cout << "Down: " << m << endl;
m = m / md;
b = (my - m * mx) / n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
m = 1, b = -4;
if (type == "func")
{
// cout << "Output: " << m << " " << b << endl;
if (m == -1 && b < 0) cout << "y = -x - " << abs(b) << endl;
else if (m == -1 && b == 0) cout << "y = -x" << endl;
else if (m == -1) cout << "y = -x + " << b << endl;
else if (b > -1 && b <= 0) cout << "y = " << m << "x" << endl;
else if (m == 1 && b < 0) cout << "y = x - " << abs(b) << endl;
else if (m == 1 && b == 0) cout << "y = x" << endl;
else if (m == 1) cout << "y = x + " << b << endl;
else if (m == 0 && b == 0) cout << "y = 0" << endl;
else if (m > -1 && m <= 0) cout << "y = " << b << endl;
else if (m > 1 && b < 0) cout << "y = " << m << "x - " << abs(b) << endl;
else if (m > 1 && b > 1) cout << "y = " << m << "x + " << b << endl;
else if (m > 1 && b == 0) cout << "y = " << m << "x" << endl;
}
} | # 0942, 2024-11-02 14:06:32, ----------PP----PP-PPPPP (37%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string type;
cin >> n;
cin >> type;
// cout << n << " " << type << endl;
vector<float> x, y;
for (int i = 0; i < n; i++)
{
float xx, yy;
cin >> xx >> yy;
x.push_back(xx);
y.push_back(yy);
}
// for (int i = 0; i < n; i++)
// {
// cout << x[i] << " " << y[i] << endl;
// }
float m = 0.0, b = 0.0;
float mx = 0.0;
for (int i = 0; i < n; i++)
{
mx += x[i];
}
float my = 0.0;
for (int i = 0; i < n; i++)
{
my += y[i];
}
float mxy = 0.0;
for (int i = 0; i < n; i++)
{
mxy += x[i] * y[i];
}
// cout << "mxy " << mxy << " mx " << mx << " my " << my << endl;
float mx2 = 0.0;
for (int i = 0; i < n; i++)
{
mx2 += pow(x[i], 2);
}
m = (n * mxy) - (mx * my);
// cout << "Up: " << m << endl;
float md = (n * mx2) - pow(mx, 2);
// cout << "Down: " << m << endl;
m = m / md;
b = (my - m * mx) / n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
//m = 1, b = -4;
if (type == "func")
{
// cout << "Output: " << m << " " << b << endl;
if (m == -1 && b < 0) cout << "y = -x - " << abs(b) << endl;
else if (m == -1 && b == 0) cout << "y = -x" << endl;
else if (m == -1) cout << "y = -x + " << b << endl;
else if (b > -1 && b <= 0) cout << "y = " << m << "x" << endl;
else if (m == 1 && b < 0) cout << "y = x - " << abs(b) << endl;
else if (m == 1 && b == 0) cout << "y = x" << endl;
else if (m == 1) cout << "y = x + " << b << endl;
else if (m == 0 && b == 0) cout << "y = 0" << endl;
else if (m > -1 && m <= 0) cout << "y = " << b << endl;
else if (m > 1 && b < 0) cout << "y = " << m << "x - " << abs(b) << endl;
else if (m > 1 && b > 1) cout << "y = " << m << "x + " << b << endl;
else if (m > 1 && b == 0) cout << "y = " << m << "x" << endl;
}
} | # 0943, 2024-11-02 14:06:51, ----------PP---PPPPPPPPP (45%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string type;
cin >> n;
cin >> type;
// cout << n << " " << type << endl;
vector<float> x, y;
for (int i = 0; i < n; i++)
{
float xx, yy;
cin >> xx >> yy;
x.push_back(xx);
y.push_back(yy);
}
// for (int i = 0; i < n; i++)
// {
// cout << x[i] << " " << y[i] << endl;
// }
float m = 0.0, b = 0.0;
float mx = 0.0;
for (int i = 0; i < n; i++)
{
mx += x[i];
}
float my = 0.0;
for (int i = 0; i < n; i++)
{
my += y[i];
}
float mxy = 0.0;
for (int i = 0; i < n; i++)
{
mxy += x[i] * y[i];
}
// cout << "mxy " << mxy << " mx " << mx << " my " << my << endl;
float mx2 = 0.0;
for (int i = 0; i < n; i++)
{
mx2 += pow(x[i], 2);
}
m = (n * mxy) - (mx * my);
// cout << "Up: " << m << endl;
float md = (n * mx2) - pow(mx, 2);
// cout << "Down: " << m << endl;
m = m / md;
b = (my - m * mx) / n;
m=round(m*1e3)/1e3;
b=round(b*1e3)/1e3;
//m = 1, b = -4;
if (type == "func")
{
// cout << "Output: " << m << " " << b << endl;
if (m == -1 && b < 0) cout << "y = -x - " << abs(b) << endl;
else if (m == -1 && b == 0) cout << "y = -x" << endl;
else if (m == -1) cout << "y = -x + " << b << endl;
else if (m == 1 && b < 0) cout << "y = x - " << abs(b) << endl;
else if (m == 1 && b == 0) cout << "y = x" << endl;
else if (m == 1) cout << "y = x + " << b << endl;
else if (m == 0 && b == 0) cout << "y = 0" << endl;
else if (m > -1 && m <= 0) cout << "y = " << b << endl;
else if (m > 1 && b < 0) cout << "y = " << m << "x - " << abs(b) << endl;
else if (m > 1 && b > 1) cout << "y = " << m << "x + " << b << endl;
else if (m > 1 && b == 0) cout << "y = " << m << "x" << endl;
else if (b > -1 && b <= 0) cout << "y = " << m << "x" << endl;
}
} | # 0944, 2024-11-02 14:07:48, PPPPPP-PPPPP---PPPPPPPPP (83%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string type;
cin >> n;
cin >> type;
// cout << n << " " << type << endl;
vector<float> x, y;
for (int i = 0; i < n; i++)
{
float xx, yy;
cin >> xx >> yy;
x.push_back(xx);
y.push_back(yy);
}
// for (int i = 0; i < n; i++)
// {
// cout << x[i] << " " << y[i] << endl;
// }
float m = 0.0, b = 0.0;
float mx = 0.0;
for (int i = 0; i < n; i++)
{
mx += x[i];
}
float my = 0.0;
for (int i = 0; i < n; i++)
{
my += y[i];
}
float mxy = 0.0;
for (int i = 0; i < n; i++)
{
mxy += x[i] * y[i];
}
// cout << "mxy " << mxy << " mx " << mx << " my " << my << endl;
float mx2 = 0.0;
for (int i = 0; i < n; i++)
{
mx2 += pow(x[i], 2);
}
m = (n * mxy) - (mx * my);
// cout << "Up: " << m << endl;
float md = (n * mx2) - pow(mx, 2);
// cout << "Down: " << m << endl;
m = m / md;
b = (my - m * mx) / n;
m = round(m * 1e3) / 1e3;
b = round(b * 1e3) / 1e3;
// m = 1, b = -4;
if (type == "mb")
{
cout << m << endl
<< b << endl;
}
else if (type == "func")
{
// cout << "Output: " << m << " " << b << endl;
if (m == -1 && b < 0)
cout << "y = -x - " << abs(b) << endl;
else if (m == -1 && b == 0)
cout << "y = -x" << endl;
else if (m == -1)
cout << "y = -x + " << b << endl;
else if (m == 1 && b < 0)
cout << "y = x - " << abs(b) << endl;
else if (m == 1 && b == 0)
cout << "y = x" << endl;
else if (m == 1)
cout << "y = x + " << b << endl;
else if (m == 0 && b == 0)
cout << "y = 0" << endl;
else if (m > -1 && m <= 0)
cout << "y = " << b << endl;
else if (m > 1 && b < 0)
cout << "y = " << m << "x - " << abs(b) << endl;
else if (m > 1 && b > 1)
cout << "y = " << m << "x + " << b << endl;
else if (m > 1 && b == 0)
cout << "y = " << m << "x" << endl;
else if (b > -1 && b <= 0)
cout << "y = " << m << "x" << endl;
}
} |
# 0945, 2024-11-02 14:18:05, PPPPPPPPPPP-P--PP---PP-- (66%)
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<cmath>
using namespace std;
int main(){
int num;
cin>>num;
int numn = num;
string y;
cin>>y;
vector<pair<float,float>> p;
while(num--){
float a,b;
cin>>a>>b;
p.push_back(make_pair(a,b));
}
float sumxy =0.0;
for(auto&e:p){
sumxy+=e.first*e.second;
}
float sumx =0.0;
float sumy =0.0;
for(auto&e:p){
sumx+=e.first;
sumy+=e.second;
}
float sumpx =0.0;
for(auto&e:p){
sumpx += pow(e.first,2);
}
float up = (numn*sumxy)-sumx*sumy;
float down = (numn*sumpx)-sumx*sumx;
float m = up/down;
float b = (sumy-m*sumx)/numn;
float mn = round(m*1e3)/1e3;
float bn = round(b*1e3)/1e3;
if(y == "mb"){
cout<<mn<<endl;
cout<<bn<<endl;
}
if(y=="func"){
if(mn==0&&bn==0){
cout<<"y"<<" = "<<"0 ";
}
else if(mn==0&&bn!=0){
cout<<"y"<<" = "<<bn;
}
else if(bn==0&&mn!=0){
cout<<"y"<<" = "<<mn;
}
else if(mn==-1){
cout<<"y"<<" "<<" = "<<" -x "<<" + "<<bn;
}
else{
cout<<"y"<<" "<<" = "<<mn<<"x"<<" + "<<bn;
}
}
} | # 0946, 2024-11-02 14:40:50, ------------------------ (0%)
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<cmath>
using namespace std;
int main(){
int num;
cin>>num;
int numn = num;
string y;
cin>>y;
vector<pair<float,float>> p;
while(num--){
float a,b;
cin>>a>>b;
p.push_back(make_pair(a,b));
}
float sumxy =0.0;
for(auto&e:p){
sumxy+=e.first*e.second;
}
float sumx =0.0;
float sumy =0.0;
for(auto&e:p){
sumx+=e.first;
sumy+=e.second;
}
float sumpx =0.0;
for(auto&e:p){
sumpx += pow(e.first,2);
}
float up = (numn*sumxy)-sumx*sumy;
float down = (numn*sumpx)-sumx*sumx;
float m = up/down;
float b = (sumy-m*sumx)/numn;
float mn = round(m*1e3)/1e3;
float bn = round(b*1e3)/1e3;
cout<<mn<<' '<<bn<<endl;
if(y == "mb"){
cout<<mn<<endl;
cout<<bn<<endl;
}
if(y=="func"){
if(mn==0&&bn!=0){
cout<<"y"<<" = "<<bn;
}
else if(bn==0&&mn!=0){
if(m==1){
cout<<"y"<<" = "<<"x";
}
else if(m==-1){
cout<<"y"<<" = "<<"-x";
}
else{
cout<<"y"<<" = "<<mn<<"x";
}
}
else if(mn==0&&bn==0){
cout<<"y"<<" = "<<"0";
}
else if(bn!=0&&mn!=0){
if(m==-1&&bn<0){
cout<<"y"<<" = "<<"-x"<<" - "<<-bn;
}
else if(m==-1&&bn>0){
cout<<"y"<<" = "<<"-x"<<" + "<<bn;
}
else if(m==1&&bn>0){
cout<<"y"<<" = "<<"x"<<" + "<<bn;
}
else if(m==1&&bn<0){
cout<<"y"<<" = "<<"x"<<" - "<<-bn;
}
else if(bn>0){
cout<<"y"<<" = "<<mn<<"x"<<" + "<<bn;
}
}
}
} | # 0947, 2024-11-02 14:43:40, ------------------------ (0%)
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<cmath>
using namespace std;
int main(){
int num;
cin>>num;
int numn = num;
string y;
cin>>y;
vector<pair<float,float>> p;
while(num--){
float a,b;
cin>>a>>b;
p.push_back(make_pair(a,b));
}
float sumxy =0.0;
for(auto&e:p){
sumxy+=e.first*e.second;
}
float sumx =0.0;
float sumy =0.0;
for(auto&e:p){
sumx+=e.first;
sumy+=e.second;
}
float sumpx =0.0;
for(auto&e:p){
sumpx += pow(e.first,2);
}
float up = (numn*sumxy)-sumx*sumy;
float down = (numn*sumpx)-sumx*sumx;
float m = up/down;
float b = (sumy-m*sumx)/numn;
float mn = round(m*1e3)/1e3;
float bn = round(b*1e3)/1e3;
cout<<mn<<' '<<bn<<endl;
if(y == "mb"){
cout<<mn<<endl;
cout<<bn<<endl;
}
if(y=="func"){
if(mn==0&&bn!=0){
cout<<"y"<<" = "<<bn;
}
else if(bn==0&&mn!=0){
if(m==1){
cout<<"y"<<" = "<<"x";
}
else if(m==-1){
cout<<"y"<<" = "<<"-x";
}
else{
cout<<"y"<<" = "<<mn<<"x";
}
}
else if(mn==0&&bn==0){
cout<<"y"<<" = "<<"0";
}
else if(bn!=0&&mn!=0){
if(m==-1&&bn<0){
cout<<"y"<<" = "<<"-x"<<" - "<<-bn;
}
else if(m==-1&&bn>0){
cout<<"y"<<" = "<<"-x"<<" + "<<bn;
}
else if(m==1&&bn>0){
cout<<"y"<<" = "<<"x"<<" + "<<bn;
}
else if(m==1&&bn<0){
cout<<"y"<<" = "<<"x"<<" - "<<-bn;
}
else if(bn>0){
cout<<"y"<<" = "<<mn<<"x"<<" + "<<bn;
}
}
}
} | # 0948, 2024-11-02 14:44:11, PPPPPPPPPPP-P--PP-PP-P-- (70%)
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<cmath>
using namespace std;
int main(){
int num;
cin>>num;
int numn = num;
string y;
cin>>y;
vector<pair<float,float>> p;
while(num--){
float a,b;
cin>>a>>b;
p.push_back(make_pair(a,b));
}
float sumxy =0.0;
for(auto&e:p){
sumxy+=e.first*e.second;
}
float sumx =0.0;
float sumy =0.0;
for(auto&e:p){
sumx+=e.first;
sumy+=e.second;
}
float sumpx =0.0;
for(auto&e:p){
sumpx += pow(e.first,2);
}
float up = (numn*sumxy)-sumx*sumy;
float down = (numn*sumpx)-sumx*sumx;
float m = up/down;
float b = (sumy-m*sumx)/numn;
float mn = round(m*1e3)/1e3;
float bn = round(b*1e3)/1e3;
if(y == "mb"){
cout<<mn<<endl;
cout<<bn<<endl;
}
if(y=="func"){
if(mn==0&&bn!=0){
cout<<"y"<<" = "<<bn;
}
else if(bn==0&&mn!=0){
if(m==1){
cout<<"y"<<" = "<<"x";
}
else if(m==-1){
cout<<"y"<<" = "<<"-x";
}
else{
cout<<"y"<<" = "<<mn<<"x";
}
}
else if(mn==0&&bn==0){
cout<<"y"<<" = "<<"0";
}
else if(bn!=0&&mn!=0){
if(m==-1&&bn<0){
cout<<"y"<<" = "<<"-x"<<" - "<<-bn;
}
else if(m==-1&&bn>0){
cout<<"y"<<" = "<<"-x"<<" + "<<bn;
}
else if(m==1&&bn>0){
cout<<"y"<<" = "<<"x"<<" + "<<bn;
}
else if(m==1&&bn<0){
cout<<"y"<<" = "<<"x"<<" - "<<-bn;
}
else if(bn>0){
cout<<"y"<<" = "<<mn<<"x"<<" + "<<bn;
}
}
}
} | # 0949, 2024-11-02 14:52:01, PPPPPPPPPP-----PP-PP-P-- (62%)
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<cmath>
using namespace std;
int main(){
int num;
cin>>num;
int numn = num;
string y;
cin>>y;
vector<pair<float,float>> p;
while(num--){
float a,b;
cin>>a>>b;
p.push_back(make_pair(a,b));
}
float sumxy =0.0;
for(auto&e:p){
sumxy+=e.first*e.second;
}
float sumx =0.0;
float sumy =0.0;
for(auto&e:p){
sumx+=e.first;
sumy+=e.second;
}
float sumpx =0.0;
for(auto&e:p){
sumpx += pow(e.first,2);
}
float up = (numn*sumxy)-sumx*sumy;
float down = (numn*sumpx)-sumx*sumx;
float m = up/down;
float b = (sumy-m*sumx)/numn;
float mn = round(m*1e3)/1e3;
float bn = round(b*1e3)/1e3;
if(y == "mb"){
cout<<mn<<endl;
cout<<bn<<endl;
}
if(y=="func"){
if(mn==0&&bn!=0){
cout<<"y"<<" = "<<bn;
}
else if(bn==0&&mn!=0){
if(m==1){
cout<<"y"<<" = "<<"x";
}
else if(m==-1){
cout<<"y"<<" = "<<"-x";
}
else{
cout<<"y"<<" = "<<mn<<"x";
}
}
else if(mn==0&&bn==0){
cout<<"y"<<" = "<<"0";
}
else if(bn!=0&&mn!=0){
if(m==-1&&bn<0){
cout<<"y"<<" = "<<"-x"<<" - "<<-bn;
}
else if(m==-1&&bn>0){
cout<<"y"<<" = "<<"-x"<<" + "<<bn;
}
else if(m==1&&bn>0){
cout<<"y"<<" = "<<"x"<<" + "<<bn;
}
else if(m==1&&bn<0){
cout<<"y"<<" = "<<"x"<<" - "<<-bn;
}
else if(mn!=1&&mn!=-1&&bn>0){
cout<<"y"<<" = "<<mn<<"x"<<" - "<<-bn;
}
else if(bn>0){
cout<<"y"<<" = "<<mn<<"x"<<" + "<<bn;
}
}
}
} | # 0950, 2024-11-02 14:54:24, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<cmath>
using namespace std;
int main(){
int num;
cin>>num;
int numn = num;
string y;
cin>>y;
vector<pair<float,float>> p;
while(num--){
float a,b;
cin>>a>>b;
p.push_back(make_pair(a,b));
}
float sumxy =0.0;
for(auto&e:p){
sumxy+=e.first*e.second;
}
float sumx =0.0;
float sumy =0.0;
for(auto&e:p){
sumx+=e.first;
sumy+=e.second;
}
float sumpx =0.0;
for(auto&e:p){
sumpx += pow(e.first,2);
}
float up = (numn*sumxy)-sumx*sumy;
float down = (numn*sumpx)-sumx*sumx;
float m = up/down;
float b = (sumy-m*sumx)/numn;
float mn = round(m*1e3)/1e3;
float bn = round(b*1e3)/1e3;
if(y == "mb"){
cout<<mn<<endl;
cout<<bn<<endl;
}
if(y=="func"){
if(mn==0&&bn!=0){
cout<<"y"<<" = "<<bn;
}
else if(bn==0&&mn!=0){
if(m==1){
cout<<"y"<<" = "<<"x";
}
else if(m==-1){
cout<<"y"<<" = "<<"-x";
}
else{
cout<<"y"<<" = "<<mn<<"x";
}
}
else if(mn==0&&bn==0){
cout<<"y"<<" = "<<"0";
}
else if(bn!=0&&mn!=0){
if(m==-1&&bn<0){
cout<<"y"<<" = "<<"-x"<<" - "<<-bn;
}
else if(m==-1&&bn>0){
cout<<"y"<<" = "<<"-x"<<" + "<<bn;
}
else if(m==1&&bn>0){
cout<<"y"<<" = "<<"x"<<" + "<<bn;
}
else if(m==1&&bn<0){
cout<<"y"<<" = "<<"x"<<" - "<<-bn;
}
else if(mn!=1&&mn!=-1&&bn<0){
cout<<"y"<<" = "<<mn<<"x"<<" - "<<-bn;
}
else if(bn>0){
cout<<"y"<<" = "<<mn<<"x"<<" + "<<bn;
}
}
}
} | # 0951, 2024-11-02 15:10:56, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<cmath>
using namespace std;
int main(){
int num;
cin>>num;
int numn = num;
string y;
cin>>y;
vector<pair<float,float>> p;
while(num--){
float a,b;
cin>>a>>b;
p.push_back(make_pair(a,b));
}
float sumxy =0.0;
for(auto&e:p){
sumxy+=e.first*e.second;
}
float sumx =0.0;
float sumy =0.0;
for(auto&e:p){
sumx+=e.first;
sumy+=e.second;
}
float sumpx =0.0;
for(auto&e:p){
sumpx += pow(e.first,2);
}
float up = (numn*sumxy)-sumx*sumy;
float down = (numn*sumpx)-sumx*sumx;
float m = up/down;
float b = (sumy-m*sumx)/numn;
float mn = round(m*1e3)/1e3;
float bn = round(b*1e3)/1e3;
if(y == "mb"){
cout<<mn<<endl;
cout<<bn<<endl;
}
if(y=="func"){
if(mn==0&&bn!=0){
cout<<"y"<<" = "<<bn;
}
else if(bn==0&&mn!=0){
if(m==1){
cout<<"y"<<" = "<<"x";
}
else if(m==-1){
cout<<"y"<<" = "<<"-x";
}
else{
cout<<"y"<<" = "<<mn<<"x";
}
}
else if(mn==0&&bn==0){
cout<<"y"<<" = "<<"0";
}
else if(bn!=0&&mn!=0){
if(m==-1&&bn<0){
cout<<"y"<<" = "<<"-x"<<" - "<<-bn;
}
else if(m==-1&&bn>0){
cout<<"y"<<" = "<<"-x"<<" + "<<bn;
}
else if(m==1&&bn>0){
cout<<"y"<<" = "<<"x"<<" + "<<bn;
}
else if(m==1&&bn<0){
cout<<"y"<<" = "<<"x"<<" - "<<-bn;
}
else if(mn!=1&&mn!=-1&&bn<0){
cout<<"y"<<" = "<<mn<<"x"<<" - "<<-bn;
}
else{
cout<<"y"<<" = "<<mn<<"x"<<" + "<<bn;
}
}
}
} | # 0952, 2024-11-02 15:12:27, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<cmath>
using namespace std;
int main(){
int num;
cin>>num;
int numn = num;
string y;
cin>>y;
vector<pair<float,float>> p;
while(num--){
float a,b;
cin>>a>>b;
p.push_back(make_pair(a,b));
}
float sumxy =0.0;
for(auto&e:p){
sumxy+=e.first*e.second;
}
float sumx =0.0;
float sumy =0.0;
for(auto&e:p){
sumx+=e.first;
sumy+=e.second;
}
float sumpx =0.0;
for(auto&e:p){
sumpx += pow(e.first,2);
}
float up = (numn*sumxy)-sumx*sumy;
float down = (numn*sumpx)-sumx*sumx;
float m = up/down;
float b = (sumy-m*sumx)/numn;
float mn = round(m*1e3)/1e3;
float bn = round(b*1e3)/1e3;
if(y == "mb"){
cout<<mn<<endl;
cout<<bn<<endl;
}
if(y=="func"){
if(mn==0&&bn!=0){
cout<<"y"<<" = "<<bn;
}
else if(bn==0&&mn!=0){
if(m==1){
cout<<"y"<<" = "<<"x";
}
else if(m==-1){
cout<<"y"<<" = "<<"-x";
}
else{
cout<<"y"<<" = "<<mn<<"x";
}
}
else if(mn==0&&bn==0){
cout<<"y"<<" = "<<"0";
}
else if(bn!=0&&mn!=0){
if(m==-1&&bn<0){
cout<<"y"<<" = "<<"-x"<<" - "<<-bn;
}
else if(m==-1&&bn>0){
cout<<"y"<<" = "<<"-x"<<" + "<<bn;
}
else if(m==1&&bn>0){
cout<<"y"<<" = "<<"x"<<" + "<<bn;
}
else if(m==1&&bn<0){
cout<<"y"<<" = "<<"x"<<" - "<<-bn;
}
else if(mn!=1&&mn!=-1&&bn<0){
cout<<"y"<<" = "<<mn<<"x"<<" - "<<-bn;
}
else if(mn!=1&&mn!=-1&&bn>0){
cout<<"y"<<" = "<<mn<<"x"<<" + "<<bn;
}
}
}
} |
# 0953, 2024-11-02 14:13:15, ------------------------ (0%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
string ope;
cin >> n >> ope;
//input
vector<pair<float,float>> pairoder;
for(int i=0;i<n;i++){
float x,y;
cin >> x >> y;
pairoder.push_back({x,y});
}
// for(auto e : pairoder){
// cout << e.first << " "<< e.second << endl;
// }
//cal m,b
float m,b;
float sum1=0; //sum xy
for(int i=1;i<=n;i++){
sum1+= (pairoder[i-1].first * pairoder[i-1].second);
//cout << sum1 << endl;
}
float sum2=0; //sum x
for(int i=1;i<=n;i++){
sum2 += pairoder[i-1].first;
//cout << sum2 << endl;
}
float sum3=0; //sum y
for(int i=1;i<=n;i++){
sum3 += pairoder[i-1].second;
}
float sum4=0; //sum x*x
for(int i=1;i<=n;i++){
sum4 += (pairoder[i-1].first*pairoder[i-1].first);
}
cout << "----" << endl;
cout << sum1 << " " << sum2 << " " << sum3 << " " << sum4 << endl;
cout << "----" << endl;
m = ((n * sum1) - (sum2*sum3)) / ((n*sum4) - (sum2*sum2));
b = (sum3 - (m*sum2)) / n;
if(ope == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else if(ope == "func"){
if(m == 1){
if(b < 0){
cout << "y = " << "x - " << abs(b);
}else{
cout << "y = " << "x + " << b;
}
}else if(m == -1){
if(b < 0){
cout << "y = " << "-x - " << abs(b);
}else{
cout << "y = " << "-x + " << b;
}
}else if(m == 0 && b == 0){
cout << "y = 0" << endl;
}else{
if(b < 0){
cout << "y = " << m << "x " << "- " << abs(b);
}else{
cout << "y = " << m << "x " << "+ " << b;
}
}
}
} | # 0954, 2024-11-02 14:13:36, PPPPPPPPPP-----P-------- (45%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
string ope;
cin >> n >> ope;
//input
vector<pair<float,float>> pairoder;
for(int i=0;i<n;i++){
float x,y;
cin >> x >> y;
pairoder.push_back({x,y});
}
// for(auto e : pairoder){
// cout << e.first << " "<< e.second << endl;
// }
//cal m,b
float m,b;
float sum1=0; //sum xy
for(int i=1;i<=n;i++){
sum1+= (pairoder[i-1].first * pairoder[i-1].second);
//cout << sum1 << endl;
}
float sum2=0; //sum x
for(int i=1;i<=n;i++){
sum2 += pairoder[i-1].first;
//cout << sum2 << endl;
}
float sum3=0; //sum y
for(int i=1;i<=n;i++){
sum3 += pairoder[i-1].second;
}
float sum4=0; //sum x*x
for(int i=1;i<=n;i++){
sum4 += (pairoder[i-1].first*pairoder[i-1].first);
}
// cout << "----" << endl;
// cout << sum1 << " " << sum2 << " " << sum3 << " " << sum4 << endl;
// cout << "----" << endl;
m = ((n * sum1) - (sum2*sum3)) / ((n*sum4) - (sum2*sum2));
b = (sum3 - (m*sum2)) / n;
if(ope == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else if(ope == "func"){
if(m == 1){
if(b < 0){
cout << "y = " << "x - " << abs(b);
}else{
cout << "y = " << "x + " << b;
}
}else if(m == -1){
if(b < 0){
cout << "y = " << "-x - " << abs(b);
}else{
cout << "y = " << "-x + " << b;
}
}else if(m == 0 && b == 0){
cout << "y = 0" << endl;
}else{
if(b < 0){
cout << "y = " << m << "x " << "- " << abs(b);
}else{
cout << "y = " << m << "x " << "+ " << b;
}
}
}
} | # 0955, 2024-11-02 14:18:48, PPPPPPPPPPPPPPPP--PP---- (75%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
string ope;
cin >> n >> ope;
//input
vector<pair<float,float>> pairoder;
for(int i=0;i<n;i++){
float x,y;
cin >> x >> y;
pairoder.push_back({x,y});
}
// for(auto e : pairoder){
// cout << e.first << " "<< e.second << endl;
// }
//cal m,b
float m,b;
float sum1=0; //sum xy
for(int i=1;i<=n;i++){
sum1+= (pairoder[i-1].first * pairoder[i-1].second);
//cout << sum1 << endl;
}
float sum2=0; //sum x
for(int i=1;i<=n;i++){
sum2 += pairoder[i-1].first;
//cout << sum2 << endl;
}
float sum3=0; //sum y
for(int i=1;i<=n;i++){
sum3 += pairoder[i-1].second;
}
float sum4=0; //sum x*x
for(int i=1;i<=n;i++){
sum4 += (pairoder[i-1].first*pairoder[i-1].first);
}
// cout << "----" << endl;
// cout << sum1 << " " << sum2 << " " << sum3 << " " << sum4 << endl;
// cout << "----" << endl;
m = ((n * sum1) - (sum2*sum3)) / ((n*sum4) - (sum2*sum2));
b = (sum3 - (m*sum2)) / n;
if(ope == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else if(ope == "func"){
if(m == 1){
if(b < 0){
cout << "y = " << "x - " << round(abs(b)*1e3)/1e3;
}else if(b > 0){
cout << "y = " << "x + " << round(b*1e3)/1e3;
}else{
cout << "y = " << "x";
}
}else if(m == -1){
if(b < 0){
cout << "y = " << "-x - " << round(abs(b)*1e3)/1e3;
}else if(b > 0){
cout << "y = " << "-x + " << round(b*1e3)/1e3;
}else {
cout << "y = " << "-x";
}
}else if(m == 0 && b == 0){
cout << "y = 0" << endl;
}else{
if(b < 0){
cout << "y = " << round(m*1e3)/1e3 << "x " << "- " << round(abs(b)*1e3)/1e3;
}else{
cout << "y = " << round(m*1e3)/1e3 << "x " << "+ " << round(b*1e3)/1e3;
}
}
}
} | # 0956, 2024-11-02 14:23:28, PPPPPPPPPPPPPPPP--PP---- (75%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
string ope;
cin >> n >> ope;
//input
vector<pair<float,float>> pairoder;
for(int i=0;i<n;i++){
float x,y;
cin >> x >> y;
pairoder.push_back({x,y});
}
// for(auto e : pairoder){
// cout << e.first << " "<< e.second << endl;
// }
//cal m,b
float m,b;
float sum1=0; //sum xy
for(int i=1;i<=n;i++){
sum1+= (pairoder[i-1].first * pairoder[i-1].second);
//cout << sum1 << endl;
}
float sum2=0; //sum x
for(int i=1;i<=n;i++){
sum2 += pairoder[i-1].first;
//cout << sum2 << endl;
}
float sum3=0; //sum y
for(int i=1;i<=n;i++){
sum3 += pairoder[i-1].second;
}
float sum4=0; //sum x*x
for(int i=1;i<=n;i++){
sum4 += (pairoder[i-1].first*pairoder[i-1].first);
}
// cout << "----" << endl;
// cout << sum1 << " " << sum2 << " " << sum3 << " " << sum4 << endl;
// cout << "----" << endl;
m = ((n * sum1) - (sum2*sum3)) / ((n*sum4) - (sum2*sum2));
b = (sum3 - (m*sum2)) / n;
if(ope == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else if(ope == "func"){
if(m == 1 && m!= 0){
if(b < 0){
cout << "y = " << "x - " << round(abs(b)*1e3)/1e3;
}else if(b > 0){
cout << "y = " << "x + " << round(b*1e3)/1e3;
}else{
cout << "y = " << "x";
}
}else if(m == -1 && m != 0){
if(b < 0){
cout << "y = " << "-x - " << round(abs(b)*1e3)/1e3;
}else if(b > 0){
cout << "y = " << "-x + " << round(b*1e3)/1e3;
}else {
cout << "y = " << "-x";
}
}else if(m == 0 && b == 0){
cout << "y = 0" << endl;
}else if(m == 0){
if(b > 0){
cout << round(b*1e3)/1e3;
}else if(b < 0){
cout << round(b*1e3)/1e3;
}
}else{
if(b < 0){
cout << "y = " << round(m*1e3)/1e3 << "x " << "- " << round(abs(b)*1e3)/1e3;
}else{
cout << "y = " << round(m*1e3)/1e3 << "x " << "+ " << round(b*1e3)/1e3;
}
}
}
} | # 0957, 2024-11-02 14:41:36, PPPPPPPPPPPP---P--PP---- (62%)
#include <bits/stdc++.h>
using namespace std;
int main(){
float n;
string ope;
cin >> n >> ope;
//input
vector<pair<float,float>> pairoder;
for(int i=0;i<n;i++){
float x,y;
cin >> x >> y;
pairoder.push_back({x,y});
}
// for(auto e : pairoder){
// cout << e.first << " "<< e.second << endl;
// }
//cal m,b
float m,b;
float sum1=0; //sum xy
for(int i=1;i<=n;i++){
sum1+= (pairoder[i-1].first * pairoder[i-1].second);
//cout << sum1 << endl;
}
float sum2=0; //sum x
for(int i=1;i<=n;i++){
sum2 += pairoder[i-1].first;
//cout << sum2 << endl;
}
float sum3=0; //sum y
for(int i=1;i<=n;i++){
sum3 += pairoder[i-1].second;
}
float sum4=0; //sum x*x
for(int i=1;i<=n;i++){
sum4 += (pairoder[i-1].first*pairoder[i-1].first);
}
// cout << "----" << endl;
// cout << sum1 << " " << sum2 << " " << sum3 << " " << sum4 << endl;
// cout << "----" << endl;
m = ((n * sum1) - (sum2*sum3)) / ((n*sum4) - (sum2*sum2));
b = (sum3 - (m*sum2)) / n;
//cout << round(m*1e3)/1e3 << endl;
if(ope == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else if(ope == "func"){
if(m == 1){
if(b < 0){
cout << "y = " << "x - " << round(abs(b)*1e3)/1e3;
}else if(b > 0){
cout << "y = " << "x + " << round(b*1e3)/1e3;
}else{
cout << "y = " << "x";
}
}else if(m == -1){
if(b < 0){
cout << "y = " << "-x - " << round(abs(b)*1e3)/1e3;
}else if(b > 0){
cout << "y = " << "-x + " << round(b*1e3)/1e3;
}else {
cout << "y = " << "-x";
}
}else if(m == 0 && b == 0){
cout << "y = 0" << endl;
}else if(abs(round(m*1e3)/1e3) == 0){
if(b > 0){
cout << round(b*1e3)/1e3;
}else if(b < 0){
cout << round(b*1e3)/1e3;
}
}else if(m > 1){
if(b < 0){
cout << "y = " << round(m*1e3)/1e3 << "x " << "- " << round(abs(b)*1e3)/1e3;
}else{
cout << "y = " << round(m*1e3)/1e3 << "x " << "+ " << round(b*1e3)/1e3;
}
}
}
} | # 0958, 2024-11-02 14:41:52, PPPPPPPPPPPPPPPP--PP---- (75%)
#include <bits/stdc++.h>
using namespace std;
int main(){
float n;
string ope;
cin >> n >> ope;
//input
vector<pair<float,float>> pairoder;
for(int i=0;i<n;i++){
float x,y;
cin >> x >> y;
pairoder.push_back({x,y});
}
// for(auto e : pairoder){
// cout << e.first << " "<< e.second << endl;
// }
//cal m,b
float m,b;
float sum1=0; //sum xy
for(int i=1;i<=n;i++){
sum1+= (pairoder[i-1].first * pairoder[i-1].second);
//cout << sum1 << endl;
}
float sum2=0; //sum x
for(int i=1;i<=n;i++){
sum2 += pairoder[i-1].first;
//cout << sum2 << endl;
}
float sum3=0; //sum y
for(int i=1;i<=n;i++){
sum3 += pairoder[i-1].second;
}
float sum4=0; //sum x*x
for(int i=1;i<=n;i++){
sum4 += (pairoder[i-1].first*pairoder[i-1].first);
}
// cout << "----" << endl;
// cout << sum1 << " " << sum2 << " " << sum3 << " " << sum4 << endl;
// cout << "----" << endl;
m = ((n * sum1) - (sum2*sum3)) / ((n*sum4) - (sum2*sum2));
b = (sum3 - (m*sum2)) / n;
//cout << round(m*1e3)/1e3 << endl;
if(ope == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else if(ope == "func"){
if(m == 1){
if(b < 0){
cout << "y = " << "x - " << round(abs(b)*1e3)/1e3;
}else if(b > 0){
cout << "y = " << "x + " << round(b*1e3)/1e3;
}else{
cout << "y = " << "x";
}
}else if(m == -1){
if(b < 0){
cout << "y = " << "-x - " << round(abs(b)*1e3)/1e3;
}else if(b > 0){
cout << "y = " << "-x + " << round(b*1e3)/1e3;
}else {
cout << "y = " << "-x";
}
}else if(m == 0 && b == 0){
cout << "y = 0" << endl;
}else if(abs(round(m*1e3)/1e3) == 0){
if(b > 0){
cout << round(b*1e3)/1e3;
}else if(b < 0){
cout << round(b*1e3)/1e3;
}
}else{
if(b < 0){
cout << "y = " << round(m*1e3)/1e3 << "x " << "- " << round(abs(b)*1e3)/1e3;
}else{
cout << "y = " << round(m*1e3)/1e3 << "x " << "+ " << round(b*1e3)/1e3;
}
}
}
} | # 0959, 2024-11-02 14:42:54, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include <bits/stdc++.h>
using namespace std;
int main(){
float n;
string ope;
cin >> n >> ope;
//input
vector<pair<float,float>> pairoder;
for(int i=0;i<n;i++){
float x,y;
cin >> x >> y;
pairoder.push_back({x,y});
}
// for(auto e : pairoder){
// cout << e.first << " "<< e.second << endl;
// }
//cal m,b
float m,b;
float sum1=0; //sum xy
for(int i=1;i<=n;i++){
sum1+= (pairoder[i-1].first * pairoder[i-1].second);
//cout << sum1 << endl;
}
float sum2=0; //sum x
for(int i=1;i<=n;i++){
sum2 += pairoder[i-1].first;
//cout << sum2 << endl;
}
float sum3=0; //sum y
for(int i=1;i<=n;i++){
sum3 += pairoder[i-1].second;
}
float sum4=0; //sum x*x
for(int i=1;i<=n;i++){
sum4 += (pairoder[i-1].first*pairoder[i-1].first);
}
// cout << "----" << endl;
// cout << sum1 << " " << sum2 << " " << sum3 << " " << sum4 << endl;
// cout << "----" << endl;
m = ((n * sum1) - (sum2*sum3)) / ((n*sum4) - (sum2*sum2));
b = (sum3 - (m*sum2)) / n;
//cout << round(m*1e3)/1e3 << endl;
if(ope == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}else if(ope == "func"){
if(m == 1){
if(b < 0){
cout << "y = " << "x - " << round(abs(b)*1e3)/1e3;
}else if(b > 0){
cout << "y = " << "x + " << round(b*1e3)/1e3;
}else{
cout << "y = " << "x";
}
}else if(m == -1){
if(b < 0){
cout << "y = " << "-x - " << round(abs(b)*1e3)/1e3;
}else if(b > 0){
cout << "y = " << "-x + " << round(b*1e3)/1e3;
}else {
cout << "y = " << "-x";
}
}else if(m == 0 && b == 0){
cout << "y = 0" << endl;
}else if(abs(round(m*1e3)/1e3) == 0){
if(b > 0){
cout << "y = " << round(b*1e3)/1e3;
}else if(b < 0){
cout << "y = " << round(b*1e3)/1e3;
}
}else{
if(b < 0){
cout << "y = " << round(m*1e3)/1e3 << "x " << "- " << round(abs(b)*1e3)/1e3;
}else{
cout << "y = " << round(m*1e3)/1e3 << "x " << "+ " << round(b*1e3)/1e3;
}
}
}
} |
# 0960, 2024-11-02 09:34:20, ------------------------ (0%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
int n;
cin >> n;
vector <float> x;
vector <float> y;
float temp_x;
float temp_y;
float m;
float b;
string whattodo;
float temp1 = 0;
float temp2 = 0;
float temp3 = 0;
float temp4 = 0;
float temp5 = 0;
float temp6 = 0;
float temp7 = 0;
float temp8 = 0;
cin >> n >> whattodo;
for(int i = 0;i < n;i++){
cin >> temp_x >> temp_y;
x.push_back(temp_x);
y.push_back(temp_y);
}
for(size_t i = 0; i < x.size(); i++){
temp1+=x[i]*y[i];
}
temp1*=x.size();
for(size_t i = 0; i < x.size(); i++){
temp2+=x[i];
temp3+=y[i];
}
temp4 = temp2*temp3;
for(size_t i = 0; i < x.size(); i++){
temp5+=pow(x[i],2);
}
temp6 = temp5*x.size();
for(size_t i = 0; i < x.size(); i++){
temp7+=x[i];
}
temp7 = pow(temp7,2);
m = (temp1 - temp4)/(temp6-temp7);
temp8 = temp2*m;
b = (temp3 - temp8)/x.size();
if(whattodo == "mb"){
cout << m << endl << b;
}
else if(whattodo == "func"){
cout << "y = " << m << "x - " << b;
}
} | # 0961, 2024-11-02 10:33:17, PPPPPPPPPPPPPPP--------- (62%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
int n;
vector <float> x;
vector <float> y;
float temp_x;
float temp_y;
float m;
float b;
string whattodo;
cin >> n >> whattodo;
float sum_x = 0;
float sum_y = 0;
float sum_xy = 0;
float sum_xx = 0;
for(int i = 0;i < n;i++){
cin >> temp_x >> temp_y;
sum_x+=temp_x;
sum_y+=temp_y;
sum_xx+=pow(temp_x,2);
sum_xy+=(temp_x*temp_y);
}
m = (n*sum_xy - sum_x*sum_y)/(n*sum_xx - pow(sum_x,2));
b = (sum_y - m*sum_x)/n;
if(whattodo == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(whattodo == "func"){
if(b < 0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << round((b*-1)*1e3)/1e3;
}
else if(b > 0){
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
}
} | # 0962, 2024-11-02 10:36:12, PPPPPPPPPP------------P- (45%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
int n;
vector <float> x;
vector <float> y;
float temp_x;
float temp_y;
float m;
float b;
string whattodo;
cin >> n >> whattodo;
float sum_x = 0;
float sum_y = 0;
float sum_xy = 0;
float sum_xx = 0;
for(int i = 0;i < n;i++){
cin >> temp_x >> temp_y;
sum_x+=temp_x;
sum_y+=temp_y;
sum_xx+=pow(temp_x,2);
sum_xy+=(temp_x*temp_y);
}
m = (n*sum_xy - sum_x*sum_y)/(n*sum_xx - pow(sum_x,2));
b = (sum_y - m*sum_x)/n;
if(whattodo == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(whattodo == "func"){
if(m == 1){
if(b < 0){
cout << "y = " << "x - " << round((b*-1)*1e3)/1e3;
}
else if(b > 0){
cout << "y = " << "x + " << round(b*1e3)/1e3;
}
else if(m == -1){
if(b < 0){
cout << "y = " << "-x - " << round((b*-1)*1e3)/1e3;
}
else if(b > 0){
cout << "y = " << "-x + " << round(b*1e3)/1e3;
}
}
else{
if(b < 0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << round((b*-1)*1e3)/1e3;
}
else if(b > 0){
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
}
}
}
} | # 0963, 2024-11-02 10:37:57, PPPPPPPPPPPPPPP-------P- (66%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
int n;
vector <float> x;
vector <float> y;
float temp_x;
float temp_y;
float m;
float b;
string whattodo;
cin >> n >> whattodo;
float sum_x = 0;
float sum_y = 0;
float sum_xy = 0;
float sum_xx = 0;
for(int i = 0;i < n;i++){
cin >> temp_x >> temp_y;
sum_x+=temp_x;
sum_y+=temp_y;
sum_xx+=pow(temp_x,2);
sum_xy+=(temp_x*temp_y);
}
m = (n*sum_xy - sum_x*sum_y)/(n*sum_xx - pow(sum_x,2));
b = (sum_y - m*sum_x)/n;
if(whattodo == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(whattodo == "func"){
if(m == 1){
if(b < 0){
cout << "y = " << "x - " << round((b*-1)*1e3)/1e3;
}
else if(b > 0){
cout << "y = " << "x + " << round(b*1e3)/1e3;
}
}
else if(m == -1){
if(b < 0){
cout << "y = " << "-x - " << round((b*-1)*1e3)/1e3;
}
else if(b > 0){
cout << "y = " << "-x + " << round(b*1e3)/1e3;
}
}
else{
if(b < 0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << round((b*-1)*1e3)/1e3;
}
else if(b > 0){
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
}
}
} | # 0964, 2024-11-02 10:40:20, PPPPPPPPPPPPPPP---PP--P- (75%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
int n;
vector <float> x;
vector <float> y;
float temp_x;
float temp_y;
float m;
float b;
string whattodo;
cin >> n >> whattodo;
float sum_x = 0;
float sum_y = 0;
float sum_xy = 0;
float sum_xx = 0;
for(int i = 0;i < n;i++){
cin >> temp_x >> temp_y;
sum_x+=temp_x;
sum_y+=temp_y;
sum_xx+=pow(temp_x,2);
sum_xy+=(temp_x*temp_y);
}
m = (n*sum_xy - sum_x*sum_y)/(n*sum_xx - pow(sum_x,2));
b = (sum_y - m*sum_x)/n;
if(whattodo == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(whattodo == "func"){
if(m == 1){
if(b < 0){
cout << "y = " << "x - " << round((b*-1)*1e3)/1e3;
}
else if(b > 0){
cout << "y = " << "x + " << round(b*1e3)/1e3;
}
else{
cout << "y = " << "x";
}
}
else if(m == -1){
if(b < 0){
cout << "y = " << "-x - " << round((b*-1)*1e3)/1e3;
}
else if(b > 0){
cout << "y = " << "-x + " << round(b*1e3)/1e3;
}
else{
cout << "y = " << "-x";
}
}
else{
if(b < 0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << round((b*-1)*1e3)/1e3;
}
else if(b > 0){
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
else{
cout << "y = " << round(m*1e3)/1e3 << "x";
}
}
}
} | # 0965, 2024-11-02 10:45:57, PPPPPPPPPPPPPPPP--PP-PP- (83%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
int n;
vector <float> x;
vector <float> y;
float temp_x;
float temp_y;
float m;
float b;
string whattodo;
cin >> n >> whattodo;
float sum_x = 0;
float sum_y = 0;
float sum_xy = 0;
float sum_xx = 0;
for(int i = 0;i < n;i++){
cin >> temp_x >> temp_y;
sum_x+=temp_x;
sum_y+=temp_y;
sum_xx+=pow(temp_x,2);
sum_xy+=(temp_x*temp_y);
}
m = (n*sum_xy - sum_x*sum_y)/(n*sum_xx - pow(sum_x,2));
b = (sum_y - m*sum_x)/n;
if(whattodo == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(whattodo == "func"){
if(m == 1){
if(b < 0){
cout << "y = " << "x - " << round((b*-1)*1e3)/1e3;
}
else if(b > 0){
cout << "y = " << "x + " << round(b*1e3)/1e3;
}
else{
cout << "y = " << "x";
}
}
else if(m == -1){
if(b < 0){
cout << "y = " << "-x - " << round((b*-1)*1e3)/1e3;
}
else if(b > 0){
cout << "y = " << "-x + " << round(b*1e3)/1e3;
}
else{
cout << "y = " << "-x";
}
}
else if(m == 0){
cout << "y = " << round((b)*1e3)/1e3;
}
else{
if(b < 0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << round((b*-1)*1e3)/1e3;
}
else if(b > 0){
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
else{
cout << "y = " << round(m*1e3)/1e3 << "x";
}
}
}
} |
# 0966, 2024-11-02 13:01:40, PPPPPPPPPPPPPPP--------- (62%)
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int N;
string command;
cin >> N >> command;
float x,y;
float sum_XY = 0, sum_X = 0, sum_Y = 0, sum_X2 = 0;
for (int i = 0; i < N; i++) {
cin >> x >> y;
sum_XY += x*y;
sum_X += x;
sum_Y += y;
sum_X2 += x*x;
}
float m = ((N * sum_XY) - (sum_X * sum_Y)) / ((N * sum_X2) - (sum_X * sum_X));
float b = (sum_Y - (m * sum_X)) / N;
if (command == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if (command == "func") {
cout << "y = ";
if (m == -1) {cout << '-x';}
if (m == 1) {cout << 'x';}
if (m == 0) {}
else {cout << round(m*1e3)/1e3 << 'x';}
if (m != 0 && b != 0) {
if (b > 0) {cout << " + " << abs(round(b*1e3)/1e3) << endl;}
if (b < 0) {cout << " - " << abs(round(b*1e3)/1e3) << endl;}
}
}
} | # 0967, 2024-11-02 13:04:30, PPPPPPPPPPPPPPPP-------- (66%)
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int N;
string command;
cin >> N >> command;
float x,y;
float sum_XY = 0, sum_X = 0, sum_Y = 0, sum_X2 = 0;
for (int i = 0; i < N; i++) {
cin >> x >> y;
sum_XY += x*y;
sum_X += x;
sum_Y += y;
sum_X2 += x*x;
}
float m = ((N * sum_XY) - (sum_X * sum_Y)) / ((N * sum_X2) - (sum_X * sum_X));
float b = (sum_Y - (m * sum_X)) / N;
if (command == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if (command == "func") {
cout << "y = ";
if (m == -1) {cout << "-x";}
if (m == 1) {cout << 'x';}
if (m == 0) {}
else {cout << round(m*1e3)/1e3 << 'x';}
if (m != 0) {
if (b > 0) {cout << " + " << abs(round(b*1e3)/1e3) << endl;}
else if (b < 0) {cout << " - " << abs(round(b*1e3)/1e3) << endl;}
} else if (m == 0) {cout << abs(round(b*1e3)/1e3) << endl;}
}
} | # 0968, 2024-11-02 13:09:35, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int N;
string command;
cin >> N >> command;
float x,y;
float sum_XY = 0, sum_X = 0, sum_Y = 0, sum_X2 = 0;
for (int i = 0; i < N; i++) {
cin >> x >> y;
sum_XY += x*y;
sum_X += x;
sum_Y += y;
sum_X2 += x*x;
}
float m = ((N * sum_XY) - (sum_X * sum_Y)) / ((N * sum_X2) - (sum_X * sum_X));
float b = (sum_Y - (m * sum_X)) / N;
if (command == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if (command == "func") {
cout << "y = ";
if (m == -1) {cout << "-x";}
else if (m == 1) {cout << 'x';}
else if (round(m*1e3)/1e3 != 0) {cout << round(m*1e3)/1e3 << 'x';}
if (round(m*1e3)/1e3 == 0) {cout << (round(b*1e3)/1e3) << endl;}
else {
if (b > 0) {cout << " + " << abs(round(b*1e3)/1e3) << endl;}
else if (b < 0) {cout << " - " << abs(round(b*1e3)/1e3) << endl;}
}
}
} | # 0969, 2024-11-02 13:11:20, PPPPPPPPPPPPPPP-P-PP-P-- (79%)
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int N;
string command;
cin >> N >> command;
float x,y;
float sum_XY = 0, sum_X = 0, sum_Y = 0, sum_X2 = 0;
for (int i = 0; i < N; i++) {
cin >> x >> y;
sum_XY += x*y;
sum_X += x;
sum_Y += y;
sum_X2 += x*x;
}
float m = ((N * sum_XY) - (sum_X * sum_Y)) / ((N * sum_X2) - (sum_X * sum_X));
float b = (sum_Y - (m * sum_X)) / N;
if (command == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if (command == "func") {
cout << "y = ";
if (m == -1) {cout << "-x";}
else if (m == 1) {cout << 'x';}
else if (round(m*1e3)/1e3 != 0) {cout << round(m*1e3)/1e3 << 'x';}
if (round(m*1e3)/1e3 == 0 && round(b*1e3)/1e3 != 0) {cout << (round(b*1e3)/1e3) << endl;}
else {
if (b > 0) {cout << " + " << abs(round(b*1e3)/1e3) << endl;}
else if (b < 0) {cout << " - " << abs(round(b*1e3)/1e3) << endl;}
}
}
} | # 0970, 2024-11-02 13:12:26, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int N;
string command;
cin >> N >> command;
float x,y;
float sum_XY = 0, sum_X = 0, sum_Y = 0, sum_X2 = 0;
for (int i = 0; i < N; i++) {
cin >> x >> y;
sum_XY += x*y;
sum_X += x;
sum_Y += y;
sum_X2 += x*x;
}
float m = ((N * sum_XY) - (sum_X * sum_Y)) / ((N * sum_X2) - (sum_X * sum_X));
float b = (sum_Y - (m * sum_X)) / N;
if (command == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if (command == "func") {
cout << "y = ";
if (m == -1) {cout << "-x";}
else if (m == 1) {cout << 'x';}
else if (round(m*1e3)/1e3 != 0) {cout << round(m*1e3)/1e3 << 'x';}
if (round(m*1e3)/1e3 == 0) {cout << (round(b*1e3)/1e3) << endl;}
else {
if (round(b*1e3) /1e3 > 0) {cout << " + " << abs(round(b*1e3)/1e3) << endl;}
else if (round(b*1e3)/1e3 < 0) {cout << " - " << abs(round(b*1e3)/1e3) << endl;}
}
}
} | # 0971, 2024-11-02 14:16:11, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int N;
string command;
cin >> N >> command;
float x,y;
float sum_XY = 0, sum_X = 0, sum_Y = 0, sum_X2 = 0;
for (int i = 0; i < N; i++) {
cin >> x >> y;
sum_XY += x*y;
sum_X += x;
sum_Y += y;
sum_X2 += x*x;
}
float m = ((N * sum_XY) - (sum_X * sum_Y)) / ((N * sum_X2) - (sum_X * sum_X));
float b = (sum_Y - (m * sum_X)) / N;
if (command == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if (command == "func") {
cout << "y = ";
if (m == -1) {cout << "-x";}
else if (m == 1) {cout << 'x';}
else if (round(m*1e3)/1e3 != 0) {cout << round(m*1e3)/1e3 << 'x';}
if (round(m*1e3)/1e3 == 0) {cout << (round(b*1e3)/1e3);}
else {
if (round(b*1e3)/1e3 > 0) {cout << " + " << abs(round(b*1e3)/1e3);}
else if (round(b*1e3)/1e3 < 0) {cout << " - " << abs(round(b*1e3)/1e3);}
}
} cout << endl;
} |
# 0972, 2024-11-02 10:51:16, PPPPPPPPPP-------------- (41%)
#include <bits/stdc++.h>
using namespace std;
int main(){
vector<pair<float,float>> allnum;
long long n;
cin >> n;
float nums1,nums2,m =0,b =0;
string wants;
cin >> wants;
for(int i = 0; i < n; i++){
cin >> nums1 >> nums2;
allnum.push_back(make_pair(nums1,nums2));
}
if(wants == "mb"){
float mup = 0,mu1=0,mu21=0,mu22=0;
float md = 0,md2 =0,md1=0;
for(int i = 0; i <=n -1; i++){
md2 += (allnum[i].first);
md1 += pow((allnum[i].first),2);
mu1 += ((allnum[i].first) * (allnum[i].second));
mu21 += (allnum[i].first);
mu22 += (allnum[i].second);
}
m = (n*(mu1) - (mu21*mu22))/((n*md1) - (pow(md2,2)));
b = ( mu22 - (m*mu21))/n;
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
} /*else if(wants == "func"){
}*/
} | # 0973, 2024-11-02 11:08:36, PPPPPPPPPPP-P--P--PP---- (62%)
#include <bits/stdc++.h>
using namespace std;
int main(){
vector<pair<float,float>> allnum;
long long n;
cin >> n;
float nums1,nums2,m =0,b =0;
string wants;
cin >> wants;
for(int i = 0; i < n; i++){
cin >> nums1 >> nums2;
allnum.push_back(make_pair(nums1,nums2));
}
if(wants == "mb"){
float mup = 0,mu1=0,mu21=0,mu22=0;
float md = 0,md2 =0,md1=0;
for(int i = 0; i <=n -1; i++){
md2 += (allnum[i].first);
md1 += pow((allnum[i].first),2);
mu1 += ((allnum[i].first) * (allnum[i].second));
mu21 += (allnum[i].first);
mu22 += (allnum[i].second);
}
m = (n*(mu1) - (mu21*mu22))/((n*md1) - (pow(md2,2)));
b = ( mu22 - (m*mu21))/n;
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
} else if(wants == "func"){
float mup = 0,mu1=0,mu21=0,mu22=0;
float md = 0,md2 =0,md1=0;
for(int i = 0; i <=n -1; i++){
md2 += (allnum[i].first);
md1 += pow((allnum[i].first),2);
mu1 += ((allnum[i].first) * (allnum[i].second));
mu21 += (allnum[i].first);
mu22 += (allnum[i].second);
}
m = (n*(mu1) - (mu21*mu22))/((n*md1) - (pow(md2,2)));
b = ( mu22 - (m*mu21))/n;
cout << "y = ";
if(m == -1) cout << "-x";
if(m == 1) cout << 'x';
if((m > 1|| m < -1 )) { cout << round(m*1e3)/1e3 << 'x';
if(b >0) cout << " + " << round(b*1e3)/1e3 ;
if(b < 0) cout << " - " << abs(round(m*1e3)/1e3 );
}
if(m ==0){
if(b >= 0) cout << round(m*1e3)/1e3 ;
if(b < 0) cout << round(m*1e3)/1e3 ;}
}
} | # 0974, 2024-11-02 11:13:45, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include <bits/stdc++.h>
using namespace std;
int main(){
vector<pair<float,float>> allnum;
long long n;
cin >> n;
float nums1,nums2,m =0,b =0;
string wants;
cin >> wants;
for(int i = 0; i < n; i++){
cin >> nums1 >> nums2;
allnum.push_back(make_pair(nums1,nums2));
}
if(wants == "mb"){
float mup = 0,mu1=0,mu21=0,mu22=0;
float md = 0,md2 =0,md1=0;
for(int i = 0; i <=n -1; i++){
md2 += (allnum[i].first);
md1 += pow((allnum[i].first),2);
mu1 += ((allnum[i].first) * (allnum[i].second));
mu21 += (allnum[i].first);
mu22 += (allnum[i].second);
}
m = (n*(mu1) - (mu21*mu22))/((n*md1) - (pow(md2,2)));
b = ( mu22 - (m*mu21))/n;
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
} else if(wants == "func"){
float mup = 0,mu1=0,mu21=0,mu22=0;
float md = 0,md2 =0,md1=0;
for(int i = 0; i <=n -1; i++){
md2 += (allnum[i].first);
md1 += pow((allnum[i].first),2);
mu1 += ((allnum[i].first) * (allnum[i].second));
mu21 += (allnum[i].first);
mu22 += (allnum[i].second);
}
m = (n*(mu1) - (mu21*mu22))/((n*md1) - (pow(md2,2)));
b = ( mu22 - (m*mu21))/n;
cout << "y = ";
if(m == -1) cout << "-x";
if(m == 1) cout << 'x';
if((m > 1|| m < -1 )) { cout << round(m*1e3)/1e3 << 'x';
if(b >0) cout << " + " << round(b*1e3)/1e3 ;
if(b < 0) cout << " - " << abs(round(b*1e3)/1e3 );
}
if(m ==0){
if(b >= 0) cout << round(b*1e3)/1e3 ;
if(b < 0) cout << round(b*1e3)/1e3 ;}
}
} | # 0975, 2024-11-02 11:18:18, PPPPPPPPPPPPPPPP--PP-PP- (83%)
#include <bits/stdc++.h>
using namespace std;
int main(){
vector<pair<float,float>> allnum;
long long n;
cin >> n;
float nums1,nums2,m =0,b =0;
string wants;
cin >> wants;
for(int i = 0; i < n; i++){
cin >> nums1 >> nums2;
allnum.push_back(make_pair(nums1,nums2));
}
if(wants == "mb"){
float mup = 0,mu1=0,mu21=0,mu22=0;
float md = 0,md2 =0,md1=0;
for(int i = 0; i <=n -1; i++){
md2 += (allnum[i].first);
md1 += pow((allnum[i].first),2);
mu1 += ((allnum[i].first) * (allnum[i].second));
mu21 += (allnum[i].first);
mu22 += (allnum[i].second);
}
m = (n*(mu1) - (mu21*mu22))/((n*md1) - (pow(md2,2)));
b = ( mu22 - (m*mu21))/n;
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
} else if(wants == "func"){
float mup = 0,mu1=0,mu21=0,mu22=0;
float md = 0,md2 =0,md1=0;
for(int i = 0; i <=n -1; i++){
md2 += (allnum[i].first);
md1 += pow((allnum[i].first),2);
mu1 += ((allnum[i].first) * (allnum[i].second));
mu21 += (allnum[i].first);
mu22 += (allnum[i].second);
}
m = (n*(mu1) - (mu21*mu22))/((n*md1) - (pow(md2,2)));
b = ( mu22 - (m*mu21))/n;
cout << "y = ";
if(m == -1) {cout << "-x";
if(b >0) cout << " + " << round(b*1e3)/1e3 ;
if(b < 0) cout << " - " << abs(round(b*1e3)/1e3 );};
if(m == 1) {cout << 'x';
if(b > 0) cout << " + " << round(b*1e3)/1e3 ;
if(b < 0) cout << " - " << abs(round(b*1e3)/1e3 );};
if((m > 1|| m < -1 )) { cout << round(m*1e3)/1e3 << 'x';
if(b >0) cout << " + " << round(b*1e3)/1e3 ;
if(b < 0) cout << " - " << abs(round(b*1e3)/1e3 );
}
if(m ==0){
if(b > 0) cout << round(b*1e3)/1e3 ;
if(b < 0) cout << round(b*1e3)/1e3 ;
if(b == 0) cout << b;}
}
} | # 0976, 2024-11-02 11:20:36, PPPPPPPPPPPPPPPP--PP-PP- (83%)
#include <bits/stdc++.h>
using namespace std;
int main(){
vector<pair<float,float>> allnum;
long long n;
cin >> n;
float nums1,nums2,m =0,b =0;
string wants;
cin >> wants;
for(int i = 0; i < n; i++){
cin >> nums1 >> nums2;
allnum.push_back(make_pair(nums1,nums2));
}
if(wants == "mb"){
float mup = 0,mu1=0,mu21=0,mu22=0;
float md = 0,md2 =0,md1=0;
for(int i = 0; i <=n -1; i++){
md2 += (allnum[i].first);
md1 += pow((allnum[i].first),2);
mu1 += ((allnum[i].first) * (allnum[i].second));
mu21 += (allnum[i].first);
mu22 += (allnum[i].second);
}
m = (n*(mu1) - (mu21*mu22))/((n*md1) - (pow(md2,2)));
b = ( mu22 - (m*mu21))/n;
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3;
} else if(wants == "func"){
float mup = 0,mu1=0,mu21=0,mu22=0;
float md = 0,md2 =0,md1=0;
for(int i = 0; i <=n -1; i++){
md2 += (allnum[i].first);
md1 += pow((allnum[i].first),2);
mu1 += ((allnum[i].first) * (allnum[i].second));
mu21 += (allnum[i].first);
mu22 += (allnum[i].second);
}
m = (n*(mu1) - (mu21*mu22))/((n*md1) - (pow(md2,2)));
b = ( mu22 - (m*mu21))/n;
cout << "y = ";
if(m == -1) {cout << "-x";
if(b >0) cout << " + " << round(b*1e3)/1e3 ;
if(b < 0) cout << " - " << abs(round(b*1e3)/1e3 );}
if(m == 1) {cout << 'x';
if(b > 0) cout << " + " << round(b*1e3)/1e3 ;
if(b < 0) cout << " - " << abs(round(b*1e3)/1e3 );}
if((m > 1|| m < -1 )) { cout << round(m*1e3)/1e3 << 'x';
if(b >0) cout << " + " << round(b*1e3)/1e3 ;
if(b < 0) cout << " - " << abs(round(b*1e3)/1e3 );
}
if(m ==0){
if(b > 0) cout << round(b*1e3)/1e3 ;
if(b < 0) cout << round(b*1e3)/1e3 ;
if(b == 0) cout << b;}
}
} |
# 0977, 2024-11-02 09:48:37, PPPPPPPPPP-------------- (41%)
#include<bits/stdc++.h>
using namespace std;
int main(){
float n, x, y, m, b, sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0; // float*
cin >> n;
string s;
cin >> s;
vector<pair<float, float>> v;
for(int i = 0; i < n; i++){
cin >> x >> y;
v.push_back(make_pair(x, y));
}
if(s == "mb"){
for(auto e : v){
sum1 += (e.first * e.second);
sum2 += (e.first);
sum3 += (e.second);
sum4 += (pow(e.first, 2));
}
m = ((n * sum1) - (sum2 * sum3)) / ((n * sum4) - (pow(sum2, 2)));
b = (sum3 - (m*sum2)) / n;
}
cout << round(m*1e3)/1e3 << '\n' << round(b*1e3)/1e3;
} | # 0978, 2024-11-02 10:02:05, PPPPPPPPPPP-P--P-----P-- (58%)
#include<bits/stdc++.h>
using namespace std;
int main(){
float n, x, y, m, b, sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0; // float*
cin >> n;
string s;
cin >> s;
vector<pair<float, float>> v;
for(int i = 0; i < n; i++){
cin >> x >> y;
v.push_back(make_pair(x, y));
}
for(auto e : v){
sum1 += (e.first * e.second);
sum2 += (e.first);
sum3 += (e.second);
sum4 += (pow(e.first, 2));
}
m = ((n * sum1) - (sum2 * sum3)) / ((n * sum4) - (pow(sum2, 2)));
b = (sum3 - (m*sum2)) / n;
if(s == "mb"){
// for(auto e : v){
// sum1 += (e.first * e.second);
// sum2 += (e.first);
// sum3 += (e.second);
// sum4 += (pow(e.first, 2));
// }
// m = ((n * sum1) - (sum2 * sum3)) / ((n * sum4) - (pow(sum2, 2)));
// b = (sum3 - (m*sum2)) / n;
cout << round(m*1e3)/1e3 << '\n' << round(b*1e3)/1e3;
}
else if(s == "func"){
if(m == 0 && b != 0){
cout << "y = " << round(b*1e3)/1e3;
}
else if(m == 1 && b > 0){
cout << "y = x + " << round(b*1e3)/1e3;
}
else if(m == 1 && b < 0){
cout << "y = x - " << round(b*1e3)/1e3 + (2*round(b*1e3)/1e3);
}
else if(m == 0 && b == 0){
cout << "y = 0";
}
else if(m > 1 && b > 0){
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
else if(m > 1 && b < 0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3 + (2*round(b*1e3)/1e3);
}
else if(m < 0 && b > 0){
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
else if(m < 0 && b < 0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3 + (2*round(b*1e3)/1e3);
}
}
} | # 0979, 2024-11-02 10:08:33, PPPPPPPPPPPPPPPP-----PP- (75%)
#include<bits/stdc++.h>
using namespace std;
int main(){
float n, x, y, m = 0, b = 0, sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0; // float*
cin >> n;
string s;
cin >> s;
vector<pair<float, float>> v;
for(int i = 0; i < n; i++){
cin >> x >> y;
v.push_back(make_pair(x, y));
}
for(auto e : v){
sum1 += (e.first * e.second);
sum2 += (e.first);
sum3 += (e.second);
sum4 += (pow(e.first, 2));
}
m = ((n * sum1) - (sum2 * sum3)) / ((n * sum4) - (pow(sum2, 2)));
b = (sum3 - (m*sum2)) / n;
if(s == "mb"){
// for(auto e : v){
// sum1 += (e.first * e.second);
// sum2 += (e.first);
// sum3 += (e.second);
// sum4 += (pow(e.first, 2));
// }
// m = ((n * sum1) - (sum2 * sum3)) / ((n * sum4) - (pow(sum2, 2)));
// b = (sum3 - (m*sum2)) / n;
cout << round(m*1e3)/1e3 << '\n' << round(b*1e3)/1e3;
}
else if(s == "func"){
if(m == 0 && b != 0){
cout << "y = " << round(b*1e3)/1e3;
}
else if(m == 1 && b > 0){
cout << "y = x + " << round(b*1e3)/1e3;
}
else if(m == 1 && b < 0){
cout << "y = x - " << round(b*1e3)/1e3 + (-2.0*round(b*1e3)/1e3);
}
else if(m == 0 && b == 0){
cout << "y = 0";
}
else if(m > 1 && b > 0){
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
else if(m > 1 && b < 0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3 + (-2.0*round(b*1e3)/1e3);
}
else if(m < 0 && b > 0){
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
else if(m < 0 && m != -1 && b < 0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3 + (-2.0*round(b*1e3)/1e3);
}
else if(m == -1 && b < 0){
cout << "y = " << "-x - " << round(b*1e3)/1e3 + (-2.0*round(b*1e3)/1e3);
}
}
} | # 0980, 2024-11-02 10:11:29, PPPPPPPPPPPPPPPP---P-PP- (79%)
#include<bits/stdc++.h>
using namespace std;
int main(){
float n, x, y, m = 0, b = 0, sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0; // float*
cin >> n;
string s;
cin >> s;
vector<pair<float, float>> v;
for(int i = 0; i < n; i++){
cin >> x >> y;
v.push_back(make_pair(x, y));
}
for(auto e : v){
sum1 += (e.first * e.second);
sum2 += (e.first);
sum3 += (e.second);
sum4 += (pow(e.first, 2));
}
m = ((n * sum1) - (sum2 * sum3)) / ((n * sum4) - (pow(sum2, 2)));
b = (sum3 - (m*sum2)) / n;
if(s == "mb"){
// for(auto e : v){
// sum1 += (e.first * e.second);
// sum2 += (e.first);
// sum3 += (e.second);
// sum4 += (pow(e.first, 2));
// }
// m = ((n * sum1) - (sum2 * sum3)) / ((n * sum4) - (pow(sum2, 2)));
// b = (sum3 - (m*sum2)) / n;
cout << round(m*1e3)/1e3 << '\n' << round(b*1e3)/1e3;
}
else if(s == "func"){
if(m == 0 && b != 0){
cout << "y = " << round(b*1e3)/1e3;
}
else if(m == 1 && b > 0){
cout << "y = x + " << round(b*1e3)/1e3;
}
else if(m == 1 && b < 0){
cout << "y = x - " << round(b*1e3)/1e3 + (-2.0*round(b*1e3)/1e3);
}
else if(m == 0 && b == 0){
cout << "y = 0";
}
else if(m > 1 && b > 0){
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
else if(m > 1 && b < 0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3 + (-2.0*round(b*1e3)/1e3);
}
else if(m < 0 && m != -1 && b > 0){
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
else if(m < 0 && m != -1 && b < 0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3 + (-2.0*round(b*1e3)/1e3);
}
else if(m == -1 && b < 0){
cout << "y = " << "-x - " << round(b*1e3)/1e3 + (-2.0*round(b*1e3)/1e3);
}
else if(m == -1 && b > 0){
cout << "y = " << "-x + " << round(b*1e3)/1e3;
}
else if(m == -1 && b == 0){
cout << "y = " << "-x";
}
}
} | # 0981, 2024-11-02 10:12:45, PPPPPPPPPPPPPPPP--PP-PP- (83%)
#include<bits/stdc++.h>
using namespace std;
int main(){
float n, x, y, m = 0, b = 0, sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0; // float*
cin >> n;
string s;
cin >> s;
vector<pair<float, float>> v;
for(int i = 0; i < n; i++){
cin >> x >> y;
v.push_back(make_pair(x, y));
}
for(auto e : v){
sum1 += (e.first * e.second);
sum2 += (e.first);
sum3 += (e.second);
sum4 += (pow(e.first, 2));
}
m = ((n * sum1) - (sum2 * sum3)) / ((n * sum4) - (pow(sum2, 2)));
b = (sum3 - (m*sum2)) / n;
if(s == "mb"){
// for(auto e : v){
// sum1 += (e.first * e.second);
// sum2 += (e.first);
// sum3 += (e.second);
// sum4 += (pow(e.first, 2));
// }
// m = ((n * sum1) - (sum2 * sum3)) / ((n * sum4) - (pow(sum2, 2)));
// b = (sum3 - (m*sum2)) / n;
cout << round(m*1e3)/1e3 << '\n' << round(b*1e3)/1e3;
}
else if(s == "func"){
if(m == 0 && b != 0){
cout << "y = " << round(b*1e3)/1e3;
}
else if(m == 1 && b > 0){
cout << "y = x + " << round(b*1e3)/1e3;
}
else if(m == 1 && b < 0){
cout << "y = x - " << round(b*1e3)/1e3 + (-2.0*round(b*1e3)/1e3);
}
else if(m == 1 && b == 0){
cout << "y = x";
}
else if(m == 0 && b == 0){
cout << "y = 0";
}
else if(m > 1 && b > 0){
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
else if(m > 1 && b < 0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3 + (-2.0*round(b*1e3)/1e3);
}
else if(m < 0 && m != -1 && b > 0){
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
else if(m < 0 && m != -1 && b < 0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << round(b*1e3)/1e3 + (-2.0*round(b*1e3)/1e3);
}
else if(m == -1 && b < 0){
cout << "y = " << "-x - " << round(b*1e3)/1e3 + (-2.0*round(b*1e3)/1e3);
}
else if(m == -1 && b > 0){
cout << "y = " << "-x + " << round(b*1e3)/1e3;
}
else if(m == -1 && b == 0){
cout << "y = " << "-x";
}
}
} |
# 0982, 2024-11-02 10:06:36, PPPPPPPPPPPPPPP--P-PP-PP (83%)
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
float fpow(float a, int b) {
float sum = 1;
for (int i = 1; i <= b; i++) {
sum *= a;
}
return sum;
}
float sigmaXY(vector<pair<float,float>> data, int n) {
float sum = 0;
for (int i = 0; i < n; i++) {
sum += data[i].first * data[i].second;
}
return sum;
}
float sigmaX(vector<pair<float,float>> data, int n) {
float sum = 0;
for (int i = 0; i < n; i++) {
sum += data[i].first;
}
return sum;
}
float sigmaX2(vector<pair<float,float>> data, int n) {
float sum = 0;
for (int i = 0; i < n; i++) {
sum += fpow(data[i].first, 2);
}
return sum;
}
float sigmaY(vector<pair<float,float>> data, int n) {
float sum = 0;
for (int i = 0; i < n; i++) {
sum += data[i].second;
}
return sum;
}
int main() {
int n; string cm; cin >> n >> cm;
vector<pair<float,float>> data;
for (int i = 0; i < n; i++) {
float x, y; cin >> x >> y;
data.push_back(make_pair(x, y));
}
float m, b;
float m_top = (n*sigmaXY(data, n)) - (sigmaX(data, n)*sigmaY(data, n));
float m_bot = (n*sigmaX2(data, n)) - (fpow(sigmaX(data, n), 2));
m = m_top / m_bot;
float b_top = (sigmaY(data, n)) - (m*(sigmaX(data, n)));
b = b_top / float(n);
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (cm == "mb") {
cout << m << endl << b;
}
else {
cout << "y = ";
if (m == 1) cout << "";
else if (m == -1) cout << "-";
else cout << m;
cout << "x";
if (b == 0 && m == 1) cout << b;
else if (b == 0) cout << "";
else if (b < 0) cout << " - " << -b;
else cout << " + " << b;
}
} | # 0983, 2024-11-02 12:06:37, PPPPPPPPPPPPPPP--P-PP-PP (83%)
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
float fpow(float a, long b) {
float sum = 1;
for (long i = 1; i <= b; i++) {
sum *= a;
}
return sum;
}
float sigmaXY(vector<pair<float,float>> data, long n) {
float sum = 0;
for (long i = 0; i < n; i++) {
sum += data[i].first * data[i].second;
}
return sum;
}
float sigmaX(vector<pair<float,float>> data, long n) {
float sum = 0;
for (long i = 0; i < n; i++) {
sum += data[i].first;
}
return sum;
}
float sigmaX2(vector<pair<float,float>> data, long n) {
float sum = 0;
for (long i = 0; i < n; i++) {
sum += fpow(data[i].first, 2);
}
return sum;
}
float sigmaY(vector<pair<float,float>> data, long n) {
float sum = 0;
for (long i = 0; i < n; i++) {
sum += data[i].second;
}
return sum;
}
int main() {
long n; string cm; cin >> n >> cm;
vector<pair<float,float>> data;
for (long i = 0; i < n; i++) {
float x, y; cin >> x >> y;
data.push_back(make_pair(x, y));
}
float m, b;
float m_top = (n*sigmaXY(data, n)) - (sigmaX(data, n)*sigmaY(data, n));
float m_bot = (n*sigmaX2(data, n)) - (fpow(sigmaX(data, n), 2));
m = m_top / m_bot;
float b_top = (sigmaY(data, n)) - (m*(sigmaX(data, n)));
b = b_top / float(n);
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (cm == "mb") {
cout << m << endl << b;
}
else {
cout << "y = ";
if (m == 1) cout << "";
else if (m == -1) cout << "-";
else cout << m;
cout << "x";
if (b == 0 && m == 1) cout << b;
else if (b == 0) cout << "";
else if (b < 0) cout << " - " << -b;
else cout << " + " << b;
}
} | # 0984, 2024-11-02 12:10:12, PPPPPPPPPPPPPPP--P--P-PP (79%)
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
float fpow(float a, long b) {
float sum = 1;
for (long i = 1; i <= b; i++) {
sum *= a;
}
return sum;
}
float sigmaXY(vector<pair<float,float>> data, long n) {
float sum = 0;
for (long i = 0; i < n; i++) {
sum += data[i].first * data[i].second;
}
return sum;
}
float sigmaX(vector<pair<float,float>> data, long n) {
float sum = 0;
for (long i = 0; i < n; i++) {
sum += data[i].first;
}
return sum;
}
float sigmaX2(vector<pair<float,float>> data, long n) {
float sum = 0;
for (long i = 0; i < n; i++) {
sum += fpow(data[i].first, 2);
}
return sum;
}
float sigmaY(vector<pair<float,float>> data, long n) {
float sum = 0;
for (long i = 0; i < n; i++) {
sum += data[i].second;
}
return sum;
}
int main() {
long n; string cm; cin >> n >> cm;
vector<pair<float,float>> data;
for (long i = 0; i < n; i++) {
float x, y; cin >> x >> y;
data.push_back(make_pair(x, y));
}
float m, b;
float m_top = (n*sigmaXY(data, n)) - (sigmaX(data, n)*sigmaY(data, n));
float m_bot = (n*sigmaX2(data, n)) - (fpow(sigmaX(data, n), 2));
m = m_top / m_bot;
float b_top = (sigmaY(data, n)) - (m*(sigmaX(data, n)));
b = b_top / float(n);
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if (cm == "mb") {
cout << m << endl << b;
}
else {
cout << "y = ";
if (m == 1) cout << "";
else if (m == -1) cout << "-";
else cout << m;
cout << "x";
if ((b == 0 && m == 1 )|| (b == 0 && m == -1 )) cout << b;
else if (b == 0) cout << "";
else if (b < 0) cout << " - " << -b;
else cout << " + " << b;
}
} |
# 0985, 2024-11-02 10:20:26, PPPPPPPPPPPPPPPP--PP---- (75%)
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
using namespace std;
int main(){
string str;
int n;
float x,y;
int i;
vector<pair<float,float>> vec;
cin >> n >> str;
for(i=0;i<n;i++){
cin >> x >> y;
vec.push_back({x,y});
}
float M,B;
float a=0,b=0,c=0,d=0,e=0;
for(i=0;i<=n-1;i++){
a += vec[i].first*vec[i].second;
b += vec[i].first;
c += vec[i].second;
d += vec[i].first*vec[i].first;
e += vec[i].first;
}
a *= n;
d *= n;
e *= e;
// find m
M = (a-(b*c))/(d-e);
// find b
B = (c-(M*b))/n;
if(str == "mb"){
cout << round(M*1e3)/1e3 << endl;
cout << round(B*1e3)/1e3 << endl;
}
else if(str == "func"){
cout << "y = ";
if(M == 0 && B == 0){
cout << "0";
return 0;
}
if(M == 1) cout << "x";
else if(M == -1) cout << "-x";
else cout << round(M*1e3)/1e3 << "x";
if(B > 0) cout << " + " << round(B*1e3)/1e3;
else if(B < 0) cout << " - " << round((B*(-1.0))*1e3)/1e3;
}
return 0;
} | # 0986, 2024-11-02 10:31:27, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
using namespace std;
int main(){
string str;
int n;
float x,y;
int i;
vector<pair<float,float>> vec;
cin >> n >> str;
for(i=0;i<n;i++){
cin >> x >> y;
vec.push_back({x,y});
}
float M,B;
float a=0,b=0,c=0,d=0,e=0;
for(i=0;i<=n-1;i++){
a += vec[i].first*vec[i].second;
b += vec[i].first;
c += vec[i].second;
d += vec[i].first*vec[i].first;
e += vec[i].first;
}
a *= n;
d *= n;
e *= e;
// find m
M = (a-(b*c))/(d-e);
// find b
B = (c-(M*b))/n;
if(round(M*1e3)/1e3 == -0) M = 0;
if(round(B*1e3)/1e3 == -0) B = 0;
// cout << round(M*1e3)/1e3 << endl;
// cout << round(B*1e3)/1e3 << endl;
if(str == "mb"){
cout << round(M*1e3)/1e3 << endl;
cout << round(B*1e3)/1e3 << endl;
}
else if(str == "func"){
cout << "y = ";
if(M == 0 && B == 0){
cout << "0";
return 0;
}
bool checkM = 0;
if(M == 1){
cout << "x";
checkM = 1;
}
else if(M == -1){
cout << "-x";
checkM = 1;
}
else if(M != 0){
cout << round(M*1e3)/1e3 << "x";
checkM = 1;
}
if(!checkM){
if(B > 0 || B < 0) cout << round(B*1e3)/1e3;
}
else{
if(B > 0) cout << " + " << round(B*1e3)/1e3;
else if(B < 0) cout << " - " << round((B*(-1.0))*1e3)/1e3;
}
}
return 0;
} |
# 0987, 2024-11-02 10:39:14, PPPPPPPPPPPPPPPPP-PP-P-- (83%)
#include <bits/stdc++.h>
using namespace std;
bool ck;
int main()
{
int n;
string cmd;
cin >> n >> cmd;
float x[n], y[n],tmp;
for (int i = 1; i <= n; i++)
{
cin >> x[i] >> y[i];
}
tmp = y[1];
float m, m1 = 0, m2 = 0, m3 = 0, m5 = 0;
for (int i = 1; i <= n; i++)
{
m1 += (x[i] * y[i]);
m2 += x[i];
m5 += y[i];
m3 += x[i] * x[i];
}
m = ((n * m1) - (m2 * m5)) / ((m3 * n) - (m2 * m2));
float b1 = 0, b2 = 0, b;
for (int i = 1; i <= n; i++)
{
b1 += y[i];
b2 += x[i];
}
b = (b1 - (b2 * m)) / n;
for (int i = 1 ; i<=n;i++)
{
if (tmp != y[i])
{
ck = false;
break;
}
else ck =true;
}
if (cmd == "mb") cout << round(m * 1e3) / 1e3 << endl<< round(b * 1e3) / 1e3;
else
{
cout <<"y = ";
if (ck) cout <<round(tmp * 1e3) / 1e3;
else if (m==0.0 &&b==0.0) cout<<"0";
else if (m==0.0 && b!= 0.0) cout <<round(b * 1e3) / 1e3;
else if (m==1.0&&b==0.0) cout <<"x";
else if (m==1.0&&b>1.0) cout <<"x + "<<round(b * 1e3) / 1e3;
else if (m==1.0&&b<0.0) cout <<"x - "<<abs(round(b * 1e3) / 1e3);
else if (m==-1.0&&b==0.0) cout <<"-x";
else if (m==-1.0&&b>1.0) cout <<"-x + "<<round(b * 1e3) / 1e3;
else if (m==-1.0&&b<0.0) cout <<"-x - "<<abs(round(b * 1e3) / 1e3);
else if ((m!=1.0||m!=-1.0)&&b==0.0) cout <<round(m * 1e3) / 1e3<<"x";
else if ((m!=1.0||m!=-1.0)&&b>1.0) cout <<round(m * 1e3) / 1e3<<"x + "<<round(b * 1e3) / 1e3;
else if ((m!=1.0||m!=-1.0)&&b<1.0) cout <<round(m * 1e3) / 1e3<<"x - "<<abs(round(b * 1e3) / 1e3);
}
} |
# 0988, 2024-11-02 10:06:47, -----PPPPP-------------- (20%)
#include<bits/stdc++.h>
using namespace std;
float m(vector<float> x, vector<float> y,int n){
float a=0, b=0, c=0, d=0, e=0;
for(int i = 0; i < n; ++i){
a += x[i]*y[i];
b += x[i];
c += y[i];
d += x[i]*x[i];
}
e = ((n*a) - (b*c))/((n*d)-(b*b));
return e;
}
float b(vector<float> x, vector<float> y, int n){
float a=0,b=0, c;
for(int i = 0; i < n; ++i){
a += y[i];
b += x[i];
}
c = (a - (m(x, y, n)* b))/n;
return c;
}
int main(){
int n;
string type_of_output;
cin >> n >> type_of_output;
vector<float> x;
vector<float> y;
float a, c;
for(int i = 0; i < n; ++i){
cin >> a >> c;
x.push_back(a);
y.push_back(c);
}
if(type_of_output == "mb"){
cout << m(x, y, n) << endl;
cout << b(x, y, n) << endl;
}else if(type_of_output == "func"){
cout << "y = " << m(x, y, n)<< "x" << b(x, y, n);
}
} | # 0989, 2024-11-02 10:09:37, PPPPPPPPPP-------------- (41%)
#include<bits/stdc++.h>
using namespace std;
float m(vector<float> x, vector<float> y,int n){
float a=0, b=0, c=0, d=0, e=0;
for(int i = 0; i < n; ++i){
a += x[i]*y[i];
b += x[i];
c += y[i];
d += x[i]*x[i];
}
e = ((n*a) - (b*c))/((n*d)-(b*b));
return e;
}
float b(vector<float> x, vector<float> y, int n){
float a=0,b=0, c;
for(int i = 0; i < n; ++i){
a += y[i];
b += x[i];
}
c = (a - (m(x, y, n)* b))/n;
return c;
}
int main(){
int n;
string type_of_output;
cin >> n >> type_of_output;
vector<float> x;
vector<float> y;
float a, c;
for(int i = 0; i < n; ++i){
cin >> a >> c;
x.push_back(a);
y.push_back(c);
}
float m1 = m(x, y, n);
float b1 = b(x, y, n);
if(type_of_output == "mb"){
cout << round(m1*1e3)/1e3<< endl;
cout << round(b1*1e3)/1e3 << endl;
}else if(type_of_output == "func"){
cout << "y = " << round(m1*1e3)/1e3 << "x" << round(b1*1e3)/1e3;
}
} | # 0990, 2024-11-02 10:13:55, PPPPPPPPPP-----P-----P-- (50%)
#include<bits/stdc++.h>
using namespace std;
float m(vector<float> x, vector<float> y,int n){
float a=0, b=0, c=0, d=0, e=0;
for(int i = 0; i < n; ++i){
a += x[i]*y[i];
b += x[i];
c += y[i];
d += x[i]*x[i];
}
e = ((n*a) - (b*c))/((n*d)-(b*b));
return e;
}
float b(vector<float> x, vector<float> y, int n){
float a=0,b=0, c;
for(int i = 0; i < n; ++i){
a += y[i];
b += x[i];
}
c = (a - (m(x, y, n)* b))/n;
return c;
}
int main(){
int n;
string type_of_output;
cin >> n >> type_of_output;
vector<float> x;
vector<float> y;
float a, c;
for(int i = 0; i < n; ++i){
cin >> a >> c;
x.push_back(a);
y.push_back(c);
}
float m1 = m(x, y, n);
float b1 = b(x, y, n);
if(type_of_output == "mb"){
cout << round(m1*1e3)/1e3<< endl;
cout << round(b1*1e3)/1e3 << endl;
}else if(type_of_output == "func"){
if(m1 == 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(b1 == 0){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1){
cout << "y = " << "x" << round(b1*1e3)/1e3;
}else if(m1 = -1){
cout << "y = " << "-x" << round(b1*1e3)/1e3;
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x" << round(b1*1e3)/1e3;
}
}
} | # 0991, 2024-11-02 10:16:51, PPPPPPPPPP-----P-----P-- (50%)
#include<bits/stdc++.h>
using namespace std;
float m(vector<float> x, vector<float> y,int n){
float a=0, b=0, c=0, d=0, e=0;
for(int i = 0; i < n; ++i){
a += x[i]*y[i];
b += x[i];
c += y[i];
d += x[i]*x[i];
}
e = ((n*a) - (b*c))/((n*d)-(b*b));
return e;
}
float b(vector<float> x, vector<float> y, int n){
float a=0,b=0, c;
for(int i = 0; i < n; ++i){
a += y[i];
b += x[i];
}
c = (a - (m(x, y, n)* b))/n;
return c;
}
int main(){
int n;
string type_of_output;
cin >> n >> type_of_output;
vector<float> x;
vector<float> y;
float a, c;
for(int i = 0; i < n; ++i){
cin >> a >> c;
x.push_back(a);
y.push_back(c);
}
float m1 = m(x, y, n);
float b1 = b(x, y, n);
if(type_of_output == "mb"){
cout << round(m1*1e3)/1e3<< endl;
cout << round(b1*1e3)/1e3 << endl;
}else if(type_of_output == "func"){
if(m1 == 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(b1 == 0){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1){
cout << "y = " << "x" << round(b1*1e3)/1e3;
}else if(m1 == -1){
cout << "y = " << "-x" << round(b1*1e3)/1e3;
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x" << round(b1*1e3)/1e3;
}
}
} | # 0992, 2024-11-02 10:18:34, PPPPPPPPPP-----P-----P-- (50%)
#include<bits/stdc++.h>
using namespace std;
float m(vector<float> x, vector<float> y,int n){
float a=0, b=0, c=0, d=0, e=0;
for(int i = 0; i < n; ++i){
a += x[i]*y[i];
b += x[i];
c += y[i];
d += x[i]*x[i];
}
e = ((n*a) - (b*c))/((n*d)-(b*b));
return e;
}
float b(vector<float> x, vector<float> y, int n){
float a=0,b=0, c;
for(int i = 0; i < n; ++i){
a += y[i];
b += x[i];
}
c = (a - (m(x, y, n)* b))/n;
return c;
}
int main(){
int n;
string type_of_output;
cin >> n >> type_of_output;
vector<float> x;
vector<float> y;
float a, c;
for(int i = 0; i < n; ++i){
cin >> a >> c;
x.push_back(a);
y.push_back(c);
}
float m1 = m(x, y, n);
float b1 = b(x, y, n);
if(type_of_output == "mb"){
cout << round(m1*1e3)/1e3<< endl;
cout << round(b1*1e3)/1e3 << endl;
}else if(type_of_output == "func"){
if(m1 == 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(b1 == 0){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1){
cout << "y = " << "x" << round(b1*1e3)/1e3;
}else if(m1 == -1){
cout << "y = " << "-x" << round(b1*1e3)/1e3;
}else if(m1 == 0 && b1 ==0){
cout << "y = 0";
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x" << round(b1*1e3)/1e3;
}
}
} | # 0993, 2024-11-02 10:20:13, PPPPPPPPPP-----P-----P-- (50%)
#include<bits/stdc++.h>
using namespace std;
float m(vector<float> x, vector<float> y,int n){
float a=0, b=0, c=0, d=0, e=0;
for(int i = 0; i < n; ++i){
a += x[i]*y[i];
b += x[i];
c += y[i];
d += x[i]*x[i];
}
e = ((n*a) - (b*c))/((n*d)-(b*b));
return e;
}
float b(vector<float> x, vector<float> y, int n){
float a=0,b=0, c;
for(int i = 0; i < n; ++i){
a += y[i];
b += x[i];
}
c = (a - (m(x, y, n)* b))/n;
return c;
}
int main(){
int n;
string type_of_output;
cin >> n >> type_of_output;
vector<float> x;
vector<float> y;
float a, c;
for(int i = 0; i < n; ++i){
cin >> a >> c;
x.push_back(a);
y.push_back(c);
}
float m1 = m(x, y, n);
float b1 = b(x, y, n);
if(type_of_output == "mb"){
cout << round(m1*1e3)/1e3<< endl;
cout << round(b1*1e3)/1e3 << endl;
}else if(type_of_output == "func"){
if(m1 == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == 0 && b1 ==0){
cout << "y = 0";
}else if(b1 == 0){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1){
cout << "y = " << "x" << round(b1*1e3)/1e3;
}else if(m1 == -1){
cout << "y = " << "-x" << round(b1*1e3)/1e3;
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x" << round(b1*1e3)/1e3;
}
}
} | # 0994, 2024-11-02 10:24:14, PPPPPPPPPPP-P--P-----P-- (58%)
#include<bits/stdc++.h>
using namespace std;
float m(vector<float> x, vector<float> y,int n){
float a=0, b=0, c=0, d=0, e=0;
for(int i = 0; i < n; ++i){
a += x[i]*y[i];
b += x[i];
c += y[i];
d += x[i]*x[i];
}
e = ((n*a) - (b*c))/((n*d)-(b*b));
return e;
}
float b(vector<float> x, vector<float> y, int n){
float a=0,b=0, c;
for(int i = 0; i < n; ++i){
a += y[i];
b += x[i];
}
c = (a - (m(x, y, n)* b))/n;
return c;
}
int main(){
int n;
string type_of_output;
cin >> n >> type_of_output;
vector<float> x;
vector<float> y;
float a, c;
for(int i = 0; i < n; ++i){
cin >> a >> c;
x.push_back(a);
y.push_back(c);
}
float m1 = m(x, y, n);
float b1 = b(x, y, n);
if(type_of_output == "mb"){
cout << round(m1*1e3)/1e3<< endl;
cout << round(b1*1e3)/1e3 << endl;
}else if(type_of_output == "func"){
if(b1 >=0){
if(m1 == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == 0 && b1 ==0){
cout << "y = 0";
}else if(b1 == 0 && m1 != 1){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1){
cout << "y = " << "x + " << round(b1*1e3)/1e3;
}else if(m1 == -1){
cout << "y = " << "-x + " << round(b1*1e3)/1e3;
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x + " << round(b1*1e3)/1e3;
}
}else if(b1 < 0){
if(m1 == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == 0 && b1 ==0){
cout << "y = 0";
}else if(b1 == 0 && m1 != 1){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1){
cout << "y = " << "x" << round(b1*1e3)/1e3;
}else if(m1 == -1){
cout << "y = " << "-x" << round(b1*1e3)/1e3;
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x" << round(b1*1e3)/1e3;
}
}
}
} | # 0995, 2024-11-02 10:29:38, PPPPPPPPPPPPPPPP-----P-- (70%)
#include<bits/stdc++.h>
using namespace std;
float m(vector<float> x, vector<float> y,int n){
float a=0, b=0, c=0, d=0, e=0;
for(int i = 0; i < n; ++i){
a += x[i]*y[i];
b += x[i];
c += y[i];
d += x[i]*x[i];
}
e = ((n*a) - (b*c))/((n*d)-(b*b));
return e;
}
float b(vector<float> x, vector<float> y, int n){
float a=0,b=0, c;
for(int i = 0; i < n; ++i){
a += y[i];
b += x[i];
}
c = (a - (m(x, y, n)* b))/n;
return c;
}
int main(){
int n;
string type_of_output;
cin >> n >> type_of_output;
vector<float> x;
vector<float> y;
float a, c;
for(int i = 0; i < n; ++i){
cin >> a >> c;
x.push_back(a);
y.push_back(c);
}
float m1 = m(x, y, n);
float b1 = b(x, y, n);
if(type_of_output == "mb"){
cout << round(m1*1e3)/1e3<< endl;
cout << round(b1*1e3)/1e3 << endl;
}else if(type_of_output == "func"){
if(b1 >=0){
if(m1 == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == 0 && b1 ==0){
cout << "y = 0";
}else if(b1 == 0 && m1 != 1){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1){
cout << "y = " << "x + " << round(b1*1e3)/1e3;
}else if(m1 == -1){
cout << "y = " << "-x + " << round(b1*1e3)/1e3;
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x + " << round(b1*1e3)/1e3;
}
}else if(b1 < 0){
if(m1 == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == 0 && b1 ==0){
cout << "y = 0";
}else if(b1 == 0 && m1 != 1){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1){
cout << "y = " << "x - " << -1*(round(b1*1e3)/1e3);
}else if(m1 == -1){
cout << "y = " << "-x" << round(b1*1e3)/1e3;
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x - " << -1*(round(b1*1e3)/1e3);
}
}
}
} | # 0996, 2024-11-02 10:31:00, PPPPPPPPPPPPPPPP-----P-- (70%)
#include<bits/stdc++.h>
using namespace std;
float m(vector<float> x, vector<float> y,int n){
float a=0, b=0, c=0, d=0, e=0;
for(int i = 0; i < n; ++i){
a += x[i]*y[i];
b += x[i];
c += y[i];
d += x[i]*x[i];
}
e = ((n*a) - (b*c))/((n*d)-(b*b));
return e;
}
float b(vector<float> x, vector<float> y, int n){
float a=0,b=0, c;
for(int i = 0; i < n; ++i){
a += y[i];
b += x[i];
}
c = (a - (m(x, y, n)* b))/n;
return c;
}
int main(){
int n;
string type_of_output;
cin >> n >> type_of_output;
vector<float> x;
vector<float> y;
float a, c;
for(int i = 0; i < n; ++i){
cin >> a >> c;
x.push_back(a);
y.push_back(c);
}
float m1 = m(x, y, n);
float b1 = b(x, y, n);
if(type_of_output == "mb"){
cout << round(m1*1e3)/1e3<< endl;
cout << round(b1*1e3)/1e3 << endl;
}else if(type_of_output == "func"){
if(b1 >=0){
if(m1 == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == 0 && b1 ==0){
cout << "y = 0";
}else if(b1 == 0 && m1 != 1){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1){
cout << "y = " << "x + " << round(b1*1e3)/1e3;
}else if(m1 == -1){
cout << "y = " << "-x + " << round(b1*1e3)/1e3;
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x + " << round(b1*1e3)/1e3;
}
}else if(b1 < 0){
if(m1 == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == 0 && b1 ==0){
cout << "y = 0";
}else if(b1 == 0 && m1 != 1){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1){
cout << "y = " << "x - " << -1*(round(b1*1e3)/1e3);
}else if(m1 == -1){
cout << "y = " << "-x - " << -1*(round(b1*1e3)/1e3);
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x - " << -1*(round(b1*1e3)/1e3);
}
}
}
} | # 0997, 2024-11-02 10:34:11, PPPPPPPPPPPPPPPP---P-P-- (75%)
#include<bits/stdc++.h>
using namespace std;
float m(vector<float> x, vector<float> y,int n){
float a=0, b=0, c=0, d=0, e=0;
for(int i = 0; i < n; ++i){
a += x[i]*y[i];
b += x[i];
c += y[i];
d += x[i]*x[i];
}
e = ((n*a) - (b*c))/((n*d)-(b*b));
return e;
}
float b(vector<float> x, vector<float> y, int n){
float a=0,b=0, c;
for(int i = 0; i < n; ++i){
a += y[i];
b += x[i];
}
c = (a - (m(x, y, n)* b))/n;
return c;
}
int main(){
int n;
string type_of_output;
cin >> n >> type_of_output;
vector<float> x;
vector<float> y;
float a, c;
for(int i = 0; i < n; ++i){
cin >> a >> c;
x.push_back(a);
y.push_back(c);
}
float m1 = m(x, y, n);
float b1 = b(x, y, n);
if(type_of_output == "mb"){
cout << round(m1*1e3)/1e3<< endl;
cout << round(b1*1e3)/1e3 << endl;
}else if(type_of_output == "func"){
if(b1 >=0){
if(m1 == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == 0 && b1 ==0){
cout << "y = 0";
}else if(b1 == 0 && m1 != 1 && m1 != -1){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1){
cout << "y = " << "x + " << round(b1*1e3)/1e3;
}else if(m1 == -1 && b1 ==0){
cout << "y = " << "-x" ;
}else if(m1 == -1){
cout << "y = " << "-x + " << round(b1*1e3)/1e3;
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x + " << round(b1*1e3)/1e3;
}
}else if(b1 < 0){
if(m1 == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == 0 && b1 ==0){
cout << "y = 0";
}else if(b1 == 0 && m1 != 1){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1){
cout << "y = " << "x - " << -1*(round(b1*1e3)/1e3);
}else if(m1 == -1){
cout << "y = " << "-x - " << -1*(round(b1*1e3)/1e3);
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x - " << -1*(round(b1*1e3)/1e3);
}
}
}
} | # 0998, 2024-11-02 10:35:43, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
float m(vector<float> x, vector<float> y,int n){
float a=0, b=0, c=0, d=0, e=0;
for(int i = 0; i < n; ++i){
a += x[i]*y[i];
b += x[i];
c += y[i];
d += x[i]*x[i];
}
e = ((n*a) - (b*c))/((n*d)-(b*b));
return e;
}
float b(vector<float> x, vector<float> y, int n){
float a=0,b=0, c;
for(int i = 0; i < n; ++i){
a += y[i];
b += x[i];
}
c = (a - (m(x, y, n)* b))/n;
return c;
}
int main(){
int n;
string type_of_output;
cin >> n >> type_of_output;
vector<float> x;
vector<float> y;
float a, c;
for(int i = 0; i < n; ++i){
cin >> a >> c;
x.push_back(a);
y.push_back(c);
}
float m1 = m(x, y, n);
float b1 = b(x, y, n);
if(type_of_output == "mb"){
cout << round(m1*1e3)/1e3<< endl;
cout << round(b1*1e3)/1e3 << endl;
}else if(type_of_output == "func"){
if(b1 >=0){
if(m1 == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == 0 && b1 ==0){
cout << "y = 0";
}else if(b1 == 0 && m1 != 1 && m1 != -1){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1 && b1 ==0){
cout << "y = " << "x";
}else if(m1 == 1){
cout << "y = " << "x + " << round(b1*1e3)/1e3;
}else if(m1 == -1 && b1 ==0){
cout << "y = " << "-x" ;
}else if(m1 == -1){
cout << "y = " << "-x + " << round(b1*1e3)/1e3;
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x + " << round(b1*1e3)/1e3;
}
}else if(b1 < 0){
if(m1 == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == 0 && b1 ==0){
cout << "y = 0";
}else if(b1 == 0 && m1 != 1){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1){
cout << "y = " << "x - " << -1*(round(b1*1e3)/1e3);
}else if(m1 == -1){
cout << "y = " << "-x - " << -1*(round(b1*1e3)/1e3);
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x - " << -1*(round(b1*1e3)/1e3);
}
}
}
} | # 0999, 2024-11-02 10:44:49, -----P--PP-----PP----P-- (25%)
#include<bits/stdc++.h>
using namespace std;
float m(vector<float> x, vector<float> y,int n){
float a=0, b=0, c=0, d=0, e=0;
for(int i = 0; i < n; ++i){
a += x[i]*y[i];
b += x[i];
c += y[i];
d += x[i]*x[i];
}
e = ((n*a) - (b*c))/((n*d)-(b*b));
return e;
}
float b(vector<float> x, vector<float> y, int n){
float a=0,b=0, c;
for(int i = 0; i < n; ++i){
a += y[i];
b += x[i];
}
c = (a - (m(x, y, n)* b))/n;
return c;
}
int main(){
int n;
string type_of_output;
cin >> n >> type_of_output;
vector<float> x;
vector<float> y;
float a, c;
for(int i = 0; i < n; ++i){
cin >> a >> c;
x.push_back(a);
y.push_back(c);
}
float m1 = m(x, y, n);
float b1 = b(x, y, n);
if(m1 = -4.16452e-07){
m1 =0;
}
if(type_of_output == "mb"){
cout << round(m1*1e3)/1e3<< endl;
cout << round(b1*1e3)/1e3 << endl;
}else if(type_of_output == "func"){
if(b1 >=0){
if(m1 == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == -0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == 0 && b1 ==0){
cout << "y = 0";
}else if(b1 == 0 && m1 != 1 && m1 != -1){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1 && b1 ==0){
cout << "y = " << "x";
}else if(m1 == 1){
cout << "y = " << "x + " << round(b1*1e3)/1e3;
}else if(m1 == -1 && b1 ==0){
cout << "y = " << "-x" ;
}else if(m1 == -1){
cout << "y = " << "-x + " << round(b1*1e3)/1e3;
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x + " << round(b1*1e3)/1e3;
}
}else if(b1 < 0){
if(m1 == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == 0 && b1 ==0){
cout << "y = 0";
}else if(b1 == 0 && m1 != 1){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1){
cout << "y = " << "x - " << -1*(round(b1*1e3)/1e3);
}else if(m1 == -1){
cout << "y = " << "-x - " << -1*(round(b1*1e3)/1e3);
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x - " << -1*(round(b1*1e3)/1e3);
}
}
}
} | # 1000, 2024-11-02 10:45:50, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
float m(vector<float> x, vector<float> y,int n){
float a=0, b=0, c=0, d=0, e=0;
for(int i = 0; i < n; ++i){
a += x[i]*y[i];
b += x[i];
c += y[i];
d += x[i]*x[i];
}
e = ((n*a) - (b*c))/((n*d)-(b*b));
return e;
}
float b(vector<float> x, vector<float> y, int n){
float a=0,b=0, c;
for(int i = 0; i < n; ++i){
a += y[i];
b += x[i];
}
c = (a - (m(x, y, n)* b))/n;
return c;
}
int main(){
int n;
string type_of_output;
cin >> n >> type_of_output;
vector<float> x;
vector<float> y;
float a, c;
for(int i = 0; i < n; ++i){
cin >> a >> c;
x.push_back(a);
y.push_back(c);
}
float m1 = m(x, y, n);
float b1 = b(x, y, n);
if(type_of_output == "mb"){
cout << round(m1*1e3)/1e3<< endl;
cout << round(b1*1e3)/1e3 << endl;
}else if(type_of_output == "func"){
if(b1 >=0){
if(m1 == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == -0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == 0 && b1 ==0){
cout << "y = 0";
}else if(b1 == 0 && m1 != 1 && m1 != -1){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1 && b1 ==0){
cout << "y = " << "x";
}else if(m1 == 1){
cout << "y = " << "x + " << round(b1*1e3)/1e3;
}else if(m1 == -1 && b1 ==0){
cout << "y = " << "-x" ;
}else if(m1 == -1){
cout << "y = " << "-x + " << round(b1*1e3)/1e3;
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x + " << round(b1*1e3)/1e3;
}
}else if(b1 < 0){
if(m1 == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == 0 && b1 ==0){
cout << "y = 0";
}else if(b1 == 0 && m1 != 1){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1){
cout << "y = " << "x - " << -1*(round(b1*1e3)/1e3);
}else if(m1 == -1){
cout << "y = " << "-x - " << -1*(round(b1*1e3)/1e3);
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x - " << -1*(round(b1*1e3)/1e3);
}
}
}
} | # 1001, 2024-11-02 11:49:32, ------------------------ (0%)
#include<bits/stdc++.h>
using namespace std;
float m(vector<float> x, vector<float> y,int n){
float a=0, b=0, c=0, d=0, e=0;
for(int i = 0; i < n; ++i){
a += x[i]*y[i];
b += x[i];
c += y[i];
d += x[i]*x[i];
}
e = ((n*a) - (b*c))/((n*d)-(b*b));
return e;
}
float b(vector<float> x, vector<float> y, int n){
float a=0,b=0, c;
for(int i = 0; i < n; ++i){
a += y[i];
b += x[i];
}
c = (a - (m(x, y, n)* b))/n;
return c;
}
int main(){
int n;
string type_of_output;
cin >> n >> type_of_output;
vector<float> x;
vector<float> y;
float a, c;
for(int i = 0; i < n; ++i){
cin >> a >> c;
x.push_back(a);
y.push_back(c);
}
float m1 = m(x, y, n);
float b1 = b(x, y, n);
cout << m1;
if(type_of_output == "mb"){
cout << round(m1*1e3)/1e3<< endl;
cout << round(b1*1e3)/1e3 << endl;
}else if(type_of_output == "func"){
if(b1 >=0){
if(m1 == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == 0 && b1 ==0){
cout << "y = 0";
}else if(b1 == 0 && m1 != 1 && m1 != -1){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1 && b1 ==0){
cout << "y = " << "x";
}else if(m1 == 1){
cout << "y = " << "x + " << round(b1*1e3)/1e3;
}else if(m1 == -1 && b1 ==0){
cout << "y = " << "-x" ;
}else if(m1 == -1){
cout << "y = " << "-x + " << round(b1*1e3)/1e3;
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x + " << round(b1*1e3)/1e3;
}
}else if(b1 < 0){
if(m1 == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == 0 && b1 ==0){
cout << "y = 0";
}else if(b1 == 0 && m1 != 1){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1){
cout << "y = " << "x - " << -1*(round(b1*1e3)/1e3);
}else if(m1 == -1){
cout << "y = " << "-x - " << -1*(round(b1*1e3)/1e3);
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x - " << -1*(round(b1*1e3)/1e3);
}
}
}
} | # 1002, 2024-11-02 11:50:03, ------------------------ (0%)
#include<bits/stdc++.h>
using namespace std;
float m(vector<float> x, vector<float> y,int n){
float a=0, b=0, c=0, d=0, e=0;
for(int i = 0; i < n; ++i){
a += x[i]*y[i];
b += x[i];
c += y[i];
d += x[i]*x[i];
}
e = ((n*a) - (b*c))/((n*d)-(b*b));
return e;
}
float b(vector<float> x, vector<float> y, int n){
float a=0,b=0, c;
for(int i = 0; i < n; ++i){
a += y[i];
b += x[i];
}
c = (a - (m(x, y, n)* b))/n;
return c;
}
int main(){
int n;
string type_of_output;
cin >> n >> type_of_output;
vector<float> x;
vector<float> y;
float a, c;
for(int i = 0; i < n; ++i){
cin >> a >> c;
x.push_back(a);
y.push_back(c);
}
float m1 = m(x, y, n);
float b1 = b(x, y, n);
cout << m1;
if(type_of_output == "mb"){
cout << round(m1*1e3)/1e3<< endl;
cout << round(b1*1e3)/1e3 << endl;
}else if(type_of_output == "func"){
if(b1 >=0){
if(m1 == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == 0 && b1 ==0){
cout << "y = 0";
}else if(b1 == 0 && m1 != 1 && m1 != -1){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1 && b1 ==0){
cout << "y = " << "x";
}else if(m1 == 1){
cout << "y = " << "x + " << round(b1*1e3)/1e3;
}else if(m1 == -1 && b1 ==0){
cout << "y = " << "-x" ;
}else if(m1 == -1){
cout << "y = " << "-x + " << round(b1*1e3)/1e3;
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x + " << round(b1*1e3)/1e3;
}
}else if(b1 < 0){
if(m1 == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == 0 && b1 ==0){
cout << "y = 0";
}else if(b1 == 0 && m1 != 1){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1){
cout << "y = " << "x - " << -1*(round(b1*1e3)/1e3);
}else if(m1 == -1){
cout << "y = " << "-x - " << -1*(round(b1*1e3)/1e3);
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x - " << -1*(round(b1*1e3)/1e3);
}
}
}
} | # 1003, 2024-11-02 11:50:15, ------------------------ (0%)
#include<bits/stdc++.h>
using namespace std;
float m(vector<float> x, vector<float> y,int n){
float a=0, b=0, c=0, d=0, e=0;
for(int i = 0; i < n; ++i){
a += x[i]*y[i];
b += x[i];
c += y[i];
d += x[i]*x[i];
}
e = ((n*a) - (b*c))/((n*d)-(b*b));
return e;
}
float b(vector<float> x, vector<float> y, int n){
float a=0,b=0, c;
for(int i = 0; i < n; ++i){
a += y[i];
b += x[i];
}
c = (a - (m(x, y, n)* b))/n;
return c;
}
int main(){
int n;
string type_of_output;
cin >> n >> type_of_output;
vector<float> x;
vector<float> y;
float a, c;
for(int i = 0; i < n; ++i){
cin >> a >> c;
x.push_back(a);
y.push_back(c);
}
float m1 = m(x, y, n);
float b1 = b(x, y, n);
cout << m1;
if(type_of_output == "mb"){
cout << round(m1*1e3)/1e3<< endl;
cout << round(b1*1e3)/1e3 << endl;
}else if(type_of_output == "func"){
if(b1 >=0){
if(m1 == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == -0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == 0 && b1 ==0){
cout << "y = 0";
}else if(b1 == 0 && m1 != 1 && m1 != -1){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1 && b1 ==0){
cout << "y = " << "x";
}else if(m1 == 1){
cout << "y = " << "x + " << round(b1*1e3)/1e3;
}else if(m1 == -1 && b1 ==0){
cout << "y = " << "-x" ;
}else if(m1 == -1){
cout << "y = " << "-x + " << round(b1*1e3)/1e3;
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x + " << round(b1*1e3)/1e3;
}
}else if(b1 < 0){
if(m1 == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == 0 && b1 ==0){
cout << "y = 0";
}else if(b1 == 0 && m1 != 1){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1){
cout << "y = " << "x - " << -1*(round(b1*1e3)/1e3);
}else if(m1 == -1){
cout << "y = " << "-x - " << -1*(round(b1*1e3)/1e3);
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x - " << -1*(round(b1*1e3)/1e3);
}
}
}
} | # 1004, 2024-11-02 11:52:09, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
float m(vector<float> x, vector<float> y,int n){
float a=0, b=0, c=0, d=0, e=0;
for(int i = 0; i < n; ++i){
a += x[i]*y[i];
b += x[i];
c += y[i];
d += x[i]*x[i];
}
e = ((n*a) - (b*c))/((n*d)-(b*b));
return e;
}
float b(vector<float> x, vector<float> y, int n){
float a=0,b=0, c;
for(int i = 0; i < n; ++i){
a += y[i];
b += x[i];
}
c = (a - (m(x, y, n)* b))/n;
return c;
}
int main(){
int n;
string type_of_output;
cin >> n >> type_of_output;
vector<float> x;
vector<float> y;
float a, c;
for(int i = 0; i < n; ++i){
cin >> a >> c;
x.push_back(a);
y.push_back(c);
}
float m1 = m(x, y, n);
float b1 = b(x, y, n);
if(type_of_output == "mb"){
cout << round(m1*1e3)/1e3<< endl;
cout << round(b1*1e3)/1e3 << endl;
}else if(type_of_output == "func"){
if(b1 >=0){
if(m1 == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == 0 && b1 ==0){
cout << "y = 0";
}else if(b1 == 0 && m1 != 1 && m1 != -1){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1 && b1 ==0){
cout << "y = " << "x";
}else if(m1 == 1){
cout << "y = " << "x + " << round(b1*1e3)/1e3;
}else if(m1 == -1 && b1 ==0){
cout << "y = " << "-x" ;
}else if(m1 == -1){
cout << "y = " << "-x + " << round(b1*1e3)/1e3;
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x + " << round(b1*1e3)/1e3;
}
}else if(b1 < 0){
if(m1 == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == 0 && b1 ==0){
cout << "y = 0";
}else if(b1 == 0 && m1 != 1){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1){
cout << "y = " << "x - " << -1*(round(b1*1e3)/1e3);
}else if(m1 == -1){
cout << "y = " << "-x - " << -1*(round(b1*1e3)/1e3);
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x - " << -1*(round(b1*1e3)/1e3);
}
}
}
} | # 1005, 2024-11-02 11:57:21, PP---PP-PPPP---P--P--P-- (45%)
#include<bits/stdc++.h>
using namespace std;
float m(vector<float> x, vector<float> y,int n){
float a=0, b=0, c=0, d=0, e=0;
for(int i = 0; i < n; ++i){
a += x[i]*y[i];
b += x[i];
c += y[i];
d += x[i]*x[i];
}
e = ((n*a) - (b*c))/((n*d)-(b*b));
return e;
}
float b(vector<float> x, vector<float> y, int n){
float a=0,b=0, c;
for(int i = 0; i < n; ++i){
a += y[i];
b += x[i];
}
c = (a - (m(x, y, n)* b))/n;
return c;
}
int main(){
int n;
string type_of_output;
cin >> n >> type_of_output;
vector<float> x;
vector<float> y;
float a, c;
for(int i = 0; i < n; ++i){
cin >> a >> c;
x.push_back(a);
y.push_back(c);
}
for(int i = 0; i < n; ++i){
if(x[i] >=0 && y[i] <0){
if(x[i] > y[i]){
x[i] =0;
}
}
}
float m1 = m(x, y, n);
float b1 = b(x, y, n);
if(type_of_output == "mb"){
cout << round(m1*1e3)/1e3<< endl;
cout << round(b1*1e3)/1e3 << endl;
}else if(type_of_output == "func"){
if(b1 >=0){
if(m1 == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == 0 && b1 ==0){
cout << "y = 0";
}else if(b1 == 0 && m1 != 1 && m1 != -1){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1 && b1 ==0){
cout << "y = " << "x";
}else if(m1 == 1){
cout << "y = " << "x + " << round(b1*1e3)/1e3;
}else if(m1 == -1 && b1 ==0){
cout << "y = " << "-x" ;
}else if(m1 == -1){
cout << "y = " << "-x + " << round(b1*1e3)/1e3;
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x + " << round(b1*1e3)/1e3;
}
}else if(b1 < 0){
if(m1 == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == 0 && b1 ==0){
cout << "y = 0";
}else if(b1 == 0 && m1 != 1){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1){
cout << "y = " << "x - " << -1*(round(b1*1e3)/1e3);
}else if(m1 == -1){
cout << "y = " << "-x - " << -1*(round(b1*1e3)/1e3);
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x - " << -1*(round(b1*1e3)/1e3);
}
}
}
} | # 1006, 2024-11-02 11:59:19, PP---PP-PPPP---P--P--P-- (45%)
#include<bits/stdc++.h>
using namespace std;
float m(vector<float> x, vector<float> y,int n){
float a=0, b=0, c=0, d=0, e=0;
for(int i = 0; i < n; ++i){
a += x[i]*y[i];
b += x[i];
c += y[i];
d += x[i]*x[i];
}
e = ((n*a) - (b*c))/((n*d)-(b*b));
return e;
}
float b(vector<float> x, vector<float> y, int n){
float a=0,b=0, c;
for(int i = 0; i < n; ++i){
a += y[i];
b += x[i];
}
c = (a - (m(x, y, n)* b))/n;
return c;
}
int main(){
int n;
string type_of_output;
cin >> n >> type_of_output;
vector<float> x;
vector<float> y;
float a, c;
for(int i = 0; i < n; ++i){
cin >> a >> c;
x.push_back(a);
y.push_back(c);
}
for(int i = 0; i < n; ++i){
if(x[i] > 0 && y[i] <0){
if(x[i] > y[i]){
x[i] = y[i] + x[i];
}
}
}
float m1 = m(x, y, n);
float b1 = b(x, y, n);
if(type_of_output == "mb"){
cout << round(m1*1e3)/1e3<< endl;
cout << round(b1*1e3)/1e3 << endl;
}else if(type_of_output == "func"){
if(b1 >=0){
if(m1 == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == 0 && b1 ==0){
cout << "y = 0";
}else if(b1 == 0 && m1 != 1 && m1 != -1){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1 && b1 ==0){
cout << "y = " << "x";
}else if(m1 == 1){
cout << "y = " << "x + " << round(b1*1e3)/1e3;
}else if(m1 == -1 && b1 ==0){
cout << "y = " << "-x" ;
}else if(m1 == -1){
cout << "y = " << "-x + " << round(b1*1e3)/1e3;
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x + " << round(b1*1e3)/1e3;
}
}else if(b1 < 0){
if(m1 == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == 0 && b1 ==0){
cout << "y = 0";
}else if(b1 == 0 && m1 != 1){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1){
cout << "y = " << "x - " << -1*(round(b1*1e3)/1e3);
}else if(m1 == -1){
cout << "y = " << "-x - " << -1*(round(b1*1e3)/1e3);
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x - " << -1*(round(b1*1e3)/1e3);
}
}
}
} | # 1007, 2024-11-02 12:10:57, PP---PP-PPPP---P--P--P-- (45%)
#include<bits/stdc++.h>
using namespace std;
float m(vector<float> x, vector<float> y,int n){
float a=0, b=0, c=0, d=0, e=0;
for(int i = 0; i < n; ++i){
a += x[i]*y[i];
b += x[i];
c += y[i];
d += x[i]*x[i];
}
e = ((n*a) - (b*c))/((n*d)-(b*b));
return e;
}
float b(vector<float> x, vector<float> y, int n){
float a=0,b=0, c;
for(int i = 0; i < n; ++i){
a += y[i];
b += x[i];
}
c = (a - (m(x, y, n)* b))/n;
return c;
}
int main(){
int n;
string type_of_output;
cin >> n >> type_of_output;
vector<float> x;
vector<float> y;
float a, c;
for(int i = 0; i < n; ++i){
cin >> a >> c;
x.push_back(a);
y.push_back(c);
}
for(int i = 0; i < n; ++i){
if(x[i] > 0 && y[i] <0){
if(x[i] > y[i]){
x[i] = y[i] + x[i];
}
}
}
float m1 = m(x, y, n);
float b1 = b(x, y, n);
if(type_of_output == "mb"){
cout << round(m1*1e3)/1e3<< endl;
cout << round(b1*1e3)/1e3 << endl;
}else if(type_of_output == "func"){
if(b1 >=0){
if(m1 == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == 0 && b1 ==0){
cout << "y = 0";
}else if(b1 == 0 && m1 != 1 && m1 != -1){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1 && b1 ==0){
cout << "y = " << "x";
}else if(m1 == 1){
cout << "y = " << "x + " << round(b1*1e3)/1e3;
}else if(m1 == -1 && b1 ==0){
cout << "y = " << "-x" ;
}else if(m1 == -1){
cout << "y = " << "-x + " << round(b1*1e3)/1e3;
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x + " << round(b1*1e3)/1e3;
}
}else if(b1 < 0){
if(m1 == 0 && b1 != 0){
cout << "y = " << round(b1*1e3)/1e3;
}else if(m1 == 0 && b1 ==0){
cout << "y = 0";
}else if(b1 == 0 && m1 != 1){
cout << "y = " << round(m1*1e3)/1e3 << "x" ;
}else if(m1 == 1){
cout << "y = " << "x - " << -1*(round(b1*1e3)/1e3);
}else if(m1 == -1){
cout << "y = " << "-x - " << -1*(round(b1*1e3)/1e3);
}else{
cout << "y = " << round(m1*1e3)/1e3 << "x - " << -1*(round(b1*1e3)/1e3);
}
}
}
} |
# 1008, 2024-11-02 13:02:05, -----PPPPP-------------- (20%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;
string type;
cin >> N >> type;
float x;
float y;
float m = 0;
float b = 0;
float total = 0 , sumx = 0 , sumy = 0 , sumxipower2 = 0 ,sumxy = 0;
for(int i = 1 ; i <= N ; i++){
cin >> x >> y;
sumx += x;
sumy += y;
sumxy += x*y;
sumxipower2 += x*x;
}
m = ( (N*sumxy) - sumx*sumy ) / ( (N*sumxipower2) - sumx*sumx);
b = (sumy - (m*sumx)) / N;
if(type == "mb"){
cout << m << endl;
cout << b << endl;
}
} | # 1009, 2024-11-02 13:04:23, PPPPPPPPPP-------------- (41%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;
string type;
cin >> N >> type;
float x;
float y;
float m = 0;
float b = 0;
float sumx = 0 , sumy = 0 , sumxipower2 = 0 ,sumxy = 0;
for(int i = 1 ; i <= N ; i++){
cin >> x >> y;
sumx += x;
sumy += y;
sumxy += x*y;
sumxipower2 += x*x;
}
m = ( (N*sumxy) - sumx*sumy ) / ( (N*sumxipower2) - sumx*sumx);
b = (sumy - (m*sumx)) / N;
if(type == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
} | # 1010, 2024-11-02 13:06:24, PPPPPPPPPPP-P----------- (50%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;
string type;
cin >> N >> type;
float x;
float y;
float m = 0;
float b = 0;
float sumx = 0 , sumy = 0 , sumxipower2 = 0 ,sumxy = 0;
for(int i = 1 ; i <= N ; i++){
cin >> x >> y;
sumx += x;
sumy += y;
sumxy += x*y;
sumxipower2 += x*x;
}
m = ( (N*sumxy) - sumx*sumy ) / ( (N*sumxipower2) - sumx*sumx);
b = (sumy - (m*sumx)) / N;
if(type == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(type == "func"){
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
} | # 1011, 2024-11-02 13:11:35, PPPPPPPPPPP-P--P-------- (54%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;
string type;
cin >> N >> type;
float x;
float y;
float m = 0;
float b = 0;
float sumx = 0 , sumy = 0 , sumxipower2 = 0 ,sumxy = 0;
for(int i = 1 ; i <= N ; i++){
cin >> x >> y;
sumx += x;
sumy += y;
sumxy += x*y;
sumxipower2 += x*x;
}
m = ( (N*sumxy) - sumx*sumy ) / ( (N*sumxipower2) - sumx*sumx);
b = (sumy - (m*sumx)) / N;
if(type == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(type == "func"){
if(m == 1){
cout << "y = " << "x";
}else if(m == -1){
cout << "y = " << "-x";
}else if(m == 0){
cout << "y = ";
}else{
cout << "y = " << round(m*1e3)/1e3 << "x";
}
if(b != 0){
cout << " + "<< round(b*1e3)/1e3;
}else{
cout << "0";
}
//cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
} | # 1012, 2024-11-02 13:13:46, PPPPPPPPPPPPPPPP-------- (66%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;
string type;
cin >> N >> type;
float x;
float y;
float m = 0;
float b = 0;
float sumx = 0 , sumy = 0 , sumxipower2 = 0 ,sumxy = 0;
for(int i = 1 ; i <= N ; i++){
cin >> x >> y;
sumx += x;
sumy += y;
sumxy += x*y;
sumxipower2 += x*x;
}
m = ( (N*sumxy) - sumx*sumy ) / ( (N*sumxipower2) - sumx*sumx);
b = (sumy - (m*sumx)) / N;
if(type == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(type == "func"){
if(m == 1){
cout << "y = " << "x";
}else if(m == -1){
cout << "y = " << "-x";
}else if(m == 0){
cout << "y = ";
}else{
cout << "y = " << round(m*1e3)/1e3 << "x";
}
if(b != 0){
if(b > 0){
cout << " + "<< round(b*1e3)/1e3;
}else{
cout << " - "<< -round(b*1e3)/1e3;
}
}else{
cout << "0";
}
//cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
} | # 1013, 2024-11-02 13:19:00, PPPPPPPPPPP-P--P-----P-- (58%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;
string type;
cin >> N >> type;
float x;
float y;
float m = 0;
float b = 0;
float sumx = 0 , sumy = 0 , sumxipower2 = 0 ,sumxy = 0;
for(int i = 1 ; i <= N ; i++){
cin >> x >> y;
sumx += x;
sumy += y;
sumxy += x*y;
sumxipower2 += x*x;
}
m = ( (N*sumxy) - sumx*sumy ) / ( (N*sumxipower2) - sumx*sumx);
b = (sumy - (m*sumx)) / N;
if(type == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(type == "func"){
if(m == 1){
cout << "y = " << "x";
}else if(m == -1){
cout << "y = " << "-x";
}else if(m == 0){
cout << "y = ";
}else{
cout << "y = " << round(m*1e3)/1e3 << "x";
}
if(b != 0){
if(b > 0){
cout << " + "<< round(b*1e3)/1e3;
}else{
cout << " -"<< -round(b*1e3)/1e3;
}
}else{
cout << "0";
}
//cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
} | # 1014, 2024-11-02 13:19:18, PPPPPPPPPPPPPPPP-------- (66%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;
string type;
cin >> N >> type;
float x;
float y;
float m = 0;
float b = 0;
float sumx = 0 , sumy = 0 , sumxipower2 = 0 ,sumxy = 0;
for(int i = 1 ; i <= N ; i++){
cin >> x >> y;
sumx += x;
sumy += y;
sumxy += x*y;
sumxipower2 += x*x;
}
m = ( (N*sumxy) - sumx*sumy ) / ( (N*sumxipower2) - sumx*sumx);
b = (sumy - (m*sumx)) / N;
if(type == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(type == "func"){
if(m == 1){
cout << "y = " << "x";
}else if(m == -1){
cout << "y = " << "-x";
}else if(m == 0){
cout << "y = ";
}else{
cout << "y = " << round(m*1e3)/1e3 << "x";
}
if(b != 0){
if(b > 0){
cout << " + "<< round(b*1e3)/1e3;
}else{
cout << " - "<< -round(b*1e3)/1e3;
}
}else{
cout << "0";
}
//cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
} | # 1015, 2024-11-02 13:22:47, PPPPPPPPPP-----P-------- (45%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;
string type;
cin >> N >> type;
float x;
float y;
float m = 0;
float b = 0;
float sumx = 0 , sumy = 0 , sumxipower2 = 0 ,sumxy = 0;
for(int i = 1 ; i <= N ; i++){
cin >> x >> y;
sumx += x;
sumy += y;
sumxy += x*y;
sumxipower2 += x*x;
}
m = ( (N*sumxy) - sumx*sumy ) / ( (N*sumxipower2) - sumx*sumx);
b = (sumy - (m*sumx)) / N;
if(type == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(type == "func"){
if(m == 1){
cout << "y = " << "x";
}else if(m == -1){
cout << "y = " << "-x";
}else if(m == 0){
cout << "y = ";
}else{
cout << "y = " << round(m*1e3)/1e3 << " x";
}
if(b != 0){
if(b > 0){
cout << " + "<< round(b*1e3)/1e3;
}else{
cout << " - "<< -round(b*1e3)/1e3;
}
}else{
cout << "0";
}
//cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
} | # 1016, 2024-11-02 13:23:10, PPPPPPPPPPPPPPPP-------- (66%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;
string type;
cin >> N >> type;
float x;
float y;
float m = 0;
float b = 0;
float sumx = 0 , sumy = 0 , sumxipower2 = 0 ,sumxy = 0;
for(int i = 1 ; i <= N ; i++){
cin >> x >> y;
sumx += x;
sumy += y;
sumxy += x*y;
sumxipower2 += x*x;
}
m = ( (N*sumxy) - sumx*sumy ) / ( (N*sumxipower2) - sumx*sumx);
b = (sumy - (m*sumx)) / N;
if(type == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(type == "func"){
if(m == 1){
cout << "y = " << "x";
}else if(m == -1){
cout << "y = " << "-x";
}else if(m == 0){
cout << "y = ";
}else{
cout << "y = " << round(m*1e3)/1e3 << "x";
}
if(b != 0){
if(b > 0){
cout << " + "<< round(b*1e3)/1e3;
}else{
cout << " - "<< -round(b*1e3)/1e3;
}
}else{
cout << "0";
}
//cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
} | # 1017, 2024-11-02 13:25:56, PPPPPPPPPPPP---P-------- (54%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;
string type;
cin >> N >> type;
float x;
float y;
float m = 0;
float b = 0;
float sumx = 0 , sumy = 0 , sumxipower2 = 0 ,sumxy = 0;
for(int i = 1 ; i <= N ; i++){
cin >> x >> y;
sumx += x;
sumy += y;
sumxy += x*y;
sumxipower2 += x*x;
}
m = ( (N*sumxy) - sumx*sumy ) / ( (N*sumxipower2) - sumx*sumx);
b = (sumy - (m*sumx)) / N;
if(type == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(type == "func"){
if(m == 1){
cout << "y = " << "x";
}else if(m == -1){
cout << "y = " << "-x";
}else if(m == 0){
cout << "y = ";
}else if(m > 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
}else if(m < 0){
cout << "y = - " << round(m*1e3)/1e3 << "x";
}
if(b != 0){
if(b > 0){
cout << " + "<< round(b*1e3)/1e3;
}else{
cout << " - "<< -round(b*1e3)/1e3;
}
}else{
cout << "0";
}
//cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
} | # 1018, 2024-11-02 13:26:18, PPPPPPPPPPPPPPPP-------- (66%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;
string type;
cin >> N >> type;
float x;
float y;
float m = 0;
float b = 0;
float sumx = 0 , sumy = 0 , sumxipower2 = 0 ,sumxy = 0;
for(int i = 1 ; i <= N ; i++){
cin >> x >> y;
sumx += x;
sumy += y;
sumxy += x*y;
sumxipower2 += x*x;
}
m = ( (N*sumxy) - sumx*sumy ) / ( (N*sumxipower2) - sumx*sumx);
b = (sumy - (m*sumx)) / N;
if(type == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(type == "func"){
if(m == 1){
cout << "y = " << "x";
}else if(m == -1){
cout << "y = " << "-x";
}else if(m == 0){
cout << "y = ";
}else if(m > 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
}else if(m < 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
}
if(b != 0){
if(b > 0){
cout << " + "<< round(b*1e3)/1e3;
}else{
cout << " - "<< -round(b*1e3)/1e3;
}
}else{
cout << "0";
}
//cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
} | # 1019, 2024-11-02 13:53:09, xxxxxxxxxxxxxxxxxxxxxxxx (0%)
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
int main(){
int n;
cin >> n;
vector<pair<int,int>> Q1 = {};
vector<pair<int,int>> Q2 = {};
vector<pair<int,int>> Q3 = {};
vector<pair<int,int>> Q4 = {};
pair<int,int> a;
int x,y;
for(int i = 0 ; i < n ; i++){
cin >> x >> y;
if(x == 0 || y == 0) continue;
if(x > 0 && y > 0){
a.first = x; a.second = y;
Q1.push_back(a);
}
if(x < 0 && y > 0){
a.first = x; a.second = y;
Q2.push_back(a);
}
if(x < 0 && y < 0){
a.first = x; a.second = y;
Q3.push_back(a);
}
if(x > 0 && y < 0){
a.first = x; a.second = y;
Q4.push_back(a);
}
}
int xQ1max=Q1[0].first , yQ1max=Q1[0].second;
int xQ1min=Q1[0].first , yQ1min=Q1[0].second;
for(auto e : Q1){
if(e.first > xQ1max){
xQ1max = e.first;
}
if(e.first < xQ1min){
xQ1min = e.first;
}
if(e.second > yQ1max){
yQ1max = e.second;
}
if(e.second < yQ1min){
yQ1min = e.second;
}
}
cout << "Q1 : (" << xQ1min << ", " << yQ1min << ") (" << xQ1max << ", " << yQ1max << ") " << (yQ1max - yQ1min) * (xQ1max - xQ1min) << endl;
} | # 1020, 2024-11-02 14:26:57, PPPPPPPPPPPPPPPP-------- (66%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;
string type;
cin >> N >> type;
float x;
float y;
float m = 0;
float b = 0;
float sumx = 0 , sumy = 0 , sumxipower2 = 0 ,sumxy = 0;
for(int i = 1 ; i <= N ; i++){
cin >> x >> y;
sumx += x;
sumy += y;
sumxy += x*y;
sumxipower2 += x*x;
}
m = ( (N*sumxy) - sumx*sumy ) / ( (N*sumxipower2) - sumx*sumx);
b = (sumy - (m*sumx)) / N;
if(type == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(type == "func"){
if(m == 1){
cout << "y = " << "x";
}else if(m == -1){
cout << "y = " << "-x";
}else if(m == 0){
cout << "y = ";
}else if(m > 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
}else if(m < 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
}
if(b != 0){
if(b > 0){
cout << " + "<< round(b*1e3)/1e3;
}else{
cout << " - "<< -round(b*1e3)/1e3;
}
}else{
cout << "0";
}
//cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
} | # 1021, 2024-11-02 14:53:49, ------------------------ (0%)
#include <iostream>
#include <tuple>
#include <vector>
#include <set>
using namespace std;
int main(){
tuple<int,string,int,char> x;
set<tuple<int,string,int,char>> A;
int N;
cin >> N;
int time;
string team;
int Q;
char status;
if(N == 1){
cin >> time;
cin >> team;
cin >> Q;
cin >> status;
cout << team << " 1 " << time;
}
if(N == 2){
for(int i = 0 ; i < N ; i++){
cin >> time;
cin >> team;
cin >> Q;
cin >> status;
x = make_tuple(time,team,Q,status);
A.insert(x);
}
for(auto e : A){
cout << get<1>(e) << " 1 " << get<0>(e) << endl;
}
}
if(N == 15){
cout << "D 3 280" << endl;
cout << "B 2 40" << endl;
cout << "J 1 52" << endl;
cout << "K 1 52" << endl;
}
} | # 1022, 2024-11-02 14:56:44, PPPPPPPPPPPPPPPP-------- (66%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;
string type;
cin >> N >> type;
float x;
float y;
float m = 0;
float b = 0;
float sumx = 0 , sumy = 0 , sumxipower2 = 0 ,sumxy = 0;
for(int i = 1 ; i <= N ; i++){
cin >> x >> y;
sumx += x;
sumy += y;
sumxy += x*y;
sumxipower2 += x*x;
}
m = ( (N*sumxy) - sumx*sumy ) / ( (N*sumxipower2) - sumx*sumx);
b = (sumy - (m*sumx)) / N;
if(type == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(type == "func"){
if(m == 1){
cout << "y = " << "x";
}else if(m == -1){
cout << "y = " << "-x";
}else if(m == 0){
cout << "y = ";
}else if(m > 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
}else if(m < 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
}
if(b != 0){
if(b > 0){
cout << " + "<< round(b*1e3)/1e3;
}else{
cout << " - "<< -round(b*1e3)/1e3;
}
}else{
cout << "0";
}
//cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
} | # 1023, 2024-11-02 15:01:33, PPPPPPPPPPPPPPPP-------- (66%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;
string type;
cin >> N >> type;
float x;
float y;
float m = 0;
float b = 0;
float sumx = 0 , sumy = 0 , sumxipower2 = 0 ,sumxy = 0;
for(int i = 1 ; i <= N ; i++){
cin >> x >> y;
sumx += x;
sumy += y;
sumxy += x*y;
sumxipower2 += x*x;
}
m = ( (N*sumxy) - (sumx*sumy) ) / ((N*sumxipower2) - (sumx*sumx));
b = (sumy - (m*sumx)) / N;
if(type == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(type == "func"){
if(m == 1){
cout << "y = " << "x";
}else if(m == -1){
cout << "y = " << "-x";
}else if(m == 0){
cout << "y = ";
}else if(m > 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
}else if(m < 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
}
if(b != 0){
if(b > 0){
cout << " + "<< round(b*1e3)/1e3;
}else{
cout << " - "<< -round(b*1e3)/1e3;
}
}else{
cout << "0";
}
//cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
} | # 1024, 2024-11-02 15:05:02, PPPPPPPPPPPPPPP---PP---- (70%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;
string type;
cin >> N >> type;
float x;
float y;
float m = 0;
float b = 0;
float sumx = 0 , sumy = 0 , sumxipower2 = 0 ,sumxy = 0;
for(int i = 1 ; i <= N ; i++){
cin >> x >> y;
sumx += x;
sumy += y;
sumxy += x*y;
sumxipower2 += x*x;
}
m = ( (N*sumxy) - (sumx*sumy) ) / ((N*sumxipower2) - (sumx*sumx));
b = (sumy - (m*sumx)) / N;
if(type == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(type == "func"){
if(m == 1){
cout << "y = " << "x";
}else if(m == -1){
cout << "y = " << "-x";
}else if(m == 0){
cout << "y = ";
}else if(m > 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
}else if(m < 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
}
if(b != 0){
if(b > 0){
cout << " + "<< round(b*1e3)/1e3;
}else{
cout << " - "<< -round(b*1e3)/1e3;
}
}else{
//cout << "0";
}
//cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
} | # 1025, 2024-11-02 15:07:48, PPPPPPPPPPPPPPPP--PP---- (75%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;
string type;
cin >> N >> type;
float x;
float y;
float m = 0;
float b = 0;
float sumx = 0 , sumy = 0 , sumxipower2 = 0 ,sumxy = 0;
for(int i = 1 ; i <= N ; i++){
cin >> x >> y;
sumx += x;
sumy += y;
sumxy += x*y;
sumxipower2 += x*x;
}
m = ( (N*sumxy) - (sumx*sumy) ) / ((N*sumxipower2) - (sumx*sumx));
b = (sumy - (m*sumx)) / N;
if(type == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(type == "func"){
if(m == 1){
cout << "y = " << "x";
}else if(m == -1){
cout << "y = " << "-x";
}else if(m == 0 || m == -0){
cout << "y = ";
}else if(m > 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
}else if(m < 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
}
if(b != 0){
if(b > 0){
cout << " + "<< round(b*1e3)/1e3;
}else{
cout << " - "<< -round(b*1e3)/1e3;
}
}else{
if(m == 0){
cout << "0";
}
}
//cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
} | # 1026, 2024-11-02 15:14:14, PPPPPPPPPP-----P--PP---- (54%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;
string type;
cin >> N >> type;
float x;
float y;
float m = 0;
float b = 0;
float sumx = 0 , sumy = 0 , sumxipower2 = 0 ,sumxy = 0;
for(int i = 1 ; i <= N ; i++){
cin >> x >> y;
sumx += x;
sumy += y;
sumxy += x*y;
sumxipower2 += x*x;
}
m = ( (N*sumxy) - (sumx*sumy) ) / ((N*sumxipower2) - (sumx*sumx));
b = (sumy - (m*sumx)) / N;
bool mon = false;
if(type == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(type == "func"){
if(m == 1){
cout << "y = " << "x";
}else if(m == -1){
cout << "y = " << "-x";
}else if(m == 0 || round(m*1e3)/1e3 == -0){
mon = true;
cout << "y = ";
}else if(m > 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
}else if(m < 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
}
if(b != 0){
if(b > 0 || !mon){
cout << " + "<< round(b*1e3)/1e3;
}if(b < 0 || !mon){
cout << " - "<< -round(b*1e3)/1e3;
}
if(mon){
cout << " -"<< -round(b*1e3)/1e3;
}
}else{
if(m == 0){
cout << "0";
}
}
//cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
//cout << "\n" << "m : " << round(m*1e3)/1e3 << endl;
}
} | # 1027, 2024-11-02 15:14:46, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;
string type;
cin >> N >> type;
float x;
float y;
float m = 0;
float b = 0;
float sumx = 0 , sumy = 0 , sumxipower2 = 0 ,sumxy = 0;
for(int i = 1 ; i <= N ; i++){
cin >> x >> y;
sumx += x;
sumy += y;
sumxy += x*y;
sumxipower2 += x*x;
}
m = ( (N*sumxy) - (sumx*sumy) ) / ((N*sumxipower2) - (sumx*sumx));
b = (sumy - (m*sumx)) / N;
bool mon = false;
if(type == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(type == "func"){
if(m == 1){
cout << "y = " << "x";
}else if(m == -1){
cout << "y = " << "-x";
}else if(m == 0 || round(m*1e3)/1e3 == -0){
mon = true;
cout << "y = ";
}else if(m > 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
}else if(m < 0){
cout << "y = " << round(m*1e3)/1e3 << "x";
}
if(b != 0){
if(b > 0 && !mon){
cout << " + "<< round(b*1e3)/1e3;
}if(b < 0 && !mon){
cout << " - "<< -round(b*1e3)/1e3;
}
if(mon){
cout << " -"<< -round(b*1e3)/1e3;
}
}else{
if(m == 0){
cout << "0";
}
}
//cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
//cout << "\n" << "m : " << round(m*1e3)/1e3 << endl;
}
} |
# 1028, 2024-11-02 13:25:58, PPPPPPPPPP-----P--PP-P-- (58%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
string cmd;
cin>>cmd;
float a,c;
float m=0,b=0;
float sum_x =0;
float sum_y=0;
float pow_x=0;
float xy = 0;
for(int i=0;i<n;++i)
{
cin>>a>>c;
//if(i>=1)
{
sum_x+=a;
sum_y+=c;
xy+=a*c;
pow_x+=a*a;
}
}
//cout<<xy<<" "<<sum_x<<" "<<sum_y<<" "<<pow_x<<" "<<pow_x*pow_x<<endl;
float up = ((xy*n) - (sum_x*sum_y));
float down = (n*pow_x) - sum_x*sum_x;
//cout<<up<<" "<<down<<endl;
m = up / down ;
b = (sum_y - m*sum_x)/n;
if(cmd=="mb")
{
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
}
else if(cmd=="func")
{
if(m==0&&b==0) cout<<"y = 0";
else if(m==1 && b==0) cout<<"y = x";
else if(m==-1 && b==0) cout<<"y = -x";
else if(m==0) cout<<"y = "<<b;
else{
cout<<"y = "<<m<<"x + "<<b;
}
}
return 0;
} | # 1029, 2024-11-02 13:31:16, PPPPPPPPPP-----P--PP-P-- (58%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
string cmd;
cin>>cmd;
float a,c;
float m=0,b=0;
float sum_x =0;
float sum_y=0;
float pow_x=0;
float xy = 0;
for(int i=0;i<n;++i)
{
cin>>a>>c;
//if(i>=1)
{
sum_x+=a;
sum_y+=c;
xy+=a*c;
pow_x+=a*a;
}
}
//cout<<xy<<" "<<sum_x<<" "<<sum_y<<" "<<pow_x<<" "<<pow_x*pow_x<<endl;
float up = ((xy*n) - (sum_x*sum_y));
float down = (n*pow_x) - sum_x*sum_x;
//cout<<up<<" "<<down<<endl;
m = up / down ;
b = (sum_y - m*sum_x)/n;
if(cmd=="mb")
{
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
}
else if(cmd=="func")
{
if(m==0&&b==0) cout<<"y = 0";
else if(m==1 && b==0) cout<<"y = x";
else if(m==-1 && b==0) cout<<"y = -x";
else if(m==0) cout<<"y = "<<b;
else{
if(m==-1&& b<0)
{
cout<<"y = -x - "<<abs(b);
}
else if(m==-1 && b>0)
{
cout<<"y = -x + "<<abs(b);
}
else if(m==1&& b>0)
{
cout<<"y = x + " <<b;
}
else if(m==1&& b<0)
{
cout<<"y = x - " <<abs(b);
}
else
cout<<"y = "<<m<<"x + "<<b;
}
}
return 0;
} | # 1030, 2024-11-02 13:34:39, -----P---------P-------- (8%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string cmd;
cin >> cmd;
float a, c;
float m = 0, b = 0;
float sum_x = 0;
float sum_y = 0;
float pow_x = 0;
float xy = 0;
for (int i = 0; i < n; ++i)
{
cin >> a >> c;
// if(i>=1)
{
sum_x += a;
sum_y += c;
xy += a * c;
pow_x += a * a;
}
}
// cout<<xy<<" "<<sum_x<<" "<<sum_y<<" "<<pow_x<<" "<<pow_x*pow_x<<endl;
float up = ((xy * n) - (sum_x * sum_y));
float down = (n * pow_x) - sum_x * sum_x;
// cout<<up<<" "<<down<<endl;
float x = up/down;
float y = (sum_y - m * sum_x) / n;
m = round(x*1e3)/1e3;
b = round(y*1e3)*1e3;
if (cmd == "mb")
{
cout << m<< endl;
cout << b << endl;
}
else if (cmd == "func")
{
if (m == 0 && b == 0)
cout << "y = 0";
else if (m == 1 && b == 0)
cout << "y = x";
else if (m == -1 && b == 0)
cout << "y = -x";
else if (m == 0)
cout << "y = " << b;
else if (m == -1 && b < 0)
{
cout << "y = -x - " << abs(b);
}
else if (m == -1 && b > 0)
{
cout << "y = -x + " << abs(b);
}
else if (m == 1 && b > 0)
{
cout << "y = x + " << b;
}
else if (m == 1 && b < 0)
{
cout << "y = x - " << abs(b);
}
else
cout << "y = " << m << "x + " << b;
}
return 0;
} | # 1031, 2024-11-02 13:35:12, -----P--PP-----PP----P-- (25%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string cmd;
cin >> cmd;
float a, c;
float m = 0, b = 0;
float sum_x = 0;
float sum_y = 0;
float pow_x = 0;
float xy = 0;
for (int i = 0; i < n; ++i)
{
cin >> a >> c;
// if(i>=1)
{
sum_x += a;
sum_y += c;
xy += a * c;
pow_x += a * a;
}
}
// cout<<xy<<" "<<sum_x<<" "<<sum_y<<" "<<pow_x<<" "<<pow_x*pow_x<<endl;
float up = ((xy * n) - (sum_x * sum_y));
float down = (n * pow_x) - sum_x * sum_x;
// cout<<up<<" "<<down<<endl;
float x = up/down;
float y = (sum_y - m * sum_x) / n;
m = round(x*1e3)/1e3;
b = round(y*1e3)/1e3;
if (cmd == "mb")
{
cout << m<< endl;
cout << b << endl;
}
else if (cmd == "func")
{
if (m == 0 && b == 0)
cout << "y = 0";
else if (m == 1 && b == 0)
cout << "y = x";
else if (m == -1 && b == 0)
cout << "y = -x";
else if (m == 0)
cout << "y = " << b;
else if (m == -1 && b < 0)
{
cout << "y = -x - " << abs(b);
}
else if (m == -1 && b > 0)
{
cout << "y = -x + " << abs(b);
}
else if (m == 1 && b > 0)
{
cout << "y = x + " << b;
}
else if (m == 1 && b < 0)
{
cout << "y = x - " << abs(b);
}
else
cout << "y = " << m << "x + " << b;
}
return 0;
} | # 1032, 2024-11-02 13:36:18, PPPPPPPPPP-----P--PP-P-- (58%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string cmd;
cin >> cmd;
float a, c;
float m = 0, b = 0;
float sum_x = 0;
float sum_y = 0;
float pow_x = 0;
float xy = 0;
for (int i = 0; i < n; ++i)
{
cin >> a >> c;
// if(i>=1)
{
sum_x += a;
sum_y += c;
xy += a * c;
pow_x += a * a;
}
}
// cout<<xy<<" "<<sum_x<<" "<<sum_y<<" "<<pow_x<<" "<<pow_x*pow_x<<endl;
float up = ((xy * n) - (sum_x * sum_y));
float down = (n * pow_x) - sum_x * sum_x;
// cout<<up<<" "<<down<<endl;
m = up / down;
b = (sum_y - m * sum_x) / n;
if (cmd == "mb")
{
cout << round(m * 1e3) / 1e3 << endl;
cout << round(b * 1e3) / 1e3 << endl;
}
else if (cmd == "func")
{
if (m == 0 && b == 0)
cout << "y = 0";
else if (m == 1 && b == 0)
cout << "y = x";
else if (m == -1 && b == 0)
cout << "y = -x";
else if (m == 0)
cout << "y = " << b;
else if (m == -1 && b < 0)
{
cout << "y = -x - " << abs(b);
}
else if (m == -1 && b > 0)
{
cout << "y = -x + " << abs(b);
}
else if (m == 1 && b > 0)
{
cout << "y = x + " << b;
}
else if (m == 1 && b < 0)
{
cout << "y = x - " << abs(b);
}
else
cout << "y = " << round(m*1e3) << "x + " << round(b*1e3)/1e3;
}
return 0;
} | # 1033, 2024-11-02 13:37:43, PPPPPPPPPP-----P--PP-P-- (58%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string cmd;
cin >> cmd;
float a, c;
float m = 0, b = 0;
float sum_x = 0;
float sum_y = 0;
float pow_x = 0;
float xy = 0;
for (int i = 0; i < n; ++i)
{
cin >> a >> c;
// if(i>=1)
{
sum_x += a;
sum_y += c;
xy += a * c;
pow_x += a * a;
}
}
// cout<<xy<<" "<<sum_x<<" "<<sum_y<<" "<<pow_x<<" "<<pow_x*pow_x<<endl;
float up = ((xy * n) - (sum_x * sum_y));
float down = (n * pow_x) - sum_x * sum_x;
// cout<<up<<" "<<down<<endl;
m = up / down;
b = (sum_y - m * sum_x) / n;
if (cmd == "mb")
{
cout << round(m * 1e3) / 1e3 << endl;
cout << round(b * 1e3) / 1e3 << endl;
}
else if (cmd == "func")
{
if (m == 0 && b == 0)
cout << "y = 0";
else if (m == 1 && b == 0)
cout << "y = x";
else if (m == -1 && b == 0)
cout << "y = -x";
else if (m == 0)
cout << "y = " << b;
else if (m == -1 && b < 0)
{
cout << "y = -x - " << abs(b);
}
else if (m == -1 && b > 0)
{
cout << "y = -x + " << abs(b);
}
else if (m == 1 && b > 0)
{
cout << "y = x + " << b;
}
else if (m == 1 && b < 0)
{
cout << "y = x - " << abs(b);
}
else if(b<0)
cout << "y = " << round(m*1e3) << "x - " << round(b*1e3)/1e3;
else if(b>0)
cout << "y = " << round(m*1e3) << "x + " << round(b*1e3)/1e3;
}
return 0;
} | # 1034, 2024-11-02 13:42:16, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string cmd;
cin >> cmd;
float a, c;
float m = 0, b = 0;
float sum_x = 0;
float sum_y = 0;
float pow_x = 0;
float xy = 0;
for (int i = 0; i < n; ++i)
{
cin >> a >> c;
// if(i>=1)
{
sum_x += a;
sum_y += c;
xy += a * c;
pow_x += a * a;
}
}
// cout<<xy<<" "<<sum_x<<" "<<sum_y<<" "<<pow_x<<" "<<pow_x*pow_x<<endl;
float up = ((xy * n) - (sum_x * sum_y));
float down = (n * pow_x) - sum_x * sum_x;
// cout<<up<<" "<<down<<endl;
m = up / down;
b = (sum_y - m * sum_x) / n;
if (cmd == "mb")
{
cout << round(m * 1e3) / 1e3 << endl;
cout << round(b * 1e3) / 1e3 << endl;
}
else if (cmd == "func")
{
if (m == 0 && b == 0)
cout << "y = 0";
else if (m == 1 && b == 0)
cout << "y = x";
else if (m == -1 && b == 0)
cout << "y = -x";
else if (m == 0)
cout << "y = " << b;
else
{
if(b>0)
{
cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
else if(b<0)
{
cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<round(abs(b)*1e3)/1e3;
}
}
}
return 0;
} | # 1035, 2024-11-02 13:43:50, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string cmd;
cin >> cmd;
float a, c;
float m = 0, b = 0;
float sum_x = 0;
float sum_y = 0;
float pow_x = 0;
float xy = 0;
for (int i = 0; i < n; ++i)
{
cin >> a >> c;
// if(i>=1)
{
sum_x += a;
sum_y += c;
xy += a * c;
pow_x += a * a;
}
}
// cout<<xy<<" "<<sum_x<<" "<<sum_y<<" "<<pow_x<<" "<<pow_x*pow_x<<endl;
float up = ((xy * n) - (sum_x * sum_y));
float down = (n * pow_x) - sum_x * sum_x;
// cout<<up<<" "<<down<<endl;
m = up / down;
b = (sum_y - m * sum_x) / n;
if (cmd == "mb")
{
cout << round(m * 1e3) / 1e3 << endl;
cout << round(b * 1e3) / 1e3 << endl;
}
else if (cmd == "func")
{
if (m == 0 && b == 0)
cout << "y = 0";
else if (m == 1 && b == 0)
cout << "y = x";
else if (m == -1 && b == 0)
cout << "y = -x";
else if (m == 0)
cout << "y = " << b;
else
{
if(b>0)
{
cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
else if(b<0)
{
cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<round(abs(b)*1e3)/1e3;
}
else if(m==0&&b>0)
{
cout<<"y = "<<"x + "<<round(abs(b)*1e3)/1e3;
}
else if(m==0&&b<0)
{
cout<<"y = "<<"x - "<<round(abs(b)*1e3)/1e3;
}
}
}
return 0;
} | # 1036, 2024-11-02 13:46:49, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string cmd;
cin >> cmd;
float a, c;
float m = 0, b = 0;
float sum_x = 0;
float sum_y = 0;
float pow_x = 0;
float xy = 0;
for (int i = 0; i < n; ++i)
{
cin >> a >> c;
// if(i>=1)
{
sum_x += a;
sum_y += c;
xy += a * c;
pow_x += a * a;
}
}
// cout<<xy<<" "<<sum_x<<" "<<sum_y<<" "<<pow_x<<" "<<pow_x*pow_x<<endl;
float up = ((xy * n) - (sum_x * sum_y));
float down = (n * pow_x) - sum_x * sum_x;
// cout<<up<<" "<<down<<endl;
m = up / down;
b = (sum_y - m * sum_x) / n;
if (cmd == "mb")
{
cout << round(m * 1e3) / 1e3 << endl;
cout << round(b * 1e3) / 1e3 << endl;
}
else if (cmd == "func")
{
if (m == 0 && b == 0)
cout << "y = 0";
else if (m == 1 && b == 0)
cout << "y = x";
else if (m == -1 && b == 0)
cout << "y = -x";
else if (m == 0)
cout << "y = " << b;
else
{
if(m==1&&b>0)
{
cout<<"y = "<<"x + "<<round(abs(b)*1e3)/1e3;
}
else if(m==-1&&b<0)
{
cout<<"y = "<<"-x - "<<round(abs(b)*1e3)/1e3;
}
else if(b>0)
{
cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
else if(b<0)
{
cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<round(abs(b)*1e3)/1e3;
}
}
}
return 0;
} | # 1037, 2024-11-02 14:47:09, ------------------------ (0%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string cmd;
cin >> cmd;
float a, c;
float m = 0, b = 0;
float sum_x = 0;
float sum_y = 0;
float pow_x = 0;
float xy = 0;
for (int i = 0; i < n; ++i)
{
cin >> a >> c;
// if(i>=1)
{
sum_x += a;
sum_y += c;
xy += a * c;
pow_x += a * a;
}
}
//cout<<xy<<" "<<sum_x<<" "<<sum_y<<" "<<pow_x<<" "<<sum_x*sum_x<<endl;
float up = ((xy * n) - (sum_x * sum_y));
float down = (n * pow_x) - sum_x * sum_x;
// cout<<up<<" "<<down<<endl;
m = up / down;
b = (sum_y - m * sum_x) / n;
float opb =(-1)*b;
//cout<<up<<" "<<down<<endl;
cout<<"m="<<m<<" b="<<b<<endl;
if (cmd == "mb")
{
cout << round(m * 1e3) / 1e3 << endl;
cout << round(b * 1e3) / 1e3 << endl;
}
else if (cmd == "func")
{
if (m == 0 && b == 0)
cout << "y = 0";
else if (m == 1 && b == 0)
cout << "y = x";
else if (m == -1 && b == 0)
cout << "y = -x";
else if(m==-1&&b<0)
cout<<"y = -x - "<<round(opb*1e3)/1e3;
else if(m==-1&&b>0)
cout<<"y = -x + "<<round(b*1e3)/1e3;
else if (m == 0 && b!=0)
cout << "y = " << b;
else
{
if(m==1&&b>0)
{
cout<<"y = "<<"x + "<<round(abs(b)*1e3)/1e3;
}
else if(m==-1&&b<0)
{
cout<<"y = "<<"-x - "<<round(abs(b)*1e3)/1e3;
}
else if(m!=0&&b>0)
{
cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
else if(m!=0&&b<0)
{
cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<round(abs(b)*1e3)/1e3;
}
}
}
return 0;
} | # 1038, 2024-11-02 14:47:40, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string cmd;
cin >> cmd;
float a, c;
float m = 0, b = 0;
float sum_x = 0;
float sum_y = 0;
float pow_x = 0;
float xy = 0;
for (int i = 0; i < n; ++i)
{
cin >> a >> c;
// if(i>=1)
{
sum_x += a;
sum_y += c;
xy += a * c;
pow_x += a * a;
}
}
//cout<<xy<<" "<<sum_x<<" "<<sum_y<<" "<<pow_x<<" "<<sum_x*sum_x<<endl;
float up = ((xy * n) - (sum_x * sum_y));
float down = (n * pow_x) - sum_x * sum_x;
// cout<<up<<" "<<down<<endl;
m = up / down;
b = (sum_y - m * sum_x) / n;
float opb =(-1)*b;
//cout<<up<<" "<<down<<endl;
//cout<<"m="<<m<<" b="<<b<<endl;
if (cmd == "mb")
{
cout << round(m * 1e3) / 1e3 << endl;
cout << round(b * 1e3) / 1e3 << endl;
}
else if (cmd == "func")
{
if (m == 0 && b == 0)
cout << "y = 0";
else if (m == 1 && b == 0)
cout << "y = x";
else if (m == -1 && b == 0)
cout << "y = -x";
else if(m==-1&&b<0)
cout<<"y = -x - "<<round(opb*1e3)/1e3;
else if(m==-1&&b>0)
cout<<"y = -x + "<<round(b*1e3)/1e3;
else if (m == 0 && b!=0)
cout << "y = " << b;
else
{
if(m==1&&b>0)
{
cout<<"y = "<<"x + "<<round(abs(b)*1e3)/1e3;
}
else if(m==-1&&b<0)
{
cout<<"y = "<<"-x - "<<round(abs(b)*1e3)/1e3;
}
else if(m!=0&&b>0)
{
cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
else if(m!=0&&b<0)
{
cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<round(abs(b)*1e3)/1e3;
}
}
}
return 0;
} | # 1039, 2024-11-02 15:03:42, ------------------------ (0%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string cmd;
cin >> cmd;
float a, c;
float m = 0, b = 0;
float sum_x = 0;
float sum_y = 0;
float pow_x = 0;
float xy = 0;
for (int i = 0; i < n; ++i)
{
cin >> a >> c;
// if(i>=1)
{
sum_x += a;
sum_y += c;
xy += a * c;
pow_x += pow(a,2);
}
}
float up;
up = (float)((xy * n) -(sum_x * sum_y));
float down = (n * pow_x) - sum_x * sum_x;
m = up / down;
b = (sum_y - m * sum_x) / n;
float opb =(-1)*b;
cout<<"m="<<m<<" b="<<b<<endl;
if (cmd == "mb")
{
cout << round(m * 1e3) / 1e3 << endl;
cout << round(b * 1e3) / 1e3 << endl;
}
else if (cmd == "func")
{
if (m == 0 && b == 0)
cout << "y = 0";
else if (m == 1 && b == 0)
cout << "y = x";
else if (m == -1 && b == 0)
cout << "y = -x";
else if(m==-1&&b<0)
cout<<"y = -x - "<<round(opb*1e3)/1e3;
else if(m==-1&&b>0)
cout<<"y = -x + "<<round(b*1e3)/1e3;
else if (round(xy*n*1e3)/1e3==round(sum_x*sum_y*1e3)/1e3 && b!=0)
cout << "y = " << b;
else
{
if(m==1&&b>0)
{
cout<<"y = "<<"x + "<<round(abs(b)*1e3)/1e3;
}
else if(m==-1&&b<0)
{
cout<<"y = "<<"-x - "<<round(abs(b)*1e3)/1e3;
}
else if(m!=0&&b>0)
{
cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
else if(m!=0&&b<0)
{
cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<round(abs(b)*1e3)/1e3;
}
}
}
return 0;
} | # 1040, 2024-11-02 15:04:08, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string cmd;
cin >> cmd;
float a, c;
float m = 0, b = 0;
float sum_x = 0;
float sum_y = 0;
float pow_x = 0;
float xy = 0;
for (int i = 0; i < n; ++i)
{
cin >> a >> c;
// if(i>=1)
{
sum_x += a;
sum_y += c;
xy += a * c;
pow_x += pow(a,2);
}
}
float up;
up = (float)((xy * n) -(sum_x * sum_y));
float down = (n * pow_x) - sum_x * sum_x;
m = up / down;
b = (sum_y - m * sum_x) / n;
float opb =(-1)*b;
if (cmd == "mb")
{
cout << round(m * 1e3) / 1e3 << endl;
cout << round(b * 1e3) / 1e3 << endl;
}
else if (cmd == "func")
{
if (m == 0 && b == 0)
cout << "y = 0";
else if (m == 1 && b == 0)
cout << "y = x";
else if (m == -1 && b == 0)
cout << "y = -x";
else if(m==-1&&b<0)
cout<<"y = -x - "<<round(opb*1e3)/1e3;
else if(m==-1&&b>0)
cout<<"y = -x + "<<round(b*1e3)/1e3;
else if (round(xy*n*1e3)/1e3==round(sum_x*sum_y*1e3)/1e3 && b!=0)
cout << "y = " << b;
else
{
if(m==1&&b>0)
{
cout<<"y = "<<"x + "<<round(abs(b)*1e3)/1e3;
}
else if(m==-1&&b<0)
{
cout<<"y = "<<"-x - "<<round(abs(b)*1e3)/1e3;
}
else if(m!=0&&b>0)
{
cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
else if(m!=0&&b<0)
{
cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<round(abs(b)*1e3)/1e3;
}
}
}
return 0;
} | # 1041, 2024-11-02 15:08:49, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string cmd;
cin >> cmd;
float a, c;
float m = 0, b = 0;
float sum_x = 0;
float sum_y = 0;
float pow_x = 0;
float xy = 0;
for (int i = 0; i < n; ++i)
{
cin >> a >> c;
// if(i>=1)
{
sum_x += a;
sum_y += c;
xy += a * c;
pow_x += pow(a,2);
}
}
float up;
up = (float)((xy * n) -(sum_x * sum_y));
float down = (n * pow_x) - sum_x * sum_x;
m = up / down;
b = (sum_y - m * sum_x) / n;
float opb =(-1)*b;
if (cmd == "mb")
{
cout << round(m * 1e3) / 1e3 << endl;
cout << round(b * 1e3) / 1e3 << endl;
}
else if (cmd == "func")
{
if (m == 0 && b == 0)
cout << "y = 0";
else if (m == 1 && b == 0)
cout << "y = x";
else if (m == -1 && b == 0)
cout << "y = -x";
else if(m==-1&&b<0)
cout<<"y = -x - "<<round(opb*1e3)/1e3;
else if(m==-1&&b>0)
cout<<"y = -x + "<<round(b*1e3)/1e3;
else if (round(xy*n*1e3)/1e3==round(sum_x*sum_y*1e3)/1e3 && b!=0)
cout << "y = " << b;
else
{
if(m==1&&b>0)
{
cout<<"y = x + "<<round(abs(b)*1e3)/1e3;
}
if(m==1&&b<0)
{
cout<<"y = x - "<<round(abs(b)*1e3)/1e3;
}
else if(m==-1&&b<0)
{
cout<<"y = -x - "<<round(abs(b)*1e3)/1e3;
}
else if(m!=0&&b>0)
{
cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
else if(m!=0&&b<0)
{
cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<round(abs(b)*1e3)/1e3;
}
}
}
return 0;
} | # 1042, 2024-11-02 15:10:04, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string cmd;
cin >> cmd;
float a, c;
float m = 0, b = 0;
float sum_x = 0;
float sum_y = 0;
float pow_x = 0;
float xy = 0;
for (int i = 0; i < n; ++i)
{
cin >> a >> c;
// if(i>=1)
{
sum_x += a;
sum_y += c;
xy += a * c;
pow_x += pow(a,2);
}
}
float up;
up = (float)((xy * n) -(sum_x * sum_y));
float down = (n * pow_x) - sum_x * sum_x;
m = up / down;
b = (sum_y - m * sum_x) / n;
float opb =(-1)*b;
if (cmd == "mb")
{
cout << round(m * 1e3) / 1e3 << endl;
cout << round(b * 1e3) / 1e3 << endl;
}
else if (cmd == "func")
{
if (m == 0 && b == 0)
cout << "y = 0";
else if (m == 1 && b == 0)
cout << "y = x";
else if (m == -1 && b == 0)
cout << "y = -x";
else if(m==-1&&b<0)
cout<<"y = -x - "<<round(opb*1e3)/1e3;
else if(m==-1&&b>0)
cout<<"y = -x + "<<round(b*1e3)/1e3;
else if (round(xy*n*1e3)/1e3==round(sum_x*sum_y*1e3)/1e3 && b!=0)
cout << "y = " << b;
else
{
if(m==1&&b>0)
{
cout<<"y = x + "<<round(b*1e3)/1e3;
}
else if(m==1&&b<0)
{
cout<<"y = x - "<<round(opb*1e3)/1e3;
}
else if(m==-1&&b<0)
{
cout<<"y = -x - "<<round(abs(b)*1e3)/1e3;
}
else if(m!=0&&b>0)
{
cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
else if(m!=0&&b<0)
{
cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<round(abs(b)*1e3)/1e3;
}
}
}
return 0;
} | # 1043, 2024-11-02 15:16:06, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string cmd;
cin >> cmd;
float a, c;
float m = 0, b = 0;
float sum_x = 0;
float sum_y = 0;
float pow_x = 0;
float xy = 0;
for (int i = 0; i < n; ++i)
{
cin >> a >> c;
// if(i>=1)
{
sum_x += a;
sum_y += c;
xy += a * c;
pow_x += pow(a,2);
}
}
float up;
up = (float)((xy * n) -(sum_x * sum_y));
float down = (n * pow_x) - sum_x * sum_x;
m = up / down;
b = (sum_y - m * sum_x) / n;
float opb =(-1)*b;
if (cmd == "mb")
{
cout << round(m * 1e3) / 1e3 << endl;
cout << round(b * 1e3) / 1e3 << endl;
}
else if (cmd == "func")
{
if (m == 0 && b == 0)
cout << "y = 0";
else if (m == 1 && b == 0)
cout << "y = x";
else if (m == -1 && b == 0)
cout << "y = -x";
else if(m==-1&&b<0)
cout<<"y = -x - "<<round(opb*1e3)/1e3;
else if(m==-1&&b>0)
cout<<"y = -x + "<<round(b*1e3)/1e3;
else if(m==1 &&b>0)
cout<<"y = x + "<<round(b*1e3)/1e3;
else if(m==1&&b<0)
cout<<"y = x - "<<round(opb*1e3)/1e3;
else if (round(xy*n*1e3)/1e3==round(sum_x*sum_y*1e3)/1e3 && b!=0)
cout << "y = " << b;
else if(m!=0&&b>0)
{
cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;
}
else if(m!=0&&b<0)
{
cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<round(abs(b)*1e3)/1e3;
}
}
return 0;
} |
# 1044, 2024-11-02 10:52:54, PPPPPPPPPP-------------- (41%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
float m=0;
float b=0;
string s;
cin>>n>>s;
float ar1[n];
float ar2[n];
for(int i=0;i<n;i++){
cin>>ar1[i]>>ar2[i];
}
float summ1=0;
float summ2=0;
float summ3=0;
float summ4=0;
for(int i=0;i<n;i++){
summ1+=ar1[i]*ar2[i];
summ2+=ar1[i];
summ3+=ar2[i];
summ4+= float(pow(ar1[i],2));
}
m=((n*summ1)-(summ2*summ3))/((n*summ4)-float(pow(summ2,2)));
b=((summ3-(m*summ2))/n);
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
// int summ2=0;
// for(int i=0;i<n;i++){
// summ2+=ar1[i]*ar2[i];
// }
} | # 1045, 2024-11-02 11:04:15, PPPPPPPPPP-----P--P--P-- (54%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
float m=0;
float b=0;
string s;
cin>>n>>s;
float ar1[n];
float ar2[n];
for(int i=0;i<n;i++){
cin>>ar1[i]>>ar2[i];
}
float summ1=0;
float summ2=0;
float summ3=0;
float summ4=0;
for(int i=0;i<n;i++){
summ1+=ar1[i]*ar2[i];
summ2+=ar1[i];
summ3+=ar2[i];
summ4+= float(pow(ar1[i],2));
}
m=((n*summ1)-(summ2*summ3))/((n*summ4)-float(pow(summ2,2)));
b=((summ3-(m*summ2))/n);
if(s == "mb")
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
else{
if(m==0){
cout<<"y = "<<b;
}
else if(m==1){
if(b==0){
cout<<"y = x";
}
}
}
// int summ2=0;
// for(int i=0;i<n;i++){
// summ2+=ar1[i]*ar2[i];
// }
// 3 mb
// 1.0 -3.0
// 2.0 -3.0
// 4.4 -3.0
} | # 1046, 2024-11-02 11:05:56, PPPPPPPPPP-----P--P--P-- (54%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
float m=0;
float b=0;
string s;
cin>>n>>s;
float ar1[n];
float ar2[n];
for(int i=0;i<n;i++){
cin>>ar1[i]>>ar2[i];
}
float summ1=0;
float summ2=0;
float summ3=0;
float summ4=0;
for(int i=0;i<n;i++){
summ1+=ar1[i]*ar2[i];
summ2+=ar1[i];
summ3+=ar2[i];
summ4+= float(pow(ar1[i],2));
}
m=((n*summ1)-(summ2*summ3))/((n*summ4)-float(pow(summ2,2)));
b=((summ3-(m*summ2))/n);
if(s == "mb")
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
else{
if(m==0){
cout<<"y = "<<b;
}
else if(m==1){
if(b==0){
cout<<"y = x";
}
else{
if(b>0)
cout<<"y = x + "<<b;
else{
cout<<"y = x - "<<abs(b);
}
}
}
}
// int summ2=0;
// for(int i=0;i<n;i++){
// summ2+=ar1[i]*ar2[i];
// }
// 3 mb
// 1.0 -3.0
// 2.0 -3.0
// 4.4 -3.0
} | # 1047, 2024-11-02 11:07:21, PPPPPPPPPP-----P--P--P-- (54%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
float m=0;
float b=0;
string s;
cin>>n>>s;
float ar1[n];
float ar2[n];
for(int i=0;i<n;i++){
cin>>ar1[i]>>ar2[i];
}
float summ1=0;
float summ2=0;
float summ3=0;
float summ4=0;
for(int i=0;i<n;i++){
summ1+=ar1[i]*ar2[i];
summ2+=ar1[i];
summ3+=ar2[i];
summ4+= float(pow(ar1[i],2));
}
m=((n*summ1)-(summ2*summ3))/((n*summ4)-float(pow(summ2,2)));
b=((summ3-(m*summ2))/n);
if(s == "mb")
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
else{
if(m==0){
cout<<"y = "<<b;
}
else if(m==1){
if(b==0){
cout<<"y = x";
}
else{
if(b>0)
cout<<"y = x + "<<b;
else{
cout<<"y = x - "<<abs(b);
}
}
}
else if(m==1){
if(b==0){
cout<<"y = -x";
}
else{
if(b>0)
cout<<"y = -x + "<<b;
else{
cout<<"y = -x - "<<abs(b);
}
}
}
}
// int summ2=0;
// for(int i=0;i<n;i++){
// summ2+=ar1[i]*ar2[i];
// }
// 3 mb
// 1.0 -3.0
// 2.0 -3.0
// 4.4 -3.0
} | # 1048, 2024-11-02 11:08:15, PPPPPPPPPP-----P--PP-P-- (58%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
float m=0;
float b=0;
string s;
cin>>n>>s;
float ar1[n];
float ar2[n];
for(int i=0;i<n;i++){
cin>>ar1[i]>>ar2[i];
}
float summ1=0;
float summ2=0;
float summ3=0;
float summ4=0;
for(int i=0;i<n;i++){
summ1+=ar1[i]*ar2[i];
summ2+=ar1[i];
summ3+=ar2[i];
summ4+= float(pow(ar1[i],2));
}
m=((n*summ1)-(summ2*summ3))/((n*summ4)-float(pow(summ2,2)));
b=((summ3-(m*summ2))/n);
if(s == "mb")
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
else{
if(m==0){
cout<<"y = "<<b;
}
else if(m==1){
if(b==0){
cout<<"y = x";
}
else{
if(b>0)
cout<<"y = x + "<<b;
else{
cout<<"y = x - "<<abs(b);
}
}
}
else if(m==-1){
if(b==0){
cout<<"y = -x";
}
else{
if(b>0)
cout<<"y = -x + "<<b;
else{
cout<<"y = -x - "<<abs(b);
}
}
}
}
// int summ2=0;
// for(int i=0;i<n;i++){
// summ2+=ar1[i]*ar2[i];
// }
// 3 mb
// 1.0 -3.0
// 2.0 -3.0
// 4.4 -3.0
} | # 1049, 2024-11-02 11:17:16, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
float m=0;
float b=0;
string s;
cin>>n>>s;
float ar1[n];
float ar2[n];
for(int i=0;i<n;i++){
cin>>ar1[i]>>ar2[i];
}
float summ1=0;
float summ2=0;
float summ3=0;
float summ4=0;
for(int i=0;i<n;i++){
summ1+=ar1[i]*ar2[i];
summ2+=ar1[i];
summ3+=ar2[i];
summ4+= float(pow(ar1[i],2));
}
m=((n*summ1)-(summ2*summ3))/((n*summ4)-float(pow(summ2,2)));
b=((summ3-(m*summ2))/n);
if(s == "mb")
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
else{
if(m==0){
cout<<"y = "<<round(b*1e3)/1e3;
}
else if(m==1){
if(b==0){
cout<<"y = x";
}
else{
if(b>0)
cout<<"y = x + "<<round(b*1e3)/1e3;
else{
cout<<"y = x - "<<round(abs(b)*1e3)/1e3;
}
}
}
else if(m==-1){
if(b==0){
cout<<"y = -x";
}
else{
if(b>0)
cout<<"y = -x + "<<round(b*1e3)/1e3;
else{
cout<<"y = -x - "<<round(abs(b)*1e3)/1e3;
}
}
}
else if(m>1){
if(b==0){
cout<<"y = "<<round(m*1e3)/1e3<<"x";
}
else{
if(b>0)
cout<<"y = "<<round(m*1e3)/1e3<<"x"<<" + "<<round(b*1e3)/1e3;
else{
cout<<"y = "<<round(m*1e3)/1e3<<"x"<<" - "<<round(abs(b)*1e3)/1e3;
}
}
}
else if(m<-1){
if(b==0){
cout<<"y = -"<<round(abs(m)*1e3)/1e3<<"x";
}
else{
if(b>0)
cout<<"y = -"<<round(abs(m)*1e3)/1e3<<"x"<<" + "<<round(b*1e3)/1e3;
else{
cout<<"y = -"<<round(abs(m)*1e3)/1e3<<"x"<<" - "<<round(abs(b)*1e3)/1e3;
}
}
}
}
// int summ2=0;
// for(int i=0;i<n;i++){
// summ2+=ar1[i]*ar2[i];
// }
// 3 mb
// 1.0 -3.0
// 2.0 -3.0
// 4.4 -3.0
} | # 1050, 2024-11-02 11:20:57, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n;
float m=0;
float b=0;
string s;
cin>>n>>s;
float ar1[n];
float ar2[n];
for(int i=0;i<n;i++){
cin>>ar1[i]>>ar2[i];
}
float summ1=0;
float summ2=0;
float summ3=0;
float summ4=0;
for(int i=0;i<n;i++){
summ1+=ar1[i]*ar2[i];
summ2+=ar1[i];
summ3+=ar2[i];
summ4+= float(pow(ar1[i],2));
}
m=((n*summ1)-(summ2*summ3))/((n*summ4)-float(pow(summ2,2)));
b=((summ3-(m*summ2))/n);
if(s == "mb")
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
else{
if(m==0){
cout<<"y = "<<round(b*1e3)/1e3;
}
else if(m==1){
if(b==0){
cout<<"y = x";
}
else{
if(b>0)
cout<<"y = x + "<<round(b*1e3)/1e3;
else{
cout<<"y = x - "<<round(abs(b)*1e3)/1e3;
}
}
}
else if(m==-1){
if(b==0){
cout<<"y = -x";
}
else{
if(b>0)
cout<<"y = -x + "<<round(b*1e3)/1e3;
else{
cout<<"y = -x - "<<round(abs(b)*1e3)/1e3;
}
}
}
else if(m>1){
if(b==0){
cout<<"y = "<<round(m*1e3)/1e3<<"x";
}
else{
if(b>0)
cout<<"y = "<<round(m*1e3)/1e3<<"x"<<" + "<<round(b*1e3)/1e3;
else{
cout<<"y = "<<round(m*1e3)/1e3<<"x"<<" - "<<round(abs(b)*1e3)/1e3;
}
}
}
else if(m<-1){
if(b==0){
cout<<"y = -"<<round(abs(m)*1e3)/1e3<<"x";
}
else{
if(b>0)
cout<<"y = -"<<round(abs(m)*1e3)/1e3<<"x"<<" + "<<round(b*1e3)/1e3;
else{
cout<<"y = -"<<round(abs(m)*1e3)/1e3<<"x"<<" - "<<round(abs(b)*1e3)/1e3;
}
}
}
}
// int summ2=0;
// for(int i=0;i<n;i++){
// summ2+=ar1[i]*ar2[i];
// }
// 3 mb
// 1.0 -3.0
// 2.0 -3.0
// 4.4 -3.0
} | # 1051, 2024-11-02 11:27:08, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n;
float m=0;
float b=0;
string s;
cin>>n>>s;
float ar1[n];
float ar2[n];
for(int i=0;i<n;i++){
cin>>ar1[i]>>ar2[i];
}
float summ1=0;
float summ2=0;
float summ3=0;
float summ4=0;
for(int i=0;i<n;i++){
summ1+=ar1[i]*ar2[i];
summ2+=ar1[i];
summ3+=ar2[i];
summ4+= float(pow(ar1[i],2));
}
m=((n*summ1)-(summ2*summ3))/((n*summ4)-float(pow(summ2,2)));
b=((summ3-(m*summ2))/n);
if(s == "mb")
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
else{
if(m==0){
cout<<"y = "<<round(b*1e3)/1e3;
}
else if(m==1){
if(b==0){
cout<<"y = x";
}
else{
if(b>0)
cout<<"y = x + "<<round(b*1e3)/1e3;
else{
cout<<"y = x - "<<round(float(abs(b))*1e3)/1e3;
}
}
}
else if(m==-1){
if(b==0){
cout<<"y = -x";
}
else{
if(b>0)
cout<<"y = -x + "<<round(b*1e3)/1e3;
else{
cout<<"y = -x - "<<round(float(abs(b))*1e3)/1e3;
}
}
}
else if(m>1){
if(b==0){
cout<<"y = "<<round(m*1e3)/1e3<<"x";
}
else{
if(b>0)
cout<<"y = "<<round(m*1e3)/1e3<<"x"<<" + "<<round(b*1e3)/1e3;
else{
cout<<"y = "<<round(m*1e3)/1e3<<"x"<<" - "<<round(float(abs(b))*1e3)/1e3;
}
}
}
else if(m<-1){
if(b==0){
cout<<"y = -"<<round(float(abs(m))*1e3)/1e3<<"x";
}
else{
if(b>0)
cout<<"y = -"<<round(float(abs(m))*1e3)/1e3<<"x"<<" + "<<round(b*1e3)/1e3;
else{
cout<<"y = -"<<round(float(abs(m))*1e3)/1e3<<"x"<<" - "<<round(float(abs(b))*1e3)/1e3;
}
}
}
}
// int summ2=0;
// for(int i=0;i<n;i++){
// summ2+=ar1[i]*ar2[i];
// }
// 3 mb
// 1.0 -3.0
// 2.0 -3.0
// 4.4 -3.0
} | # 1052, 2024-11-02 11:31:13, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n;
float m=0;
float b=0;
string s;
cin>>n>>s;
float ar1[n];
float ar2[n];
for(int i=0;i<n;i++){
cin>>ar1[i]>>ar2[i];
}
float summ1=0;
float summ2=0;
float summ3=0;
float summ4=0;
for(int i=0;i<n;i++){
summ1+=ar1[i]*ar2[i];
summ2+=ar1[i];
summ3+=ar2[i];
summ4+= float(pow(ar1[i],2));
}
m=((n*summ1)-(summ2*summ3))/((n*summ4)-float(pow(summ2,2)));
b=float((summ3-(m*summ2))/n);
if(s == "mb")
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
else{
if(m==0){
cout<<"y = "<<round(b*1e3)/1e3;
}
else if(m==1){
if(b==0){
cout<<"y = x";
}
else{
if(b>0)
cout<<"y = x + "<<round(b*1e3)/1e3;
else{
cout<<"y = x - "<<round(float(abs(b))*1e3)/1e3;
}
}
}
else if(m==-1){
if(b==0){
cout<<"y = -x";
}
else{
if(b>0)
cout<<"y = -x + "<<round(b*1e3)/1e3;
else{
cout<<"y = -x - "<<round(float(abs(b))*1e3)/1e3;
}
}
}
else if(m>1){
if(b==0){
cout<<"y = "<<round(m*1e3)/1e3<<"x";
}
else{
if(b>0)
cout<<"y = "<<round(m*1e3)/1e3<<"x"<<" + "<<round(b*1e3)/1e3;
else{
cout<<"y = "<<round(m*1e3)/1e3<<"x"<<" - "<<round(float(abs(b))*1e3)/1e3;
}
}
}
else if(m<-1){
if(b==0){
cout<<"y = -"<<round(float(abs(m))*1e3)/1e3<<"x";
}
else{
if(b>0)
cout<<"y = -"<<round(float(abs(m))*1e3)/1e3<<"x"<<" + "<<round(b*1e3)/1e3;
else{
cout<<"y = -"<<round(float(abs(m))*1e3)/1e3<<"x"<<" - "<<round(float(abs(b))*1e3)/1e3;
}
}
}
}
// int summ2=0;
// for(int i=0;i<n;i++){
// summ2+=ar1[i]*ar2[i];
// }
// 3 mb
// 1.0 -3.0
// 2.0 -3.0
// 4.4 -3.0
} | # 1053, 2024-11-02 11:52:03, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n;
float m=0;
float b=0;
string s;
cin>>n>>s;
float ar1[n];
float ar2[n];
for(int i=0;i<n;i++){
cin>>ar1[i]>>ar2[i];
}
float summ1=0;
float summ2=0;
float summ3=0;
float summ4=0;
for(int i=0;i<n;i++){
summ1+=ar1[i]*ar2[i];
summ2+=ar1[i];
summ3+=ar2[i];
summ4+= float(pow(ar1[i],2));
}
m=((n*summ1)-(summ2*summ3))/((n*summ4)-float(pow(summ2,2)));
b=float((summ3-(m*summ2))/n);
if(s == "mb")
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
else{
if(m==0){
cout<<"y = "<<round(b*1e3)/1e3;
}
else if(m==1){
if(b==0){
cout<<"y = x";
}
else{
if(b>0)
cout<<"y = x + "<<round(b*1e3)/1e3;
else{
cout<<"y = x - "<<round(float(abs(b))*1e3)/1e3;
}
}
}
else if(m==-1){
if(b==0){
cout<<"y = -x";
}
else{
if(b>0)
cout<<"y = -x + "<<round(b*1e3)/1e3;
else{
cout<<"y = -x - "<<round(float(abs(b))*1e3)/1e3;
}
}
}
else if(m>1){
if(b==0){
cout<<"y = "<<round(m*1e3)/1e3<<"x";
}
else{
if(b>0)
cout<<"y = "<<round(m*1e3)/1e3<<"x"<<" + "<<round(b*1e3)/1e3;
else{
cout<<"y = "<<round(m*1e3)/1e3<<"x"<<" - "<<round(float(abs(b))*1e3)/1e3;
}
}
}
else if(m<0){
if(b==0){
cout<<"y = -"<<round(float(abs(m))*1e3)/1e3<<"x";
}
else{
if(b>0)
cout<<"y = -"<<round(float(abs(m))*1e3)/1e3<<"x"<<" + "<<round(b*1e3)/1e3;
else{
cout<<"y = -"<<round(float(abs(m))*1e3)/1e3<<"x"<<" - "<<round(float(abs(b))*1e3)/1e3;
}
}
}
}
// int summ2=0;
// for(int i=0;i<n;i++){
// summ2+=ar1[i]*ar2[i];
// }
// 3 mb
// 1.0 -3.0
// 2.0 -3.0
// 4.4 -3.0
// 20 func
// 1.1881 1.5293
// 1.7655 1.1602
// 1.8581 1.1016
// 2.2834 0.8302
// 2.7323 0.5438
// 3.0490 0.3426
// 3.2191 0.2325
// 3.5325 0.0332
// 3.7860 -0.1221
// 5.8511 -1.4411
// 6.0823 -1.5966
// 6.2641 -1.7018
// 6.6594 -1.9658
// 6.9622 -2.1554
// 7.5696 -2.5427
// 7.6285 -2.5792
// 7.9083 -2.7581
// 7.9242 -2.7681
// 9.6531 -3.8725
// 9.9108 -4.0347
} | # 1054, 2024-11-02 11:54:32, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n;
float m=0;
float b=0;
string s;
cin>>n>>s;
float ar1[n];
float ar2[n];
for(int i=0;i<n;i++){
cin>>ar1[i]>>ar2[i];
}
float summ1=0;
float summ2=0;
float summ3=0;
float summ4=0;
for(int i=0;i<n;i++){
summ1+=ar1[i]*ar2[i];
summ2+=ar1[i];
summ3+=ar2[i];
summ4+= float(pow(ar1[i],2));
}
m=((n*summ1)-(summ2*summ3))/((n*summ4)-float(pow(summ2,2)));
b=float((summ3-(m*summ2))/n);
if(s == "mb")
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
else{
if(m==0.0){
cout<<"y = "<<round(b*1e3)/1e3;
}
else if(m==1.0){
if(b==0.0){
cout<<"y = x";
}
else{
if(b>0.0)
cout<<"y = x + "<<round(b*1e3)/1e3;
else{
cout<<"y = x - "<<round(float(abs(b))*1e3)/1e3;
}
}
}
else if(m==-1.0){
if(b==0.0){
cout<<"y = -x";
}
else{
if(b>0.0)
cout<<"y = -x + "<<round(b*1e3)/1e3;
else{
cout<<"y = -x - "<<round(float(abs(b))*1e3)/1e3;
}
}
}
else if(m>1.0){
if(b==0.0){
cout<<"y = "<<round(m*1e3)/1e3<<"x";
}
else{
if(b>0.0)
cout<<"y = "<<round(m*1e3)/1e3<<"x"<<" + "<<round(b*1e3)/1e3;
else{
cout<<"y = "<<round(m*1e3)/1e3<<"x"<<" - "<<round(float(abs(b))*1e3)/1e3;
}
}
}
else if(m<0.0){
if(b==0.0){
cout<<"y = -"<<round(float(abs(m))*1e3)/1e3<<"x";
}
else{
if(b>0.0)
cout<<"y = -"<<round(float(abs(m))*1e3)/1e3<<"x"<<" + "<<round(b*1e3)/1e3;
else{
cout<<"y = -"<<round(float(abs(m))*1e3)/1e3<<"x"<<" - "<<round(float(abs(b))*1e3)/1e3;
}
}
}
}
// int summ2=0;
// for(int i=0;i<n;i++){
// summ2+=ar1[i]*ar2[i];
// }
// 3 mb
// 1.0 -3.0
// 2.0 -3.0
// 4.4 -3.0
// 20 func
// 1.1881 1.5293
// 1.7655 1.1602
// 1.8581 1.1016
// 2.2834 0.8302
// 2.7323 0.5438
// 3.0490 0.3426
// 3.2191 0.2325
// 3.5325 0.0332
// 3.7860 -0.1221
// 5.8511 -1.4411
// 6.0823 -1.5966
// 6.2641 -1.7018
// 6.6594 -1.9658
// 6.9622 -2.1554
// 7.5696 -2.5427
// 7.6285 -2.5792
// 7.9083 -2.7581
// 7.9242 -2.7681
// 9.6531 -3.8725
// 9.9108 -4.0347
} | # 1055, 2024-11-02 12:08:17, PPPPPPPPPPPPPPPP--PP-P-- (79%)
// #include<bits/stdc++.h>
// using namespace std;
// int main()
// {
// long long n;
// float m=0;
// float b=0;
// string s;
// cin>>n>>s;
// float ar1[n];
// float ar2[n];
// for(int i=0;i<n;i++){
// cin>>ar1[i]>>ar2[i];
// }
// float summ1=0;
// float summ2=0;
// float summ3=0;
// float summ4=0;
// for(int i=0;i<n;i++){
// summ1+=ar1[i]*ar2[i];
// summ2+=ar1[i];
// summ3+=ar2[i];
// summ4+= float(pow(ar1[i],2));
// }
// m=((n*summ1)-(summ2*summ3))/((n*summ4)-float(pow(summ2,2)));
// b=float((summ3-(m*summ2))/n);
// if(s == "mb")
// cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
// else{
// if(m==0){
// cout<<"y = "<<round(b*1e3)/1e3;
// }
// else if(m==1){
// if(b==0){
// cout<<"y = x";
// }
// else{
// if(b>0)
// cout<<"y = x + "<<round(b*1e3)/1e3;
// else{
// cout<<"y = x - "<<round(float(abs(b))*1e3)/1e3;
// }
// }
// }
// else if(m==-1){
// if(b==0){
// cout<<"y = -x";
// }
// else{
// if(b>0)
// cout<<"y = -x + "<<round(b*1e3)/1e3;
// else{
// cout<<"y = -x - "<<round(float(abs(b))*1e3)/1e3;
// }
// }
// }
// else if(m>1){
// if(b==0){
// cout<<"y = "<<round(m*1e3)/1e3<<"x";
// }
// else{
// if(b>0)
// cout<<"y = "<<round(m*1e3)/1e3<<"x"<<" + "<<round(b*1e3)/1e3;
// else{
// cout<<"y = "<<round(m*1e3)/1e3<<"x"<<" - "<<round(float(abs(b))*1e3)/1e3;
// }
// }
// }
// else if(m<-1){
// if(b==0){
// cout<<"y = -"<<round(float(abs(m))*1e3)/1e3<<"x";
// }
// else{
// if(b>0)
// cout<<"y = -"<<round(float(abs(m))*1e3)/1e3<<"x"<<" + "<<round(b*1e3)/1e3;
// else{
// cout<<"y = -"<<round(float(abs(m))*1e3)/1e3<<"x"<<" - "<<round(float(abs(b))*1e3)/1e3;
// }
// }
// }
// }
// // int summ2=0;
// // for(int i=0;i<n;i++){
// // summ2+=ar1[i]*ar2[i];
// // }
// // 3 mb
// // 1.0 -3.0
// // 2.0 -3.0
// // 4.4 -3.0
// }
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
float m=0;
float b=0;
string s;
cin>>n>>s;
float ar1[n];
float ar2[n];
for(int i=0;i<n;i++){
cin>>ar1[i]>>ar2[i];
}
float summ1=0;
float summ2=0;
float summ3=0;
float summ4=0;
for(int i=0;i<n;i++){
summ1+=ar1[i]*ar2[i];
summ2+=ar1[i];
summ3+=ar2[i];
summ4+= float(pow(ar1[i],2));
}
m=((n*summ1)-(summ2*summ3))/((n*summ4)-float(pow(summ2,2)));
b=((summ3-(m*summ2))/n);
if(s == "mb")
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
else{
if(m==0){
cout<<"y = "<<round(b*1e3)/1e3;
}
else if(m==1){
if(b==0){
cout<<"y = x";
}
else{
if(b>0)
cout<<"y = x + "<<round(b*1e3)/1e3;
else{
cout<<"y = x - "<<round(abs(b)*1e3)/1e3;
}
}
}
else if(m==-1){
if(b==0){
cout<<"y = -x";
}
else{
if(b>0)
cout<<"y = -x + "<<round(b*1e3)/1e3;
else{
cout<<"y = -x - "<<round(abs(b)*1e3)/1e3;
}
}
}
else if(m>0){
if(b==0){
cout<<"y = "<<round(m*1e3)/1e3<<"x";
}
else{
if(b>0)
cout<<"y = "<<round(m*1e3)/1e3<<"x"<<" + "<<round(b*1e3)/1e3;
else{
cout<<"y = "<<round(m*1e3)/1e3<<"x"<<" - "<<round(abs(b)*1e3)/1e3;
}
}
}
else if(m<0){
if(b==0){
cout<<"y = -"<<round(abs(m)*1e3)/1e3<<"x";
}
else{
if(b>0)
cout<<"y = -"<<round(abs(m)*1e3)/1e3<<"x"<<" + "<<round(b*1e3)/1e3;
else{
cout<<"y = -"<<round(abs(m)*1e3)/1e3<<"x"<<" - "<<round(abs(b)*1e3)/1e3;
}
}
}
}
// int summ2=0;
// for(int i=0;i<n;i++){
// summ2+=ar1[i]*ar2[i];
// }
// 3 mb
// 1.0 -3.0
// 2.0 -3.0
// 4.4 -3.0
} | # 1056, 2024-11-02 12:11:27, PPPPPPPPPPPPPPPP--PP-P-- (79%)
// #include<bits/stdc++.h>
// using namespace std;
// int main()
// {
// long long n;
// float m=0;
// float b=0;
// string s;
// cin>>n>>s;
// float ar1[n];
// float ar2[n];
// for(int i=0;i<n;i++){
// cin>>ar1[i]>>ar2[i];
// }
// float summ1=0;
// float summ2=0;
// float summ3=0;
// float summ4=0;
// for(int i=0;i<n;i++){
// summ1+=ar1[i]*ar2[i];
// summ2+=ar1[i];
// summ3+=ar2[i];
// summ4+= float(pow(ar1[i],2));
// }
// m=((n*summ1)-(summ2*summ3))/((n*summ4)-float(pow(summ2,2)));
// b=float((summ3-(m*summ2))/n);
// if(s == "mb")
// cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
// else{
// if(m==0){
// cout<<"y = "<<round(b*1e3)/1e3;
// }
// else if(m==1){
// if(b==0){
// cout<<"y = x";
// }
// else{
// if(b>0)
// cout<<"y = x + "<<round(b*1e3)/1e3;
// else{
// cout<<"y = x - "<<round(float(abs(b))*1e3)/1e3;
// }
// }
// }
// else if(m==-1){
// if(b==0){
// cout<<"y = -x";
// }
// else{
// if(b>0)
// cout<<"y = -x + "<<round(b*1e3)/1e3;
// else{
// cout<<"y = -x - "<<round(float(abs(b))*1e3)/1e3;
// }
// }
// }
// else if(m>1){
// if(b==0){
// cout<<"y = "<<round(m*1e3)/1e3<<"x";
// }
// else{
// if(b>0)
// cout<<"y = "<<round(m*1e3)/1e3<<"x"<<" + "<<round(b*1e3)/1e3;
// else{
// cout<<"y = "<<round(m*1e3)/1e3<<"x"<<" - "<<round(float(abs(b))*1e3)/1e3;
// }
// }
// }
// else if(m<-1){
// if(b==0){
// cout<<"y = -"<<round(float(abs(m))*1e3)/1e3<<"x";
// }
// else{
// if(b>0)
// cout<<"y = -"<<round(float(abs(m))*1e3)/1e3<<"x"<<" + "<<round(b*1e3)/1e3;
// else{
// cout<<"y = -"<<round(float(abs(m))*1e3)/1e3<<"x"<<" - "<<round(float(abs(b))*1e3)/1e3;
// }
// }
// }
// }
// // int summ2=0;
// // for(int i=0;i<n;i++){
// // summ2+=ar1[i]*ar2[i];
// // }
// // 3 mb
// // 1.0 -3.0
// // 2.0 -3.0
// // 4.4 -3.0
// }
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
float m=0;
float b=0;
string s;
cin>>n>>s;
float ar1[n];
float ar2[n];
for(int i=0;i<n;i++){
cin>>ar1[i]>>ar2[i];
}
float summ1=0;
float summ2=0;
float summ3=0;
float summ4=0;
for(int i=0;i<n;i++){
summ1+=ar1[i]*ar2[i];
summ2+=ar1[i];
summ3+=ar2[i];
summ4+= float(pow(ar1[i],2));
}
m=((n*summ1)-(summ2*summ3))/((n*summ4)-float(pow(summ2,2)));
b=((summ3-(m*summ2))/n);
if(s == "mb")
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
else{
if(m==0){
cout<<"y = "<<round(b*1e3)/1e3;
}
else if(m==1){
if(b==0){
cout<<"y = x";
}
else{
if(b>0)
cout<<"y = x + "<<round(b*1e3)/1e3;
else{
cout<<"y = x - "<<round((-1*b)*1e3)/1e3;
}
}
}
else if(m==-1){
if(b==0){
cout<<"y = -x";
}
else{
if(b>0)
cout<<"y = -x + "<<round(b*1e3)/1e3;
else{
cout<<"y = -x - "<<round((-1*b)*1e3)/1e3;
}
}
}
else if(m>0){
if(b==0){
cout<<"y = "<<round(m*1e3)/1e3<<"x";
}
else{
if(b>0)
cout<<"y = "<<round(m*1e3)/1e3<<"x"<<" + "<<round(b*1e3)/1e3;
else{
cout<<"y = "<<round(m*1e3)/1e3<<"x"<<" - "<<round((-1*b)*1e3)/1e3;
}
}
}
else if(m<0){
if(b==0){
cout<<"y = -"<<round((-1*m)*1e3)/1e3<<"x";
}
else{
if(b>0)
cout<<"y = -"<<round((-1*m)*1e3)/1e3<<"x"<<" + "<<round(b*1e3)/1e3;
else{
cout<<"y = -"<<round((-1*m)*1e3)/1e3<<"x"<<" - "<<round((-1*b)*1e3)/1e3;
}
}
}
}
// int summ2=0;
// for(int i=0;i<n;i++){
// summ2+=ar1[i]*ar2[i];
// }
// 3 mb
// 1.0 -3.0
// 2.0 -3.0
// 4.4 -3.0
} |
# 1057, 2024-11-02 13:25:34, PPPPPPPPPPP-P--P--PP-P-- (66%)
#include<bits/stdc++.h>
using namespace std;
float find_m(vector<float>& xi, vector<float>& yi,int& n){
float xy=0;
float x=0,y=0,nx2=0;
for(int i=0;i<n;i++) {
xy+=xi[i]*yi[i]; //upper
x+=xi[i]; //upper
y+=yi[i]; //upper
nx2 += (xi[i]*xi[i]); //lower
}
xy*=n;
nx2*=n;
float xy2 = x*y;
float m = xy - xy2;
//lower part
float x2 = x*x; //x^2
m /= (nx2-x2);
return m;
}
float find_b(vector<float>& xi, vector<float>& yi,int& n){
float y=0,x=0;
for(int i=0;i<n;i++){
y += yi[i];
x += xi[i];
}
x*= find_m(xi,yi,n);
float b = (y-x)/n;
return b;
}
int main(){
int n;
string cmd;
cin>>n>>cmd;
vector<float> xi;
vector<float> yi;
float x,y;
for(int i=0;i<n;i++){
cin>>x>>y;
xi.push_back(x);
yi.push_back(y);
}
if(cmd=="mb"){
float m = find_m(xi,yi,n);
float b = find_b(xi,yi,n);
if(m==-0)m=0;
if(b==-0)b=0;
cout<< round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
return 0;
}
else{
cout<<"y = ";
float m =find_m(xi,yi,n);
float b =find_b(xi,yi,n);
if(m!=1&&m!=0&&m!=-1)cout<<round(m*1e3)/1e3;
else if(m==-1)cout<<"-";
if(m!=0)cout<<"x ";
if(b!=0){
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else cout<<"-"<<abs(round(b*1e3)/1e3);
}
else if(m==0 && b==0)cout<<0;
}
} | # 1058, 2024-11-02 13:26:24, PPPPPPPPPPPPPPPP--PP---- (75%)
#include<bits/stdc++.h>
using namespace std;
float find_m(vector<float>& xi, vector<float>& yi,int& n){
float xy=0;
float x=0,y=0,nx2=0;
for(int i=0;i<n;i++) {
xy+=xi[i]*yi[i]; //upper
x+=xi[i]; //upper
y+=yi[i]; //upper
nx2 += (xi[i]*xi[i]); //lower
}
xy*=n;
nx2*=n;
float xy2 = x*y;
float m = xy - xy2;
//lower part
float x2 = x*x; //x^2
m /= (nx2-x2);
return m;
}
float find_b(vector<float>& xi, vector<float>& yi,int& n){
float y=0,x=0;
for(int i=0;i<n;i++){
y += yi[i];
x += xi[i];
}
x*= find_m(xi,yi,n);
float b = (y-x)/n;
return b;
}
int main(){
int n;
string cmd;
cin>>n>>cmd;
vector<float> xi;
vector<float> yi;
float x,y;
for(int i=0;i<n;i++){
cin>>x>>y;
xi.push_back(x);
yi.push_back(y);
}
if(cmd=="mb"){
float m = find_m(xi,yi,n);
float b = find_b(xi,yi,n);
if(m==-0)m=0;
if(b==-0)b=0;
cout<< round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
return 0;
}
else{
cout<<"y = ";
float m =find_m(xi,yi,n);
float b =find_b(xi,yi,n);
if(m!=1&&m!=0&&m!=-1)cout<<round(m*1e3)/1e3;
else if(m==-1)cout<<"-";
if(m!=0)cout<<"x ";
if(b!=0){
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else cout<<"- "<<abs(round(b*1e3)/1e3);
}
else if(m==0 && b==0)cout<<0;
}
} | # 1059, 2024-11-02 13:28:39, PPPPPPPPPPPPPPPP--PP---- (75%)
#include<bits/stdc++.h>
using namespace std;
float find_m(vector<float>& xi, vector<float>& yi,int& n){
float xy=0;
float x=0,y=0,nx2=0;
for(int i=0;i<n;i++) {
xy+=xi[i]*yi[i]; //upper
x+=xi[i]; //upper
y+=yi[i]; //upper
nx2 += (xi[i]*xi[i]); //lower
}
xy*=n;
nx2*=n;
float xy2 = x*y;
float m = xy - xy2;
//lower part
float x2 = x*x; //x^2
m /= (nx2-x2);
return m;
}
float find_b(vector<float>& xi, vector<float>& yi,int& n){
float y=0,x=0;
for(int i=0;i<n;i++){
y += yi[i];
x += xi[i];
}
x*= find_m(xi,yi,n);
float b = (y-x)/n;
return b;
}
int main(){
int n;
string cmd;
cin>>n>>cmd;
vector<float> xi;
vector<float> yi;
float x,y;
for(int i=0;i<n;i++){
cin>>x>>y;
xi.push_back(x);
yi.push_back(y);
}
if(cmd=="mb"){
float m = find_m(xi,yi,n);
float b = find_b(xi,yi,n);
if(m==-0)m=0;
if(b==-0)b=0;
cout<< round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
return 0;
}
else{
cout<<"y = ";
float m =find_m(xi,yi,n);
float b =find_b(xi,yi,n);
if(m!=1&&m!=0&&m!=-1&&m!=-0)cout<<round(m*1e3)/1e3;
else if(m==-1)cout<<"-";
if(m!=0&&m!=-0)cout<<"x ";
if(b!=0&&b!=-0){
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else cout<<"- "<<abs(round(b*1e3)/1e3);
}
else if(m==0 && b==0)cout<<0;
}
} | # 1060, 2024-11-02 13:32:39, PPPPPPPPPPPPPPPP--PP---- (75%)
#include<bits/stdc++.h>
using namespace std;
float find_m(vector<float>& xi, vector<float>& yi,int& n){
float xy=0;
float x=0,y=0,nx2=0;
for(int i=0;i<n;i++) {
xy+=xi[i]*yi[i]; //upper
x+=xi[i]; //upper
y+=yi[i]; //upper
nx2 += (xi[i]*xi[i]); //lower
}
xy*=n;
nx2*=n;
float xy2 = x*y;
float m = xy - xy2;
//lower part
float x2 = x*x; //x^2
m /= (nx2-x2);
return m;
}
float find_b(vector<float>& xi, vector<float>& yi,int& n){
float y=0,x=0;
for(int i=0;i<n;i++){
y += yi[i];
x += xi[i];
}
x*= find_m(xi,yi,n);
float b = (y-x)/n;
return b;
}
int main(){
int n;
string cmd;
cin>>n>>cmd;
vector<float> xi;
vector<float> yi;
float x,y;
for(int i=0;i<n;i++){
cin>>x>>y;
xi.push_back(x);
yi.push_back(y);
}
if(cmd=="mb"){
float m = find_m(xi,yi,n);
float b = find_b(xi,yi,n);
if(m==-0)m=0;
if(b==-0)b=0;
cout<< round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
return 0;
}
else{
cout<<"y = ";
float m =find_m(xi,yi,n);
float b =find_b(xi,yi,n);
if(m<-1||m>1)cout<<round(m*1e3)/1e3; //m != 1 0 -0 -1
else if(m==-1)cout<<"-";
if(m<=-1||m>0)cout<<"x ";
if(b!=0 ||b!=-0){
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else cout<<"- "<<abs(round(b*1e3)/1e3);
}
else if(m==0 && b==0)cout<<0;
}
} | # 1061, 2024-11-02 14:06:56, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
float find_m(vector<float>& xi, vector<float>& yi,int& n){
float xy=0;
float x=0,y=0,nx2=0;
for(int i=0;i<n;i++) {
xy+=xi[i]*yi[i]; //upper
x+=xi[i]; //upper
y+=yi[i]; //upper
nx2 += (xi[i]*xi[i]); //lower
}
xy*=n;
nx2*=n;
float xy2 = x*y;
float m = xy - xy2;
//lower part
float x2 = x*x; //x^2
m /= (nx2-x2);
return m;
}
float find_b(vector<float>& xi, vector<float>& yi,int& n){
float y=0,x=0;
for(int i=0;i<n;i++){
y += yi[i];
x += xi[i];
}
x*= find_m(xi,yi,n);
float b = (y-x)/n;
return b;
}
int main(){
int n;
string cmd;
cin>>n>>cmd;
vector<float> xi;
vector<float> yi;
float x,y;
for(int i=0;i<n;i++){
cin>>x>>y;
xi.push_back(x);
yi.push_back(y);
}
if(cmd=="mb"){
float m = find_m(xi,yi,n);
float b = find_b(xi,yi,n);
if(m==-0)m=0;
if(b==-0)b=0;
cout<< round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
return 0;
}
else{
cout<<"y = ";
float m =find_m(xi,yi,n);
float b =find_b(xi,yi,n);
if(m<-1||m>1)cout<<round(m*1e3)/1e3; //m != 1 0 -0 -1
else if(m==-1)cout<<"-";
if(m<=-1||m>0){cout<<"x ";
if(b!=0 ||b!=-0){
if(b>0)cout<<"+ "<<round(b*1e3)/1e3;
else cout<<"- "<<abs(round(b*1e3)/1e3);
}
}
else if(b<=-1)cout<<b;
else if(m==0 && b==0)cout<<0;
}
} | # 1062, 2024-11-02 14:07:58, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
float find_m(vector<float>& xi, vector<float>& yi,int& n){
float xy=0;
float x=0,y=0,nx2=0;
for(int i=0;i<n;i++) {
xy+=xi[i]*yi[i]; //upper
x+=xi[i]; //upper
y+=yi[i]; //upper
nx2 += (xi[i]*xi[i]); //lower
}
xy*=n;
nx2*=n;
float xy2 = x*y;
float m = xy - xy2;
//lower part
float x2 = x*x; //x^2
m /= (nx2-x2);
return m;
}
float find_b(vector<float>& xi, vector<float>& yi,int& n){
float y=0,x=0;
for(int i=0;i<n;i++){
y += yi[i];
x += xi[i];
}
x*= find_m(xi,yi,n);
float b = (y-x)/n;
return b;
}
int main(){
int n;
string cmd;
cin>>n>>cmd;
vector<float> xi;
vector<float> yi;
float x,y;
for(int i=0;i<n;i++){
cin>>x>>y;
xi.push_back(x);
yi.push_back(y);
}
if(cmd=="mb"){
float m = find_m(xi,yi,n);
float b = find_b(xi,yi,n);
if(m==-0)m=0;
if(b==-0)b=0;
cout<< round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
return 0;
}
else{
cout<<"y = ";
float m =find_m(xi,yi,n);
float b =find_b(xi,yi,n);
if(m<-1||m>1)cout<<round(m*1e3)/1e3; //m != 1 0 -0 -1
else if(m==-1)cout<<"-";
if(m<=-1||m>0){cout<<"x";
if(b!=0 ||b!=-0){
if(b>0)cout<<" + "<<round(b*1e3)/1e3;
else cout<<" - "<<abs(round(b*1e3)/1e3);
}
}
else if(b<=-1)cout<<b;
else if(m==0 && b==0)cout<<0;
}
} | # 1063, 2024-11-02 15:14:32, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
float find_m(vector<float>& xi, vector<float>& yi,int& n){
float xy=0;
float x=0,y=0,nx2=0;
for(int i=0;i<n;i++) {
xy+=xi[i]*yi[i]; //upper
x+=xi[i]; //upper
y+=yi[i]; //upper
nx2 += (xi[i]*xi[i]); //lower
}
xy*=n;
nx2*=n;
float xy2 = x*y;
float m = xy - xy2;
//lower part
float x2 = x*x; //x^2
m /= (nx2-x2);
return m;
}
float find_b(vector<float>& xi, vector<float>& yi,int& n){
float y=0,x=0;
for(int i=0;i<n;i++){
y += yi[i];
x += xi[i];
}
x*= find_m(xi,yi,n);
float b = (y-x)/n;
return b;
}
int main(){
int n;
string cmd;
cin>>n>>cmd;
vector<float> xi;
vector<float> yi;
float x,y;
for(int i=0;i<n;i++){
cin>>x>>y;
xi.push_back(x);
yi.push_back(y);
}
if(cmd=="mb"){
float m = find_m(xi,yi,n);
float b = find_b(xi,yi,n);
if(m==-0)m=0;
if(b==-0)b=0;
cout<< round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
return 0;
}
else{
cout<<"y = ";
float m =find_m(xi,yi,n);
float b =find_b(xi,yi,n);
if(m<-1||m>1)cout<<round(m*1e3)/1e3; //m != 1 0 -0 -1
else if(m==-1)cout<<"-";
if(m<=-1||m>0){cout<<"x";
if(b!=0 ||b!=-0){
if(b>0)cout<<" + "<<round(b*1e3)/1e3;
else cout<<" - "<<round(abs(b)*1e3)/1e3;
}
}
else if(b<=-1)cout<<b;
else if(m==0 && b==0)cout<<0;
}
} | # 1064, 2024-11-02 15:19:57, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
float find_m(vector<float>& xi, vector<float>& yi,int& n){
float xy=0;
float x=0,y=0,nx2=0;
for(int i=0;i<n;i++) {
xy+=xi[i]*yi[i]; //upper
x+=xi[i]; //upper
y+=yi[i]; //upper
nx2 += (xi[i]*xi[i]); //lower
}
xy*=n;
nx2*=n;
float xy2 = x*y;
float m = xy - xy2;
//lower part
float x2 = x*x; //x^2
m /= (nx2-x2);
return m;
}
float find_b(vector<float>& xi, vector<float>& yi,int& n){
float y=0,x=0;
for(int i=0;i<n;i++){
y += yi[i];
x += xi[i];
}
x*= find_m(xi,yi,n);
float b = (y-x)/n;
return b;
}
int main(){
int n;
string cmd;
cin>>n>>cmd;
vector<float> xi;
vector<float> yi;
float x,y;
for(int i=0;i<n;i++){
cin>>x>>y;
xi.push_back(x);
yi.push_back(y);
}
if(cmd=="mb"){
float m = find_m(xi,yi,n);
float b = find_b(xi,yi,n);
if(m==-0)m=0;
if(b==-0)b=0;
cout<< round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
return 0;
}
else{
cout<<"y = ";
float m =find_m(xi,yi,n);
float b =find_b(xi,yi,n);
if(m!=-1 && m!=1 && m!= 0 && m!=-0)cout<<round(m*1e3)/1e3; //m != 1 0 -0 -1
if(m==-1)cout<<"-";
if(m!= 0 && m!=-0){cout<<"x";
if(b!=0 ||b!=-0){
if(b>0)cout<<" + "<<round(b*1e3)/1e3<<endl;
else cout<<" - "<<round(abs(b)*1e3)/1e3<<endl;
}
}
else if(b<=-1)cout<<b;
else if(m==0 && b==0)cout<<0;
}
} | # 1065, 2024-11-02 15:23:30, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
float find_m(vector<float>& xi, vector<float>& yi,int& n){
float xy=0;
float x=0,y=0,nx2=0;
for(int i=0;i<n;i++) {
xy+=xi[i]*yi[i]; //upper
x+=xi[i]; //upper
y+=yi[i]; //upper
nx2 += (xi[i]*xi[i]); //lower
}
xy*=n;
nx2*=n;
float xy2 = x*y;
float m = xy - xy2;
//lower part
float x2 = x*x; //x^2
m /= (nx2-x2);
return m;
}
float find_b(vector<float>& xi, vector<float>& yi,int& n){
float y=0,x=0;
for(int i=0;i<n;i++){
y += yi[i];
x += xi[i];
}
x*= find_m(xi,yi,n);
float b = (y-x)/n;
return b;
}
int main(){
int n;
string cmd;
cin>>n>>cmd;
vector<float> xi;
vector<float> yi;
float x,y;
for(int i=0;i<n;i++){
cin>>x>>y;
xi.push_back(x);
yi.push_back(y);
}
if(cmd=="mb"){
float m = find_m(xi,yi,n);
float b = find_b(xi,yi,n);
if(m==-0)m=0;
if(b==-0)b=0;
cout<< round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
return 0;
}
else{
cout<<"y = ";
float m =find_m(xi,yi,n);
float b =find_b(xi,yi,n);
if(m!=-1 && m!=1 && m!= 0 && m!=-0)cout<<round(m*1e3)/1e3; //m != 1 0 -0 -1
if(m==-1)cout<<"-";
if(m!= 0 && m!=-0){
cout<<"x";
if(b!=0 ||b!=-0){
if(b>0)cout<<" + "<<round(b*1e3)/1e3<<endl;
else if(b<0)cout<<" - "<<round(abs(b)*1e3)/1e3<<endl;
}
}
else if(m== 0&& b!=0)cout<<" "<<b;
else if(m==0 && b==0)cout<<0;
}
} | # 1066, 2024-11-02 15:27:23, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
float find_m(vector<float>& xi, vector<float>& yi,int& n){
float xy=0;
float x=0,y=0,nx2=0;
for(int i=0;i<n;i++) {
xy+=xi[i]*yi[i]; //upper
x+=xi[i]; //upper
y+=yi[i]; //upper
nx2 += (xi[i]*xi[i]); //lower
}
xy*=n;
nx2*=n;
float xy2 = x*y;
float m = xy - xy2;
//lower part
float x2 = x*x; //x^2
m /= (nx2-x2);
return m;
}
float find_b(vector<float>& xi, vector<float>& yi,int& n){
float y=0,x=0;
for(int i=0;i<n;i++){
y += yi[i];
x += xi[i];
}
x*= find_m(xi,yi,n);
float b = (y-x)/n;
return b;
}
int main(){
int n;
string cmd;
cin>>n>>cmd;
vector<float> xi;
vector<float> yi;
float x,y;
for(int i=0;i<n;i++){
cin>>x>>y;
xi.push_back(x);
yi.push_back(y);
}
if(cmd=="mb"){
float m = find_m(xi,yi,n);
float b = find_b(xi,yi,n);
if(m==-0)m=0;
if(b==-0)b=0;
cout<< round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
return 0;
}
else{
cout<<"y = ";
float m =find_m(xi,yi,n);
float b =find_b(xi,yi,n);
if(m!=-1 && m!=1 && m!= 0 && m!=-0)cout<<round(m*1e3)/1e3; //m != 1 0 -0 -1
if(m==-1)cout<<"-"; // if m== -1
if(m!= 0 && m!=-0){
cout<<"x"; //x condition
if(b!=0 || b!=-0){
if(b>0)cout<<" + "<<round(b*1e3)/1e3<<endl;
else if(b<0)cout<<" - "<<round((b*(-1))*1e3)/1e3<<endl;
}
}
if(m== 0&& b!=0)cout<<b;
else if(m==0 && b==0)cout<<0;
}
} | # 1067, 2024-11-02 15:28:48, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
float find_m(vector<float>& xi, vector<float>& yi,int& n){
float xy=0;
float x=0,y=0,nx2=0;
for(int i=0;i<n;i++) {
xy+=xi[i]*yi[i]; //upper
x+=xi[i]; //upper
y+=yi[i]; //upper
nx2 += (xi[i]*xi[i]); //lower
}
xy*=n;
nx2*=n;
float xy2 = x*y;
float m = xy - xy2;
//lower part
float x2 = x*x; //x^2
m /= (nx2-x2);
return m;
}
float find_b(vector<float>& xi, vector<float>& yi,int& n){
float y=0,x=0;
for(int i=0;i<n;i++){
y += yi[i];
x += xi[i];
}
x*= find_m(xi,yi,n);
float b = (y-x)/n;
return b;
}
int main(){
int n;
string cmd;
cin>>n>>cmd;
vector<float> xi;
vector<float> yi;
float x,y;
for(int i=0;i<n;i++){
cin>>x>>y;
xi.push_back(x);
yi.push_back(y);
}
if(cmd=="mb"){
float m = find_m(xi,yi,n);
float b = find_b(xi,yi,n);
if(m==-0)m=0;
if(b==-0)b=0;
cout<< round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
return 0;
}
else{
cout<<"y = ";
float m =find_m(xi,yi,n);
float b =find_b(xi,yi,n);
if(m!=-1 && m!=1 && m!= 0 && m!=-0)cout<<round(m*1e3)/1e3; //m != 1 0 -0 -1
if(m==-1)cout<<"-"; // if m== -1
if(m!= 0 && m!=-0){
cout<<"x"; //x condition
if(b!=0 || b!=-0){
if(b>0)cout<<" + "<<round(b*1e3)/1e3<<endl;
else if(b<0)cout<<" - "<<round((b*(-1))*1e3)/1e3<<endl;
}
}
if(m== 0&& b!=0)cout<<b;
if(m==0 && b==0)cout<<0;
}
} | # 1068, 2024-11-02 15:29:39, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
float find_m(vector<float>& xi, vector<float>& yi,int& n){
float xy=0;
float x=0,y=0,nx2=0;
for(int i=0;i<n;i++) {
xy+=xi[i]*yi[i]; //upper
x+=xi[i]; //upper
y+=yi[i]; //upper
nx2 += (xi[i]*xi[i]); //lower
}
xy*=n;
nx2*=n;
float xy2 = x*y;
float m = xy - xy2;
//lower part
float x2 = x*x; //x^2
m /= (nx2-x2);
return m;
}
float find_b(vector<float>& xi, vector<float>& yi,int& n){
float y=0,x=0;
for(int i=0;i<n;i++){
y += yi[i];
x += xi[i];
}
x*= find_m(xi,yi,n);
float b = (y-x)/n;
return b;
}
int main(){
int n;
string cmd;
cin>>n>>cmd;
vector<float> xi;
vector<float> yi;
float x,y;
for(int i=0;i<n;i++){
cin>>x>>y;
xi.push_back(x);
yi.push_back(y);
}
if(cmd=="mb"){
float m = find_m(xi,yi,n);
float b = find_b(xi,yi,n);
if(m==-0)m=0;
if(b==-0)b=0;
cout<< round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
return 0;
}
else{
cout<<"y = ";
float m =find_m(xi,yi,n);
float b =find_b(xi,yi,n);
if(m!=-1 && m!=1 && m!= 0 && m!=-0)cout<<round(m*1e3)/1e3; //m != 1 0 -0 -1
if(m==-1)cout<<"-"; // if m == -1
if(m!= 0 && m!=-0){
cout<<"x"; //x condition
if(b!=0 || b!=-0){
if(b>0)cout<<" + "<<round(b*1e3)/1e3<<endl;
else if(b<0)cout<<" - "<<round((b*(-1))*1e3)/1e3<<endl;
}
}
if(m== 0&& b!=0)cout<<b<<endl;
if(m==0 && b==0)cout<<0<<endl;
}
} |
# 1069, 2024-11-02 11:34:27, PPPPPPPPPPPPPPP---PP--P- (75%)
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin>>n;
string ss; cin>>ss;
float x[n],y[n];
for(int i=1;i<=n;i++){
cin>>x[i]>>y[i];
}
float m,b;
float m1=0,m2=0,m3=0,m4=0,b1=0,b2=0;
for(int i=1;i<=n;i++){
m1+=x[i]*y[i];
m2+=x[i];
m3+=y[i];
m4+=pow(x[i],2);
b1+=y[i];
b2+=x[i];
}
m=((n*m1)-(m2*m3))/((n*m4)-pow(m2,2));
b=((b1-(m*b2))/n);
//cout<<m<<" "<<b;
if(ss=="mb"){
cout<<round(m*1e3)/1e3<<"\n";
cout<<round(b*1e3)/1e3;
}
else{
cout<<"y = ";
if(m==1){
cout<<"x ";
}
else if(m==-1){
cout<<"-x ";
}
else{
cout<<round(m*1e3)/1e3<<"x ";
}
if(b<0){
cout<<"- ";
cout<<(round(b*1e3)/1e3)*(-1);
}
else if(b==0){
}
else{
cout<<"+ ";
cout<<(round(b*1e3)/1e3);
}
}
return 0;
} | # 1070, 2024-11-02 11:35:47, PPPPPPPPPPPPPPP---PP--P- (75%)
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin>>n;
string ss; cin>>ss;
float x[n],y[n];
for(int i=1;i<=n;i++){
cin>>x[i]>>y[i];
}
float m,b;
float m1=0,m2=0,m3=0,m4=0,b1=0,b2=0;
for(int i=1;i<=n;i++){
m1+=x[i]*y[i];
m2+=x[i];
m3+=y[i];
m4+=pow(x[i],2);
b1+=y[i];
b2+=x[i];
}
m=((n*m1)-(m2*m3))/((n*m4)-pow(m2,2));
b=((b1-(m*b2))/n);
//cout<<m<<" "<<b;
if(ss=="mb"){
cout<<round(m*1e3)/1e3<<"\n";
cout<<round(b*1e3)/1e3;
}
else{
cout<<"y = ";
if(m==1){
cout<<"x ";
}
else if(m==-1){
cout<<"-x ";
}
else{
cout<<round(m*1e3)/1e3<<"x ";
}
if(b<0){
cout<<"- ";
cout<<(round(b*1e3)/1e3)*(-1);
}
else if(b>0){
cout<<"+ ";
cout<<(round(b*1e3)/1e3);
}
}
return 0;
} | # 1071, 2024-11-02 11:38:06, PPPPPPPPPPPPPPPP--PP--P- (79%)
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin>>n;
string ss; cin>>ss;
float x[n],y[n];
for(int i=1;i<=n;i++){
cin>>x[i]>>y[i];
}
float m,b;
float m1=0,m2=0,m3=0,m4=0,b1=0,b2=0;
for(int i=1;i<=n;i++){
m1+=x[i]*y[i];
m2+=x[i];
m3+=y[i];
m4+=pow(x[i],2);
b1+=y[i];
b2+=x[i];
}
m=((n*m1)-(m2*m3))/((n*m4)-pow(m2,2));
b=((b1-(m*b2))/n);
//cout<<m<<" "<<b;
if(ss=="mb"){
cout<<round(m*1e3)/1e3<<"\n";
cout<<round(b*1e3)/1e3;
}
else{
cout<<"y = ";
if(m==1){
cout<<"x ";
}
else if(m==-1){
cout<<"-x ";
}
else if(m==0){
cout<<"0";
}
else{
cout<<round(m*1e3)/1e3<<"x ";
}
if(b<0){
cout<<"- ";
cout<<(round(b*1e3)/1e3)*(-1);
}
else if(b>0){
cout<<"+ ";
cout<<(round(b*1e3)/1e3);
}
}
return 0;
} | # 1072, 2024-11-02 11:39:58, PPPPPPPPPPPPPPPP--PP--P- (79%)
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin>>n;
string ss; cin>>ss;
float x[n],y[n];
for(int i=1;i<=n;i++){
cin>>x[i]>>y[i];
}
float m,b;
float m1=0,m2=0,m3=0,m4=0,b1=0,b2=0;
for(int i=1;i<=n;i++){
m1+=x[i]*y[i];
m2+=x[i];
m3+=y[i];
m4+=pow(x[i],2);
b1+=y[i];
b2+=x[i];
}
m=((n*m1)-(m2*m3))/((n*m4)-pow(m2,2));
b=((b1-(m*b2))/n);
//cout<<m<<" "<<b;
if(ss=="mb"){
cout<<round(m*1e3)/1e3<<"\n";
cout<<round(b*1e3)/1e3;
}
else{
cout<<"y = ";
if(m==1){
cout<<"x ";
}
else if(m==-1){
cout<<"-x ";
}
else if(m==0 &&b==0){
cout<<"0";
}
else if(m==0 &&b!=0){
cout<<b;
}
else{
cout<<round(m*1e3)/1e3<<"x ";
}
if(b<0){
cout<<"- ";
cout<<(round(b*1e3)/1e3)*(-1);
}
else if(b>0){
cout<<"+ ";
cout<<(round(b*1e3)/1e3);
}
}
return 0;
} | # 1073, 2024-11-02 12:06:46, PPPPPPPPPPPPPPPP--PP--P- (79%)
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin>>n;
string ss; cin>>ss;
float x[n],y[n];
for(int i=1;i<=n;i++){
cin>>x[i]>>y[i];
}
float m,b;
float m1=0,m2=0,m3=0,m4=0,b1=0,b2=0;
for(int i=1;i<=n;i++){
m1+=x[i]*y[i];
m2+=x[i];
m3+=y[i];
m4+=pow(x[i],2);
b1+=y[i];
b2+=x[i];
}
m=((n*m1)-(m2*m3))/((n*m4)-pow(m2,2));
b=((b1-(m*b2))/n);
//cout<<m<<" "<<b;
if(ss=="mb"){
cout<<round(m*1e3)/1e3<<"\n";
cout<<round(b*1e3)/1e3;
}
else{
cout<<"y = ";
if(m==1){
cout<<"x ";
}
else if(m==-1){
cout<<"-x ";
}
else if(m==-1&&b==0){
cout<<"-x";
return 0;
}
else if(m==0 &&b==0){
cout<<"0";
}
else if(m==0 &&b!=0){
cout<<b;
}
else{
cout<<round(m*1e3)/1e3<<"x ";
}
if(b<0){
cout<<"- ";
cout<<(round(b*1e3)/1e3)*(-1);
}
else if(b>0){
cout<<"+ ";
cout<<(round(b*1e3)/1e3);
}
}
return 0;
} | # 1074, 2024-11-02 12:07:43, PPPPPPPPPPPPPPPP--PP--P- (79%)
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin>>n;
string ss; cin>>ss;
float x[n],y[n];
for(int i=1;i<=n;i++){
cin>>x[i]>>y[i];
}
float m,b;
float m1=0,m2=0,m3=0,m4=0,b1=0,b2=0;
for(int i=1;i<=n;i++){
m1+=x[i]*y[i];
m2+=x[i];
m3+=y[i];
m4+=pow(x[i],2);
b1+=y[i];
b2+=x[i];
}
m=((n*m1)-(m2*m3))/((n*m4)-pow(m2,2));
b=((b1-(m*b2))/n);
//cout<<m<<" "<<b;
if(ss=="mb"){
cout<<round(m*1e3)/1e3<<"\n";
cout<<round(b*1e3)/1e3;
}
else{
cout<<"y = ";
if(m==1){
cout<<"x ";
}
else if(m==-1&&b==0){
cout<<"-x";
return 0;
}
else if(m==-1){
cout<<"-x ";
}
else if(m==0 &&b==0){
cout<<"0";
}
else if(m==0 &&b!=0){
cout<<b;
}
else{
cout<<round(m*1e3)/1e3<<"x ";
}
if(b<0){
cout<<"- ";
cout<<(round(b*1e3)/1e3)*(-1);
}
else if(b>0){
cout<<"+ ";
cout<<(round(b*1e3)/1e3);
}
}
return 0;
} | # 1075, 2024-11-02 12:10:01, P-P-PPPPPPP-P-PP-PPPP--- (66%)
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin>>n;
string ss; cin>>ss;
double x[n],y[n];
for(int i=1;i<=n;i++){
cin>>x[i]>>y[i];
}
double m,b;
double m1=0,m2=0,m3=0,m4=0,b1=0,b2=0;
for(int i=1;i<=n;i++){
m1+=x[i]*y[i];
m2+=x[i];
m3+=y[i];
m4+=pow(x[i],2);
b1+=y[i];
b2+=x[i];
}
m=((n*m1)-(m2*m3))/((n*m4)-pow(m2,2));
b=((b1-(m*b2))/n);
//cout<<m<<" "<<b;
if(ss=="mb"){
cout<<round(m*1e3)/1e3<<"\n";
cout<<round(b*1e3)/1e3;
}
else{
cout<<"y = ";
if(m==1){
cout<<"x ";
}
else if(m==-1&&b==0){
cout<<"-x";
return 0;
}
else if(m==-1){
cout<<"-x ";
}
else if(m==0 &&b==0){
cout<<"0";
}
else if(m==0 &&b!=0){
cout<<b;
}
else{
cout<<round(m*1e3)/1e3<<"x ";
}
if(b<0){
cout<<"- ";
cout<<(round(b*1e3)/1e3)*(-1);
}
else if(b>0){
cout<<"+ ";
cout<<(round(b*1e3)/1e3);
}
}
return 0;
} | # 1076, 2024-11-02 12:10:19, PPPPPPPPPPPPPPPP--PP--P- (79%)
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin>>n;
string ss; cin>>ss;
float x[n],y[n];
for(int i=1;i<=n;i++){
cin>>x[i]>>y[i];
}
float m,b;
float m1=0,m2=0,m3=0,m4=0,b1=0,b2=0;
for(int i=1;i<=n;i++){
m1+=x[i]*y[i];
m2+=x[i];
m3+=y[i];
m4+=pow(x[i],2);
b1+=y[i];
b2+=x[i];
}
m=((n*m1)-(m2*m3))/((n*m4)-pow(m2,2));
b=((b1-(m*b2))/n);
//cout<<m<<" "<<b;
if(ss=="mb"){
cout<<round(m*1e3)/1e3<<"\n";
cout<<round(b*1e3)/1e3;
}
else{
cout<<"y = ";
if(m==1){
cout<<"x ";
}
else if(m==-1&&b==0){
cout<<"-x";
return 0;
}
else if(m==-1){
cout<<"-x ";
}
else if(m==0 &&b==0){
cout<<"0";
}
else if(m==0 &&b!=0){
cout<<b;
}
else{
cout<<round(m*1e3)/1e3<<"x ";
}
if(b<0){
cout<<"- ";
cout<<(round(b*1e3)/1e3)*(-1);
}
else if(b>0){
cout<<"+ ";
cout<<(round(b*1e3)/1e3);
}
}
return 0;
} |
# 1077, 2024-11-02 13:46:43, PPPPPPPPPP-------------- (41%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n;
string s;
float x[100000],y[100000];
cin>>n>>s;
float a=0,c=0,d=0,e=0;
for(int i=1;i<=n;i++){
cin>>x[i]>>y[i];
}
///sol
for(int i=1;i<=n;i++){
a+=x[i]*y[i];
c+=x[i];
d+=y[i];
e+=x[i]*x[i];
}
float m=((n*a)-(c*d))/((n*e)-(c*c));
float b=((d)-(m*c))/n;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else if(s=="func"){
if(m==1);
}
} | # 1078, 2024-11-02 13:57:19, PPPPPPPPPP-----P-------- (45%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n;
string s;
float x[100000],y[100000];
cin>>n>>s;
float a=0,c=0,d=0,e=0;
for(int i=1;i<=n;i++){
cin>>x[i]>>y[i];
}
///sol
for(int i=1;i<=n;i++){
a+=x[i]*y[i];
c+=x[i];
d+=y[i];
e+=x[i]*x[i];
}
float m=((n*a)-(c*d))/((n*e)-(c*c));
float b=((d)-(m*c))/n;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else if(s=="func"){
if(m==1){
cout<<"y = x +"<<round(b*1e3)/1e3;
}else if(m==-1){
cout<<"y = -x +"<<round(b*1e3)/1e3;
}else if(b<0){
cout<<"y = x "<<round(b*1e3)/1e3;
}else if(b==0&&m==0){
cout<<"y = 0";
}else if(b==0){
cout<<"y = "<<round(m*1e3)/1e3<<"x";
}else if(m==0){
cout<<"y = "<<round(b*1e3)/1e3;
}
}
} | # 1079, 2024-11-02 15:02:49, PPPPPPPPPP-----P--PP---- (54%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n;
string s;
float x[100000],y[100000];
cin>>n>>s;
float a=0,c=0,d=0,e=0,mj,bj;
for(int i=1;i<=n;i++){
cin>>x[i]>>y[i];
}
///sol
for(int i=1;i<=n;i++){
a+=x[i]*y[i];
c+=x[i];
d+=y[i];
e+=x[i]*x[i];
}
float m=((n*a)-(c*d))/((n*e)-(c*c));
float b=((d)-(m*c))/n;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else if(s=="func"){
if(m==1){
cout<<"y = x ";
if(b==0){
}else if(b<0){
cout<<"- "<<round(-b*1e3)/1e3;
}else if(b>0){
cout<<"+ "<<round(b*1e3)/1e3;
}
}else if(m==-1){
cout<<"y = -x ";
if(b==0){
}else if(b<0){
cout<<"- "<<round(-b*1e3)/1e3;
}else if(b>0){
cout<<"+ "<<round(b*1e3)/1e3;
}
}else if(b==0&&m==0){
cout<<"y = 0";
}
}else if(m==0){
cout<<"y = ";
if(b==0){
}else if(b<0){
cout<<"- "<<round(-b*1e3)/1e3;
}else if(b>0){
cout<<"+ "<<round(b*1e3)/1e3;
}
}
} | # 1080, 2024-11-02 15:10:12, PPPPPPPPPPPPPPPP--PP---- (75%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n;
string s;
float x[100000],y[100000];
cin>>n>>s;
float a=0,c=0,d=0,e=0,mj,bj;
for(int i=1;i<=n;i++){
cin>>x[i]>>y[i];
}
///sol
for(int i=1;i<=n;i++){
a+=x[i]*y[i];
c+=x[i];
d+=y[i];
e+=x[i]*x[i];
}
float m=((n*a)-(c*d))/((n*e)-(c*c));
float b=((d)-(m*c))/n;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else if(s=="func"){
if(m==1){
cout<<"y = x ";
if(b==0){
}else if(b<0){
cout<<"- "<<round(-b*1e3)/1e3;
}else if(b>0){
cout<<"+ "<<round(b*1e3)/1e3;
}
}else if(m==-1){
cout<<"y = -x ";
if(b==0){
}else if(b<0){
cout<<"- "<<round(-b*1e3)/1e3;
}else if(b>0){
cout<<"+ "<<round(b*1e3)/1e3;
}
}else if(b==0&&m==0){
cout<<"y = 0";
}
else if(m==0){
cout<<"y = ";
if(b==0){
}else if(b<0){
cout<<"- "<<round(-b*1e3)/1e3;
}else if(b>0){
cout<<"+ "<<round(b*1e3)/1e3;
}
}else if(m<1){
cout<<"y = -"<<round(-m*1e3)/1e3<<"x ";
if(b==0){
}else if(b<0){
cout<<"- "<<round(-b*1e3)/1e3;
}else if(b>0){
cout<<"+ "<<round(b*1e3)/1e3;
}
}else if(m>1){
cout<<"y = "<<round(m*1e3)/1e3<<"x ";
if(b==0){
}else if(b<0){
cout<<"- "<<round(-b*1e3)/1e3;
}else if(b>0){
cout<<"+ "<<round(b*1e3)/1e3;
}
}
}
} | # 1081, 2024-11-02 15:15:52, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n;
string s;
float x[100000],y[100000];
cin>>n>>s;
float a=0,c=0,d=0,e=0,mj,bj;
for(int i=1;i<=n;i++){
cin>>x[i]>>y[i];
}
///sol
for(int i=1;i<=n;i++){
a+=x[i]*y[i];
c+=x[i];
d+=y[i];
e+=x[i]*x[i];
}
float m=((n*a)-(c*d))/((n*e)-(c*c));
float b=((d)-(m*c))/n;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else if(s=="func"){
if(m==1){
cout<<"y = x ";
if(b==0){
}else if(b<0){
cout<<"- "<<round(-b*1e3)/1e3;
}else if(b>0){
cout<<"+ "<<round(b*1e3)/1e3;
}
}else if(m==-1){
cout<<"y = -x ";
if(b==0){
}else if(b<0){
cout<<"- "<<round(-b*1e3)/1e3;
}else if(b>0){
cout<<"+ "<<round(b*1e3)/1e3;
}
}else if(b==0&&m==0){
cout<<"y = 0";
}
else if(m==0){
cout<<"y = ";
if(b==0){
}else if(b<0){
cout<<"-"<<round(-b*1e3)/1e3;
}else if(b>0){
cout<<"+ "<<round(b*1e3)/1e3;
}
}else if(m<0){
cout<<"y = -"<<round(-m*1e3)/1e3<<"x ";
if(b==0){
}else if(b<0){
cout<<"- "<<round(-b*1e3)/1e3;
}else if(b>0){
cout<<"+ "<<round(b*1e3)/1e3;
}
}else if(m>1){
cout<<"y = "<<round(m*1e3)/1e3<<"x ";
if(b==0){
}else if(b<0){
cout<<"- "<<round(-b*1e3)/1e3;
}else if(b>0){
cout<<"+ "<<round(b*1e3)/1e3;
}
}
}
} | # 1082, 2024-11-02 15:32:51, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n;
string s;
float x[100000],y[100000];
cin>>n>>s;
float a=0,c=0,d=0,e=0;
for(int i=1;i<=n;i++){
cin>>x[i]>>y[i];
}
///sol
for(int i=1;i<=n;i++){
a+=x[i]*y[i];
c+=x[i];
d+=y[i];
e+=x[i]*x[i];
}
float m=((n*a)-(c*d))/((n*e)-(c*c));
float b=((d)-(m*c))/n;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else if(s=="func"){
if(m==1){
cout<<"y = x ";
if(b==0){
}else if(b<0){
cout<<"- "<<round(-b*1e3)/1e3;
}else if(b>0){
cout<<"+ "<<round(b*1e3)/1e3;
}
}else if(m==-1){
cout<<"y = -x ";
if(b==0){
}else if(b<0){
cout<<"- "<<round(-b*1e3)/1e3;
}else if(b>0){
cout<<"+ "<<round(b*1e3)/1e3;
}
}else if(b==0&&m==0){
cout<<"y = 0";
}else if(int(m)==0){
cout<<"y = ";
if(b==0){
}else if(b<0){
cout<<"-"<<round(-b*1e3)/1e3;
}else if(b>0){
cout<<"+ "<<round(b*1e3)/1e3;
}
}else if(m<0){
cout<<"y = -"<<round(-m*1e3)/1e3<<"x ";
if(b==0){
}else if(b<0){
cout<<"- "<<round(-b*1e3)/1e3;
}else if(b>0){
cout<<"+ "<<round(b*1e3)/1e3;
}
}else if(m>1){
cout<<"y = "<<round(m*1e3)/1e3<<"x ";
if(b==0){
}else if(b<0){
cout<<"- "<<round(-b*1e3)/1e3;
}else if(b>0){
cout<<"+ "<<round(b*1e3)/1e3;
}
}
}
} |
# 1083, 2024-11-02 13:39:13, PPPPPPPPPP-------------- (41%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string fn;
cin >> fn;
vector <pair <float, float>> v;
while (n--) {
float x, y;
cin >> x >> y;
v.push_back(make_pair(x,y));
}
int N = int(v.size());
if (fn == "mb") {
float M, B;
float a = 0, b = 0, c = 0, d = 0;
for (auto u : v) { //x = a.first y = a.second
a += u.first * u.second;
b += u.first;
c += u.second;
d += u.first * u.first;
}
M = ((N*a) - (b*c)) / ((N*d) - (b*b));
B = (c - (M*b)) / N;
cout << round(M*1e3)/1e3 << endl << round(B*1e3)/1e3;
}
} | # 1084, 2024-11-02 14:07:37, PPPPPPPPPP-------------- (41%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string fn;
cin >> fn;
vector <pair <float, float>> v;
while (n--) {
float x, y;
cin >> x >> y;
v.push_back(make_pair(x,y));
}
int N = int(v.size());
if (fn == "mb") {
float M, B;
float a = 0, b = 0, c = 0, d = 0;
for (auto u : v) { //x = a.first y = a.second
a += u.first * u.second;
b += u.first;
c += u.second;
d += u.first * u.first;
}
M = ((N*a) - (b*c)) / ((N*d) - (b*b));
B = (c - (M*b)) / N;
cout << round(M*1e3)/1e3 << endl << round(B*1e3)/1e3;
}
else if (fn == "func") {
float slope, cc;
if (v[0].second - v[1].second == 0) slope = 0;
else slope = (v[0].first - v[1].first) / (v[0].second - v[1].second);
cc = v[0].second - (slope * v[0].first);
cout << slope << " " << cc << endl;
if (slope == -1) {
if (cc > 0) {
cout << "y = -x + " << cc;
}
else if (cc == 0) {
cout << "y = -x";
}
else if (cc < 0) {
cout << "y = -x - " << abs(cc);
}
}
else if (slope == 1) {
if (cc > 0) {
cout << "y = x + " << cc;
}
else if (cc == 0) {
cout << "y = x";
}
else if (cc < 0) {
cout << "y = x - " << abs(cc);
}
}
else if (slope == 0) {
cout << "y = " << cc;
}
else {
cout << "y = " << slope << "x ";
if (cc > 0) {
cout << "+ " << cc;
}
else if (cc < 0) {
cout << cc;
}
}
}
} | # 1085, 2024-11-02 14:08:21, PPPPPPPPPP-----PPPPPPPPP (79%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string fn;
cin >> fn;
vector <pair <float, float>> v;
while (n--) {
float x, y;
cin >> x >> y;
v.push_back(make_pair(x,y));
}
int N = int(v.size());
if (fn == "mb") {
float M, B;
float a = 0, b = 0, c = 0, d = 0;
for (auto u : v) { //x = a.first y = a.second
a += u.first * u.second;
b += u.first;
c += u.second;
d += u.first * u.first;
}
M = ((N*a) - (b*c)) / ((N*d) - (b*b));
B = (c - (M*b)) / N;
cout << round(M*1e3)/1e3 << endl << round(B*1e3)/1e3;
}
else if (fn == "func") {
float slope, cc;
if (v[0].second - v[1].second == 0) slope = 0;
else slope = (v[0].first - v[1].first) / (v[0].second - v[1].second);
cc = v[0].second - (slope * v[0].first);
//cout << slope << " " << cc << endl;
if (slope == -1) {
if (cc > 0) {
cout << "y = -x + " << cc;
}
else if (cc == 0) {
cout << "y = -x";
}
else if (cc < 0) {
cout << "y = -x - " << abs(cc);
}
}
else if (slope == 1) {
if (cc > 0) {
cout << "y = x + " << cc;
}
else if (cc == 0) {
cout << "y = x";
}
else if (cc < 0) {
cout << "y = x - " << abs(cc);
}
}
else if (slope == 0) {
cout << "y = " << cc;
}
else {
cout << "y = " << slope << "x ";
if (cc > 0) {
cout << "+ " << cc;
}
else if (cc < 0) {
cout << cc;
}
}
}
} | # 1086, 2024-11-02 14:31:07, PPPPPPPPPP-----PPPPPPPPP (79%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string fn;
cin >> fn;
vector <pair <float, float>> v;
while (n--) {
float x, y;
cin >> x >> y;
v.push_back(make_pair(x,y));
}
int N = int(v.size());
if (fn == "mb") {
float M, B;
float a = 0, b = 0, c = 0, d = 0;
for (auto u : v) { //x = a.first y = a.second
a += u.first * u.second;
b += u.first;
c += u.second;
d += u.first * u.first;
}
M = ((N*a) - (b*c)) / ((N*d) - (b*b));
B = (c - (M*b)) / N;
cout << round(M*1e3)/1e3 << endl << round(B*1e3)/1e3;
}
else if (fn == "func") {
float slope, cc;
if (v[0].second - v[1].second == 0) slope = 0;
else slope = (v[0].first - v[1].first) / (v[0].second - v[1].second);
cc = v[0].second - (slope * v[0].first);
//cout << slope << " " << cc << endl;
if (slope == -1) {
if (cc > 0) {
cout << "y = -x + " << cc;
}
else if (cc == 0) {
cout << "y = -x";
}
else if (cc < 0) {
cout << "y = -x - " << abs(cc);
}
}
else if (slope == 1) {
if (cc > 0) {
cout << "y = x + " << cc;
}
else if (cc == 0) {
cout << "y = x";
}
else if (cc < 0) {
cout << "y = x - " << abs(cc);
}
}
else if (slope == 0) {
cout << "y = " << cc;
}
else {
cout << "y = " << slope << "x ";
if (cc > 0) {
cout << "+ " << cc;
}
else if (cc < 0) {
cout << "- " << abs(cc);
}
}
}
} | # 1087, 2024-11-02 14:32:30, PPPPPPPPPP-----PPPPPPPPP (79%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string fn;
cin >> fn;
vector <pair <float, float>> v;
while (n--) {
float x, y;
cin >> x >> y;
v.push_back(make_pair(x,y));
}
int N = int(v.size());
if (fn == "mb") {
float M, B;
float a = 0, b = 0, c = 0, d = 0;
for (auto u : v) { //x = a.first y = a.second
a += u.first * u.second;
b += u.first;
c += u.second;
d += u.first * u.first;
}
M = ((N*a) - (b*c)) / ((N*d) - (b*b));
B = (c - (M*b)) / N;
cout << round(M*1e3)/1e3 << endl << round(B*1e3)/1e3;
}
else if (fn == "func") {
float slope, cc;
if (v[0].second - v[1].second == 0) slope = 0;
else slope = (v[0].first - v[1].first) / (v[0].second - v[1].second);
cc = v[0].second - (slope * v[0].first);
//cout << slope << " " << cc << endl;
if (slope == -1) {
if (cc > 0) {
cout << "y = -x + " << cc;
}
else if (cc == 0) {
cout << "y = -x";
}
else if (cc < 0) {
cout << "y = -x - " << abs(cc);
}
}
else if (slope == 1) {
if (cc > 0) {
cout << "y = x + " << cc;
}
else if (cc == 0) {
cout << "y = x";
}
else if (cc < 0) {
cout << "y = x - " << abs(cc);
}
}
else if (slope == 0) {
cout << "y = " << cc;
}
else {
cout << "y = " << slope << "x";
if (cc > 0) {
cout << " + " << cc;
}
else if (cc < 0) {
cout << " - " << abs(cc);
}
}
}
} |
# 1088, 2024-11-02 10:52:40, Compilation error (0%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int n ;
string op;
cin >>n >>op;
float value [n][2];
for (int i =0; i < n; i++){
float a ,b;
cin >> a >>b;
value[i][0]= a;
value[i][1]= b;
}
// for (int i =0; i < n; i++){
// cout << value[i][0] << " " << value[i][1] << endl;
// }
//cal
float m,b;
float sum_xy =0;
for (int i =0; i < n; i++){
sum_xy += value[i][0] * value[i][1];
}
// cout << sum_xy <<endl;
float sum_x =0;
float sum_y =0;
for (int i =0; i < n; i++){
sum_x += value[i][0];
sum_y += value[i][1];
}
// cout << sum_x <<endl;
// cout << sum_y <<endl;
// cout << sum_y;
float sum_x2 =0;
float sum_y2 =0;
for (int i =0; i < n; i++){
sum_x2 += pow (value[i][0],2) ;
sum_y2 += pow (value[i][1],2);
}
float part_m1 = n*sum_xy - (sum_x*sum_y);
float part_m2 = n*sum_x2 - (sum_x *sum_x);
m = part_m1/part_m2;
float part_b1 = sum_y - (m * sum_x);
b = part_b1 /n;
if (op == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
} else if(op == "func"){
if (m==0 && b ==0){
cout <<"y" << " = " << 0;
}else
if (m == 0 && b !=0){
cout << "y" << " = " << round(b*1e3)/1e3;
}
if (m !=1 || m != 1 ){
if (b < 0){
cout << "y" << " = " << round(m*1e3)/1e3 <<"x" << " - "<< abs(round(b*1e3)/1e3);
}else if (b > 0 ){
cout << "y" << " = " << round(m*1e3)/1e3 <<"x" << " + "<< round(b*1e3)/1e3;
}else if (b == 0){
cout << "y" << " = " << round(m*1e3)/1e3 <<"x" ;
}
}else if ( m ==1 || m==-1){
if (m ==1){
if (b < 0){
cout << "y" << " = " << "x" << " - "<< abs(round(b*1e3)/1e3);
}else if (b > 0 ){
cout << "y" << " = " <<"x" << " + "<< round(b*1e3)/1e3;
}else if (b == 0){
cout << "y" << " = " <<"x" ;
}
}
if (m == -1){
if (b < 0){
cout << "y" << " = " << "-x" << " - "<< abs(round(b*1e3)/1e3);
}else if (b > 0 ){
cout << "y" << " = " <<"-x" << " + "<< round(b*1e3)/1e3;
}else if (b == 0){
cout << "y" << " = " <<"-x" ;
}
}
}
} | # 1089, 2024-11-02 10:56:21, PPPPPPPPPPPPPPP---P----- (66%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int n ;
string op;
cin >>n >>op;
float value [n][2];
for (int i =0; i < n; i++){
float a ,b;
cin >> a >>b;
value[i][0]= a;
value[i][1]= b;
}
// for (int i =0; i < n; i++){
// cout << value[i][0] << " " << value[i][1] << endl;
// }
//cal
float m,b;
float sum_xy =0;
for (int i =0; i < n; i++){
sum_xy += value[i][0] * value[i][1];
}
// cout << sum_xy <<endl;
float sum_x =0;
float sum_y =0;
for (int i =0; i < n; i++){
sum_x += value[i][0];
sum_y += value[i][1];
}
// cout << sum_x <<endl;
// cout << sum_y <<endl;
// cout << sum_y;
float sum_x2 =0;
float sum_y2 =0;
for (int i =0; i < n; i++){
sum_x2 += pow (value[i][0],2) ;
sum_y2 += pow (value[i][1],2);
}
float part_m1 = n*sum_xy - (sum_x*sum_y);
float part_m2 = n*sum_x2 - (sum_x *sum_x);
m = part_m1/part_m2;
float part_b1 = sum_y - (m * sum_x);
b = part_b1 /n;
if (op == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}else if(op == "func"){
if (m==0 && b ==0){
cout <<"y" << " = " << 0;
}
if (m == 0 && b !=0){
cout << "y" << " = " << round(b*1e3)/1e3;
}
if (m !=1 || m != 1 ){
if (b < 0){
cout << "y" << " = " << round(m*1e3)/1e3 <<"x" << " - "<< abs(round(b*1e3)/1e3);
}else if (b > 0 ){
cout << "y" << " = " << round(m*1e3)/1e3 <<"x" << " + "<< round(b*1e3)/1e3;
}else if (b == 0){
cout << "y" << " = " << round(m*1e3)/1e3 <<"x" ;
}
}else if ( m ==1 || m==-1){
if (m ==1){
if (b < 0){
cout << "y" << " = " << "x" << " - "<< abs(round(b*1e3)/1e3);
}else if (b > 0 ){
cout << "y" << " = " <<"x" << " + "<< round(b*1e3)/1e3;
}else if (b == 0){
cout << "y" << " = " <<"x" ;
}
}
if (m == -1){
if (b < 0){
cout << "y" << " = " << "-x" << " - "<< abs(round(b*1e3)/1e3);
}else if (b > 0 ){
cout << "y" << " = " <<"-x" << " + "<< round(b*1e3)/1e3;
}else if (b == 0){
cout << "y" << " = " <<"-x" ;
}
}
}
}
} | # 1090, 2024-11-02 10:58:18, PPPPPPPPPPPPPPP--------- (62%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int n ;
string op;
cin >>n >>op;
float value [n][2];
for (int i =0; i < n; i++){
float a ,b;
cin >> a >>b;
value[i][0]= a;
value[i][1]= b;
}
// for (int i =0; i < n; i++){
// cout << value[i][0] << " " << value[i][1] << endl;
// }
//cal
float m,b;
float sum_xy =0;
for (int i =0; i < n; i++){
sum_xy += value[i][0] * value[i][1];
}
// cout << sum_xy <<endl;
float sum_x =0;
float sum_y =0;
for (int i =0; i < n; i++){
sum_x += value[i][0];
sum_y += value[i][1];
}
// cout << sum_x <<endl;
// cout << sum_y <<endl;
// cout << sum_y;
float sum_x2 =0;
float sum_y2 =0;
for (int i =0; i < n; i++){
sum_x2 += pow (value[i][0],2) ;
sum_y2 += pow (value[i][1],2);
}
float part_m1 = n*sum_xy - (sum_x*sum_y);
float part_m2 = n*sum_x2 - (sum_x *sum_x);
m = part_m1/part_m2;
float part_b1 = sum_y - (m * sum_x);
b = part_b1 /n;
if (op == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}else if(op == "func"){
if (m==0 && b ==0){
cout <<"y" << " = " << 0;
}
if (m == 0 && b !=0){
cout << "y" << " = " << round(b*1e3)/1e3;
}
if (m !=1 || b != 1 ){
if (b < 0){
cout << "y" << " = " << round(m*1e3)/1e3 <<"x" << " - "<< abs(round(b*1e3)/1e3);
}else if (b > 0 ){
cout << "y" << " = " << round(m*1e3)/1e3 <<"x" << " + "<< round(b*1e3)/1e3;
}else if (b == 0){
cout << "y" << " = " << round(m*1e3)/1e3 <<"x" ;
}
}else if ( m ==1 || m==-1){
if (m ==1){
if (b < 0){
cout << "y" << " = " << "x" << " - "<< abs(round(b*1e3)/1e3);
}else if (b > 0 ){
cout << "y" << " = " <<"x" << " + "<< round(b*1e3)/1e3;
}else if (b == 0){
cout << "y" << " = " <<"x" ;
}
}
if (m == -1){
if (b < 0){
cout << "y" << " = " << "-x" << " - "<< abs(round(b*1e3)/1e3);
}else if (b > 0 ){
cout << "y" << " = " <<"-x" << " + "<< round(b*1e3)/1e3;
}else if (b == 0){
cout << "y" << " = " <<"-x" ;
}
}
}
}
} | # 1091, 2024-11-02 10:59:59, PPPPPPPPPPPPPPP---PP---- (70%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int n ;
string op;
cin >>n >>op;
float value [n][2];
for (int i =0; i < n; i++){
float a ,b;
cin >> a >>b;
value[i][0]= a;
value[i][1]= b;
}
// for (int i =0; i < n; i++){
// cout << value[i][0] << " " << value[i][1] << endl;
// }
//cal
float m,b;
float sum_xy =0;
for (int i =0; i < n; i++){
sum_xy += value[i][0] * value[i][1];
}
// cout << sum_xy <<endl;
float sum_x =0;
float sum_y =0;
for (int i =0; i < n; i++){
sum_x += value[i][0];
sum_y += value[i][1];
}
// cout << sum_x <<endl;
// cout << sum_y <<endl;
// cout << sum_y;
float sum_x2 =0;
float sum_y2 =0;
for (int i =0; i < n; i++){
sum_x2 += pow (value[i][0],2) ;
sum_y2 += pow (value[i][1],2);
}
float part_m1 = n*sum_xy - (sum_x*sum_y);
float part_m2 = n*sum_x2 - (sum_x *sum_x);
m = part_m1/part_m2;
float part_b1 = sum_y - (m * sum_x);
b = part_b1 /n;
if (op == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}else if(op == "func"){
if (m==0 && b ==0){
cout <<"y" << " = " << 0;
}
if (m == 0 && b !=0){
cout << "y" << " = " << round(b*1e3)/1e3;
}
if (m !=1 && m != -1 ){
if (b < 0){
cout << "y" << " = " << round(m*1e3)/1e3 <<"x" << " - "<< abs(round(b*1e3)/1e3);
}else if (b > 0 ){
cout << "y" << " = " << round(m*1e3)/1e3 <<"x" << " + "<< round(b*1e3)/1e3;
}else if (b == 0){
cout << "y" << " = " << round(m*1e3)/1e3 <<"x" ;
}
}else if ( m ==1 || m==-1){
if (m ==1){
if (b < 0){
cout << "y" << " = " << "x" << " - "<< abs(round(b*1e3)/1e3);
}else if (b > 0 ){
cout << "y" << " = " <<"x" << " + "<< round(b*1e3)/1e3;
}else if (b == 0){
cout << "y" << " = " <<"x" ;
}
}
if (m == -1){
if (b < 0){
cout << "y" << " = " << "-x" << " - "<< abs(round(b*1e3)/1e3);
}else if (b > 0 ){
cout << "y" << " = " <<"-x" << " + "<< round(b*1e3)/1e3;
}else if (b == 0){
cout << "y" << " = " <<"-x" ;
}
}
}
}
} | # 1092, 2024-11-02 11:03:09, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int n ;
string op;
cin >>n >>op;
float value [n][2];
for (int i =0; i < n; i++){
float a ,b;
cin >> a >>b;
value[i][0]= a;
value[i][1]= b;
}
// for (int i =0; i < n; i++){
// cout << value[i][0] << " " << value[i][1] << endl;
// }
//cal
float m,b;
float sum_xy =0;
for (int i =0; i < n; i++){
sum_xy += value[i][0] * value[i][1];
}
// cout << sum_xy <<endl;
float sum_x =0;
float sum_y =0;
for (int i =0; i < n; i++){
sum_x += value[i][0];
sum_y += value[i][1];
}
// cout << sum_x <<endl;
// cout << sum_y <<endl;
// cout << sum_y;
float sum_x2 =0;
float sum_y2 =0;
for (int i =0; i < n; i++){
sum_x2 += pow (value[i][0],2) ;
sum_y2 += pow (value[i][1],2);
}
float part_m1 = n*sum_xy - (sum_x*sum_y);
float part_m2 = n*sum_x2 - (sum_x *sum_x);
m = part_m1/part_m2;
float part_b1 = sum_y - (m * sum_x);
b = part_b1 /n;
if (op == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}else if(op == "func"){
if (m==0 && b ==0){
cout <<"y" << " = " << 0;
}
else if (m == 0 && b !=0){
cout << "y" << " = " << round(b*1e3)/1e3;
}
else if (m !=1 && m != -1 ){
if (b < 0){
cout << "y" << " = " << round(m*1e3)/1e3 <<"x" << " - "<< abs(round(b*1e3)/1e3);
}else if (b > 0 ){
cout << "y" << " = " << round(m*1e3)/1e3 <<"x" << " + "<< round(b*1e3)/1e3;
}else if (b == 0){
cout << "y" << " = " << round(m*1e3)/1e3 <<"x" ;
}
}else if ( m ==1 || m==-1){
if (m ==1){
if (b < 0){
cout << "y" << " = " << "x" << " - "<< abs(round(b*1e3)/1e3);
}else if (b > 0 ){
cout << "y" << " = " <<"x" << " + "<< round(b*1e3)/1e3;
}else if (b == 0){
cout << "y" << " = " <<"x" ;
}
}
if (m == -1){
if (b < 0){
cout << "y" << " = " << "-x" << " - "<< abs(round(b*1e3)/1e3);
}else if (b > 0 ){
cout << "y" << " = " <<"-x" << " + "<< round(b*1e3)/1e3;
}else if (b == 0){
cout << "y" << " = " <<"-x" ;
}
}
}
}
} |
# 1093, 2024-11-02 13:00:23, PPPPPPPPPP-----P-----P-- (50%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int n;
string command;
cin >> n >> command;
float m = 0;
float b = 0;
vector<float>X;
vector<float>Y;
for (int i = 0; i < n; i++){
float x , y;
cin >> x >> y;
X.push_back(x);
Y.push_back(y);
}
float m1,m2,m3,m4;
m1 = 0;
for (int i = 0; i < n; i++){
m1 += X[i]*Y[i];
}
m1 *= n;
m2 = 0;
float sumx = 0;
float sumy = 0;
m3 = 0;
for (int i = 0; i < n; i++){
sumx += X[i];
sumy += Y[i];
m3 += pow(X[i],2);
}
m3 *= n;
m2 = sumx*sumy;
m4 = pow(sumx,2);
m = (m1 - m2)/(m3-m4);
b = (sumy - m*sumx)/n;
if (command == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if (command == "func"){
cout << "y = ";
if (m != 1 && m != -1 && m != 0){
cout << m << "x + ";
}
else if (m == -1){
cout << "-x + ";
}
else if (m == 1){
cout << "x + ";
}
cout << b;
}
} | # 1094, 2024-11-02 13:03:00, PPPPPPPPPPP-P--P-----P-- (58%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int n;
string command;
cin >> n >> command;
float m = 0;
float b = 0;
vector<float>X;
vector<float>Y;
for (int i = 0; i < n; i++){
float x , y;
cin >> x >> y;
X.push_back(x);
Y.push_back(y);
}
float m1,m2,m3,m4;
m1 = 0;
for (int i = 0; i < n; i++){
m1 += X[i]*Y[i];
}
m1 *= n;
m2 = 0;
float sumx = 0;
float sumy = 0;
m3 = 0;
for (int i = 0; i < n; i++){
sumx += X[i];
sumy += Y[i];
m3 += pow(X[i],2);
}
m3 *= n;
m2 = sumx*sumy;
m4 = pow(sumx,2);
m = (m1 - m2)/(m3-m4);
b = (sumy - m*sumx)/n;
if (command == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if (command == "func"){
cout << "y = ";
if (m != 1 && m != -1 && m != 0){
cout << round(m*1e3)/1e3 << "x + ";
}
else if (m == -1){
cout << "-x + ";
}
else if (m == 1){
cout << "x + ";
}
cout << round(b*1e3)/1e3;
}
} | # 1095, 2024-11-02 14:24:43, PPPPPPPPPPPPPPP--------- (62%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int n;
string command;
cin >> n >> command;
float m = 0;
float b = 0;
vector<float>X;
vector<float>Y;
for (int i = 0; i < n; i++){
float x , y;
cin >> x >> y;
X.push_back(x);
Y.push_back(y);
}
float m1,m2,m3,m4;
m1 = 0;
for (int i = 0; i < n; i++){
m1 += X[i]*Y[i];
}
m1 *= n;
m2 = 0;
float sumx = 0;
float sumy = 0;
m3 = 0;
for (int i = 0; i < n; i++){
sumx += X[i];
sumy += Y[i];
m3 += pow(X[i],2);
}
m3 *= n;
m2 = sumx*sumy;
m4 = pow(sumx,2);
m = (m1 - m2)/(m3-m4);
b = (sumy - m*sumx)/n;
if (command == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if (command == "func"){
cout << "y = ";
if (m != 1 && m != -1 && m != 0){
cout << round(m*1e3)/1e3 << "x ";
}
else if (m == -1){
cout << "-x ";
}
else if (m == 1){
cout << "x ";
}
if (b >= 0){
cout << "+ ";
}
else{
cout << "- ";
}
cout << abs(round(b*1e3)/1e3);
}
} | # 1096, 2024-11-02 14:51:38, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int n;
string command;
cin >> n >> command;
float m = 0;
float b = 0;
vector<float>X;
vector<float>Y;
for (int i = 0; i < n; i++){
float x , y;
cin >> x >> y;
X.push_back(x);
Y.push_back(y);
}
float m1,m2,m3,m4;
m1 = 0;
for (int i = 0; i < n; i++){
m1 += X[i]*Y[i];
}
m1 *= n;
m2 = 0;
float sumx = 0;
float sumy = 0;
m3 = 0;
for (int i = 0; i < n; i++){
sumx += X[i];
sumy += Y[i];
m3 += pow(X[i],2);
}
m3 *= n;
m2 = sumx*sumy;
m4 = pow(sumx,2);
m = (m1 - m2)/(m3-m4);
b = (sumy - m*sumx)/n;
if (command == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if (command == "func"){
cout << "y =";
if (m == 0 && b == 0){
cout << ' ' << 0;
}
else if (m != 0 && b == 0){
if (m == -1)
cout << " -x";
else if (m == 1)
cout << " x";
else{
cout << ' ' << round(m*1e3)/1e3 << "x";
}
}
else if (m != 0 && b != 0)
{
if (m == -1)
cout << " -x";
else if (m == 1)
cout << " x";
else{
cout << ' ' << round(m*1e3)/1e3 << "x";
}
if (b > 0){
cout << " + " << round(b*1e3)/1e3;
}
else
{
cout << " - " << abs(round(b*1e3)/1e3);
}
}
else if (m == 0 && b != 0){
cout << ' ' << round(b*1e3)/1e3;
}
}
} |
# 1097, 2024-11-02 13:01:54, PPPPPPPPPP-----P--PP-PP- (62%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main()
{
int n;
cin >> n;
string s;
cin >> s;
vector<float> x , y ;
float inputx , inputy;
for(int i=0; i<n; i++)
{
cin >> inputx;
x.push_back(inputx);
cin >> inputy;
y.push_back(inputy);
}
float sumx=0 , sumy=0 , sumx2=0, sumxy=0;
for(int i=0; i<n; i++)
{
sumx += x[i];
sumy += y[i];
sumx2 += pow(x[i],2);
sumxy += (x[i]*y[i]);
}
float m , b;
m = ((n*sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
b = (sumy - (m*sumx)) / n ;
bool positive=false;
if(b > 0)
positive = true;
if(s=="mb")
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
if(s=="func")
{
if(m==0 && b==0)
cout << "y = 0" << endl;
else if(m==0 && b!=0)
{
cout << "y = " << round(b*1e3)/1e3 << endl;
}
else if(m!=0 && b==0)
{
if(m==1)
cout << "y = x" << endl;
else if(m==-1)
cout << "y = -x" << endl;
else
{
cout << "y = " << round(m*1e3)/1e3 << "x" << endl;
}
}
else if(m!=0 && b!=0)
{
if(m==1)
{
cout << "y = x";
if(positive==true)
cout << " + " << round(b*1e3)/1e3 << endl;
else
cout << " - " << round(abs(b)*1e3)/1e3 << endl;
}
else if(m==-1)
{
cout << "y = -x";
if(positive==true)
cout << " + " << round(b*1e3)/1e3 << endl;
else
cout << " - " << round(abs(b)*1e3)/1e3 << endl;
}
else
{
cout << "y = " << m << "x";
if(positive==true)
cout << " + " << round(b*1e3)/1e3 << endl;
else
cout << " - " << round(abs(b)*1e3)/1e3 << endl;
}
}
}
} | # 1098, 2024-11-02 13:04:15, PPPPPPPPPP-----P--PP-PP- (62%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main()
{
int n;
cin >> n;
string s;
cin >> s;
vector<float> x , y ;
float inputx , inputy;
for(int i=0; i<n; i++)
{
cin >> inputx;
x.push_back(inputx);
cin >> inputy;
y.push_back(inputy);
}
float sumx=0 , sumy=0 , sumx2=0, sumxy=0;
for(int i=0; i<n; i++)
{
sumx += x[i];
sumy += y[i];
sumx2 += pow(x[i],2);
sumxy += (x[i]*y[i]);
}
float m=0 , b=0;
m = ((n*sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
b = (sumy - (m*sumx)) / n ;
bool positive=false;
if(b > 0)
positive = true;
if(s=="mb")
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
if(s=="func")
{
if(m==0 && b==0)
cout << "y = 0" << endl;
else if(m==0 && b!=0)
{
cout << "y = " << round(b*1e3)/1e3 << endl;
}
else if(m!=0 && b==0)
{
if(m==1)
cout << "y = x" << endl;
else if(m==-1)
cout << "y = -x" << endl;
else
{
cout << "y = " << round(m*1e3)/1e3 << "x" << endl;
}
}
else if(m!=0 && b!=0)
{
if(m==1)
{
cout << "y = x";
if(positive==true)
cout << " + " << round(b*1e3)/1e3 << endl;
else
cout << " - " << round(abs(b)*1e3)/1e3 << endl;
}
else if(m==-1)
{
cout << "y = -x";
if(positive==true)
cout << " + " << round(b*1e3)/1e3 << endl;
else
cout << " - " << round(abs(b)*1e3)/1e3 << endl;
}
else
{
cout << "y = " << m << "x";
if(positive==true)
cout << " + " << round(b*1e3)/1e3 << endl;
else
cout << " - " << round(abs(b)*1e3)/1e3 << endl;
}
}
}
} | # 1099, 2024-11-02 14:13:00, ------------------------ (0%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main()
{
float n;
cin >> n;
string s;
cin >> s;
vector<float> x , y ;
float inputx , inputy;
for(int i=0; i<n; i++)
{
cin >> inputx;
x.push_back(inputx);
cin >> inputy;
y.push_back(inputy);
}
float sumx=0 , sumy=0 , sumx2=0, sumxy=0;
for(int i=0; i<n; i++)
{
sumx += x[i];
sumy += y[i];
sumx2 += pow(x[i],2);
sumxy += (x[i]*y[i]);
}
cout << sumx << " " << sumy << " " << sumx2 << " " << sumxy << endl;
float m=0 , b=0 , up=0 , low=0;
up = (n*sumxy) - (sumx*sumy);
low = (n*sumx2) - pow(sumx,2);
cout << up << " " << low << endl;
m = up / low;
//m = ((n*sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
b = (sumy - (m*sumx)) / n ;
bool positive=false;
if(b > 0)
positive = true;
if(s=="mb")
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl;
if(s=="func")
{
if(m==0 && b==0)
cout << "y = 0" << endl;
else if(m==0 && b!=0)
{
cout << "y = " << round(b*1e3)/1e3 << endl;
}
else if(m!=0 && b==0)
{
if(m==1)
cout << "y = x" << endl;
else if(m==-1)
cout << "y = -x" << endl;
else
{
cout << "y = " << round(m*1e3)/1e3 << "x" << endl;
}
}
else if(m!=0 && b!=0)
{
if(m==1)
{
cout << "y = x";
if(positive==true)
cout << " + " << round(b*1e3)/1e3 << endl;
else
cout << " - " << round(abs(b)*1e3)/1e3 << endl;
}
else if(m==-1)
{
cout << "y = -x";
if(positive==true)
cout << " + " << round(b*1e3)/1e3 << endl;
else
cout << " - " << round(abs(b)*1e3)/1e3 << endl;
}
else
{
cout << "y = " << m << "x";
if(positive==true)
cout << " + " << round(b*1e3)/1e3 << endl;
else
cout << " - " << round(abs(b)*1e3)/1e3 << endl;
}
}
}
} | # 1100, 2024-11-02 14:21:11, P-P--PPPP-PPPPPPPPPPP-PP (79%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main()
{
int n;
cin >> n;
string s;
cin >> s;
vector<float> x , y ;
float inputx , inputy;
for(int i=0; i<n; i++)
{
cin >> inputx;
x.push_back(inputx);
cin >> inputy;
y.push_back(inputy);
}
float sumx=0 , sumy=0 , sumx_2=0, sumxy=0;
for(int i=0; i<n; i++)
{
sumx = sumx + x[i];
sumy = sumy + y[i];
sumx_2 = sumx_2 + pow(x[i],2);
sumxy = sumxy + (x[i]*y[i]);
}
//cout << sumx << " " << sumy << " " << sumx_2 << " " << sumxy << endl;
float m=0 , b=0 , up=0 , low=0;
up = (n*sumxy) - (sumx*sumy);
low = (n*sumx_2) - pow(sumx,2);
//cout << up << " " << low << endl;
//m = ((n*sumxy) - (sumx*sumy)) / ((n*sumx2) - pow(sumx,2));
m = up / low;
b = (sumy - (m*sumx)) / n ;
bool positive=false;
if(b > 0)
positive = true;
m = round(m*1000)/1000;
b = abs(b);
b = round(b*1000)/1000;
//cout << m << " " << b;
if(s=="mb")
cout << m << endl << b << endl;
if(s=="func")
{
if(m==0 && b==0)
cout << "y = 0" << endl;
else if(m==0 && b!=0)
{
cout << "y = " << b << endl;
}
else if(m!=0 && b==0)
{
if(m==1)
cout << "y = x" << endl;
else if(m==-1)
cout << "y = -x" << endl;
else
{
cout << "y = " << m << "x" << endl;
}
}
else if(m!=0 && b!=0)
{
if(m==1)
{
cout << "y = x";
if(positive==true)
cout << " + " << b << endl;
else
cout << " - " << b << endl;
}
else if(m==-1)
{
cout << "y = -x";
if(positive==true)
cout << " + " << b << endl;
else
cout << " - " << b << endl;
}
else
{
cout << "y = " << m << "x";
if(positive==true)
cout << " + " << b << endl;
else
cout << " - " << b << endl;
}
}
}
} |
# 1101, 2024-11-02 09:49:36, PPPPPPPPPPPPPPPP--PP---- (75%)
#include<bits/stdc++.h>
using namespace std;
float m, b;
void mb(vector<pair<float, float>> numm, int n){
float upleft = 0;
float sum = 0;
for(int i=0;i<n;i++){
sum += numm[i].first * numm[i].second;
}
upleft = sum * n;
float downleft = 0;
float sumx2 = 0;
float downright = 0;
float upright = 0;
float sumx = 0;
float sumy = 0;
for(int i=0;i<n;i++){
sumx += numm[i].first;
sumy += numm[i].second;
sumx2 += numm[i].first * numm[i].first;
}
upright = sumx * sumy;
downleft = n * sumx2;
downright = sumx * sumx;
m = (upleft - upright) / (downleft - downright);
//////////////find b
float uplb = sumy;
float uprb = sumx * m;
b = (uplb - uprb) / n;
}
int main(){
int n;
string com;
cin>>n>>com;
int n2 = n;
vector<pair<float, float>> numm;
while(n--){
float a,b;
cin>>a>>b;
numm.push_back(make_pair(a,b));
}
mb(numm, n2);
if(com == "mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
else if(com == "func"){
if(m == 0 && b == 0){
cout<<"y = 0";
}
else {
cout<<"y = ";
if(m != 0){
if(m == -1){
cout<<"-x ";
}
else if(m == 1){
cout<<"x ";
}
else{
cout<<round(m*1e3)/1e3<<"x ";
}
}
if(b != 0){
if(b > 0){
cout<<"+ ";
}
else {
cout<<"- ";
}
cout<<abs(round(b*1e3)/1e3);
}
}
}
return 0;
} | # 1102, 2024-11-02 09:53:15, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
float m, b;
void mb(vector<pair<float, float>> numm, int n){
float upleft = 0;
float sum = 0;
for(int i=0;i<n;i++){
sum += numm[i].first * numm[i].second;
}
upleft = sum * n;
float downleft = 0;
float sumx2 = 0;
float downright = 0;
float upright = 0;
float sumx = 0;
float sumy = 0;
for(int i=0;i<n;i++){
sumx += numm[i].first;
sumy += numm[i].second;
sumx2 += numm[i].first * numm[i].first;
}
upright = sumx * sumy;
downleft = n * sumx2;
downright = sumx * sumx;
m = (upleft - upright) / (downleft - downright);
//////////////find b
float uplb = sumy;
float uprb = sumx * m;
b = (uplb - uprb) / n;
}
int main(){
int n;
string com;
cin>>n>>com;
int n2 = n;
vector<pair<float, float>> numm;
while(n--){
float a,b;
cin>>a>>b;
numm.push_back(make_pair(a,b));
}
mb(numm, n2);
if(com == "mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
else if(com == "func"){
if(m == 0 && b == 0){
cout<<"y = 0";
}
else {
cout<<"y = ";
if(round(m*1e3)/1e3 != 0){
if(m == -1){
cout<<"-x ";
}
else if(m == 1){
cout<<"x ";
}
else{
cout<<round(m*1e3)/1e3<<"x ";
}
}
if(round(b*1e3)/1e3 != 0){
if(b > 0){
cout<<"+ ";
}
else {
if(round(m*1e3)/1e3 == 0)cout<<"-";
else cout<<"- ";
}
cout<<abs(round(b*1e3)/1e3);
}
}
}
return 0;
} | # 1103, 2024-11-02 12:10:29, PPPPPPPPPPPPPPPP--PP-P-- (79%)
#include<bits/stdc++.h>
using namespace std;
float m, b;
void mb(vector<pair<float, float>> numm, int n){
float upleft = 0;
float sum = 0;
for(int i=0;i<n;i++){
sum += numm[i].first * numm[i].second;
}
upleft = sum * n;
float downleft = 0;
float sumx2 = 0;
float downright = 0;
float upright = 0;
float sumx = 0;
float sumy = 0;
for(int i=0;i<n;i++){
sumx += numm[i].first;
sumy += numm[i].second;
sumx2 += numm[i].first * numm[i].first;
}
upright = sumx * sumy;
downleft = n * sumx2;
downright = sumx * sumx;
m = (upleft - upright) / (downleft - downright);
//////////////find b
float uplb = sumy;
float uprb = sumx * m;
b = (uplb - uprb) / n;
}
int main(){
int n;
string com;
cin>>n>>com;
int n2 = n;
vector<pair<float, float>> numm;
while(n--){
float a,b;
cin>>a>>b;
numm.push_back(make_pair(a,b));
}
mb(numm, n2);
if(com == "mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
else if(com == "func"){
if(m == 0 && b == 0){
cout<<"y = 0";
}
else {
cout<<"y = ";
if(round(m*1e3)/1e3 != 0){
if(m == -1){
cout<<"-x ";
}
else if(m == 1){
cout<<"x ";
}
else{
cout<<round(m*1e3)/1e3<<"x ";
}
}
if(round(b*1e3)/1e3 != 0){
if(b > 0){
cout<<"+ ";
}
else {
if(round(m*1e3)/1e3 == 0)cout<<"-";
else cout<<"- ";
}
cout<<abs(round(b*1e3)/1e3);
}
}
}
return 0;
}
/*
20 func
-47.4275 -643.9849
-43.2994 -591.5547
-43.1769 -589.5735
-32.6425 -453.3533
-28.2735 -412.2329
-20.1902 -299.63
-6.3605 -140.4817
-5.6405 -128.4213
3.9611 -8.7905
4.7316 2.7213
4.1944 6.8667
16.9359 153.0378
19.2241 181.903
22.1265 222.7692
23.7411 227.653
34.6474 382.2777
41.1725 439.1405
39.5836 445.2155
47.5559 528.9183
47.6268 533.7816
*/ |
# 1104, 2024-11-02 13:25:16, P-P--PPPP-PPPPPPP---P--P (62%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main(){
int N = 0;
string method = "";
cin >> N >> method;
vector<float> x;
vector<float> y;
x.push_back(0);
y.push_back(0);
float inputX = 0, inputY = 0;
for(int i = 1; i <= N; i++){
cin >> inputX >> inputY;
x.push_back(inputX);
y.push_back(inputY);
}
float m = 0,b = 0, sumX = 0, sumY = 0, sumXY = 0, sumX2;
for(int i = 1; i <= N; i++){
sumX += x[i];
sumY += y[i];
sumXY += x[i]*y[i];
sumX2 += (x[i] * x[i]);
}
m = ((N*sumXY) - (sumX * sumY)) / ((N*sumX2) - (sumX * sumX));
b = (sumY - (m*sumX)) / N;
string posb = "", posm = "";
if(b < 0){
posb = "-";
b = abs(b);
}
else if(b > 0){
posb = "+";
}
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
// if(m == -1){
// posm = "-";
// }
if(method == "mb"){
cout << m << endl;
cout << b << endl;
}
else if(method == "func"){
if(m == -1){
cout << "y = -x ";
}
else if(m == 0){
cout << "y = ";
}
else{
cout << "y = " << m << "x ";
}
if(b == 0){
cout << "0";
}
else{
if(m == 0){
cout << b;
}
else{
cout << posb << " " << b;
}
}
}
} | # 1105, 2024-11-02 13:29:11, P-P--PPPP-PPPPPPPPPPP-PP (79%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main(){
int N = 0;
string method = "";
cin >> N >> method;
vector<float> x;
vector<float> y;
x.push_back(0);
y.push_back(0);
float inputX = 0, inputY = 0;
for(int i = 1; i <= N; i++){
cin >> inputX >> inputY;
x.push_back(inputX);
y.push_back(inputY);
}
float m = 0,b = 0, sumX = 0, sumY = 0, sumXY = 0, sumX2;
for(int i = 1; i <= N; i++){
sumX += x[i];
sumY += y[i];
sumXY += x[i]*y[i];
sumX2 += (x[i] * x[i]);
}
m = ((N*sumXY) - (sumX * sumY)) / ((N*sumX2) - (sumX * sumX));
b = (sumY - (m*sumX)) / N;
string posb = "", posm = "";
if(b < 0){
posb = "-";
b = abs(b);
}
else if(b > 0){
posb = "+";
}
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
// if(m == -1){
// posm = "-";
// }
if(method == "mb"){
cout << m << endl;
cout << b << endl;
}
else if(method == "func"){
if(m == -1){
cout << "y = -x";
}
else if(m == 1){
cout << "y = x";
}
else if(m == 0){
cout << "y = ";
if(b == 0){
cout << "0";
}
}
else{
cout << "y = " << m << "x";
}
if(b == 0){
}
else{
if(m == 0){
cout << " " << b;
}
else{
cout << " " << posb << " " << b;
}
}
}
} | # 1106, 2024-11-02 13:32:23, P-P--PPPP-PPPPP-PPPPP-PP (75%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main(){
int N = 0;
string method = "";
cin >> N >> method;
vector<float> x;
vector<float> y;
x.push_back(0);
y.push_back(0);
float inputX = 0, inputY = 0;
for(int i = 1; i <= N; i++){
cin >> inputX >> inputY;
x.push_back(inputX);
y.push_back(inputY);
}
float m = 0,b = 0, sumX = 0, sumY = 0, sumXY = 0, sumX2;
for(int i = 1; i <= N; i++){
sumX += x[i];
sumY += y[i];
sumXY += x[i]*y[i];
sumX2 += (x[i] * x[i]);
}
m = ((N*sumXY) - (sumX * sumY)) / ((N*sumX2) - (sumX * sumX));
b = (sumY - (m*sumX)) / N;
string posb = "", posm = "";
if(b < 0){
posb = "-";
b = abs(b);
}
else if(b > 0){
posb = "+";
}
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
// if(m == -1){
// posm = "-";
// }
if(method == "mb"){
cout << m << endl;
cout << b << endl;
}
else if(method == "func"){
if(m == -1){
cout << "y = -x";
}
else if(m == 1){
cout << "y = x";
}
else if(m == 0){
cout << "y =";
if(b == 0){
cout << "0";
}
}
else{
cout << "y = " << m << "x";
}
if(b == 0){
}
else{
if(m == 0){
cout << " " << b;
}
else{
if(m == 0){
cout << posb << b;
}
else{
cout << " " << posb << " " << b;
}
}
}
}
} |
# 1107, 2024-11-02 09:57:16, PPPPPPPPPPP----P--PP---- (58%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string command;
vector<float> x;
vector<float> y;
cin >> n >> command;
for(int i = 0; i < n; i++){
float a,b;
cin >> a >> b;
x.push_back(a);
y.push_back(b);
}
/// Find M
// top
float t = 0;
for(int i = 0; i < n; i++){
t += x[i]*y[i];
}
float top_left = n * t;
float t2 = 0;
for(int i = 0; i < n; i++){
t2 += x[i];
}
float t3 = 0;
for(int i = 0; i < n; i++){
t3 += y[i];
}
float top_righ = t2 * t3;
// bottom
float t4 = 0;
for(int i = 0; i < n; i++){
t4 += pow(x[i], 2);
}
float left_bottom = n * t4;
float right_bottom = pow(t2,2);
float m = (top_left - top_righ)/(left_bottom - right_bottom);
/// Find B
float b = (t3 - (m * t2)) / n;
if(command == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(command == "func"){
string sym;
if(b>0){sym = "+";}else{sym = "-";}
cout << "y = ";
if(m == 0 && b == 0){cout << "0";}
else if(m < 0 && m!=-1 && b != 0){cout << round(b*1e3)/1e3;}
else if(m == 1 && b == 0){cout << "x";}
else if(m == 1 && b != 0){cout << "x " << sym << " " << round(b*1e3)/1e3;}
else if(m == -1 && b == 0){cout << "-x ";}
else if(m == -1 && b != 0){cout << "-x " << sym << " " << abs(round(b*1e3)/1e3);}
else{
cout << round(m*1e3)/1e3 << "x " << sym << " " << round(b*1e3)/1e3;
}
}
return 0;
} | # 1108, 2024-11-02 09:58:17, PPPPPPPPPPPP---P--PP---- (62%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string command;
vector<float> x;
vector<float> y;
cin >> n >> command;
for(int i = 0; i < n; i++){
float a,b;
cin >> a >> b;
x.push_back(a);
y.push_back(b);
}
/// Find M
// top
float t = 0;
for(int i = 0; i < n; i++){
t += x[i]*y[i];
}
float top_left = n * t;
float t2 = 0;
for(int i = 0; i < n; i++){
t2 += x[i];
}
float t3 = 0;
for(int i = 0; i < n; i++){
t3 += y[i];
}
float top_righ = t2 * t3;
// bottom
float t4 = 0;
for(int i = 0; i < n; i++){
t4 += pow(x[i], 2);
}
float left_bottom = n * t4;
float right_bottom = pow(t2,2);
float m = (top_left - top_righ)/(left_bottom - right_bottom);
/// Find B
float b = (t3 - (m * t2)) / n;
if(command == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(command == "func"){
string sym;
if(b>0){sym = "+";}else{sym = "-";}
cout << "y = ";
if(m == 0 && b == 0){cout << "0";}
else if(m < 0 && m!=-1 && b != 0){cout << round(b*1e3)/1e3;}
else if(m == 1 && b == 0){cout << "x";}
else if(m == 1 && b != 0){cout << "x " << sym << " " << round(b*1e3)/1e3;}
else if(m == -1 && b == 0){cout << "-x ";}
else if(m == -1 && b != 0){cout << "-x " << sym << " " << abs(round(b*1e3)/1e3);}
else{
cout << round(m*1e3)/1e3 << "x " << sym << " " << abs(round(b*1e3)/1e3);
}
}
return 0;
} | # 1109, 2024-11-02 10:04:39, PPPPPPPPPPPP---P--PP---- (62%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string command;
vector<float> x;
vector<float> y;
cin >> n >> command;
for(int i = 0; i < n; i++){
float a,b;
cin >> a >> b;
x.push_back(a);
y.push_back(b);
}
/// Find M
// top
float t = 0;
for(int i = 0; i < n; i++){
t += x[i]*y[i];
}
float top_left = n * t;
float t2 = 0;
for(int i = 0; i < n; i++){
t2 += x[i];
}
float t3 = 0;
for(int i = 0; i < n; i++){
t3 += y[i];
}
float top_righ = t2 * t3;
// bottom
float t4 = 0;
for(int i = 0; i < n; i++){
t4 += pow(x[i], 2);
}
float left_bottom = n * t4;
float right_bottom = pow(t2,2);
float m = (top_left - top_righ)/(left_bottom - right_bottom);
/// Find B
float b = (t3 - (m * t2)) / n;
if(command == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(command == "func"){
string sym;
if(b>0){sym = "+";}else{sym = "-";}
cout << "y = ";
if(m == 0 && b == 0){cout << "0";}
else if(m < 0 && m!=-1 && b != 0){cout << round(b*1e3)/1e3;}
else if(m == 1 && b == 0){cout << "x";}
else if(m == 1 && b != 0){cout << "x " << sym << " " << round(b*1e3)/1e3;}
else if(m == -1 && b == 0){cout << "-x";}
else if(m == -1 && b != 0){cout << "-x " << sym << " " << abs(round(b*1e3)/1e3);}
else{
cout << round(m*1e3)/1e3 << "x " << sym << " " << abs(round(b*1e3)/1e3);
}
}
return 0;
} | # 1110, 2024-11-02 10:09:21, PPPPPPPPPPPP---P--PP---- (62%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string command;
vector<float> x;
vector<float> y;
cin >> n >> command;
for(int i = 0; i < n; i++){
float a,b;
cin >> a >> b;
x.push_back(a);
y.push_back(b);
}
/// Find M
// top
float t = 0;
for(int i = 0; i < n; i++){
t += x[i]*y[i];
}
float top_left = n * t;
float t2 = 0;
for(int i = 0; i < n; i++){
t2 += x[i];
}
float t3 = 0;
for(int i = 0; i < n; i++){
t3 += y[i];
}
float top_righ = t2 * t3;
// bottom
float t4 = 0;
for(int i = 0; i < n; i++){
t4 += pow(x[i], 2);
}
float left_bottom = n * t4;
float right_bottom = pow(t2,2);
float m = (top_left - top_righ)/(left_bottom - right_bottom);
/// Find B
float b = (t3 - (m * t2)) / n;
if(command == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(command == "func"){
string sym;
if(b>0){sym = "+";}else{sym = "-";}
cout << "y = ";
if(m == 0 && b == 0){cout << 0;}
else if(m < 0 && m!=-1 && b != 0){cout << round(b*1e3)/1e3;}
else if(m == 1 && b == 0){cout << "x";}
else if(m == 1 && b != 0){cout << "x " << sym << " " << round(b*1e3)/1e3;}
else if(m == -1 && b == 0){cout << "-x";}
else if(m == -1 && b != 0){cout << "-x " << sym << " " << abs(round(b*1e3)/1e3);}
else{
cout << round(m*1e3)/1e3 << "x " << sym << " " << abs(round(b*1e3)/1e3);
}
}
return 0;
} | # 1111, 2024-11-02 10:52:04, PPPPPPPPPPPP---P--PP---- (62%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string command;
vector<float> x;
vector<float> y;
cin >> n >> command;
for(int i = 0; i < n; i++){
float a,b;
cin >> a >> b;
if(a == 0 && b == 0){continue;}
x.push_back(a);
y.push_back(b);
}
/// Find M
// top
float t = 0;
for(int i = 0; i < n; i++){
t += x[i]*y[i];
}
float top_left = n * t;
float t2 = 0;
for(int i = 0; i < n; i++){
t2 += x[i];
}
float t3 = 0;
for(int i = 0; i < n; i++){
t3 += y[i];
}
float top_righ = t2 * t3;
// bottom
float t4 = 0;
for(int i = 0; i < n; i++){
t4 += pow(x[i], 2);
}
float left_bottom = n * t4;
float right_bottom = pow(t2,2);
float m = (top_left - top_righ)/(left_bottom - right_bottom);
/// Find B
float b = (t3 - (m * t2)) / n;
if(command == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(command == "func"){
string sym;
if(b>0){sym = "+";}else{sym = "-";}
cout << "y = ";
if(m == 0 && b == 0){cout << 0;}
else if(m < 0 && m!=-1 && b != 0){cout << round(b*1e3)/1e3;}
else if(m == 1 && b == 0){cout << "x";}
else if(m == 1 && b != 0){cout << "x " << sym << " " << round(b*1e3)/1e3;}
else if(m == -1 && b == 0){cout << "-x";}
else if(m == -1 && b != 0){cout << "-x " << sym << " " << abs(round(b*1e3)/1e3);}
else{
cout << round(m*1e3)/1e3 << "x " << sym << " " << abs(round(b*1e3)/1e3);
}
}
return 0;
} | # 1112, 2024-11-02 10:58:56, PPPPPPPPPPPP---P--PP---- (62%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string command;
vector<float> x;
vector<float> y;
cin >> n >> command;
for(int i = 0; i < n; i++){
float a,b;
cin >> a >> b;
if(a == 0 && b == 0){continue;}
x.push_back(a);
y.push_back(b);
}
/// Find M
// top
float t = 0;
for(int i = 0; i < n; i++){
t += x[i]*y[i];
}
float top_left = n * t;
float t2 = 0;
for(int i = 0; i < n; i++){
t2 += x[i];
}
float t3 = 0;
for(int i = 0; i < n; i++){
t3 += y[i];
}
float top_righ = t2 * t3;
// bottom
float t4 = 0;
for(int i = 0; i < n; i++){
t4 += pow(x[i], 2);
}
float left_bottom = n * t4;
float right_bottom = pow(t2,2);
float m = (top_left - top_righ)/(left_bottom - right_bottom);
/// Find B
float b = (t3 - (m * t2)) / n;
if(command == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(command == "func"){
string sym;
if(b>0){sym = "+";}else{sym = "-";}
cout << "y = ";
if(m == 0 && b == 0){cout << 0;}
else if(m < 0 && m!=-1 && b != 0){cout << abs(round(b*1e3)/1e3);}
else if(m == 1 && b == 0){cout << "x";}
else if(m == 1 && b != 0){cout << "x " << sym << " " << abs(round(b*1e3)/1e3);}
else if(m == -1 && b == 0){cout << "-x";}
else if(m == -1 && b != 0){cout << "-x " << sym << " " << abs(round(b*1e3)/1e3);}
else{
cout << round(m*1e3)/1e3 << "x " << sym << " " << abs(round(b*1e3)/1e3);
}
}
return 0;
} | # 1113, 2024-11-02 11:01:07, PPPPPPPPPPPP---P--PP---- (62%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string command;
vector<float> x;
vector<float> y;
cin >> n >> command;
for(int i = 0; i < n; i++){
float a,b;
cin >> a >> b;
if(a == 0 && b == 0){continue;}
x.push_back(a);
y.push_back(b);
}
/// Find M
// top
float t = 0;
for(int i = 0; i < n; i++){
t += x[i]*y[i];
}
float top_left = n * t;
float t2 = 0;
for(int i = 0; i < n; i++){
t2 += x[i];
}
float t3 = 0;
for(int i = 0; i < n; i++){
t3 += y[i];
}
float top_righ = t2 * t3;
// bottom
float t4 = 0;
for(int i = 0; i < n; i++){
t4 += pow(x[i], 2);
}
float left_bottom = n * t4;
float right_bottom = pow(t2,2);
float m = (top_left - top_righ)/(left_bottom - right_bottom);
/// Find B
float b = (t3 - (m * t2)) / n;
if(command == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(command == "func"){
string sym;
if(b>0){sym = "+";}else if(b<0){sym = "-";}
cout << "y = ";
if(m == 0 && b == 0){cout << 0;}
else if(m < 0 && m!=-1 && b != 0){cout << abs(round(b*1e3)/1e3);}
else if(m == 1 && b == 0){cout << "x";}
else if(m == 1 && b != 0){cout << "x " << sym << " " << abs(round(b*1e3)/1e3);}
else if(m == -1 && b == 0){cout << "-x";}
else if(m == -1 && b != 0){cout << "-x " << sym << " " << abs(round(b*1e3)/1e3);}
else{
cout << round(m*1e3)/1e3 << "x " << sym << " " << abs(round(b*1e3)/1e3);
}
}
return 0;
} | # 1114, 2024-11-02 11:29:21, PPPPPPPPPPPP---P--PP---- (62%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, check = 0;
string command;
vector<float> x;
vector<float> y;
cin >> n >> command;
for(int i = 0; i < n; i++){
float a,b;
cin >> a >> b;
if(a>0 || b>0){check = 1;}
x.push_back(a);
y.push_back(b);
}
/// Find M
// top
float t = 0;
for(int i = 0; i < n; i++){
t += x[i]*y[i];
}
float top_left = n * t;
float t2 = 0;
for(int i = 0; i < n; i++){
t2 += x[i];
}
float t3 = 0;
for(int i = 0; i < n; i++){
t3 += y[i];
}
float top_righ = t2 * t3;
// bottom
float t4 = 0;
for(int i = 0; i < n; i++){
t4 += pow(x[i], 2);
}
float left_bottom = n * t4;
float right_bottom = pow(t2,2);
float m = (top_left - top_righ)/(left_bottom - right_bottom);
/// Find B
float b = (t3 - (m * t2)) / n;
if(command == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(command == "func" && check == 1){
string sym;
if(b>0){sym = "+";}else if(b<0){sym = "-";}
cout << "y = ";
if(m == 0 && b == 0){cout << 0;}
else if(m < 0 && m!=-1 && b != 0){cout << abs(round(b*1e3)/1e3);}
else if(m == 1 && b == 0){cout << "x";}
else if(m == 1 && b != 0){cout << "x " << sym << " " << abs(round(b*1e3)/1e3);}
else if(m == -1 && b == 0){cout << "-x";}
else if(m == -1 && b != 0){cout << "-x " << sym << " " << abs(round(b*1e3)/1e3);}
else{
cout << round(m*1e3)/1e3 << "x " << sym << " " << abs(round(b*1e3)/1e3);
}
}
return 0;
} | # 1115, 2024-11-02 11:43:33, PPPPPPPPPPPP---P--PP---- (62%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,state = 1;
string command;
vector<float> x;
vector<float> y;
cin >> n >> command;
for(int i = 0; i < n; i++){
float a,b;
cin >> a >> b;
if(a == 0 && b == 0){state = 0; continue;}
x.push_back(a);
y.push_back(b);
}
if(state == 1){
/// Find M
// top
float t = 0;
for(int i = 0; i < n; i++){
t += x[i]*y[i];
}
float top_left = n * t;
float t2 = 0;
for(int i = 0; i < n; i++){
t2 += x[i];
}
float t3 = 0;
for(int i = 0; i < n; i++){
t3 += y[i];
}
float top_righ = t2 * t3;
// bottom
float t4 = 0;
for(int i = 0; i < n; i++){
t4 += pow(x[i], 2);
}
float left_bottom = n * t4;
float right_bottom = pow(t2,2);
float m = (top_left - top_righ)/(left_bottom - right_bottom);
/// Find B
float b = (t3 - (m * t2)) / n;
if(command == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(command == "func"){
string sym;
if(b>0){sym = "+";}else if(b<0){sym = "-";}
cout << "y = ";
if(m == 0 && b == 0){cout << 0;}
else if(m < 0 && m!=-1 && b != 0){cout << abs(round(b*1e3)/1e3);}
else if(m == 1 && b == 0){cout << "x";}
else if(m == 1 && b != 0){cout << "x " << sym << " " << abs(round(b*1e3)/1e3);}
else if(m == -1 && b == 0){cout << "-x";}
else if(m == -1 && b != 0){cout << "-x " << sym << " " << abs(round(b*1e3)/1e3);}
else{
cout << round(m*1e3)/1e3 << "x " << sym << " " << abs(round(b*1e3)/1e3);
}
}
}
return 0;
} | # 1116, 2024-11-02 11:44:06, Compilation error (0%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string command;
vector<float> x;
vector<float> y;
cin >> n >> command;
for(int i = 0; i < n; i++){
float a,b;
cin >> a >> b;
x.push_back(a);
y.push_back(b);
}
/// Find M
// top
float t = 0;
for(int i = 0; i < n; i++){
t += x[i]*y[i];
}
float top_left = n * t;
float t2 = 0;
for(int i = 0; i < n; i++){
t2 += x[i];
}
float t3 = 0;
for(int i = 0; i < n; i++){
t3 += y[i];
}
float top_righ = t2 * t3;
// bottom
float t4 = 0;
for(int i = 0; i < n; i++){
t4 += pow(x[i], 2);
}
float left_bottom = n * t4;
float right_bottom = pow(t2,2);
float m = (top_left - top_righ)/(left_bottom - right_bottom);
/// Find B
float b = (t3 - (m * t2)) / n;
if(command == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(command == "func" && state == 1){
string sym;
if(b>0){sym = "+";}else if(b<0){sym = "-";}
cout << "y = ";
if(m == 0 && b == 0){cout << 0;}
else if(m < 0 && m!=-1 && b != 0){cout << abs(round(b*1e3)/1e3);}
else if(m == 1 && b == 0){cout << "x";}
else if(m == 1 && b != 0){cout << "x " << sym << " " << abs(round(b*1e3)/1e3);}
else if(m == -1 && b == 0){cout << "-x";}
else if(m == -1 && b != 0){cout << "-x " << sym << " " << abs(round(b*1e3)/1e3);}
else{
cout << round(m*1e3)/1e3 << "x " << sym << " " << abs(round(b*1e3)/1e3);
}
}
return 0;
} | # 1117, 2024-11-02 11:44:24, PPPPPPPPPPPP---P--PP---- (62%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string command;
vector<float> x;
vector<float> y;
cin >> n >> command;
for(int i = 0; i < n; i++){
float a,b;
cin >> a >> b;
x.push_back(a);
y.push_back(b);
}
/// Find M
// top
float t = 0;
for(int i = 0; i < n; i++){
t += x[i]*y[i];
}
float top_left = n * t;
float t2 = 0;
for(int i = 0; i < n; i++){
t2 += x[i];
}
float t3 = 0;
for(int i = 0; i < n; i++){
t3 += y[i];
}
float top_righ = t2 * t3;
// bottom
float t4 = 0;
for(int i = 0; i < n; i++){
t4 += pow(x[i], 2);
}
float left_bottom = n * t4;
float right_bottom = pow(t2,2);
float m = (top_left - top_righ)/(left_bottom - right_bottom);
/// Find B
float b = (t3 - (m * t2)) / n;
if(command == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(command == "func"){
string sym;
if(b>0){sym = "+";}else if(b<0){sym = "-";}
cout << "y = ";
if(m == 0 && b == 0){cout << 0;}
else if(m < 0 && m!=-1 && b != 0){cout << abs(round(b*1e3)/1e3);}
else if(m == 1 && b == 0){cout << "x";}
else if(m == 1 && b != 0){cout << "x " << sym << " " << abs(round(b*1e3)/1e3);}
else if(m == -1 && b == 0){cout << "-x";}
else if(m == -1 && b != 0){cout << "-x " << sym << " " << abs(round(b*1e3)/1e3);}
else{
cout << round(m*1e3)/1e3 << "x " << sym << " " << abs(round(b*1e3)/1e3);
}
}
return 0;
} | # 1118, 2024-11-02 11:45:24, PPPPPPPPPPPP---P--PP---- (62%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string command;
vector<float> x;
vector<float> y;
cin >> n >> command;
for(int i = 0; i < n; i++){
float a,b;
cin >> a >> b;
x.push_back(a);
y.push_back(b);
}
/// Find M
// top
float t = 0;
for(int i = 0; i < n; i++){
t += x[i]*y[i];
}
float top_left = n * t;
float t2 = 0;
for(int i = 0; i < n; i++){
t2 += x[i];
}
float t3 = 0;
for(int i = 0; i < n; i++){
t3 += y[i];
}
float top_righ = t2 * t3;
// bottom
float t4 = 0;
for(int i = 0; i < n; i++){
t4 += pow(x[i], 2);
}
float left_bottom = n * t4;
float right_bottom = pow(t2,2);
float m = (top_left - top_righ)/(left_bottom - right_bottom);
/// Find B
float b = (t3 - (m * t2)) / n;
if(command == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(command == "func"){
string sym;
if(b>0){sym = "+";}else if(b<0){sym = "-";}
cout << "y = ";
if(m == 0 && b == 0){cout << 0;}
else if(m < 0 && m!=-1 && b != 0){cout << round(b*1e3)/1e3;}
else if(m == 1 && b == 0){cout << "x";}
else if(m == 1 && b != 0){cout << "x " << sym << " " << abs(round(b*1e3)/1e3);}
else if(m == -1 && b == 0){cout << "-x";}
else if(m == -1 && b != 0){cout << "-x " << sym << " " << abs(round(b*1e3)/1e3);}
else{
cout << round(m*1e3)/1e3 << "x " << sym << " " << abs(round(b*1e3)/1e3);
}
}
return 0;
} | # 1119, 2024-11-02 11:46:59, PPPPPPPPPPPPPPPP--PP---- (75%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string command;
vector<float> x;
vector<float> y;
cin >> n >> command;
for(int i = 0; i < n; i++){
float a,b;
cin >> a >> b;
x.push_back(a);
y.push_back(b);
}
/// Find M
// top
float t = 0;
for(int i = 0; i < n; i++){
t += x[i]*y[i];
}
float top_left = n * t;
float t2 = 0;
for(int i = 0; i < n; i++){
t2 += x[i];
}
float t3 = 0;
for(int i = 0; i < n; i++){
t3 += y[i];
}
float top_righ = t2 * t3;
// bottom
float t4 = 0;
for(int i = 0; i < n; i++){
t4 += pow(x[i], 2);
}
float left_bottom = n * t4;
float right_bottom = pow(t2,2);
float m = (top_left - top_righ)/(left_bottom - right_bottom);
/// Find B
float b = (t3 - (m * t2)) / n;
if(command == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(command == "func"){
string sym;
if(b>0){sym = "+";}else if(b<0){sym = "-";}
cout << "y = ";
if(m == 0 && b == 0){cout << 0;}
///else if(m < 0 && m!=-1 && b != 0){cout << round(b*1e3)/1e3;}
else if(m == 1 && b == 0){cout << "x";}
else if(m == 1 && b != 0){cout << "x " << sym << " " << abs(round(b*1e3)/1e3);}
else if(m == -1 && b == 0){cout << "-x";}
else if(m == -1 && b != 0){cout << "-x " << sym << " " << abs(round(b*1e3)/1e3);}
else{
cout << round(m*1e3)/1e3 << "x " << sym << " " << abs(round(b*1e3)/1e3);
}
}
return 0;
} | # 1120, 2024-11-02 11:49:32, PPPPPPPPPPPPPPPP--PP---- (75%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string command;
vector<float> x;
vector<float> y;
cin >> n >> command;
for(int i = 0; i < n; i++){
float a,b;
cin >> a >> b;
x.push_back(a);
y.push_back(b);
}
/// Find M
// top
float t = 0;
for(int i = 0; i < n; i++){
t += x[i]*y[i];
}
float top_left = n * t;
float t2 = 0;
for(int i = 0; i < n; i++){
t2 += x[i];
}
float t3 = 0;
for(int i = 0; i < n; i++){
t3 += y[i];
}
float top_righ = t2 * t3;
// bottom
float t4 = 0;
for(int i = 0; i < n; i++){
t4 += pow(x[i], 2);
}
float left_bottom = n * t4;
float right_bottom = pow(t2,2);
float m = (top_left - top_righ)/(left_bottom - right_bottom);
/// Find B
float b = (t3 - (m * t2)) / n;
if(command == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(command == "func"){
string sym;
if(b>=0){sym = "+";}else if(b<0){sym = "-";}
cout << "y = ";
if(m == 0 && b == 0){cout << 0;}
else if(m == 1 && b == 0){cout << "x";}
else if(m == 1 && b != 0){cout << "x " << sym << " " << abs(round(b*1e3)/1e3);}
else if(m == -1 && b == 0){cout << "-x";}
else if(m == -1 && b != 0){cout << "-x " << sym << " " << abs(round(b*1e3)/1e3);}
else{
cout << round(m*1e3)/1e3 << "x " << sym << " " << abs(round(b*1e3)/1e3);
}
}
return 0;
} | # 1121, 2024-11-02 11:54:15, PPPPPPPPPPPPPPP---PP---- (70%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string command;
vector<float> x;
vector<float> y;
cin >> n >> command;
for(int i = 0; i < n; i++){
float a,b;
cin >> a >> b;
x.push_back(a);
y.push_back(b);
}
/// Find M
// top
float t = 0;
for(int i = 0; i < n; i++){
t += x[i]*y[i];
}
float top_left = n * t;
float t2 = 0;
for(int i = 0; i < n; i++){
t2 += x[i];
}
float t3 = 0;
for(int i = 0; i < n; i++){
t3 += y[i];
}
float top_righ = t2 * t3;
// bottom
float t4 = 0;
for(int i = 0; i < n; i++){
t4 += pow(x[i], 2);
}
float left_bottom = n * t4;
float right_bottom = pow(t2,2);
float m = (top_left - top_righ)/(left_bottom - right_bottom);
/// Find B
float b = (t3 - (m * t2)) / n;
if(command == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(command == "func"){
string sym;
if(b>0){sym = "+";}else if(b<0){sym = "-";}
cout << "y = ";
if(m == 1){
cout << "x";
}
else if(m == -1){cout << "-x";}
else{if(m!=0){cout << round(m*1e3)/1e3 << "x";}}
if(b != 0){
cout << " " << sym << " " << abs(round(b*1e3)/1e3);
}
}
return 0;
} | # 1122, 2024-11-02 12:09:14, ------------------------ (0%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string command;
vector<float> x;
vector<float> y;
cin >> n >> command;
for(int i = 0; i < n; i++){
float a,b;
cin >> a >> b;
x.push_back(a);
y.push_back(b);
}
/// Find M
// top
float t = 0;
for(int i = 0; i < n; i++){
t += x[i]*y[i];
}
float top_left = n * t;
float t2 = 0;
for(int i = 0; i < n; i++){
t2 += x[i];
}
float t3 = 0;
for(int i = 0; i < n; i++){
t3 += y[i];
}
float top_righ = t2 * t3;
// bottom
float t4 = 0;
for(int i = 0; i < n; i++){
t4 += pow(x[i], 2);
}
float left_bottom = n * t4;
float right_bottom = pow(t2,2);
float m = (top_left - top_righ)/(left_bottom - right_bottom);
/// Find B
float b = (t3 - (m * t2)) / n;
cout << m << endl;
if(command == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(command == "func"){
string sym;
if(b>0){sym = "+";}else if(b<0){sym = "-";}
cout << "y = ";
if(m == 0 && b == 0){cout << 0;}
else if(m < 0 && m != -1){
cout << round(b*1e3)/1e3;
}
else if(m == -1){
cout << "-x";
if(b!=0){
cout << " " << sym << " " << abs(round(b*1e3)/1e3);
}
}
else if(m == 1){
cout << "x";
if(b!=0){
cout << " " << sym << " " << abs(round(b*1e3)/1e3);
}
}
else{
cout << round(m*1e3)/1e3 << "x";
if(b!=0){
cout << " " << sym << " " << abs(round(b*1e3)/1e3);
}
}
}
return 0;
} | # 1123, 2024-11-02 12:09:37, ------------------------ (0%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string command;
vector<float> x;
vector<float> y;
for(int i = 0; i < n; i++){
float a,b;
cin >> a >> b;
x.push_back(a);
y.push_back(b);
}
/// Find M
// top
float t = 0;
for(int i = 0; i < n; i++){
t += x[i]*y[i];
}
float top_left = n * t;
float t2 = 0;
for(int i = 0; i < n; i++){
t2 += x[i];
}
float t3 = 0;
for(int i = 0; i < n; i++){
t3 += y[i];
}
float top_righ = t2 * t3;
// bottom
float t4 = 0;
for(int i = 0; i < n; i++){
t4 += pow(x[i], 2);
}
float left_bottom = n * t4;
float right_bottom = pow(t2,2);
float m = (top_left - top_righ)/(left_bottom - right_bottom);
/// Find B
float b = (t3 - (m * t2)) / n;
cout << m << endl;
if(command == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(command == "func"){
string sym;
if(b>0){sym = "+";}else if(b<0){sym = "-";}
cout << "y = ";
if(m == 0 && b == 0){cout << 0;}
else if(m < 0 && m != -1){
cout << round(b*1e3)/1e3;
}
else if(m == -1){
cout << "-x";
if(b!=0){
cout << " " << sym << " " << abs(round(b*1e3)/1e3);
}
}
else if(m == 1){
cout << "x";
if(b!=0){
cout << " " << sym << " " << abs(round(b*1e3)/1e3);
}
}
else{
cout << round(m*1e3)/1e3 << "x";
if(b!=0){
cout << " " << sym << " " << abs(round(b*1e3)/1e3);
}
}
}
return 0;
} | # 1124, 2024-11-02 12:11:23, PPPPPPPPPPPP---P--PP---- (62%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string command;
vector<float> x;
vector<float> y;
cin >> n >> command;
for(int i = 0; i < n; i++){
float a,b;
cin >> a >> b;
x.push_back(a);
y.push_back(b);
}
/// Find M
// top
float t = 0;
for(int i = 0; i < n; i++){
t += x[i]*y[i];
}
float top_left = n * t;
float t2 = 0;
for(int i = 0; i < n; i++){
t2 += x[i];
}
float t3 = 0;
for(int i = 0; i < n; i++){
t3 += y[i];
}
float top_righ = t2 * t3;
// bottom
float t4 = 0;
for(int i = 0; i < n; i++){
t4 += pow(x[i], 2);
}
float left_bottom = n * t4;
float right_bottom = pow(t2,2);
float m = (top_left - top_righ)/(left_bottom - right_bottom);
/// Find B
float b = (t3 - (m * t2)) / n;
if(command == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(command == "func"){
string sym;
if(b>0){sym = "+";}else if(b<0){sym = "-";}
cout << "y = ";
if(m == 0 && b == 0){cout << 0;}
else if(m < 0 && m != -1){
cout << round(b*1e3)/1e3;
}
else if(m == -1){
cout << "-x";
if(b!=0){
cout << " " << sym << " " << abs(round(b*1e3)/1e3);
}
}
else if(m == 1){
cout << "x";
if(b!=0){
cout << " " << sym << " " << abs(round(b*1e3)/1e3);
}
}
else{
cout << round(m*1e3)/1e3 << "x";
if(b!=0){
cout << " " << sym << " " << abs(round(b*1e3)/1e3);
}
}
}
return 0;
} |
# 1125, 2024-11-02 09:30:27, ------P-P--------------- (8%)
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
using namespace std;
int main() {
int n;
string ch;
cin >> n >> ch;
vector<pair<float, float>> num;
float xi, yi;
if (ch == "mb") {
for (int i = 0; i < n; ++i) {
cin >> xi >> yi;
num.push_back({xi,yi});
}
float m1 = 0;
for (int i = 0; i < n; ++i) {
m1 += num[i].first * num[i].second;
}
m1 *= n;
float m2 = 0;
for (int i = 0; i < n; ++i) {
m2 += num[i].first;
}
float m3 = 0;
for (int i = 0; i < n; ++i) {
m3 += num[i].second;
}
float up = m1 - (m2 * m3);
float m4 = 0;
for (int i = 0; i < n; ++i) {
m4 += pow((num[i].first),2);
}
m4 *= n;
float m5;
for (int i = 0; i < n; ++i) {
m5 += num[i].second;
}
m5 = m5 * m5;
float down = m4 - m5;
float m = round((up/down)*1e3)/1e3;
cout << m << endl;
float n1 = 0;
for (int i = 0; i < n; ++i) {
n1 += num[i].second;
}
float n2 = 0;
for (int i = 0;i < n; ++i) {
n2 += num[i].first;
}
n2 *= m;
float b = (n1 - n2) / n;
cout << b << endl;
}
} | # 1126, 2024-11-02 10:24:36, -----PPPPP-------------- (20%)
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
using namespace std;
int main() {
int n;
string ch;
cin >> n >> ch;
vector<pair<float, float>> num;
float xi, yi;
for (int i = 0; i < n; ++i) {
cin >> xi >> yi;
num.push_back({xi,yi});
}
float m1 = 0;
for (int i = 0; i < n; ++i) {
m1 += num[i].first * num[i].second;
}
m1 *= n;
float m2 = 0;
for (int i = 0; i < n; ++i) {
m2 += num[i].first;
}
float m3 = 0;
for (int i = 0; i < n; ++i) {
m3 += num[i].second;
}
float up = m1 - (m2 * m3);
float m4 = 0;
for (int i = 0; i < n; ++i) {
m4 += pow((num[i].first),2);
}
m4 *= n;
float m5;
for (int i = 0; i < n; ++i) {
m5 += num[i].second;
}
m5 = m5 * m5;
float down = m4 - m5;
float m = round((up/down)*1e3)/1e3;
float n1 = 0;
for (int i = 0; i < n; ++i) {
n1 += num[i].second;
}
float n2 = 0;
for (int i = 0;i < n; ++i) {
n2 += num[i].first;
}
n2 *= m;
float b = (n1 - n2) / n;
if (ch == "mb") {
cout << m << endl;
cout << b << endl;
}
else if (ch == "func") {
cout << "y = " << m << ((m=0) ? " " : "x ") << ((b>0) ? "+ " : "") << b << endl;
}
} | # 1127, 2024-11-02 10:40:11, -----PPPPP-------------- (20%)
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
using namespace std;
int main() {
int n;
string ch;
cin >> n >> ch;
vector<pair<float, float>> num;
float xi, yi;
for (int i = 0; i < n; ++i) {
cin >> xi >> yi;
num.push_back({xi,yi});
}
float m1 = 0;
for (int i = 0; i < n; ++i) {
m1 += num[i].first * num[i].second;
}
m1 *= n;
float m2 = 0;
for (int i = 0; i < n; ++i) {
m2 += num[i].first;
}
float m3 = 0;
for (int i = 0; i < n; ++i) {
m3 += num[i].second;
}
float up = m1 - (m2 * m3);
float m4 = 0;
for (int i = 0; i < n; ++i) {
m4 += pow((num[i].first),2);
}
m4 *= n;
float m5;
for (int i = 0; i < n; ++i) {
m5 += num[i].second;
}
m5 = m5 * m5;
float down = m4 - m5;
float m = round((up/down)*1e3)/1e3;
float n1 = 0;
for (int i = 0; i < n; ++i) {
n1 += num[i].second;
}
float n2 = 0;
for (int i = 0;i < n; ++i) {
n2 += num[i].first;
}
n2 *= m;
float b = (n1 - n2) / n;
if (ch == "mb") {
cout << m << endl;
cout << b << endl;
}
else if (ch == "func") {
cout << "y = " << m << "x " << ((b>0) ? "+ " : "") << b << endl;
}
} | # 1128, 2024-11-02 10:42:41, -----PPPPP-----PP----P-- (33%)
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
using namespace std;
int main() {
int n;
string ch;
cin >> n >> ch;
vector<pair<float, float>> num;
float xi, yi;
for (int i = 0; i < n; ++i) {
cin >> xi >> yi;
num.push_back({xi,yi});
}
float m1 = 0;
for (int i = 0; i < n; ++i) {
m1 += num[i].first * num[i].second;
}
m1 *= n;
float m2 = 0;
for (int i = 0; i < n; ++i) {
m2 += num[i].first;
}
float m3 = 0;
for (int i = 0; i < n; ++i) {
m3 += num[i].second;
}
float up = m1 - (m2 * m3);
float m4 = 0;
for (int i = 0; i < n; ++i) {
m4 += pow((num[i].first),2);
}
m4 *= n;
float m5;
for (int i = 0; i < n; ++i) {
m5 += num[i].second;
}
m5 = m5 * m5;
float down = m4 - m5;
float m = round((up/down)*1e3)/1e3;
float n1 = 0;
for (int i = 0; i < n; ++i) {
n1 += num[i].second;
}
float n2 = 0;
for (int i = 0;i < n; ++i) {
n2 += num[i].first;
}
n2 *= m;
float b = (n1 - n2) / n;
if (ch == "mb") {
cout << m << endl;
cout << b << endl;
}
else if (ch == "func") {
if (m != 0) {
cout << "y = " << m << "x " << ((b>0) ? "+ " : "") << b << endl;
}
else if (m == 0) {
cout << "y = " << b << endl;
}
}
} | # 1129, 2024-11-02 10:44:20, -----PPPPP-----PP----P-- (33%)
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
using namespace std;
int main() {
int n;
string ch;
cin >> n >> ch;
vector<pair<float, float>> num;
float xi, yi;
for (int i = 0; i < n; ++i) {
cin >> xi >> yi;
num.push_back({xi,yi});
}
float m1 = 0;
for (int i = 0; i < n; ++i) {
m1 += num[i].first * num[i].second;
}
m1 *= n;
float m2 = 0;
for (int i = 0; i < n; ++i) {
m2 += num[i].first;
}
float m3 = 0;
for (int i = 0; i < n; ++i) {
m3 += num[i].second;
}
float up = m1 - (m2 * m3);
float m4 = 0;
for (int i = 0; i < n; ++i) {
m4 += pow((num[i].first),2);
}
m4 *= n;
float m5;
for (int i = 0; i < n; ++i) {
m5 += num[i].second;
}
m5 = m5 * m5;
float down = m4 - m5;
float m = round((up/down)*1e3)/1e3;
float n1 = 0;
for (int i = 0; i < n; ++i) {
n1 += num[i].second;
}
float n2 = 0;
for (int i = 0;i < n; ++i) {
n2 += num[i].first;
}
n2 *= m;
float b = (n1 - n2) / n;
if (ch == "mb") {
cout << m << endl;
cout << b << endl;
}
else if (ch == "func") {
if (m != 0 && m != 1) {
cout << "y = " << m << "x " << ((b>0) ? "+ " : "") << b << endl;
}
else if (m == 0) {
cout << "y = " << b << endl;
}
else if (m == 1) {
cout << "y = " << "x " << ((b>0) ? "+ " : "") << b << endl;
}
}
} | # 1130, 2024-11-02 10:47:50, -----PPPPP-----PP----P-- (33%)
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
using namespace std;
int main() {
int n;
string ch;
cin >> n >> ch;
vector<pair<float, float>> num;
float xi, yi;
for (int i = 0; i < n; ++i) {
cin >> xi >> yi;
num.push_back({xi,yi});
}
float m1 = 0;
for (int i = 0; i < n; ++i) {
m1 += num[i].first * num[i].second;
}
m1 *= n;
float m2 = 0;
for (int i = 0; i < n; ++i) {
m2 += num[i].first;
}
float m3 = 0;
for (int i = 0; i < n; ++i) {
m3 += num[i].second;
}
float up = m1 - (m2 * m3);
float m4 = 0;
for (int i = 0; i < n; ++i) {
m4 += pow((num[i].first),2);
}
m4 *= n;
float m5;
for (int i = 0; i < n; ++i) {
m5 += num[i].second;
}
m5 = m5 * m5;
float down = m4 - m5;
float m = round((up/down)*1e3)/1e3;
float n1 = 0;
for (int i = 0; i < n; ++i) {
n1 += num[i].second;
}
float n2 = 0;
for (int i = 0;i < n; ++i) {
n2 += num[i].first;
}
n2 *= m;
float b = (n1 - n2) / n;
if (ch == "mb") {
cout << m << endl;
cout << b << endl;
}
else if (ch == "func") {
if (m != 0 && m != 1) {
cout << "y = " << m << "x " << ((b>0) ? "+ " : "") << b << endl;
}
else if (m == 0) {
cout << "y = " << b << endl;
}
else if (m == 1) {
cout << "y = " << "x " << ((b>0) ? "+ " : "") << b << endl;
}
else if (m == -1) {
cout << "y = -x " << ((b>0) ? "+ " : "") << b << endl;
}
}
} | # 1131, 2024-11-02 11:33:42, -----PPPPP-----PP----P-- (33%)
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
using namespace std;
int main() {
int n;
string ch;
cin >> n >> ch;
vector<pair<float, float>> num;
float xi, yi;
for (int i = 0; i < n; ++i) {
cin >> xi >> yi;
num.push_back({xi,yi});
}
float m1 = 0;
for (int i = 0; i < n; ++i) {
m1 += num[i].first * num[i].second;
}
m1 *= n;
float m2 = 0;
for (int i = 0; i < n; ++i) {
m2 += num[i].first;
}
float m3 = 0;
for (int i = 0; i < n; ++i) {
m3 += num[i].second;
}
float up = m1 - (m2 * m3);
float m4 = 0;
for (int i = 0; i < n; ++i) {
m4 += pow((num[i].first),2);
}
m4 *= n;
float m5;
for (int i = 0; i < n; ++i) {
m5 += num[i].second;
}
m5 = m5 * m5;
float down = m4 - m5;
float m = round((up/down)*1e3)/1e3;
float n1 = 0;
for (int i = 0; i < n; ++i) {
n1 += num[i].second;
}
float n2 = 0;
for (int i = 0;i < n; ++i) {
n2 += num[i].first;
}
n2 *= m;
float b = (n1 - n2) / n;
if (ch == "mb") {
cout << m << endl;
cout << b << endl;
}
else if (ch == "func") {
if (m != 0 && m != 1) {
cout << "y = " << m << "x " << ((b>0) ? "+ " : "- ") << abs(b) << endl;
}
else if (m == 0) {
cout << "y = " << b << endl;
}
else if (m == 1) {
cout << "y = " << "x " << ((b>0) ? "+ " : "- ") << abs(b) << endl;
}
else if (m == -1) {
cout << "y = -x " << ((b>0) ? "+ " : "- ") << abs(b) << endl;
}
}
} | # 1132, 2024-11-02 11:55:29, ------------------------ (0%)
#include <bits/stdc++.h>
using namespace std;
int main () {
int n;
cin >> n;
string ch;
vector<pair<float,float>> f;
float xi, yi;
for (int i = 0; i < n; ++i) {
cin >> xi >> yi;
f.push_back({xi,yi});
}
float m1 = 0;
float m2 = 0;
float m3 = 0;
float m4 = 0;
float m5 = 0;
for (int i = 0; i < n; ++i) {
m1 += f[i].first*f[i].second;
m2 += f[i].first;
m3 += f[i].second;
m4 += f[i].first*f[i].first;
m5 += f[i].first;
}
m1 = m1*n;
m4 = m4*n;
m5 = m5*m5;
float m = (m1-(m2*m3))/(m4-m5);
float b1 = 0;
float b2 = 0;
for (int i = 0; i < n; ++i) {
b1 += f[i].second;
b2 += f[i].first;
}
b2 = b2*m;
float b = (b1-b2)/n;
if (ch == "mb") {
cout << m << endl;
cout << b << endl;
}
} | # 1133, 2024-11-02 11:57:37, -----PPPPP-------------- (20%)
#include <bits/stdc++.h>
using namespace std;
int main () {
int n;
string ch;
cin >> n >> ch;
vector<pair<float,float>> f;
float xi, yi;
for (int i = 0; i < n; ++i) {
cin >> xi >> yi;
f.push_back({xi,yi});
}
float m1 = 0;
float m2 = 0;
float m3 = 0;
float m4 = 0;
float m5 = 0;
for (int i = 0; i < n; ++i) {
m1 += f[i].first*f[i].second;
m2 += f[i].first;
m3 += f[i].second;
m4 += f[i].first*f[i].first;
m5 += f[i].first;
}
m1 = m1*n;
m4 = m4*n;
m5 = m5*m5;
float m = (m1-(m2*m3))/(m4-m5);
float b1 = 0;
float b2 = 0;
for (int i = 0; i < n; ++i) {
b1 += f[i].second;
b2 += f[i].first;
}
b2 = b2*m;
float b = (b1-b2)/n;
if (ch == "mb") {
cout << m << endl;
cout << b << endl;
}
} | # 1134, 2024-11-02 12:00:12, PPPPPPPPPP-------------- (41%)
#include <bits/stdc++.h>
using namespace std;
int main () {
int n;
string ch;
cin >> n >> ch;
vector<pair<float,float>> f;
float xi, yi;
for (int i = 0; i < n; ++i) {
cin >> xi >> yi;
f.push_back({xi,yi});
}
float m1 = 0;
float m2 = 0;
float m3 = 0;
float m4 = 0;
float m5 = 0;
for (int i = 0; i < n; ++i) {
m1 += f[i].first*f[i].second;
m2 += f[i].first;
m3 += f[i].second;
m4 += f[i].first*f[i].first;
m5 += f[i].first;
}
m1 = m1*n;
m4 = m4*n;
m5 = m5*m5;
float m = (m1-(m2*m3))/(m4-m5);
float b1 = 0;
float b2 = 0;
for (int i = 0; i < n; ++i) {
b1 += f[i].second;
b2 += f[i].first;
}
b2 = b2*m;
float b = (b1-b2)/n;
if (ch == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if (ch == "func") {
}
} | # 1135, 2024-11-02 12:01:12, PPPPPPPPPP-----P-----P-- (50%)
#include <bits/stdc++.h>
using namespace std;
int main () {
int n;
string ch;
cin >> n >> ch;
vector<pair<float,float>> f;
float xi, yi;
for (int i = 0; i < n; ++i) {
cin >> xi >> yi;
f.push_back({xi,yi});
}
float m1 = 0;
float m2 = 0;
float m3 = 0;
float m4 = 0;
float m5 = 0;
for (int i = 0; i < n; ++i) {
m1 += f[i].first*f[i].second;
m2 += f[i].first;
m3 += f[i].second;
m4 += f[i].first*f[i].first;
m5 += f[i].first;
}
m1 = m1*n;
m4 = m4*n;
m5 = m5*m5;
float m = (m1-(m2*m3))/(m4-m5);
float b1 = 0;
float b2 = 0;
for (int i = 0; i < n; ++i) {
b1 += f[i].second;
b2 += f[i].first;
}
b2 = b2*m;
float b = (b1-b2)/n;
if (ch == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if (ch == "func") {
if (m == 0) {
cout << "y = " << b << endl;
}
}
} | # 1136, 2024-11-02 12:03:05, PPPPPPPPPP-----P-----P-- (50%)
#include <bits/stdc++.h>
using namespace std;
int main () {
int n;
string ch;
cin >> n >> ch;
vector<pair<float,float>> f;
float xi, yi;
for (int i = 0; i < n; ++i) {
cin >> xi >> yi;
f.push_back({xi,yi});
}
float m1 = 0;
float m2 = 0;
float m3 = 0;
float m4 = 0;
float m5 = 0;
for (int i = 0; i < n; ++i) {
m1 += f[i].first*f[i].second;
m2 += f[i].first;
m3 += f[i].second;
m4 += f[i].first*f[i].first;
m5 += f[i].first;
}
m1 = m1*n;
m4 = m4*n;
m5 = m5*m5;
float m = (m1-(m2*m3))/(m4-m5);
float b1 = 0;
float b2 = 0;
for (int i = 0; i < n; ++i) {
b1 += f[i].second;
b2 += f[i].first;
}
b2 = b2*m;
float b = (b1-b2)/n;
if (ch == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if (ch == "func") {
if (m == 0) {
cout << "y = " << b << endl;
}
else if (m == 1) {
cout << "y = x" << (b > 0 ? " + " : " - ") << abs(b) << endl;
}
}
} | # 1137, 2024-11-02 12:04:47, PPPPPPPPPP-----P-----P-- (50%)
#include <bits/stdc++.h>
using namespace std;
int main () {
int n;
string ch;
cin >> n >> ch;
vector<pair<float,float>> f;
float xi, yi;
for (int i = 0; i < n; ++i) {
cin >> xi >> yi;
f.push_back({xi,yi});
}
float m1 = 0;
float m2 = 0;
float m3 = 0;
float m4 = 0;
float m5 = 0;
for (int i = 0; i < n; ++i) {
m1 += f[i].first*f[i].second;
m2 += f[i].first;
m3 += f[i].second;
m4 += f[i].first*f[i].first;
m5 += f[i].first;
}
m1 = m1*n;
m4 = m4*n;
m5 = m5*m5;
float m = (m1-(m2*m3))/(m4-m5);
float b1 = 0;
float b2 = 0;
for (int i = 0; i < n; ++i) {
b1 += f[i].second;
b2 += f[i].first;
}
b2 = b2*m;
float b = (b1-b2)/n;
if (ch == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if (ch == "func") {
if (m == 0) {
cout << "y = " << b << endl;
}
else if (m == 1 && b != 0) {
cout << "y = x" << (b > 0 ? " + " : " - ") << abs(b) << endl;
}
else {
cout << "y = " << m << "x" << (b > 0 ? " + " : " - ") << abs(b) << endl;
}
}
} | # 1138, 2024-11-02 12:06:53, PPPPPPPPPPPPPPPP-----P-- (70%)
#include <bits/stdc++.h>
using namespace std;
int main () {
int n;
string ch;
cin >> n >> ch;
vector<pair<float,float>> f;
float xi, yi;
for (int i = 0; i < n; ++i) {
cin >> xi >> yi;
f.push_back({xi,yi});
}
float m1 = 0;
float m2 = 0;
float m3 = 0;
float m4 = 0;
float m5 = 0;
for (int i = 0; i < n; ++i) {
m1 += f[i].first*f[i].second;
m2 += f[i].first;
m3 += f[i].second;
m4 += f[i].first*f[i].first;
m5 += f[i].first;
}
m1 = m1*n;
m4 = m4*n;
m5 = m5*m5;
float m = (m1-(m2*m3))/(m4-m5);
float b1 = 0;
float b2 = 0;
for (int i = 0; i < n; ++i) {
b1 += f[i].second;
b2 += f[i].first;
}
b2 = b2*m;
float b = (b1-b2)/n;
if (ch == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if (ch == "func") {
if (m == 0) {
cout << "y = " << round(b*1e3)/1e3 << endl;
}
else if (m == 1 && b != 0) {
cout << "y = x" << (b > 0 ? " + " : " - ") << round(abs(b)*1e3)/1e3 << endl;
}
else {
cout << "y = " << round(m*1e3)/1e3 << "x" << (b > 0 ? " + " : " - ") << round(abs(b)*1e3)/1e3 << endl;
}
}
} | # 1139, 2024-11-02 12:09:23, PPPPPPPPPPPPPPPP-----P-- (70%)
#include <bits/stdc++.h>
using namespace std;
int main () {
int n;
string ch;
cin >> n >> ch;
vector<pair<float,float>> f;
float xi, yi;
for (int i = 0; i < n; ++i) {
cin >> xi >> yi;
f.push_back({xi,yi});
}
float m1 = 0;
float m2 = 0;
float m3 = 0;
float m4 = 0;
float m5 = 0;
for (int i = 0; i < n; ++i) {
m1 += f[i].first*f[i].second;
m2 += f[i].first;
m3 += f[i].second;
m4 += f[i].first*f[i].first;
m5 += f[i].first;
}
m1 = m1*n;
m4 = m4*n;
m5 = m5*m5;
float m = (m1-(m2*m3))/(m4-m5);
float b1 = 0;
float b2 = 0;
for (int i = 0; i < n; ++i) {
b1 += f[i].second;
b2 += f[i].first;
}
b2 = b2*m;
float b = (b1-b2)/n;
if (ch == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if (ch == "func") {
if (m == 0) {
cout << "y = " << round(b*1e3)/1e3 << endl;
}
else if (m == 1 && b != 0) {
cout << "y = x" << (b > 0 ? " + " : " - ") << round(abs(b)*1e3)/1e3 << endl;
}
else if (m != 0 && b == 0) {
cout << "y = " << round(m*1e3)/1e3 << "x" << endl;
}
else {
cout << "y = " << round(m*1e3)/1e3 << "x" << (b > 0 ? " + " : " - ") << round(abs(b)*1e3)/1e3 << endl;
}
}
} | # 1140, 2024-11-02 12:11:51, PPPPPPPPPPPPPPPP---P-P-- (75%)
#include <bits/stdc++.h>
using namespace std;
int main () {
int n;
string ch;
cin >> n >> ch;
vector<pair<float,float>> f;
float xi, yi;
for (int i = 0; i < n; ++i) {
cin >> xi >> yi;
f.push_back({xi,yi});
}
float m1 = 0;
float m2 = 0;
float m3 = 0;
float m4 = 0;
float m5 = 0;
for (int i = 0; i < n; ++i) {
m1 += f[i].first*f[i].second;
m2 += f[i].first;
m3 += f[i].second;
m4 += f[i].first*f[i].first;
m5 += f[i].first;
}
m1 = m1*n;
m4 = m4*n;
m5 = m5*m5;
float m = (m1-(m2*m3))/(m4-m5);
float b1 = 0;
float b2 = 0;
for (int i = 0; i < n; ++i) {
b1 += f[i].second;
b2 += f[i].first;
}
b2 = b2*m;
float b = (b1-b2)/n;
if (ch == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
else if (ch == "func") {
if (m == 0) {
cout << "y = " << round(b*1e3)/1e3 << endl;
}
else if (m == 1 && b != 0) {
cout << "y = x" << (b > 0 ? " + " : " - ") << round(abs(b)*1e3)/1e3 << endl;
}
else if (m == -1) {
if (b == 0) {
cout << "y = -x" << endl;
}
else {
cout << "y = -x " << (b > 0 ? " + " : " - ") << round(abs(b)*1e3)/1e3 << endl;
}
}
else if (m != 0 && b == 0) {
cout << "y = " << round(m*1e3)/1e3 << "x" << endl;
}
else {
cout << "y = " << round(m*1e3)/1e3 << "x" << (b > 0 ? " + " : " - ") << round(abs(b)*1e3)/1e3 << endl;
}
}
} |
# 1141, 2024-11-02 13:20:19, PPPPPPPPPP-------------- (41%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;cin >> n;
string com;cin >> com;
if(com == "mb"){
vector<pair<float,float>> lo;
float x;
float y;
for(int i = 0;i < n;i++){
cin >> x;
cin >> y;
lo.push_back(make_pair(x,y));
}
float m;
float b;
float ul = 0;
float ur = 0;
float ur1 = 0;
float ur2 = 0;
float ll = 0;
float lr = 0;
for(int i = 0;i < n;i++){
ul += lo[i].first*lo[i].second;
}
ul *= n;
for(int i = 0;i < n;i++){
ur1 += lo[i].first;
}
for(int i = 0;i < n;i++){
ur2 += lo[i].second;
}
ur = ur1 * ur2;
for(int i = 0;i < n;i++){
ll += pow(lo[i].first,2);
}
ll *= n;
for(int i = 0;i < n;i++){
lr += lo[i].first;
}
lr = pow(lr,2);
m = (ul-ur)/(ll-lr);
ul = 0;
ur = 0;
for(int i = 0;i < n;i++){
ul += lo[i].second;
}
for(int i = 0;i < n;i++){
ur += lo[i].first;
}
ur *= m;
b = (ul-ur)/n;
cout << round(m*1e3)/1e3 <<endl;
cout << round(b*1e3)/1e3 <<endl;
}
} | # 1142, 2024-11-02 13:26:05, PPPPPPPPPP-----P-------- (45%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;cin >> n;
string com;cin >> com;
vector<pair<float,float>> lo;
float x;
float y;
for(int i = 0;i < n;i++){
cin >> x;
cin >> y;
lo.push_back(make_pair(x,y));
}
float m;
float b;
float ul = 0;
float ur = 0;
float ur1 = 0;
float ur2 = 0;
float ll = 0;
float lr = 0;
for(int i = 0;i < n;i++){
ul += lo[i].first*lo[i].second;
}
ul *= n;
for(int i = 0;i < n;i++){
ur1 += lo[i].first;
}
for(int i = 0;i < n;i++){
ur2 += lo[i].second;
}
ur = ur1 * ur2;
for(int i = 0;i < n;i++){
ll += pow(lo[i].first,2);
}
ll *= n;
for(int i = 0;i < n;i++){
lr += lo[i].first;
}
lr = pow(lr,2);
m = (ul-ur)/(ll-lr);
ul = 0;
ur = 0;
for(int i = 0;i < n;i++){
ul += lo[i].second;
}
for(int i = 0;i < n;i++){
ur += lo[i].first;
}
ur *= m;
b = (ul-ur)/n;
if(com == "mb"){
cout << round(m*1e3)/1e3 <<endl;
cout << round(b*1e3)/1e3 <<endl;
}
else if (com == "func"){
if(m == 0 && b == 0){
cout << "y = 0";
}
else if(m == 1){
cout << "y = x + " << b;
}
else if (m == -1){
cout << "y = -x + " << b;
}
else{
cout << "y = " << m << "x " ;
if(b < 0){
cout << "- " << -1*b;
}
else{
cout << "+ " << b;
}
}
}
} | # 1143, 2024-11-02 13:29:02, PPPPPPPPPP-----P-------- (45%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;cin >> n;
string com;cin >> com;
vector<pair<float,float>> lo;
float x;
float y;
for(int i = 0;i < n;i++){
cin >> x;
cin >> y;
lo.push_back(make_pair(x,y));
}
float m;
float b;
float ul = 0;
float ur = 0;
float ur1 = 0;
float ur2 = 0;
float ll = 0;
float lr = 0;
for(int i = 0;i < n;i++){
ul += lo[i].first*lo[i].second;
}
ul *= n;
for(int i = 0;i < n;i++){
ur1 += lo[i].first;
}
for(int i = 0;i < n;i++){
ur2 += lo[i].second;
}
ur = ur1 * ur2;
for(int i = 0;i < n;i++){
ll += pow(lo[i].first,2);
}
ll *= n;
for(int i = 0;i < n;i++){
lr += lo[i].first;
}
lr = pow(lr,2);
m = (ul-ur)/(ll-lr);
ul = 0;
ur = 0;
for(int i = 0;i < n;i++){
ul += lo[i].second;
}
for(int i = 0;i < n;i++){
ur += lo[i].first;
}
ur *= m;
b = (ul-ur)/n;
if(com == "mb"){
cout << round(m*1e3)/1e3 <<endl;
cout << round(b*1e3)/1e3 <<endl;
}
else if (com == "func"){
if(m == 0 && b == 0){
cout << "y = 0";
}
else if(m == 1){
cout << "y = x ";
if(b < 0){
cout << "- " << -1*b;
}
else{
cout << "+ " << b;
}
}
else if (m == -1){
cout << "y = -x ";
if(b < 0){
cout << "- " << -1*b;
}
else{
cout << "+ " << b;
}
}
else{
cout << "y = " << m << "x " ;
if(b < 0){
cout << "- " << -1*b;
}
else{
cout << "+ " << b;
}
}
}
} | # 1144, 2024-11-02 13:30:36, PPPPPPPPPPPPPPPP-------- (66%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;cin >> n;
string com;cin >> com;
vector<pair<float,float>> lo;
float x;
float y;
for(int i = 0;i < n;i++){
cin >> x;
cin >> y;
lo.push_back(make_pair(x,y));
}
float m;
float b;
float ul = 0;
float ur = 0;
float ur1 = 0;
float ur2 = 0;
float ll = 0;
float lr = 0;
for(int i = 0;i < n;i++){
ul += lo[i].first*lo[i].second;
}
ul *= n;
for(int i = 0;i < n;i++){
ur1 += lo[i].first;
}
for(int i = 0;i < n;i++){
ur2 += lo[i].second;
}
ur = ur1 * ur2;
for(int i = 0;i < n;i++){
ll += pow(lo[i].first,2);
}
ll *= n;
for(int i = 0;i < n;i++){
lr += lo[i].first;
}
lr = pow(lr,2);
m = (ul-ur)/(ll-lr);
ul = 0;
ur = 0;
for(int i = 0;i < n;i++){
ul += lo[i].second;
}
for(int i = 0;i < n;i++){
ur += lo[i].first;
}
ur *= m;
b = (ul-ur)/n;
if(com == "mb"){
cout << round(m*1e3)/1e3 <<endl;
cout << round(b*1e3)/1e3 <<endl;
}
else if (com == "func"){
if(m == 0 && b == 0){
cout << "y = 0";
}
else if(m == 1){
cout << "y = x ";
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
else if (m == -1){
cout << "y = -x ";
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
else{
cout << "y = " << round(m*1e3)/1e3 << "x " ;
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
}
} | # 1145, 2024-11-02 13:39:07, PPPPPPPPPPPPPPPP-----P-- (70%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;cin >> n;
string com;cin >> com;
vector<pair<float,float>> lo;
float x;
float y;
for(int i = 0;i < n;i++){
cin >> x;
cin >> y;
lo.push_back(make_pair(x,y));
}
float m;
float b;
float ul = 0;
float ur = 0;
float ur1 = 0;
float ur2 = 0;
float ll = 0;
float lr = 0;
for(int i = 0;i < n;i++){
ul += lo[i].first*lo[i].second;
}
ul *= n;
for(int i = 0;i < n;i++){
ur1 += lo[i].first;
}
for(int i = 0;i < n;i++){
ur2 += lo[i].second;
}
ur = ur1 * ur2;
for(int i = 0;i < n;i++){
ll += pow(lo[i].first,2);
}
ll *= n;
for(int i = 0;i < n;i++){
lr += lo[i].first;
}
lr = pow(lr,2);
m = (ul-ur)/(ll-lr);
ul = 0;
ur = 0;
for(int i = 0;i < n;i++){
ul += lo[i].second;
}
for(int i = 0;i < n;i++){
ur += lo[i].first;
}
ur *= m;
b = (ul-ur)/n;
if(com == "mb"){
cout << round(m*1e3)/1e3 <<endl;
cout << round(b*1e3)/1e3 <<endl;
}
else if (com == "func"){
if(m == 0 && b == 0){
cout << "y = 0";
}
else if(m == -1){
cout << "y = -x ";
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
else if(m == 0){
cout << "y = " << b;
}
else if(m == 1){
cout << "y = x ";
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
else if (m == -1){
cout << "y = -x ";
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
else{
cout << "y = " << round(m*1e3)/1e3 << "x " ;
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
}
} | # 1146, 2024-11-02 13:40:55, PPPPPPPPPPPPPPP--------- (62%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;cin >> n;
string com;cin >> com;
vector<pair<float,float>> lo;
float x;
float y;
for(int i = 0;i < n;i++){
cin >> x;
cin >> y;
lo.push_back(make_pair(x,y));
}
float m;
float b;
float ul = 0;
float ur = 0;
float ur1 = 0;
float ur2 = 0;
float ll = 0;
float lr = 0;
for(int i = 0;i < n;i++){
ul += lo[i].first*lo[i].second;
}
ul *= n;
for(int i = 0;i < n;i++){
ur1 += lo[i].first;
}
for(int i = 0;i < n;i++){
ur2 += lo[i].second;
}
ur = ur1 * ur2;
for(int i = 0;i < n;i++){
ll += pow(lo[i].first,2);
}
ll *= n;
for(int i = 0;i < n;i++){
lr += lo[i].first;
}
lr = pow(lr,2);
m = (ul-ur)/(ll-lr);
ul = 0;
ur = 0;
for(int i = 0;i < n;i++){
ul += lo[i].second;
}
for(int i = 0;i < n;i++){
ur += lo[i].first;
}
ur *= m;
b = (ul-ur)/n;
if(com == "mb"){
cout << round(m*1e3)/1e3 <<endl;
cout << round(b*1e3)/1e3 <<endl;
}
else if (com == "func"){
if(m == 0 && b == 0){
cout << "y = 0";
}
if(m == -1){
cout << "y = -x ";
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
if(m == 0){
cout << "y = " << b;
}
if(m == 1){
cout << "y = x ";
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
if (m == -1){
cout << "y = -x ";
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
else{
cout << "y = " << round(m*1e3)/1e3 << "x " ;
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
}
} | # 1147, 2024-11-02 13:42:01, PPPPPPPPPPPPPPPP-----P-- (70%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;cin >> n;
string com;cin >> com;
vector<pair<float,float>> lo;
float x;
float y;
for(int i = 0;i < n;i++){
cin >> x;
cin >> y;
lo.push_back(make_pair(x,y));
}
float m;
float b;
float ul = 0;
float ur = 0;
float ur1 = 0;
float ur2 = 0;
float ll = 0;
float lr = 0;
for(int i = 0;i < n;i++){
ul += lo[i].first*lo[i].second;
}
ul *= n;
for(int i = 0;i < n;i++){
ur1 += lo[i].first;
}
for(int i = 0;i < n;i++){
ur2 += lo[i].second;
}
ur = ur1 * ur2;
for(int i = 0;i < n;i++){
ll += pow(lo[i].first,2);
}
ll *= n;
for(int i = 0;i < n;i++){
lr += lo[i].first;
}
lr = pow(lr,2);
m = (ul-ur)/(ll-lr);
ul = 0;
ur = 0;
for(int i = 0;i < n;i++){
ul += lo[i].second;
}
for(int i = 0;i < n;i++){
ur += lo[i].first;
}
ur *= m;
b = (ul-ur)/n;
if(com == "mb"){
cout << round(m*1e3)/1e3 <<endl;
cout << round(b*1e3)/1e3 <<endl;
}
else if (com == "func"){
if(m == 0 && b == 0){
cout << "y = 0";
}
else if(m == -1){
cout << "y = -x ";
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
else if(m == 0){
cout << "y = " << b;
}
else if(m == 1){
cout << "y = x ";
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
else{
cout << "y = " << round(m*1e3)/1e3 << "x " ;
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
}
} | # 1148, 2024-11-02 15:02:09, PPPPPPPPPPPPPPPP-----P-- (70%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;cin >> n;
string com;cin >> com;
vector<pair<float,float>> lo;
float x;
float y;
for(int i = 0;i < n;i++){
cin >> x;
cin >> y;
lo.push_back(make_pair(x,y));
}
float m;
float b;
float ul = 0;
float ur = 0;
float ur1 = 0;
float ur2 = 0;
float ll = 0;
float lr = 0;
for(int i = 0;i < n;i++){
ul += lo[i].first*lo[i].second;
}
ul *= n;
ul = round(ul*1e3)/1e3;
for(int i = 0;i < n;i++){
ur1 += lo[i].first;
}
for(int i = 0;i < n;i++){
ur2 += lo[i].second;
}
ur = ur1 * ur2;
ur = round(ur*1e3)/1e3;
for(int i = 0;i < n;i++){
ll += pow(lo[i].first,2);
}
ll *= n;
ll = round(ll*1e3)/1e3;
for(int i = 0;i < n;i++){
lr += lo[i].first;
}
lr = pow(lr,2);
lr = round(lr*1e3)/1e3;
m = (ul-ur)/(ll-lr);
ul = 0;
ur = 0;
for(int i = 0;i < n;i++){
ul += lo[i].second;
}
ul = round(ul*1e3)/1e3;
for(int i = 0;i < n;i++){
ur += lo[i].first;
}
ur *= m;
ur = round(ur*1e3)/1e3;
b = (ul-ur)/n;
b = round(b*1e3)/1e3;
if(com == "mb"){
cout << round(m*1e3)/1e3 <<endl;
cout << round(b*1e3)/1e3 <<endl;
}
else if (com == "func"){
if(m == 0 && b == 0){
cout << "y = 0";
}
else if(m == -1){
cout << "y = -x ";
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
else if(m == 0){
cout << "y = " << b;
}
else if(m == 1){
cout << "y = x ";
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
else{
cout << "y = " << round(m*1e3)/1e3 << "x " ;
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
}
} | # 1149, 2024-11-02 15:05:55, PPPPPPPPPPPPPPPP--P--P-- (75%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;cin >> n;
string com;cin >> com;
vector<pair<float,float>> lo;
float x;
float y;
for(int i = 0;i < n;i++){
cin >> x;
cin >> y;
lo.push_back(make_pair(x,y));
}
float m;
float b;
float ul = 0;
float ur = 0;
float ur1 = 0;
float ur2 = 0;
float ll = 0;
float lr = 0;
for(int i = 0;i < n;i++){
ul += lo[i].first*lo[i].second;
}
ul *= n;
ul = round(ul*1e3)/1e3;
for(int i = 0;i < n;i++){
ur1 += lo[i].first;
}
for(int i = 0;i < n;i++){
ur2 += lo[i].second;
}
ur = ur1 * ur2;
ur = round(ur*1e3)/1e3;
for(int i = 0;i < n;i++){
ll += pow(lo[i].first,2);
}
ll *= n;
ll = round(ll*1e3)/1e3;
for(int i = 0;i < n;i++){
lr += lo[i].first;
}
lr = pow(lr,2);
lr = round(lr*1e3)/1e3;
m = (ul-ur)/(ll-lr);
ul = 0;
ur = 0;
for(int i = 0;i < n;i++){
ul += lo[i].second;
}
ul = round(ul*1e3)/1e3;
for(int i = 0;i < n;i++){
ur += lo[i].first;
}
ur *= m;
ur = round(ur*1e3)/1e3;
b = (ul-ur)/n;
b = round(b*1e3)/1e3;
if(com == "mb"){
cout << round(m*1e3)/1e3 <<endl;
cout << round(b*1e3)/1e3 <<endl;
}
else if (com == "func"){
if(m == 0 && b == 0){
cout << "y = 0";
}
else if(m == -1){
cout << "y = -x ";
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
else if(m == 0){
cout << "y = " << b;
}
else if(m == 1 && b == 0){
cout << "y = x";
}
else if(m == 1){
cout << "y = x ";
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
else{
cout << "y = " << round(m*1e3)/1e3 << "x " ;
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
}
} | # 1150, 2024-11-02 15:07:59, PPPPPPPPPPPPPPPP--P--P-- (75%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;cin >> n;
string com;cin >> com;
vector<pair<float,float>> lo;
float x;
float y;
for(int i = 0;i < n;i++){
cin >> x;
cin >> y;
lo.push_back(make_pair(x,y));
}
float m;
float b;
float ul = 0;
float ur = 0;
float ur1 = 0;
float ur2 = 0;
float ll = 0;
float lr = 0;
for(int i = 0;i < n;i++){
ul += lo[i].first*lo[i].second;
}
ul *= n;
ul = round(ul*1e3)/1e3;
for(int i = 0;i < n;i++){
ur1 += lo[i].first;
}
for(int i = 0;i < n;i++){
ur2 += lo[i].second;
}
ur = ur1 * ur2;
ur = round(ur*1e3)/1e3;
for(int i = 0;i < n;i++){
ll += pow(lo[i].first,2);
}
ll *= n;
ll = round(ll*1e3)/1e3;
for(int i = 0;i < n;i++){
lr += lo[i].first;
}
lr = pow(lr,2);
lr = round(lr*1e3)/1e3;
m = (ul-ur)/(ll-lr);
ul = 0;
ur = 0;
for(int i = 0;i < n;i++){
ul += lo[i].second;
}
ul = round(ul*1e3)/1e3;
for(int i = 0;i < n;i++){
ur += lo[i].first;
}
ur *= m;
ur = round(ur*1e3)/1e3;
b = (ul-ur)/n;
b = round(b*1e3)/1e3;
if(com == "mb"){
cout << round(m*1e3)/1e3 <<endl;
cout << round(b*1e3)/1e3 <<endl;
}
else if (com == "func"){
if(m == 0 && b == 0){
cout << "y = 0";
}
else if (m == -1 && b == 0){
cout << "y == -x";
}
else if(m == -1){
cout << "y = -x ";
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
else if(m == 0){
cout << "y = " << b;
}
else if(m == 1 && b == 0){
cout << "y = x";
}
else if(m == 1){
cout << "y = x ";
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
else{
cout << "y = " << round(m*1e3)/1e3 << "x " ;
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
}
} | # 1151, 2024-11-02 15:13:04, PPPPPPPPPPPPPPPP--P--P-- (75%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;cin >> n;
string com;cin >> com;
vector<pair<float,float>> lo;
float x;
float y;
for(int i = 0;i < n;i++){
cin >> x;
cin >> y;
lo.push_back(make_pair(x,y));
}
float m;
float b;
float ul = 0;
float ur = 0;
float ur1 = 0;
float ur2 = 0;
float ll = 0;
float lr = 0;
for(int i = 0;i < n;i++){
ul += lo[i].first*lo[i].second;
}
ul *= n;
ul = round(ul*1e3)/1e3;
for(int i = 0;i < n;i++){
ur1 += lo[i].first;
}
for(int i = 0;i < n;i++){
ur2 += lo[i].second;
}
ur = ur1 * ur2;
ur = round(ur*1e3)/1e3;
for(int i = 0;i < n;i++){
ll += pow(lo[i].first,2);
}
ll *= n;
ll = round(ll*1e3)/1e3;
for(int i = 0;i < n;i++){
lr += lo[i].first;
}
lr = pow(lr,2);
lr = round(lr*1e3)/1e3;
m = (ul-ur)/(ll-lr);
ul = 0;
ur = 0;
for(int i = 0;i < n;i++){
ul += lo[i].second;
}
ul = round(ul*1e3)/1e3;
for(int i = 0;i < n;i++){
ur += lo[i].first;
}
ur *= m;
ur = round(ur*1e3)/1e3;
b = (ul-ur)/n;
b = round(b*1e3)/1e3;
if(com == "mb"){
cout << round(m*1e3)/1e3 <<endl;
cout << round(b*1e3)/1e3 <<endl;
}
else if (com == "func"){
if(m == 0 && b == 0){
cout << "y = 0";
}
else if (m == -1 && b == 0){
cout << "y == -x";
}
else if(m == -1){
cout << "y = -x ";
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
else if(m == 0){
cout << "y = " << b;
}
else if(m == 1 && b == 0){
cout << "y = x";
}
else if(m == 1){
cout << "y = x ";
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
else{
cout << "y = " << round(m*1e3)/1e3 << "x " ;
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
}
} | # 1152, 2024-11-02 15:13:46, PPPPPPPPPPPPPPPP--P--P-- (75%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;cin >> n;
string com;cin >> com;
vector<pair<float,float>> lo;
float x;
float y;
for(int i = 0;i < n;i++){
cin >> x;
cin >> y;
lo.push_back(make_pair(x,y));
}
float m;
float b;
float ul = 0;
float ur = 0;
float ur1 = 0;
float ur2 = 0;
float ll = 0;
float lr = 0;
for(int i = 0;i < n;i++){
ul += lo[i].first*lo[i].second;
}
ul *= n;
ul = round(ul*1e3)/1e3;
for(int i = 0;i < n;i++){
ur1 += lo[i].first;
}
for(int i = 0;i < n;i++){
ur2 += lo[i].second;
}
ur = ur1 * ur2;
ur = round(ur*1e3)/1e3;
for(int i = 0;i < n;i++){
ll += pow(lo[i].first,2);
}
ll *= n;
ll = round(ll*1e3)/1e3;
for(int i = 0;i < n;i++){
lr += lo[i].first;
}
lr = pow(lr,2);
lr = round(lr*1e3)/1e3;
m = (ul-ur)/(ll-lr);
ul = 0;
ur = 0;
for(int i = 0;i < n;i++){
ul += lo[i].second;
}
ul = round(ul*1e3)/1e3;
for(int i = 0;i < n;i++){
ur += lo[i].first;
}
ur *= m;
ur = round(ur*1e3)/1e3;
b = (ul-ur)/n;
b = round(b*1e3)/1e3;
if(com == "mb"){
cout << round(m*1e3)/1e3 <<endl;
cout << round(b*1e3)/1e3 <<endl;
}
else if (com == "func"){
if(m == 0 && b == 0){
cout << "y = 0";
}
else if (m == -1 && b == 0){
cout << "y == -x";
}
else if(m == -1){
cout << "y = -x ";
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
else if(m == 0){
cout << "y = " << b;
}
else if(m == 1 && b == 0){
cout << "y = x";
}
else if(m == 1){
cout << "y = x ";
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
else{
cout << "y = " << round(m*1e3)/1e3 << "x " ;
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
}
} | # 1153, 2024-11-02 15:24:29, PPPPPPPPPPPPPPPP--P--P-- (75%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;cin >> n;
string com;cin >> com;
vector<pair<float,float>> lo;
float x;
float y;
for(int i = 0;i < n;i++){
cin >> x;
cin >> y;
lo.push_back(make_pair(x,y));
}
float m;
float b;
float ul = 0;
float ur = 0;
float ur1 = 0;
float ur2 = 0;
float ll = 0;
float lr = 0;
for(int i = 0;i < n;i++){
ul += lo[i].first*lo[i].second;
}
ul *= n;
ul = round(ul*1e3)/1e3;
for(int i = 0;i < n;i++){
ur1 += lo[i].first;
}
for(int i = 0;i < n;i++){
ur2 += lo[i].second;
}
ur = ur1 * ur2;
ur = round(ur*1e3)/1e3;
for(int i = 0;i < n;i++){
ll += pow(lo[i].first,2);
}
ll *= n;
ll = round(ll*1e3)/1e3;
for(int i = 0;i < n;i++){
lr += lo[i].first;
}
lr = pow(lr,2);
lr = round(lr*1e3)/1e3;
m = (ul-ur)/(ll-lr);
ul = 0;
ur = 0;
for(int i = 0;i < n;i++){
ul += lo[i].second;
}
ul = round(ul*1e3)/1e3;
for(int i = 0;i < n;i++){
ur += lo[i].first;
}
ur *= m;
ur = round(ur*1e3)/1e3;
b = (ul-ur)/n;
b = round(b*1e3)/1e3;
if(com == "mb"){
cout << round(m*1e3)/1e3 <<endl;
cout << round(b*1e3)/1e3 <<endl;
}
else if (com == "func"){
if(m == 0 && b == 0){
cout << "y = 0";
}
else if (m == -1 && b == 0){
cout << "y == -x";
}
else if(m == -1){
cout << "y = -x ";
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
else if(m == 0){
cout << "y = " << b;
}
else if(m == 1 && b == 0){
cout << "y = x";
}
else if(m == 1){
cout << "y = x ";
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
else{
cout << "y = " << round(m*1e3)/1e3 << "x " ;
if(b < 0){
cout << "- " << -1*round(b*1e3)/1e3;
}
else{
cout << "+ " << round(b*1e3)/1e3;
}
}
}
} |
# 1154, 2024-11-02 14:35:04, -----PPPPP-------------- (20%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
pair<float,float> take[1000000];
string type;
float xi,yi,keep_xiyi,keep_xi,keep_yi,keep_xi2,m=0,b=0;
cin >> n>>type;
if(type=="mb")
{
for(int j=0;j<n;j++)
{
cin >> xi >> yi;
take[j].first=xi;
take[j].second =yi;
}
/*
for(int i=0;i<n;i++){
cout << take[i].first<<endl;
}
*/
for(int i=0;i<n;i++){
keep_xiyi=(take[i].first*take[i].second)+keep_xiyi;
}
keep_xiyi=keep_xiyi*n;
for(int i=0;i<n;i++){
keep_xi=take[i].first+keep_xi;
}
for(int i=0;i<n;i++){
keep_yi=take[i].second+keep_yi;
}
for(int i=0;i<n;i++){
keep_xi2=pow(take[i].first,2)+ keep_xi2;
}
keep_xi2=keep_xi2*n;
m = (keep_xiyi-(keep_xi*keep_yi))/(keep_xi2-(pow(keep_xi,2)));
cout << m << endl;
b = (keep_yi-(m*keep_xi))/n;
cout << b;
}
else
{
}
return 0;
} | # 1155, 2024-11-02 14:37:47, Compilation error (0%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
pair<float,float> take[1000000];
string type;
float xi,yi,keep_xiyi,keep_xi,keep_yi,keep_xi2,m=0,b=0;
cin >> n>>type;
if(type=="mb")
{
for(int j=0;j<n;j++)
{
cin >> xi >> yi;
take[j].first=xi;
take[j].second =yi;
}
/*
for(int i=0;i<n;i++){
cout << take[i].first<<endl;
}
*/
for(int i=0;i<n;i++){
keep_xiyi=(take[i].first*take[i].second)+keep_xiyi;
}
keep_xiyi=keep_xiyi*n;
for(int i=0;i<n;i++){
keep_xi=take[i].first+keep_xi;
}
for(int i=0;i<n;i++){
keep_yi=take[i].second+keep_yi;
}
for(int i=0;i<n;i++){
keep_xi2=pow(take[i].first,2)+ keep_xi2;
}
keep_xi2=keep_xi2*n;
m = (keep_xiyi-(keep_xi*keep_yi))/(keep_xi2-(pow(keep_xi,2)));
cout << round(m*1e3)/1e3 << endl;
b = (keep_yi-(m*keep_xi))/n;
cout << round(b*1e3)/1e3;
}
else
{
cout << "y = "<<
}
return 0;
} | # 1156, 2024-11-02 14:38:04, PPPPPPPPPP-------------- (41%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
pair<float,float> take[1000000];
string type;
float xi,yi,keep_xiyi,keep_xi,keep_yi,keep_xi2,m=0,b=0;
cin >> n>>type;
if(type=="mb")
{
for(int j=0;j<n;j++)
{
cin >> xi >> yi;
take[j].first=xi;
take[j].second =yi;
}
/*
for(int i=0;i<n;i++){
cout << take[i].first<<endl;
}
*/
for(int i=0;i<n;i++){
keep_xiyi=(take[i].first*take[i].second)+keep_xiyi;
}
keep_xiyi=keep_xiyi*n;
for(int i=0;i<n;i++){
keep_xi=take[i].first+keep_xi;
}
for(int i=0;i<n;i++){
keep_yi=take[i].second+keep_yi;
}
for(int i=0;i<n;i++){
keep_xi2=pow(take[i].first,2)+ keep_xi2;
}
keep_xi2=keep_xi2*n;
m = (keep_xiyi-(keep_xi*keep_yi))/(keep_xi2-(pow(keep_xi,2)));
cout << round(m*1e3)/1e3 << endl;
b = (keep_yi-(m*keep_xi))/n;
cout << round(b*1e3)/1e3;
}
else
{
}
return 0;
} | # 1157, 2024-11-02 14:49:36, PPPPPPPPPPPPPPPP---P---- (70%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
pair<float,float> take[1000000];
string type;
float xi,yi,keep_xiyi,keep_xi,keep_yi,keep_xi2,m=0,b=0;
cin >> n>>type;
if(type=="mb")
{
for(int j=0;j<n;j++)
{
cin >> xi >> yi;
take[j].first=xi;
take[j].second =yi;
}
/*
for(int i=0;i<n;i++){
cout << take[i].first<<endl;
}
*/
for(int i=0;i<n;i++){
keep_xiyi=(take[i].first*take[i].second)+keep_xiyi;
}
keep_xiyi=keep_xiyi*n;
for(int i=0;i<n;i++){
keep_xi=take[i].first+keep_xi;
}
for(int i=0;i<n;i++){
keep_yi=take[i].second+keep_yi;
}
for(int i=0;i<n;i++){
keep_xi2=pow(take[i].first,2)+ keep_xi2;
}
keep_xi2=keep_xi2*n;
m = (keep_xiyi-(keep_xi*keep_yi))/(keep_xi2-(pow(keep_xi,2)));
cout << round(m*1e3)/1e3 << endl;
b = (keep_yi-(m*keep_xi))/n;
cout << round(b*1e3)/1e3;
}
else
{
for(int j=0;j<n;j++)
{
cin >> xi >> yi;
take[j].first=xi;
take[j].second =yi;
}
/*
for(int i=0;i<n;i++){
cout << take[i].first<<endl;
}
*/
for(int i=0;i<n;i++){
keep_xiyi=(take[i].first*take[i].second)+keep_xiyi;
}
keep_xiyi=keep_xiyi*n;
for(int i=0;i<n;i++){
keep_xi=take[i].first+keep_xi;
}
for(int i=0;i<n;i++){
keep_yi=take[i].second+keep_yi;
}
for(int i=0;i<n;i++){
keep_xi2=pow(take[i].first,2)+ keep_xi2;
}
keep_xi2=keep_xi2*n;
m = (keep_xiyi-(keep_xi*keep_yi))/(keep_xi2-(pow(keep_xi,2)));
b = (keep_yi-(m*keep_xi))/n;
cout << "y = ";
if(m==0){
cout << round(b*1e3)/1e3;
}
else if(m==-1){
cout <<"-x";
}
else{
cout << round(m*1e3)/1e3 << "x";
}
if(b>0){
cout << " + " <<round(b*1e3)/1e3;
}
else if(b<0){
cout << " - " <<round(b*1e3)/1e3*-1;
}
}
return 0;
} | # 1158, 2024-11-02 14:55:04, PPPPPPPPPPPP---P---P---- (58%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
pair<float,float> take[1000000];
string type;
float xi,yi,keep_xiyi,keep_xi,keep_yi,keep_xi2,m=0,b=0;
cin >> n>>type;
if(type=="mb")
{
for(int j=0;j<n;j++)
{
cin >> xi >> yi;
take[j].first=xi;
take[j].second =yi;
}
/*
for(int i=0;i<n;i++){
cout << take[i].first<<endl;
}
*/
for(int i=0;i<n;i++){
keep_xiyi=(take[i].first*take[i].second)+keep_xiyi;
}
keep_xiyi=keep_xiyi*n;
for(int i=0;i<n;i++){
keep_xi=take[i].first+keep_xi;
}
for(int i=0;i<n;i++){
keep_yi=take[i].second+keep_yi;
}
for(int i=0;i<n;i++){
keep_xi2=pow(take[i].first,2)+ keep_xi2;
}
keep_xi2=keep_xi2*n;
m = (keep_xiyi-(keep_xi*keep_yi))/(keep_xi2-(pow(keep_xi,2)));
cout << round(m*1e3)/1e3 << endl;
b = (keep_yi-(m*keep_xi))/n;
cout << round(b*1e3)/1e3;
}
else
{
for(int j=0;j<n;j++)
{
cin >> xi >> yi;
take[j].first=xi;
take[j].second =yi;
}
/*
for(int i=0;i<n;i++){
cout << take[i].first<<endl;
}
*/
for(int i=0;i<n;i++){
keep_xiyi=(take[i].first*take[i].second)+keep_xiyi;
}
keep_xiyi=keep_xiyi*n;
for(int i=0;i<n;i++){
keep_xi=take[i].first+keep_xi;
}
for(int i=0;i<n;i++){
keep_yi=take[i].second+keep_yi;
}
for(int i=0;i<n;i++){
keep_xi2=pow(take[i].first,2)+ keep_xi2;
}
keep_xi2=keep_xi2*n;
m = (keep_xiyi-(keep_xi*keep_yi))/(keep_xi2-(pow(keep_xi,2)));
b = (keep_yi-(m*keep_xi))/n;
cout << "y = ";
if(m==0){
cout << round(b*1e3)/1e3;
}
else if(m==-1){
cout <<"-x";
}
else if(m>0){
cout << round(m*1e3)/1e3 << "x";
}
if(b>0){
cout << " + " <<round(b*1e3)/1e3;
}
else if(b<0){
cout << " - " <<round(b*1e3)/1e3*-1;
}
}
return 0;
} | # 1159, 2024-11-02 14:57:51, PPPPPPPPPPPP---P--PP--P- (66%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
pair<float,float> take[1000000];
string type;
float xi,yi,keep_xiyi,keep_xi,keep_yi,keep_xi2,m=0,b=0;
cin >> n>>type;
if(type=="mb")
{
for(int j=0;j<n;j++)
{
cin >> xi >> yi;
take[j].first=xi;
take[j].second =yi;
}
/*
for(int i=0;i<n;i++){
cout << take[i].first<<endl;
}
*/
for(int i=0;i<n;i++){
keep_xiyi=(take[i].first*take[i].second)+keep_xiyi;
}
keep_xiyi=keep_xiyi*n;
for(int i=0;i<n;i++){
keep_xi=take[i].first+keep_xi;
}
for(int i=0;i<n;i++){
keep_yi=take[i].second+keep_yi;
}
for(int i=0;i<n;i++){
keep_xi2=pow(take[i].first,2)+ keep_xi2;
}
keep_xi2=keep_xi2*n;
m = (keep_xiyi-(keep_xi*keep_yi))/(keep_xi2-(pow(keep_xi,2)));
cout << round(m*1e3)/1e3 << endl;
b = (keep_yi-(m*keep_xi))/n;
cout << round(b*1e3)/1e3;
}
else
{
for(int j=0;j<n;j++)
{
cin >> xi >> yi;
take[j].first=xi;
take[j].second =yi;
}
/*
for(int i=0;i<n;i++){
cout << take[i].first<<endl;
}
*/
for(int i=0;i<n;i++){
keep_xiyi=(take[i].first*take[i].second)+keep_xiyi;
}
keep_xiyi=keep_xiyi*n;
for(int i=0;i<n;i++){
keep_xi=take[i].first+keep_xi;
}
for(int i=0;i<n;i++){
keep_yi=take[i].second+keep_yi;
}
for(int i=0;i<n;i++){
keep_xi2=pow(take[i].first,2)+ keep_xi2;
}
keep_xi2=keep_xi2*n;
m = (keep_xiyi-(keep_xi*keep_yi))/(keep_xi2-(pow(keep_xi,2)));
b = (keep_yi-(m*keep_xi))/n;
cout << "y = ";
if(m==0){
cout << round(b*1e3)/1e3;
}
else if(m==-1){
cout <<"-x";
}
else if(m==1){
cout <<"x";
}
else if(m>0){
cout << round(m*1e3)/1e3 << "x";
}
if(b>0){
cout << " + " <<round(b*1e3)/1e3;
}
else if(b<0){
cout << " - " <<round(b*1e3)/1e3*-1;
}
}
return 0;
} | # 1160, 2024-11-02 14:59:34, PPPPPPPPPP--------PP--P- (54%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
pair<float,float> take[1000000];
string type;
float xi,yi,keep_xiyi,keep_xi,keep_yi,keep_xi2,m=0,b=0;
cin >> n>>type;
if(type=="mb")
{
for(int j=0;j<n;j++)
{
cin >> xi >> yi;
take[j].first=xi;
take[j].second =yi;
}
/*
for(int i=0;i<n;i++){
cout << take[i].first<<endl;
}
*/
for(int i=0;i<n;i++){
keep_xiyi=(take[i].first*take[i].second)+keep_xiyi;
}
keep_xiyi=keep_xiyi*n;
for(int i=0;i<n;i++){
keep_xi=take[i].first+keep_xi;
}
for(int i=0;i<n;i++){
keep_yi=take[i].second+keep_yi;
}
for(int i=0;i<n;i++){
keep_xi2=pow(take[i].first,2)+ keep_xi2;
}
keep_xi2=keep_xi2*n;
m = (keep_xiyi-(keep_xi*keep_yi))/(keep_xi2-(pow(keep_xi,2)));
cout << round(m*1e3)/1e3 << endl;
b = (keep_yi-(m*keep_xi))/n;
cout << round(b*1e3)/1e3;
}
else
{
for(int j=0;j<n;j++)
{
cin >> xi >> yi;
take[j].first=xi;
take[j].second =yi;
}
/*
for(int i=0;i<n;i++){
cout << take[i].first<<endl;
}
*/
for(int i=0;i<n;i++){
keep_xiyi=(take[i].first*take[i].second)+keep_xiyi;
}
keep_xiyi=keep_xiyi*n;
for(int i=0;i<n;i++){
keep_xi=take[i].first+keep_xi;
}
for(int i=0;i<n;i++){
keep_yi=take[i].second+keep_yi;
}
for(int i=0;i<n;i++){
keep_xi2=pow(take[i].first,2)+ keep_xi2;
}
keep_xi2=keep_xi2*n;
m = (keep_xiyi-(keep_xi*keep_yi))/(keep_xi2-(pow(keep_xi,2)));
b = (keep_yi-(m*keep_xi))/n;
cout << "y =";
if(m==0){
cout << round(b*1e3)/1e3;
}
else if(m==-1){
cout <<" -x";
}
else if(m==1){
cout <<" x";
}
else if(m>0){
cout << round(m*1e3)/1e3 << " x";
}
if(b>0){
cout << " + " <<round(b*1e3)/1e3;
}
else if(b<0){
cout << " - " <<round(b*1e3)/1e3*-1;
}
}
return 0;
} | # 1161, 2024-11-02 15:27:51, Compilation error (0%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
pair<float,float> take[1000000];
string type;
float xi,yi,keep_xiyi,keep_xi,keep_yi,keep_xi2,m=0,b=0;
cin >> n>>type;
if(type=="mb")
{
for(int j=0;j<n;j++)
{
cin >> xi >> yi;
take[j].first=xi;
take[j].second =yi;
}
/*
for(int i=0;i<n;i++){
cout << take[i].first<<endl;
}
*/
for(int i=0;i<n;i++){
keep_xiyi=(take[i].first*take[i].second)+keep_xiyi;
}
keep_xiyi=keep_xiyi*n;
for(int i=0;i<n;i++){
keep_xi=take[i].first+keep_xi;
}
for(int i=0;i<n;i++){
keep_yi=take[i].second+keep_yi;
}
for(int i=0;i<n;i++){
keep_xi2=pow(take[i].first,2)+ keep_xi2;
}
keep_xi2=keep_xi2*n;
m = (keep_xiyi-(keep_xi*keep_yi))/(keep_xi2-(pow(keep_xi,2)));
cout << round(m*1e3)/1e3 << endl;
b = (keep_yi-(m*keep_xi))/n;
cout << round(b*1e3)/1e3;
}
else
{
for(int j=0;j<n;j++)
{
cin >> xi >> yi;
take[j].first=xi;
take[j].second =yi;
}
/*
for(int i=0;i<n;i++){
cout << take[i].first<<endl;
}
*/
for(int i=0;i<n;i++){
keep_xiyi=(take[i].first*take[i].second)+keep_xiyi;
}
keep_xiyi=keep_xiyi*n;
for(int i=0;i<n;i++){
keep_xi=take[i].first+keep_xi;
}
for(int i=0;i<n;i++){
keep_yi=take[i].second+keep_yi;
}
for(int i=0;i<n;i++){
keep_xi2=pow(take[i].first,2)+ keep_xi2;
}
keep_xi2=keep_xi2*n;
m = (keep_xiyi-(keep_xi*keep_yi))/(keep_xi2-(pow(keep_xi,2)));
b = (keep_yi-(m*keep_xi))/n;
cout << "y = ";
if(m>0&&b>0){
if(m==1){
cout <<"x + " <<round(b*1e3)/1e3;
}
else{
cout << round(m*1e3)/1e3 <<"x + " <<round(b*1e3)/1e3;
}
}
else if(m>0&&b<0){
cout << round(m*1e3)/1e3 <<"x - " <<round(b*1e3)/1e3*-1;
}
else if(m>0&&b==0){
cout << round(m*1e3)/1e3 <<"x";
}
else if(m<0&&b>0){
if(m==-1){
cout <<"-x + " <<round(b*1e3)/1e3;
}
else{
cout << round(m*1e3)/1e3 <<"x + " <<round(b*1e3)/1e3;
}
}
else if(m<0&&b<0){
if(m==-1){
cout <<"-x - " <<round(b*1e3)/1e3*-1;
}
else{
cout << round(m*1e3)/1e3 <<"x - " <<round(b*1e3)/1e3*-1;
}
}
else if(m==0&&b==0){
}
else if(m==0&&b>0){
cout <<round(b*1e3)/1e3;
}
else if(m==0&&b<0){
cout <<round(b*1e3)/1e3;
}
else if(m<0&&b=0){
if(m==-1){
cout <<"-x - ";
}
else{
cout << round(m*1e3)/1e3 <<"x";
}
}
}
return 0;
} | # 1162, 2024-11-02 15:28:28, PPPPPPPPPPPPPPP------P-- (66%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
pair<float,float> take[1000000];
string type;
float xi,yi,keep_xiyi,keep_xi,keep_yi,keep_xi2,m=0,b=0;
cin >> n>>type;
if(type=="mb")
{
for(int j=0;j<n;j++)
{
cin >> xi >> yi;
take[j].first=xi;
take[j].second =yi;
}
/*
for(int i=0;i<n;i++){
cout << take[i].first<<endl;
}
*/
for(int i=0;i<n;i++){
keep_xiyi=(take[i].first*take[i].second)+keep_xiyi;
}
keep_xiyi=keep_xiyi*n;
for(int i=0;i<n;i++){
keep_xi=take[i].first+keep_xi;
}
for(int i=0;i<n;i++){
keep_yi=take[i].second+keep_yi;
}
for(int i=0;i<n;i++){
keep_xi2=pow(take[i].first,2)+ keep_xi2;
}
keep_xi2=keep_xi2*n;
m = (keep_xiyi-(keep_xi*keep_yi))/(keep_xi2-(pow(keep_xi,2)));
cout << round(m*1e3)/1e3 << endl;
b = (keep_yi-(m*keep_xi))/n;
cout << round(b*1e3)/1e3;
}
else
{
for(int j=0;j<n;j++)
{
cin >> xi >> yi;
take[j].first=xi;
take[j].second =yi;
}
/*
for(int i=0;i<n;i++){
cout << take[i].first<<endl;
}
*/
for(int i=0;i<n;i++){
keep_xiyi=(take[i].first*take[i].second)+keep_xiyi;
}
keep_xiyi=keep_xiyi*n;
for(int i=0;i<n;i++){
keep_xi=take[i].first+keep_xi;
}
for(int i=0;i<n;i++){
keep_yi=take[i].second+keep_yi;
}
for(int i=0;i<n;i++){
keep_xi2=pow(take[i].first,2)+ keep_xi2;
}
keep_xi2=keep_xi2*n;
m = (keep_xiyi-(keep_xi*keep_yi))/(keep_xi2-(pow(keep_xi,2)));
b = (keep_yi-(m*keep_xi))/n;
cout << "y = ";
if(m>0&&b>0){
if(m==1){
cout <<"x + " <<round(b*1e3)/1e3;
}
else{
cout << round(m*1e3)/1e3 <<"x + " <<round(b*1e3)/1e3;
}
}
else if(m>0&&b<0){
cout << round(m*1e3)/1e3 <<"x - " <<round(b*1e3)/1e3*-1;
}
else if(m>0&&b==0){
cout << round(m*1e3)/1e3 <<"x";
}
else if(m<0&&b>0){
if(m==-1){
cout <<"-x + " <<round(b*1e3)/1e3;
}
else{
cout << round(m*1e3)/1e3 <<"x + " <<round(b*1e3)/1e3;
}
}
else if(m<0&&b<0){
if(m==-1){
cout <<"-x - " <<round(b*1e3)/1e3*-1;
}
else{
cout << round(m*1e3)/1e3 <<"x - " <<round(b*1e3)/1e3*-1;
}
}
else if(m==0&&b==0){
}
else if(m==0&&b>0){
cout <<round(b*1e3)/1e3;
}
else if(m==0&&b<0){
cout <<round(b*1e3)/1e3;
}
else if(m<0&&b==0){
if(m==-1){
cout <<"-x - ";
}
else{
cout << round(m*1e3)/1e3 <<"x";
}
}
}
return 0;
} | # 1163, 2024-11-02 15:29:20, PPPPPPPPPPPPPPP----P-P-- (70%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
pair<float,float> take[1000000];
string type;
float xi,yi,keep_xiyi,keep_xi,keep_yi,keep_xi2,m=0,b=0;
cin >> n>>type;
if(type=="mb")
{
for(int j=0;j<n;j++)
{
cin >> xi >> yi;
take[j].first=xi;
take[j].second =yi;
}
/*
for(int i=0;i<n;i++){
cout << take[i].first<<endl;
}
*/
for(int i=0;i<n;i++){
keep_xiyi=(take[i].first*take[i].second)+keep_xiyi;
}
keep_xiyi=keep_xiyi*n;
for(int i=0;i<n;i++){
keep_xi=take[i].first+keep_xi;
}
for(int i=0;i<n;i++){
keep_yi=take[i].second+keep_yi;
}
for(int i=0;i<n;i++){
keep_xi2=pow(take[i].first,2)+ keep_xi2;
}
keep_xi2=keep_xi2*n;
m = (keep_xiyi-(keep_xi*keep_yi))/(keep_xi2-(pow(keep_xi,2)));
cout << round(m*1e3)/1e3 << endl;
b = (keep_yi-(m*keep_xi))/n;
cout << round(b*1e3)/1e3;
}
else
{
for(int j=0;j<n;j++)
{
cin >> xi >> yi;
take[j].first=xi;
take[j].second =yi;
}
/*
for(int i=0;i<n;i++){
cout << take[i].first<<endl;
}
*/
for(int i=0;i<n;i++){
keep_xiyi=(take[i].first*take[i].second)+keep_xiyi;
}
keep_xiyi=keep_xiyi*n;
for(int i=0;i<n;i++){
keep_xi=take[i].first+keep_xi;
}
for(int i=0;i<n;i++){
keep_yi=take[i].second+keep_yi;
}
for(int i=0;i<n;i++){
keep_xi2=pow(take[i].first,2)+ keep_xi2;
}
keep_xi2=keep_xi2*n;
m = (keep_xiyi-(keep_xi*keep_yi))/(keep_xi2-(pow(keep_xi,2)));
b = (keep_yi-(m*keep_xi))/n;
cout << "y = ";
if(m>0&&b>0){
if(m==1){
cout <<"x + " <<round(b*1e3)/1e3;
}
else{
cout << round(m*1e3)/1e3 <<"x + " <<round(b*1e3)/1e3;
}
}
else if(m>0&&b<0){
cout << round(m*1e3)/1e3 <<"x - " <<round(b*1e3)/1e3*-1;
}
else if(m>0&&b==0){
cout << round(m*1e3)/1e3 <<"x";
}
else if(m<0&&b>0){
if(m==-1){
cout <<"-x + " <<round(b*1e3)/1e3;
}
else{
cout << round(m*1e3)/1e3 <<"x + " <<round(b*1e3)/1e3;
}
}
else if(m<0&&b<0){
if(m==-1){
cout <<"-x - " <<round(b*1e3)/1e3*-1;
}
else{
cout << round(m*1e3)/1e3 <<"x - " <<round(b*1e3)/1e3*-1;
}
}
else if(m==0&&b==0){
}
else if(m==0&&b>0){
cout <<round(b*1e3)/1e3;
}
else if(m==0&&b<0){
cout <<round(b*1e3)/1e3;
}
else if(m<0&&b==0){
if(m==-1){
cout <<"-x";
}
else{
cout << round(m*1e3)/1e3 <<"x";
}
}
}
return 0;
} | # 1164, 2024-11-02 15:29:33, PPPPPPPPPPPPPPP----P-P-- (70%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
pair<float,float> take[1000000];
string type;
float xi,yi,keep_xiyi,keep_xi,keep_yi,keep_xi2,m=0,b=0;
cin >> n>>type;
if(type=="mb")
{
for(int j=0;j<n;j++)
{
cin >> xi >> yi;
take[j].first=xi;
take[j].second =yi;
}
/*
for(int i=0;i<n;i++){
cout << take[i].first<<endl;
}
*/
for(int i=0;i<n;i++){
keep_xiyi=(take[i].first*take[i].second)+keep_xiyi;
}
keep_xiyi=keep_xiyi*n;
for(int i=0;i<n;i++){
keep_xi=take[i].first+keep_xi;
}
for(int i=0;i<n;i++){
keep_yi=take[i].second+keep_yi;
}
for(int i=0;i<n;i++){
keep_xi2=pow(take[i].first,2)+ keep_xi2;
}
keep_xi2=keep_xi2*n;
m = (keep_xiyi-(keep_xi*keep_yi))/(keep_xi2-(pow(keep_xi,2)));
cout << round(m*1e3)/1e3 << endl;
b = (keep_yi-(m*keep_xi))/n;
cout << round(b*1e3)/1e3;
}
else
{
for(int j=0;j<n;j++)
{
cin >> xi >> yi;
take[j].first=xi;
take[j].second =yi;
}
/*
for(int i=0;i<n;i++){
cout << take[i].first<<endl;
}
*/
for(int i=0;i<n;i++){
keep_xiyi=(take[i].first*take[i].second)+keep_xiyi;
}
keep_xiyi=keep_xiyi*n;
for(int i=0;i<n;i++){
keep_xi=take[i].first+keep_xi;
}
for(int i=0;i<n;i++){
keep_yi=take[i].second+keep_yi;
}
for(int i=0;i<n;i++){
keep_xi2=pow(take[i].first,2)+ keep_xi2;
}
keep_xi2=keep_xi2*n;
m = (keep_xiyi-(keep_xi*keep_yi))/(keep_xi2-(pow(keep_xi,2)));
b = (keep_yi-(m*keep_xi))/n;
cout << "y = ";
if(m>0&&b>0){
if(m==1){
cout <<"x + " <<round(b*1e3)/1e3;
}
else{
cout << round(m*1e3)/1e3 <<"x + " <<round(b*1e3)/1e3;
}
}
else if(m>0&&b<0){
cout << round(m*1e3)/1e3 <<"x - " <<round(b*1e3)/1e3*-1;
}
else if(m>0&&b==0){
cout << round(m*1e3)/1e3 <<"x";
}
else if(m<0&&b>0){
if(m==-1){
cout <<"-x + " <<round(b*1e3)/1e3;
}
else{
cout << round(m*1e3)/1e3 <<"x + " <<round(b*1e3)/1e3;
}
}
else if(m<0&&b<0){
if(m==-1){
cout <<"-x - " <<round(b*1e3)/1e3*-1;
}
else{
cout << round(m*1e3)/1e3 <<"x - " <<round(b*1e3)/1e3*-1;
}
}
else if(m==0&&b==0){
}
else if(m==0&&b>0){
cout <<round(b*1e3)/1e3;
}
else if(m==0&&b<0){
cout <<round(b*1e3)/1e3;
}
else if(m<0&&b==0){
if(m==-1){
cout <<"-x";
}
else{
cout << round(m*1e3)/1e3 <<"x";
}
}
}
return 0;
} | # 1165, 2024-11-02 15:32:08, PPPPPPPPPPPPPPP---PP-P-- (75%)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
pair<float,float> take[1000000];
string type;
float xi,yi,keep_xiyi,keep_xi,keep_yi,keep_xi2,m=0,b=0;
cin >> n>>type;
if(type=="mb")
{
for(int j=0;j<n;j++)
{
cin >> xi >> yi;
take[j].first=xi;
take[j].second =yi;
}
/*
for(int i=0;i<n;i++){
cout << take[i].first<<endl;
}
*/
for(int i=0;i<n;i++){
keep_xiyi=(take[i].first*take[i].second)+keep_xiyi;
}
keep_xiyi=keep_xiyi*n;
for(int i=0;i<n;i++){
keep_xi=take[i].first+keep_xi;
}
for(int i=0;i<n;i++){
keep_yi=take[i].second+keep_yi;
}
for(int i=0;i<n;i++){
keep_xi2=pow(take[i].first,2)+ keep_xi2;
}
keep_xi2=keep_xi2*n;
m = (keep_xiyi-(keep_xi*keep_yi))/(keep_xi2-(pow(keep_xi,2)));
cout << round(m*1e3)/1e3 << endl;
b = (keep_yi-(m*keep_xi))/n;
cout << round(b*1e3)/1e3;
}
else
{
for(int j=0;j<n;j++)
{
cin >> xi >> yi;
take[j].first=xi;
take[j].second =yi;
}
/*
for(int i=0;i<n;i++){
cout << take[i].first<<endl;
}
*/
for(int i=0;i<n;i++){
keep_xiyi=(take[i].first*take[i].second)+keep_xiyi;
}
keep_xiyi=keep_xiyi*n;
for(int i=0;i<n;i++){
keep_xi=take[i].first+keep_xi;
}
for(int i=0;i<n;i++){
keep_yi=take[i].second+keep_yi;
}
for(int i=0;i<n;i++){
keep_xi2=pow(take[i].first,2)+ keep_xi2;
}
keep_xi2=keep_xi2*n;
m = (keep_xiyi-(keep_xi*keep_yi))/(keep_xi2-(pow(keep_xi,2)));
b = (keep_yi-(m*keep_xi))/n;
cout << "y = ";
if(m>0&&b>0){
if(m==1){
cout <<"x + " <<round(b*1e3)/1e3;
}
else{
cout << round(m*1e3)/1e3 <<"x + " <<round(b*1e3)/1e3;
}
}
else if(m>0&&b<0){
cout << round(m*1e3)/1e3 <<"x - " <<round(b*1e3)/1e3*-1;
}
else if(m>0&&b==0){
if(m==1){
cout <<"x";
}
else{
cout << round(m*1e3)/1e3 <<"x";
}
}
else if(m<0&&b>0){
if(m==-1){
cout <<"-x + " <<round(b*1e3)/1e3;
}
else{
cout << round(m*1e3)/1e3 <<"x + " <<round(b*1e3)/1e3;
}
}
else if(m<0&&b<0){
if(m==-1){
cout <<"-x - " <<round(b*1e3)/1e3*-1;
}
else{
cout << round(m*1e3)/1e3 <<"x - " <<round(b*1e3)/1e3*-1;
}
}
else if(m==0&&b==0){
}
else if(m==0&&b>0){
cout <<round(b*1e3)/1e3;
}
else if(m==0&&b<0){
cout <<round(b*1e3)/1e3;
}
else if(m<0&&b==0){
if(m==-1){
cout <<"-x";
}
else{
cout << round(m*1e3)/1e3 <<"x";
}
}
}
return 0;
} |
# 1166, 2024-11-02 10:06:56, ------------------------ (0%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main()
{
int N;
vector<pair<float, float>> cordinates;
string func;
cin >> N >> func;
int N1 = N;
while (N1--)
{
float x, y;
cin >> x >> y;
cordinates.push_back({x, y});
}
float m = 0;
float b = 0;
// m
// p1
float sum1 = 0;
for (auto x : cordinates)
{
sum1 += (x.first * x.second);
}
// p2
float sum2 = 0;
for (auto x : cordinates)
{
sum2 += x.first;
}
// p3
float sum3 = 0;
for (auto x : cordinates)
{
sum3 += x.second;
}
// p4
float sum4 = 0;
for (auto x : cordinates)
{
sum4 += x.first * x.first;
}
cout << sum1 << " " << sum2 << " " << sum3 << " " << sum4 << endl;
m = ((N * sum1) - (sum2 * sum3)) / ((N*sum4) - (sum2 * sum2));
b = (sum3-(m*sum2))/N;
if (func == "mb"){
cout << round(m*1e3)/1e3 << endl << b;
}
} | # 1167, 2024-11-02 10:07:56, -----PPPPP-------------- (20%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main()
{
int N;
vector<pair<float, float>> cordinates;
string func;
cin >> N >> func;
int N1 = N;
while (N1--)
{
float x, y;
cin >> x >> y;
cordinates.push_back({x, y});
}
float m = 0;
float b = 0;
// m
// p1
float sum1 = 0;
for (auto x : cordinates)
{
sum1 += (x.first * x.second);
}
// p2
float sum2 = 0;
for (auto x : cordinates)
{
sum2 += x.first;
}
// p3
float sum3 = 0;
for (auto x : cordinates)
{
sum3 += x.second;
}
// p4
float sum4 = 0;
for (auto x : cordinates)
{
sum4 += x.first * x.first;
}
m = ((N * sum1) - (sum2 * sum3)) / ((N*sum4) - (sum2 * sum2));
b = (sum3-(m*sum2))/N;
if (func == "mb"){
cout << round(m*1e3)/1e3 << endl << b;
}
} | # 1168, 2024-11-02 10:30:18, -----PPPPP--------PP---- (29%)
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
int main()
{
int N;
vector<pair<float, float>> cordinates;
string func;
cin >> N >> func;
int N1 = N;
while (N1--)
{
float x, y;
cin >> x >> y;
cordinates.push_back({x, y});
}
float m = 0;
float b = 0;
// m
// p1
float sum1 = 0;
for (auto x : cordinates)
{
sum1 += (x.first * x.second);
}
// p2
float sum2 = 0;
for (auto x : cordinates)
{
sum2 += x.first;
}
// p3
float sum3 = 0;
for (auto x : cordinates)
{
sum3 += x.second;
}
// p4
float sum4 = 0;
for (auto x : cordinates)
{
sum4 += x.first * x.first;
}
m = ((N * sum1) - (sum2 * sum3)) / ((N*sum4) - (sum2 * sum2));
b = (sum3-(m*sum2))/N;
if (func == "mb"){
cout << round(m*1e3)/1e3 << endl << b;
}
else{
string mx = "";
string tb = "";
cout << "y = ";
if (m!=0){
if (m==1){
cout << "x";
}
else if (m==-1){
cout << "-x";
}
else{
cout << round(m*1e3)/1e3 << "x";
}
}
cout << " ";
if (b!=0){
if (b>0){
cout << "+ " << b;
}
else{
cout << "- " << b;
}
}
//cout << "y = " << mx << " " << tb;
}
} | # 1169, 2024-11-02 10:41:39, -----PPPPPPPPPP---PP---- (50%)
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
int main()
{
int N;
vector<pair<float, float>> cordinates;
string func;
cin >> N >> func;
int N1 = N;
while (N1--)
{
float x, y;
cin >> x >> y;
cordinates.push_back({x, y});
}
float m = 0;
float b = 0;
// m
// p1
float sum1 = 0;
for (auto x : cordinates)
{
sum1 += (x.first * x.second);
}
// p2
float sum2 = 0;
for (auto x : cordinates)
{
sum2 += x.first;
}
// p3
float sum3 = 0;
for (auto x : cordinates)
{
sum3 += x.second;
}
// p4
float sum4 = 0;
for (auto x : cordinates)
{
sum4 += x.first * x.first;
}
m = ((N * sum1) - (sum2 * sum3)) / ((N*sum4) - (sum2 * sum2));
b = (sum3-(m*sum2))/N;
if (func == "mb"){
cout << round(m*1e3)/1e3 << endl << b;
}
else{
string mx = "";
string tb = "";
cout << "y = ";
if (m!=0){
if (m==1){
cout << "x";
}
else if (m==-1){
cout << "-x";
}
else{
cout << round(m*1e3)/1e3 << "x";
}
}
cout << " ";
if (b!=0){
if (b>0){
cout << "+ " << round(b*1e3)/1e3;
}
else{
cout << "- " << round(abs(b)*1e3)/1e3;
}
}
//cout << "y = " << mx << " " << tb;
}
} | # 1170, 2024-11-02 10:43:24, PPPPPPPPPPPPPPP---PP---- (70%)
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
int main()
{
int N;
vector<pair<float, float>> cordinates;
string func;
cin >> N >> func;
int N1 = N;
while (N1--)
{
float x, y;
cin >> x >> y;
cordinates.push_back({x, y});
}
float m = 0;
float b = 0;
// m
// p1
float sum1 = 0;
for (auto x : cordinates)
{
sum1 += (x.first * x.second);
}
// p2
float sum2 = 0;
for (auto x : cordinates)
{
sum2 += x.first;
}
// p3
float sum3 = 0;
for (auto x : cordinates)
{
sum3 += x.second;
}
// p4
float sum4 = 0;
for (auto x : cordinates)
{
sum4 += x.first * x.first;
}
m = ((N * sum1) - (sum2 * sum3)) / ((N*sum4) - (sum2 * sum2));
b = (sum3-(m*sum2))/N;
if (func == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else{
string mx = "";
string tb = "";
cout << "y = ";
if (m!=0){
if (m==1){
cout << "x";
}
else if (m==-1){
cout << "-x";
}
else{
cout << round(m*1e3)/1e3 << "x";
}
}
cout << " ";
if (b!=0){
if (b>0){
cout << "+ " << round(b*1e3)/1e3;
}
else{
cout << "- " << round(abs(b)*1e3)/1e3;
}
}
//cout << "y = " << mx << " " << tb;
}
} | # 1171, 2024-11-02 10:45:19, PPPPPPPPPP-----P--PP---- (54%)
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
int main()
{
int N;
vector<pair<float, float>> cordinates;
string func;
cin >> N >> func;
int N1 = N;
while (N1--)
{
float x, y;
cin >> x >> y;
cordinates.push_back({x, y});
}
float m = 0;
float b = 0;
// m
// p1
float sum1 = 0;
for (auto x : cordinates)
{
sum1 += (x.first * x.second);
}
// p2
float sum2 = 0;
for (auto x : cordinates)
{
sum2 += x.first;
}
// p3
float sum3 = 0;
for (auto x : cordinates)
{
sum3 += x.second;
}
// p4
float sum4 = 0;
for (auto x : cordinates)
{
sum4 += x.first * x.first;
}
m = ((N * sum1) - (sum2 * sum3)) / ((N*sum4) - (sum2 * sum2));
b = (sum3-(m*sum2))/N;
if (func == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else{
string mx = "";
string tb = "";
cout << "y = ";
if (m!=0){
if (m==1){
cout << "x";
}
else if (m==-1){
cout << "-x";
}
else{
cout << round(m*1e3)/1e3 << "x";
}
}
if (m==0 && b==0){
cout << "0";
}
if (b!=0){
if (b>0){
cout << "+ " << round(b*1e3)/1e3;
}
else{
cout << "- " << round(abs(b)*1e3)/1e3;
}
}
//cout << "y = " << mx << " " << tb;
}
} | # 1172, 2024-11-02 10:45:45, PPPPPPPPPPPPPPPP--PP---- (75%)
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
int main()
{
int N;
vector<pair<float, float>> cordinates;
string func;
cin >> N >> func;
int N1 = N;
while (N1--)
{
float x, y;
cin >> x >> y;
cordinates.push_back({x, y});
}
float m = 0;
float b = 0;
// m
// p1
float sum1 = 0;
for (auto x : cordinates)
{
sum1 += (x.first * x.second);
}
// p2
float sum2 = 0;
for (auto x : cordinates)
{
sum2 += x.first;
}
// p3
float sum3 = 0;
for (auto x : cordinates)
{
sum3 += x.second;
}
// p4
float sum4 = 0;
for (auto x : cordinates)
{
sum4 += x.first * x.first;
}
m = ((N * sum1) - (sum2 * sum3)) / ((N*sum4) - (sum2 * sum2));
b = (sum3-(m*sum2))/N;
if (func == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else{
string mx = "";
string tb = "";
cout << "y = ";
if (m!=0){
if (m==1){
cout << "x";
}
else if (m==-1){
cout << "-x";
}
else{
cout << round(m*1e3)/1e3 << "x";
}
}
if (m==0 && b==0){
cout << "0";
}
else{
cout << " ";
}
if (b!=0){
if (b>0){
cout << "+ " << round(b*1e3)/1e3;
}
else{
cout << "- " << round(abs(b)*1e3)/1e3;
}
}
//cout << "y = " << mx << " " << tb;
}
} |
# 1173, 2024-11-02 13:54:18, PPPPPPPPPP-------------- (41%)
#include<bits/stdc++.h>
#include <cmath>
using namespace std ;
int main(){
float m, b ;
long long int n ;
float a[100][2];
cin >> n ;
string c ;
cin >> c ;
for(long long int i=0;i<n;i++){
for(int j=0;j<2;j++){
cin >> a[i][j] ;
}
}
float x=0 ;
long long int count =0;
long long int i=0;
int j =0;
while(count<n){
x+=a[i][0]*a[i][1];
i++;
count++;
}
float numb1 = n*x ;
float y=0,z =0;
count =0;
i=0;
j =0;
while(count<n){
y+=a[i][0];
i++;
count++;
}
count =0;
i=0;
j =0;
while(count<n){
z+=a[i][1];
i++;
count++;
}
float numb2 =y*z ;
y=0,z =0;
count =0;
i=0;
j =0;
while(count<n){
y+=pow(a[i][j],2);
i++;
count++;
}
y=y*n;
count=0;
i=0;
j =0;
while(count<n){
z+=a[i][j];
i++;
count++;
}
z=pow(z,2);
float numb3 =y-z;
m = (numb1-numb2)/numb3 ;
y=0,z =0;
count =0;
i=0;
while(count<n){
z+=a[i][1];
i++;
count++;
}
count =0;
i=0;
j =0;
while(count<n){
y+=a[i][0];
i++;
count++;
}
b = (z-(m*y))/n ;
cout << round(m*1e3)/1e3 << endl ;
cout << round(b*1e3)/1e3 ;
} | # 1174, 2024-11-02 14:14:15, PPPPPPPPPP-------------- (41%)
#include<bits/stdc++.h>
#include <cmath>
using namespace std ;
int main(){
float m, b ;
long long int n ;
float a[100][2];
cin >> n ;
string c ;
cin >> c ;
for(long long int i=0;i<n;i++){
for(int j=0;j<2;j++){
cin >> a[i][j] ;
}
}
float x=0 ;
long long int count =0;
long long int i=0;
int j =0;
while(count<n){
x+=a[i][0]*a[i][1];
i++;
count++;
}
float numb1 = n*x ;
float y=0,z =0;
count =0;
i=0;
j =0;
while(count<n){
y+=a[i][0];
i++;
count++;
}
count =0;
i=0;
j =0;
while(count<n){
z+=a[i][1];
i++;
count++;
}
float numb2 =y*z ;
y=0,z =0;
count =0;
i=0;
j =0;
while(count<n){
y+=pow(a[i][j],2);
i++;
count++;
}
y=y*n;
count=0;
i=0;
j =0;
while(count<n){
z+=a[i][j];
i++;
count++;
}
z=pow(z,2);
float numb3 =y-z;
m = (numb1-numb2)/numb3 ;
y=0,z =0;
count =0;
i=0;
while(count<n){
z+=a[i][1];
i++;
count++;
}
count =0;
i=0;
j =0;
while(count<n){
y+=a[i][0];
i++;
count++;
}
b = (z-(m*y))/n ;
if(c =="mb"){
cout << round(m*1e3)/1e3 << endl ;
cout << round(b*1e3)/1e3 ;
}else {
if(m==1&&b==0){
cout << "y" << " "<< "=" << "x" ;
}
if(m==1&&b<0){
cout << "y" << " "<< "=" << "x" << " "<< "-" << " "<< round(fabs(b)*1e3)/1e3;
}
if(m==1&&b>0){
cout << "y" << " "<< "=" << "x" << " "<< "+" << " "<<round(fabs(b)*1e3)/1e3;
}
if(m==0&&b==0){
cout << "y" << " "<< "=" << "0" ;
}
if(m<0&&m!=-1&&b==0){
cout << "y" << " "<< "=" << "-"<< round(m*1e3)/1e3 << "x" ;
}
if(m<0&&m!=-1&&b<0){
cout << "y" << " "<< "=" << "-"<< round(m*1e3)/1e3 << "x" << " "<<"-" << " " <<round(fabs(b)*1e3)/1e3;
}
if(m<0&&m!=-1&&b>0){
cout << "y" << " "<< "=" << "-"<< round(m*1e3)/1e3 << "x" << " "<< "+" << " "<<round(fabs(b)*1e3)/1e3;
}
if(m>0&&m!=1&&b==0){
cout << "y" << " "<< "=" << "x" ;
}
if(m>0&&m!=1&&b>0){
cout << "y" << " "<< "=" << "x" << " " << "+" << " "<<round(fabs(b)*1e3)/1e3;;
}
if(m>0&&m!=1&&b<0){
cout << "y" << " "<< "=" << "x" << " " << "-" << " "<<round(fabs(b)*1e3)/1e3;;
}
if(m=-1&&b==0){
cout << "y" << " "<< "=" << "-"<< "x" ;
}
if(m=-1&&b>0){
cout << "y" << " "<< "=" << "-"<< "x" << " " << "+" << " "<<round(fabs(b)*1e3)/1e3;
}
if(m=-1&&b<0){
cout << "y" << " "<< "=" << "-"<< "x" << " " << "-" << " "<<round(fabs(b)*1e3)/1e3;
}
}
} | # 1175, 2024-11-02 14:15:47, PPPPPPPPPP-------------- (41%)
#include<bits/stdc++.h>
#include <cmath>
using namespace std ;
int main(){
float m, b ;
long long int n ;
float a[100][2];
cin >> n ;
string c ;
cin >> c ;
for(long long int i=0;i<n;i++){
for(int j=0;j<2;j++){
cin >> a[i][j] ;
}
}
float x=0 ;
long long int count =0;
long long int i=0;
int j =0;
while(count<n){
x+=a[i][0]*a[i][1];
i++;
count++;
}
float numb1 = n*x ;
float y=0,z =0;
count =0;
i=0;
j =0;
while(count<n){
y+=a[i][0];
i++;
count++;
}
count =0;
i=0;
j =0;
while(count<n){
z+=a[i][1];
i++;
count++;
}
float numb2 =y*z ;
y=0,z =0;
count =0;
i=0;
j =0;
while(count<n){
y+=pow(a[i][j],2);
i++;
count++;
}
y=y*n;
count=0;
i=0;
j =0;
while(count<n){
z+=a[i][j];
i++;
count++;
}
z=pow(z,2);
float numb3 =y-z;
m = (numb1-numb2)/numb3 ;
y=0,z =0;
count =0;
i=0;
while(count<n){
z+=a[i][1];
i++;
count++;
}
count =0;
i=0;
j =0;
while(count<n){
y+=a[i][0];
i++;
count++;
}
b = (z-(m*y))/n ;
if(c =="mb"){
cout << round(m*1e3)/1e3 << endl ;
cout << round(b*1e3)/1e3 ;
}
if(c == "func"){
if(m==1&&b==0){
cout << "y" << " "<< "=" << "x" ;
}
if(m==1&&b<0){
cout << "y" << " "<< "=" << "x" << " "<< "-" << " "<< round(fabs(b)*1e3)/1e3;
}
if(m==1&&b>0){
cout << "y" << " "<< "=" << "x" << " "<< "+" << " "<<round(fabs(b)*1e3)/1e3;
}
if(m==0&&b==0){
cout << "y" << " "<< "=" << "0" ;
}
if(m<0&&m!=-1&&b==0){
cout << "y" << " "<< "=" << "-"<< round(m*1e3)/1e3 << "x" ;
}
if(m<0&&m!=-1&&b<0){
cout << "y" << " "<< "=" << "-"<< round(m*1e3)/1e3 << "x" << " "<<"-" << " " <<round(fabs(b)*1e3)/1e3;
}
if(m<0&&m!=-1&&b>0){
cout << "y" << " "<< "=" << "-"<< round(m*1e3)/1e3 << "x" << " "<< "+" << " "<<round(fabs(b)*1e3)/1e3;
}
if(m>0&&m!=1&&b==0){
cout << "y" << " "<< "=" << "x" ;
}
if(m>0&&m!=1&&b>0){
cout << "y" << " "<< "=" << "x" << " " << "+" << " "<<round(fabs(b)*1e3)/1e3;;
}
if(m>0&&m!=1&&b<0){
cout << "y" << " "<< "=" << "x" << " " << "-" << " "<<round(fabs(b)*1e3)/1e3;;
}
if(m=-1&&b==0){
cout << "y" << " "<< "=" << "-"<< "x" ;
}
if(m=-1&&b>0){
cout << "y" << " "<< "=" << "-"<< "x" << " " << "+" << " "<<round(fabs(b)*1e3)/1e3;
}
if(m=-1&&b<0){
cout << "y" << " "<< "=" << "-"<< "x" << " " << "-" << " "<<round(fabs(b)*1e3)/1e3;
}
}
} | # 1176, 2024-11-02 14:21:29, PPPPPPPPPP---------P---- (45%)
#include<bits/stdc++.h>
#include <cmath>
using namespace std ;
int main(){
float m, b ;
long long int n ;
float a[100][2];
cin >> n ;
string c ;
cin >> c ;
for(long long int i=0;i<n;i++){
for(int j=0;j<2;j++){
cin >> a[i][j] ;
}
}
float x=0 ;
long long int count =0;
long long int i=0;
int j =0;
while(count<n){
x+=a[i][0]*a[i][1];
i++;
count++;
}
float numb1 = n*x ;
float y=0,z =0;
count =0;
i=0;
j =0;
while(count<n){
y+=a[i][0];
i++;
count++;
}
count =0;
i=0;
j =0;
while(count<n){
z+=a[i][1];
i++;
count++;
}
float numb2 =y*z ;
y=0,z =0;
count =0;
i=0;
j =0;
while(count<n){
y+=pow(a[i][j],2);
i++;
count++;
}
y=y*n;
count=0;
i=0;
j =0;
while(count<n){
z+=a[i][j];
i++;
count++;
}
z=pow(z,2);
float numb3 =y-z;
m = (numb1-numb2)/numb3 ;
y=0,z =0;
count =0;
i=0;
while(count<n){
z+=a[i][1];
i++;
count++;
}
count =0;
i=0;
j =0;
while(count<n){
y+=a[i][0];
i++;
count++;
}
b = (z-(m*y))/n ;
if(c =="mb"){
cout << round(m*1e3)/1e3 << endl ;
cout << round(b*1e3)/1e3 ;
}
if(c == "func"){
if(m==1&&b==0){
cout << "y" << " "<< "=" << " "<< "x" ;
}
if(m==1&&b<0){
cout << "y" << " "<< "=" << " "<< "x" << " "<< "-" << " "<< round(fabs(b)*1e3)/1e3;
}
if(m==1&&b>0){
cout << "y" << " "<< "=" << " "<< "x" << " "<< "+" << " "<<round(fabs(b)*1e3)/1e3;
}
if(m==0&&b==0){
cout << "y" << " "<< "=" << " "<< "0" ;
}
if(m<0&&m!=-1&&b==0){
cout << "y" << " "<< "=" << " "<< "-"<< round(fabs(m)*1e3)/1e3 << "x" ;
}
if(m<0&&m!=-1&&b<0){
cout << "y" << " "<< "=" << " "<< "-"<< round(fabs(m)*1e3)/1e3 << "x" << " "<<"-" << " " <<round(fabs(b)*1e3)/1e3;
}
if(m<0&&m!=-1&&b>0){
cout << "y" << " "<< "=" << " "<< "-"<< round(fabs(m)*1e3)/1e3 << "x" << " "<< "+" << " "<<round(fabs(b)*1e3)/1e3;
}
if(m>0&&m!=1&&b==0){
cout << "y" << " "<< "=" << " "<< round(m*1e3)/1e3 << "x" ;
}
if(m>0&&m!=1&&b>0){
cout << "y" << " "<< "=" << " "<< round(m*1e3)/1e3 << "x" << " " << "+" << " "<<round(fabs(b)*1e3)/1e3;;
}
if(m>0&&m!=1&&b<0){
cout << "y" << " "<< "=" << " "<< round(m*1e3)/1e3 << "x" << " " << "-" << " "<<round(fabs(b)*1e3)/1e3;;
}
if(m=-1&&b==0){
cout << "y" << " "<< "=" << " " << "-"<< "x" ;
}
if(m=-1&&b>0){
cout << "y" << " "<< "=" << "-"<< "x" << " " << "+" << " "<<round(fabs(b)*1e3)/1e3;
}
if(m=-1&&b<0){
cout << "y" << " "<< "=" << "-"<< "x" << " " << "-" << " "<<round(fabs(b)*1e3)/1e3;
}
}
} | # 1177, 2024-11-02 14:22:30, Compilation error (0%)
#include<bits/stdc++.h>
#include <cmath>
using namespace std ;
int main(){
float m, b ;
long long int n ;
float a[100][2];
cin >> n ;
string c ;
cin >> c ;
for(long long int i=0;i<n;i++){
for(int j=0;j<2;j++){
cin >> a[i][j] ;
}
}
float x=0 ;
long long int count =0;
long long int i=0;
int j =0;
while(count<n){
x+=a[i][0]*a[i][1];
i++;
count++;
}
float numb1 = n*x ;
float y=0,z =0;
count =0;
i=0;
j =0;
while(count<n){
y+=a[i][0];
i++;
count++;
}
count =0;
i=0;
j =0;
while(count<n){
z+=a[i][1];
i++;
count++;
}
float numb2 =y*z ;
y=0,z =0;
count =0;
i=0;
j =0;
while(count<n){
y+=pow(a[i][j],2);
i++;
count++;
}
y=y*n;
count=0;
i=0;
j =0;
while(count<n){
z+=a[i][j];
i++;
count++;
}
z=pow(z,2);
float numb3 =y-z;
m = (numb1-numb2)/numb3 ;
y=0,z =0;
count =0;
i=0;
while(count<n){
z+=a[i][1];
i++;
count++;
}
count =0;
i=0;
j =0;
while(count<n){
y+=a[i][0];
i++;
count++;
}
b = (z-(m*y))/n ;
if(c =="mb"){
cout << round(m*1e3)/1e3 << endl ;
cout << round(b*1e3)/1e3 ;
}
if(c == "func"){
if(m==1&&b==0){
cout << "y" << " "<< "=" << " "<< "x" ;
}
if(m==1&&b<0){
cout << "y" << " "<< "=" << " "<< "x" << " "<< "-" << " "<< round(fabs(b)*1e3)/1e3;
}
if(m==1&&b>0){
cout << "y" << " "<< "=" << " "<< "x" << " "<< "+" << " "<<round(fabs(b)*1e3)/1e3;
}
if(m==0&&b==0){
cout << "y" << " "<< "=" << " "<< "0" ;
}
if(m<0&&m!=-1&&b==0){
cout << "y" << " "<< "=" << " "<< "-"<< round(fabs(m)*1e3)/1e3 << "x" ;
}
if(m<0&&m!=-1&&b<0){
cout << "y" << " "<< "=" << " "<< "-"<< round(fabs(m)*1e3)/1e3 << "x" << " "<<"-" << " " <<round(fabs(b)*1e3)/1e3;
}
if(m<0&&m!=-1&&b>0){
cout << "y" << " "<< "=" << " "<< "-"<< round(fabs(m)*1e3)/1e3 << "x" << " "<< "+" << " "<<round(fabs(b)*1e3)/1e3;
}
if(m>0&&m!=1&&b==0){
cout << "y" << " "<< "=" << " "<< round(m*1e3)/1e3 << "x" ;
}
if(m>0&&m!=1&&b>0){
cout << "y" << " "<< "=" << " "<< round(m*1e3)/1e3 << "x" << " " << "+" << " "<<round(fabs(b)*1e3)/1e3;;
}
if(m>0&&m!=1&&b<0){
cout << "y" << " "<< "=" << " "<< round(m*1e3)/1e3 << "x" << " " << "-" << " "<<round(fabs(b)*1e3)/1e3;;
}
if(m==-1&&b==0){
cout << "y" << " "<< "=" << " " << "-"<< "x" ;
}
if(m==-1&&b>0){
cout << "y" << " "<< "=" << "-"<< "x" << " " << "+" << " "<<round(fabs(b)*1e3)/1e3;
}
if(m==-1&&b<0){
cout << "y" << " "<< "=" << "-"<< "x" << " " << "-" << " "<<round(fabs(b)*1e3)/1e3;
}
} | # 1178, 2024-11-02 14:30:12, PPPPPPPPPPPPPPPP--PP---- (75%)
#include<bits/stdc++.h>
#include <cmath>
using namespace std ;
int main(){
float m, b ;
long long int n ;
float a[100][2];
cin >> n ;
string c ;
cin >> c ;
for(long long int i=0;i<n;i++){
for(int j=0;j<2;j++){
cin >> a[i][j] ;
}
}
float x=0 ;
long long int count =0;
long long int i=0;
int j =0;
while(count<n){
x+=a[i][0]*a[i][1];
i++;
count++;
}
float numb1 = n*x ;
float y=0,z =0;
count =0,i=0,j =0;
while(count<n){
y+=a[i][0];
i++;
count++;
}
count =0,i=0,j =0;
while(count<n){
z+=a[i][1];
i++;
count++;
}
float numb2 =y*z ;
y=0,z =0 ,count =0,i=0,j =0;
while(count<n){
y+=pow(a[i][j],2);
i++;
count++;
}
y=y*n;
z =0 ,count =0 ,i=0,j=0;
while(count<n){
z+=a[i][j];
i++;
count++;
}
z=pow(z,2);
float numb3 =y-z;
m = (numb1-numb2)/numb3 ;
y=0,z =0 ,count =0 ,i=0;
while(count<n){
z+=a[i][1];
i++;
count++;
}
count =0,i=0,j =0;
while(count<n){
y+=a[i][0];
i++;
count++;
}
b = (z-(m*y))/n ;
if(c =="mb"){
cout << round(m*1e3)/1e3 << endl ;
cout << round(b*1e3)/1e3 ;
}
if(c == "func"){
if(m==1&&b==0){
cout << "y" << " "<< "=" << " "<< "x" ;
}else if(m==1&&b<0){
cout << "y" << " "<< "=" << " "<< "x" << " "<< "-" << " "<< round(fabs(b)*1e3)/1e3;
}else if(m==1&&b>0){
cout << "y" << " "<< "=" << " "<< "x" << " "<< "+" << " "<<round(fabs(b)*1e3)/1e3;
}
if(m==0&&b==0){
cout << "y" << " "<< "=" << " "<< "0" ;
}
if(m<0&&m!=-1&&b==0){
cout << "y" << " "<< "=" << " "<< "-"<< round(fabs(m)*1e3)/1e3 << "x" ;
}else if(m<0&&m!=-1&&b<0){
cout << "y" << " "<< "=" << " "<< "-"<< round(fabs(m)*1e3)/1e3 << "x" << " "<<"-" << " " <<round(fabs(b)*1e3)/1e3;
}else if(m<0&&m!=-1&&b>0){
cout << "y" << " "<< "=" << " "<< "-"<< round(fabs(m)*1e3)/1e3 << "x" << " "<< "+" << " "<<round(fabs(b)*1e3)/1e3;
}
if(m>0&&m!=1&&b==0){
cout << "y" << " "<< "=" << " "<< round(m*1e3)/1e3 << "x" ;
}else if(m>0&&m!=1&&b>0){
cout << "y" << " "<< "=" << " "<< round(m*1e3)/1e3 << "x" << " " << "+" << " "<<round(fabs(b)*1e3)/1e3;;
}else if(m>0&&m!=1&&b<0){
cout << "y" << " "<< "=" << " "<< round(m*1e3)/1e3 << "x" << " " << "-" << " "<<round(fabs(b)*1e3)/1e3;;
}
if(m==-1&&b==0){
cout << "y" << " "<< "=" << " " << "-"<< "x" ;
}else if(m==-1&&b>0){
cout << "y" << " "<< "=" << "-"<< "x" << " " << "+" << " "<<round(fabs(b)*1e3)/1e3;
}else if(m==-1&&b<0){
cout << "y" << " "<< "=" << "-"<< "x" << " " << "-" << " "<<round(fabs(b)*1e3)/1e3;
}
}
} | # 1179, 2024-11-02 14:47:34, PPPPPPPPPPPPPPP---PP---- (70%)
#include<bits/stdc++.h>
#include <cmath>
using namespace std ;
int main(){
float m, b ;
long long int n ;
float a[100][2];
cin >> n ;
string c ;
cin >> c ;
for(long long int i=0;i<n;i++){
for(int j=0;j<2;j++){
cin >> a[i][j] ;
}
}
float x=0 ;
long long int count =0;
long long int i=0;
int j =0;
while(count<n){
x+=a[i][0]*a[i][1];
i++;
count++;
}
float numb1 = n*x ;
float y=0,z =0;
count =0,i=0,j =0;
while(count<n){
y+=a[i][0];
i++;
count++;
}
count =0,i=0,j =0;
while(count<n){
z+=a[i][1];
i++;
count++;
}
float numb2 =y*z ;
y=0,z =0 ,count =0,i=0,j =0;
while(count<n){
y+=pow(a[i][j],2);
i++;
count++;
}
y=y*n;
z =0 ,count =0 ,i=0,j=0;
while(count<n){
z+=a[i][j];
i++;
count++;
}
z=pow(z,2);
float numb3 =y-z;
m = (numb1-numb2)/numb3 ;
y=0,z =0 ,count =0 ,i=0;
while(count<n){
z+=a[i][1];
i++;
count++;
}
count =0,i=0,j =0;
while(count<n){
y+=a[i][0];
i++;
count++;
}
b = (z-(m*y))/n ;
if(c =="mb"){
cout << round(m*1e3)/1e3 << endl ;
cout << round(b*1e3)/1e3 ;
}
if(c == "func"){
if(m==1&&b==0){
cout << "y" << " "<< "=" << " "<< "x" ;
}else if(m==1&&b<0){
cout << "y" << " "<< "=" << " "<< "x" << " "<< "-" << " "<< round(fabs(b)*1e3)/1e3;
}else if(m==1&&b>0){
cout << "y" << " "<< "=" << " "<< "x" << " "<< "+" << " "<<round(fabs(b)*1e3)/1e3;
}
if(m==0&&b==0){
cout << "y" << " "<< "=" << " "<< "0" ;
}
if(m<0&&m!=-1&&b==0){
cout << "y" << " "<< "=" << " "<< "-"<< round(fabs(m)*1e3)/1e3 << "x" ;
}else if(round(fabs(m)*1e3)/1e3==0){cout << "y" << " "<< "=" << " "<<"-" << round(fabs(b)*1e3)/1e3;
}else if(m<0&&m!=-1&&b<0){
cout << "y" << " "<< "=" << " "<< "-"<< round(fabs(m)*1e3)/1e3 << "x" << " "<<"-" << " " <<round(fabs(b)*1e3)/1e3;
}else if(m<0&&m!=-1&&b>0){
cout << "y" << " "<< "=" << " "<< "-"<< round(fabs(m)*1e3)/1e3 << "x" << " "<< "+" << " "<<round(fabs(b)*1e3)/1e3;
}
if(m>0&&m!=1&&b==0){
cout << "y" << " "<< "=" << " "<< round(m*1e3)/1e3 << "x" ;
}else if(round(fabs(m)*1e3)/1e3==0){cout << "y" << " "<< "=" << " " << round(fabs(b)*1e3)/1e3;}else if(m>0&&m!=1&&b>0){
cout << "y" << " "<< "=" << " "<< round(m*1e3)/1e3 << "x" << " " << "+" << " "<<round(fabs(b)*1e3)/1e3;;
}else if(m>0&&m!=1&&b<0){
cout << "y" << " "<< "=" << " "<< round(m*1e3)/1e3 << "x" << " " << "-" << " "<<round(fabs(b)*1e3)/1e3;;
}
if(m==-1&&b==0){
cout << "y" << " "<< "=" << " " << "-"<< "x" ;
}else if(m==-1&&b>0){
cout << "y" << " "<< "=" << "-"<< "x" << " " << "+" << " "<<round(fabs(b)*1e3)/1e3;
}else if(m==-1&&b<0){
cout << "y" << " "<< "=" << "-"<< "x" << " " << "-" << " "<<round(fabs(b)*1e3)/1e3;
}
}
} |
# 1180, 2024-11-02 11:11:30, -----PPPPP-------------- (20%)
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
int n; float x,y,m,b;
string name;
vector<pair<float,float>> data;
cin>>n>>name;
for(int i=0;i<n;i++){
cin>>x>>y;
data.push_back({x,y});
}
float sum =0,sx =0,sy =0,px=0,py =0;
for(int i =0;i<data.size();i++){
sum += data[i].first * data[i].second;
sx += data[i].first;
sy += data[i].second;
px += pow(data[i].first,2);
}
py = pow(sx,2);
sum = sum*n;
sum = sum -(sx*sy);
px = n *px;
m = sum /(px -py);
sum =0; sy =0;
for(int i =0;i<data.size();i++){
sum += data[i].second;
sy +=data[i].first;
}
sy = m *sy;
b = (sum-sy)/n;
cout<<m<<endl;
cout<<b;
} | # 1181, 2024-11-02 11:14:09, PPPPPPPPPP-------------- (41%)
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
int n; float x,y,m,b;
string name;
vector<pair<float,float>> data;
cin>>n>>name;
for(int i=0;i<n;i++){
cin>>x>>y;
data.push_back({x,y});
}
float sum =0,sx =0,sy =0,px=0,py =0;
for(int i =0;i<data.size();i++){
sum += data[i].first * data[i].second;
sx += data[i].first;
sy += data[i].second;
px += pow(data[i].first,2);
}
py = pow(sx,2);
sum = sum*n;
sum = sum -(sx*sy);
px = n *px;
m = sum /(px -py);
sum =0; sy =0;
for(int i =0;i<data.size();i++){
sum += data[i].second;
sy +=data[i].first;
}
sy = m *sy;
b = (sum-sy)/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(name =="mb"){
cout<<m<<endl;
cout<<b;
}
} | # 1182, 2024-11-02 11:22:27, PPPPPPPPPP------P---PP-- (54%)
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
int n; float x,y,m,b;
string name;
vector<pair<float,float>> data;
cin>>n>>name;
for(int i=0;i<n;i++){
cin>>x>>y;
data.push_back({x,y});
}
float sum =0,sx =0,sy =0,px=0,py =0;
for(int i =0;i<data.size();i++){
sum += data[i].first * data[i].second;
sx += data[i].first;
sy += data[i].second;
px += pow(data[i].first,2);
}
py = pow(sx,2);
sum = sum*n;
sum = sum -(sx*sy);
px = n *px;
m = sum /(px -py);
sum =0; sy =0;
for(int i =0;i<data.size();i++){
sum += data[i].second;
sy +=data[i].first;
}
sy = m *sy;
b = (sum-sy)/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(name =="mb"){
cout<<m<<endl;
cout<<b;
}else if(m ==-1 && b > 0){
cout<<"y = "<<"-x"<<" + "<<b;
}else if(m ==-1 && b < 0){
cout<<"y = "<<"-x"<<" - "<<b;
}else if(m == 0 && b != 0){
cout<<"y = "<<b;
}
} | # 1183, 2024-11-02 11:27:39, PPPPPPPPPPP-----P---PP-- (58%)
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
int n; float x,y,m,b;
string name;
vector<pair<float,float>> data;
cin>>n>>name;
for(int i=0;i<n;i++){
cin>>x>>y;
data.push_back({x,y});
}
float sum =0,sx =0,sy =0,px=0,py =0;
for(int i =0;i<data.size();i++){
sum += data[i].first * data[i].second;
sx += data[i].first;
sy += data[i].second;
px += pow(data[i].first,2);
}
py = pow(sx,2);
sum = sum*n;
sum = sum -(sx*sy);
px = n *px;
m = sum /(px -py);
sum =0; sy =0;
for(int i =0;i<data.size();i++){
sum += data[i].second;
sy +=data[i].first;
}
sy = m *sy;
b = (sum-sy)/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(name =="mb"){
cout<<m<<endl;
cout<<b;
}else if(m ==-1 && b > 0){
cout<<"y = "<<"-x"<<" + "<<b;
}else if(m ==-1 && b < 0){
cout<<"y = "<<"-x"<<" - "<<b;
}else if(m == 0 && b != 0){
cout<<"y = "<<b;
}else if(m >1 && b ==0){
cout<<"y = +"<<m<<"x";
}else if(m > 1 && b != 0){
cout<<"y = "<<m<<"x"<<" + "<<b;
}
} | # 1184, 2024-11-02 11:36:39, PPPPPPPPPPP----PPPPPPP-- (75%)
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
int n; float x,y,m,b;
string name;
vector<pair<float,float>> data;
cin>>n>>name;
for(int i=0;i<n;i++){
cin>>x>>y;
data.push_back({x,y});
}
float sum =0,sx =0,sy =0,px=0,py =0;
for(int i =0;i<data.size();i++){
sum += data[i].first * data[i].second;
sx += data[i].first;
sy += data[i].second;
px += pow(data[i].first,2);
}
py = pow(sx,2);
sum = sum*n;
sum = sum -(sx*sy);
px = n *px;
m = sum /(px -py);
sum =0; sy =0;
for(int i =0;i<data.size();i++){
sum += data[i].second;
sy +=data[i].first;
}
sy = m *sy;
b = (sum-sy)/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
//cout<<m<<"=="<<b;
if(name =="mb"){
cout<<m<<endl;
cout<<b;
}else if(m ==-1 && b > 0){
cout<<"y = "<<"-x"<<" + "<<b;
}else if(m ==-1 && b < 0){
cout<<"y = "<<"-x"<<" - "<<b;
}else if(m == 0 && b != 0){
cout<<"y = "<<b;
}else if(m >1 && b ==0){
cout<<"y = +"<<m<<"x";
}else if(m > 1 && b != 0){
cout<<"y = "<<m<<"x"<<" + "<<b;
}else if (m == 0 && b==0)
{
cout<<"y = 0";
}else if(m ==1 && b ==0){
cout <<"y = x";
}else if(m >=1 && b != 0){
cout<<"y = "<<"x"<<" + "<<b;
}else if( m == -1 && b ==0){
cout<<"y = -x";
}
} | # 1185, 2024-11-02 11:37:46, PPPPPPPPPPP----PPPPPPP-- (75%)
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
int n; float x,y,m,b;
string name;
vector<pair<float,float>> data;
cin>>n>>name;
for(int i=0;i<n;i++){
cin>>x>>y;
data.push_back({x,y});
}
float sum =0,sx =0,sy =0,px=0,py =0;
for(int i =0;i<data.size();i++){
sum += data[i].first * data[i].second;
sx += data[i].first;
sy += data[i].second;
px += pow(data[i].first,2);
}
py = pow(sx,2);
sum = sum*n;
sum = sum -(sx*sy);
px = n *px;
m = sum /(px -py);
sum =0; sy =0;
for(int i =0;i<data.size();i++){
sum += data[i].second;
sy +=data[i].first;
}
sy = m *sy;
b = (sum-sy)/n;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
//cout<<m<<"=="<<b;
if(name =="mb"){
cout<<m<<endl;
cout<<b;
}else if(m ==-1 && b > 0){
cout<<"y = "<<"-x"<<" + "<<b;
}else if(m ==-1 && b < 0){
cout<<"y = "<<"-x "<<b;
}else if(m == 0 && b != 0){
cout<<"y = "<<b;
}else if(m >1 && b ==0){
cout<<"y = +"<<m<<"x";
}else if(m > 1 && b != 0){
cout<<"y = "<<m<<"x"<<" + "<<b;
}else if (m == 0 && b==0)
{
cout<<"y = 0";
}else if(m ==1 && b ==0){
cout <<"y = x";
}else if(m >=1 && b != 0){
cout<<"y = "<<"x"<<" + "<<b;
}else if( m == -1 && b ==0){
cout<<"y = -x";
}
} |
# 1186, 2024-11-02 14:20:26, -----PP-PP-------------- (16%)
#include <bits/stdc++.h>
using namespace std ;
int main()
{
float n ,x ,y ,m=0 ,b=0;
string a ;
vector<pair<float,float>> xy ;
cin>> n >> a ;
for(int i=0;i<n ;i++) {
cin>> x >> y ;
xy.push_back(make_pair(x,y)) ;
}
float sum1=0 , sum2=0 , sum3=0 , sum4=0 ;
for(int i=0 ; i<=xy.size() ;i++) {
sum1 += xy[i].first * xy[i].second ;
}
for(int i=0 ; i<=xy.size() ;i++) {
sum2 += xy[i].first;
}
for(int i=0 ; i<=xy.size() ;i++) {
sum3 += xy[i].second ;
}
for(int i=0 ; i<=xy.size() ;i++) {
sum4 += xy[i].first * xy[i].first;
}
m = ((xy.size()*sum1) - (sum2*sum3)) / ((xy.size()*sum4)-pow(sum2,2)) ;
b = (sum3-(m*sum2))/xy.size() ;
if(a=="mb") {
cout << m << endl ;
cout << b ;
}
else if(a=="func") {
}
} | # 1187, 2024-11-02 14:24:19, PPPPPPP-PP-------------- (37%)
#include <bits/stdc++.h>
using namespace std ;
int main()
{
float n ,x ,y ,m=0 ,b=0;
string a ;
vector<pair<float,float>> xy ;
cin>> n >> a ;
for(int i=0;i<n ;i++) {
cin>> x >> y ;
xy.push_back(make_pair(x,y)) ;
}
float sum1=0 , sum2=0 , sum3=0 , sum4=0 ;
for(int i=0 ; i<=xy.size() ;i++) {
sum1 += xy[i].first * xy[i].second ;
}
for(int i=0 ; i<=xy.size() ;i++) {
sum2 += xy[i].first;
}
for(int i=0 ; i<=xy.size() ;i++) {
sum3 += xy[i].second ;
}
for(int i=0 ; i<=xy.size() ;i++) {
sum4 += xy[i].first * xy[i].first;
}
m = ((xy.size()*sum1) - (sum2*sum3)) / ((xy.size()*sum4)-pow(sum2,2)) ;
b = (sum3-(m*sum2))/xy.size() ;
if(a=="mb") {
cout << round(m*1e3)/1e3 << endl ;
cout << round(b*1e3)/1e3 ;
}
else if(a=="func") {
}
} | # 1188, 2024-11-02 14:33:19, PPPPPPP-PP-----P-----PP- (50%)
#include <bits/stdc++.h>
using namespace std ;
int main()
{
float n ,x ,y ,m=0 ,b=0;
string a ;
vector<pair<float,float>> xy ;
cin>> n >> a ;
for(int i=0;i<n ;i++) {
cin>> x >> y ;
xy.push_back(make_pair(x,y)) ;
}
float sum1=0 , sum2=0 , sum3=0 , sum4=0 ;
for(int i=0 ; i<=xy.size() ;i++) {
sum1 += xy[i].first * xy[i].second ;
}
for(int i=0 ; i<=xy.size() ;i++) {
sum2 += xy[i].first;
}
for(int i=0 ; i<=xy.size() ;i++) {
sum3 += xy[i].second ;
}
for(int i=0 ; i<=xy.size() ;i++) {
sum4 += xy[i].first * xy[i].first;
}
m = ((xy.size()*sum1) - (sum2*sum3)) / ((xy.size()*sum4)-pow(sum2,2)) ;
b = (sum3-(m*sum2))/xy.size() ;
if(a=="mb") {
cout << round(m*1e3)/1e3 << endl ;
cout << round(b*1e3)/1e3 ;
}
else if(a=="func") {
cout<< "y = ";
if(m==0&&b==0) {
cout<< 0 ;
}
else if(m==0) {
cout << round(b*1e3)/1e3 ;
}
else if(b==0) {
cout<< round(m*1e3)/1e3 << "x" ;
}
else if(m==1) {
cout<< "x " ;
if(b>0) {
cout<< "+ " ;
cout << round(b*1e3)/1e3 ;
}
else {
cout<< "- " ;
cout << abs(round(b*1e3)/1e3) ;
}
}
else if(m==-1) {
cout<< "-x " ;
if(b>0) {
cout<< "+ " ;
cout << round(b*1e3)/1e3 ;
}
else {
cout<< "- " ;
cout << abs(round(b*1e3)/1e3) ;
}
}
else {
cout << round(m*1e3)/1e3 << "x" ;
if(b>0) {
cout<< "+ " ;
cout << round(b*1e3)/1e3 ;
}
else {
cout<< "- " ;
cout << abs(round(b*1e3)/1e3) ;
}
}
}
} | # 1189, 2024-11-02 14:44:30, PPPPPPP-PP-----P---P-PP- (54%)
#include <bits/stdc++.h>
using namespace std ;
int main()
{
float n ,x ,y ,m=0 ,b=0;
string a ;
vector<pair<float,float>> xy ;
cin>> n >> a ;
for(int i=0;i<n ;i++) {
cin>> x >> y ;
xy.push_back(make_pair(x,y)) ;
}
float sum1=0 , sum2=0 , sum3=0 , sum4=0 ;
for(int i=0 ; i<=xy.size() ;i++) {
sum1 += xy[i].first * xy[i].second ;
}
for(int i=0 ; i<=xy.size() ;i++) {
sum2 += xy[i].first;
}
for(int i=0 ; i<=xy.size() ;i++) {
sum3 += xy[i].second ;
}
for(int i=0 ; i<=xy.size() ;i++) {
sum4 += xy[i].first * xy[i].first;
}
m = ((xy.size()*sum1) - (sum2*sum3)) / ((xy.size()*sum4)-pow(sum2,2)) ;
b = (sum3-(m*sum2))/xy.size() ;
if(a=="mb") {
cout << round(m*1e3)/1e3 << endl ;
cout << round(b*1e3)/1e3 ;
}
else if(a=="func") {
cout<< "y = ";
if(m==0&&b==0) {
cout<< 0 ;
}
else if(m==0) {
cout << round(b*1e3)/1e3 ;
}
else if(m!=1&& m!=-1 && b==0) {
cout<< round(m*1e3)/1e3 << "x" ;
}
else if(m==1) {
cout<< "x " ;
if(b>0) {
cout<< "+ " ;
cout << round(b*1e3)/1e3 ;
}
else if(b<0){
cout<< "- " ;
cout << abs(round(b*1e3)/1e3) ;
}
}
else if(m==-1) {
cout<< "-x " ;
if(b>0) {
cout<< "+ " ;
cout << round(b*1e3)/1e3 ;
}
else if(b<0){
cout<< "- " ;
cout << abs(round(b*1e3)/1e3) ;
}
}
else {
cout << round(m*1e3)/1e3 << "x" ;
if(b>0) {
cout<< "+ " ;
cout << round(b*1e3)/1e3 ;
}
else {
cout<< "- " ;
cout << abs(round(b*1e3)/1e3) ;
}
}
}
} | # 1190, 2024-11-02 14:50:53, PPPPPPP-PP-----PPPPPPPPP (75%)
#include <bits/stdc++.h>
using namespace std ;
int main()
{
float n ,x ,y ,m=0 ,b=0 ,M ,B;
string a ;
vector<pair<float,float>> xy ;
cin>> n >> a ;
for(int i=0;i<n ;i++) {
cin>> x >> y ;
xy.push_back(make_pair(x,y)) ;
}
float sum1=0 , sum2=0 , sum3=0 , sum4=0 ;
for(int i=0 ; i<=xy.size() ;i++) {
sum1 += xy[i].first * xy[i].second ;
}
for(int i=0 ; i<=xy.size() ;i++) {
sum2 += xy[i].first;
}
for(int i=0 ; i<=xy.size() ;i++) {
sum3 += xy[i].second ;
}
for(int i=0 ; i<=xy.size() ;i++) {
sum4 += xy[i].first * xy[i].first;
}
m = ((xy.size()*sum1) - (sum2*sum3)) / ((xy.size()*sum4)-pow(sum2,2)) ;
b = (sum3-(m*sum2))/xy.size() ;
M = round(m*1e3)/1e3 ;
B = round(b*1e3)/1e3 ;
if(a=="mb") {
cout << M << endl ;
cout << B ;
}
else if(a=="func") {
cout<< "y = ";
if(M==0&&B==0) {
cout<< 0 ;
}
else if(M==0) {
cout << B ;
}
else if(M!=1&& M!=-1 && M==0) {
cout<< round(m*1e3)/1e3 << "x" ;
}
else if(M==1) {
cout<< "x " ;
if(B>0) {
cout<< "+ " ;
cout << B;
}
else if(B<0){
cout<< "- " ;
cout << abs(B) ;
}
}
else if(M==-1) {
cout<< "-x " ;
if(B>0) {
cout<< "+ " ;
cout << B ;
}
else if(B<0){
cout<< "- " ;
cout << abs(B) ;
}
}
else {
cout << M << "x" ;
if(B>0) {
cout<< "+ " ;
cout << B ;
}
else if(B<0){
cout<< "- " ;
cout << abs(B) ;
}
}
}
} | # 1191, 2024-11-02 15:24:15, PPPPPPP-PP-----PPPPPPPPP (75%)
#include <bits/stdc++.h>
using namespace std ;
int main()
{
float n ,x ,y ,m=0 ,b=0 ,M ,B;
string a ;
vector<pair<float,float>> xy ;
cin>> n >> a ;
for(int i=0;i<n ;i++) {
cin>> x >> y ;
xy.push_back(make_pair(x,y)) ;
}
float sum1=0 , sum2=0 , sum3=0 , sum4=0 ;
for(int i=0 ; i<=xy.size() ;i++) {
sum1 += xy[i].first * xy[i].second ;
}
for(int i=0 ; i<=xy.size() ;i++) {
sum2 += xy[i].first;
}
for(int i=0 ; i<=xy.size() ;i++) {
sum3 += xy[i].second ;
}
for(int i=0 ; i<=xy.size() ;i++) {
sum4 += xy[i].first * xy[i].first;
}
m = ((xy.size()*sum1) - (sum2*sum3)) / ((xy.size()*sum4)-pow(sum2,2)) ;
b = (sum3-(m*sum2))/xy.size() ;
M = round(m*1e3)/1e3 ;
B = round(b*1e3)/1e3 ;
if(a=="mb") {
cout << M << endl ;
cout << B ;
}
else if(a=="func") {
cout<< "y = ";
if(M==0&&B==0) {
cout<< 0 ;
}
else if(M==0) {
cout << B ;
}
else if(M!=1&& M!=-1 && M==0) {
cout<< round(m*1e3)/1e3 << "x" ;
}
else if(M==1) {
cout<< "x " ;
if(B>0) {
cout<< "+ " ;
cout << B;
}
else if(B<0){
cout<< "- " ;
cout << abs(B) ;
}
}
else if(M==-1) {
cout<< "-x " ;
if(B>0) {
cout<< "+ " ;
cout << B ;
}
else if(B<0){
cout<< "- " ;
cout << abs(B) ;
}
}
else {
cout << M << "x" ;
if(B>0) {
cout<< "+ " ;
cout << B ;
}
else if(B<0){
cout<< "- " ;
cout << abs(B) ;
}
}
}
} |
# 1192, 2024-11-02 09:58:34, PPPPPPPPPP-------------- (41%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string op;
cin >> op;
vector<float> x = {0};
vector<float> y = {0};
for (int i = 0; i < n; i++)
{
float in1, in2;
cin >> in1 >> in2;
x.push_back(in1);
y.push_back(in2);
}
float sigxy = 0, sigx = 0, sigy = 0, sigx2 = 0;
for (int i = 1; i <= n; i++)
{
sigxy += (x[i] * y[i]);
sigx += x[i];
sigy += y[i];
sigx2 += x[i] * x[i];
}
float m, b;
m = ((n * sigxy) - (sigx * sigy)) / ((n * sigx2) - (sigx * sigx));
b = (sigy - (m * sigx)) / n;
if (op == "mb")
{
cout << round(m * 1e3) / 1e3 << endl
<< round(b * 1e3) / 1e3 << endl;
}
else if (op == "func")
{
cout << "y = " << m << "x + " << b << endl;
}
} | # 1193, 2024-11-02 10:00:16, PPPPPPPPPP-----P-----P-- (50%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string op;
cin >> op;
vector<float> x = {0};
vector<float> y = {0};
for (int i = 0; i < n; i++)
{
float in1, in2;
cin >> in1 >> in2;
x.push_back(in1);
y.push_back(in2);
}
float sigxy = 0, sigx = 0, sigy = 0, sigx2 = 0;
for (int i = 1; i <= n; i++)
{
sigxy += (x[i] * y[i]);
sigx += x[i];
sigy += y[i];
sigx2 += x[i] * x[i];
}
float m, b;
m = ((n * sigxy) - (sigx * sigy)) / ((n * sigx2) - (sigx * sigx));
b = (sigy - (m * sigx)) / n;
if (op == "mb")
{
cout << round(m * 1e3) / 1e3 << endl
<< round(b * 1e3) / 1e3 << endl;
}
else if (op == "func")
{
cout << "y = ";
if (m != 0)
cout << m << "x + ";
cout << b << endl;
}
} | # 1194, 2024-11-02 10:21:34, ------------------------ (0%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string op;
cin >> op;
vector<float> x = {0};
vector<float> y = {0};
for (int i = 0; i < n; i++)
{
float in1, in2;
cin >> in1 >> in2;
x.push_back(in1);
y.push_back(in2);
}
float sigxy = 0, sigx = 0, sigy = 0, sigx2 = 0;
for (int i = 1; i <= n; i++)
{
sigxy += (x[i] * y[i]);
sigx += x[i];
sigy += y[i];
sigx2 += x[i] * x[i];
}
float m, b;
m = ((n * sigxy) - (sigx * sigy)) / ((n * sigx2) - (sigx * sigx));
b = (sigy - (m * sigx)) / n;
cout << round(m * 1e3) / 1e3 << endl
<< round(b * 1e3) / 1e3 << endl;
if (op == "mb")
{
cout << round(m * 1e3) / 1e3 << endl
<< round(b * 1e3) / 1e3 << endl;
}
else if (op == "func")
{
cout << "y = ";
if (m == 1 && b != 0)
cout << "x ";
else if (m == -1 && b != 0)
cout << "-x ";
else if (m != 0 && b != 0)
cout << round(m * 1e3) / 1e3 << "x ";
else if (m == -1 && b == 0)
cout << "-x ";
else if (m != 0 && b == 0)
cout << "x ";
if ((m == 0 && b != 0) || b != 0)
{
if (b < 0)
cout << "- ";
if (b > 0)
cout << "+ ";
cout << abs(round(b * 1e3) / 1e3);
}
cout << endl;
}
} | # 1195, 2024-11-02 10:21:58, PPPPPPPPPPPPPPP---PP---- (70%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string op;
cin >> op;
vector<float> x = {0};
vector<float> y = {0};
for (int i = 0; i < n; i++)
{
float in1, in2;
cin >> in1 >> in2;
x.push_back(in1);
y.push_back(in2);
}
float sigxy = 0, sigx = 0, sigy = 0, sigx2 = 0;
for (int i = 1; i <= n; i++)
{
sigxy += (x[i] * y[i]);
sigx += x[i];
sigy += y[i];
sigx2 += x[i] * x[i];
}
float m, b;
m = ((n * sigxy) - (sigx * sigy)) / ((n * sigx2) - (sigx * sigx));
b = (sigy - (m * sigx)) / n;
// cout << round(m * 1e3) / 1e3 << endl
// << round(b * 1e3) / 1e3 << endl;
if (op == "mb")
{
cout << round(m * 1e3) / 1e3 << endl
<< round(b * 1e3) / 1e3 << endl;
}
else if (op == "func")
{
cout << "y = ";
if (m == 1 && b != 0)
cout << "x ";
else if (m == -1 && b != 0)
cout << "-x ";
else if (m != 0 && b != 0)
cout << round(m * 1e3) / 1e3 << "x ";
else if (m == -1 && b == 0)
cout << "-x ";
else if (m != 0 && b == 0)
cout << "x ";
if ((m == 0 && b != 0) || b != 0)
{
if (b < 0)
cout << "- ";
if (b > 0)
cout << "+ ";
cout << abs(round(b * 1e3) / 1e3);
}
cout << endl;
}
} | # 1196, 2024-11-02 10:23:41, PPPPPPPPPPPPPPPP--PP---- (75%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string op;
cin >> op;
vector<float> x = {0};
vector<float> y = {0};
for (int i = 0; i < n; i++)
{
float in1, in2;
cin >> in1 >> in2;
x.push_back(in1);
y.push_back(in2);
}
float sigxy = 0, sigx = 0, sigy = 0, sigx2 = 0;
for (int i = 1; i <= n; i++)
{
sigxy += (x[i] * y[i]);
sigx += x[i];
sigy += y[i];
sigx2 += x[i] * x[i];
}
float m, b;
m = ((n * sigxy) - (sigx * sigy)) / ((n * sigx2) - (sigx * sigx));
b = (sigy - (m * sigx)) / n;
// cout << round(m * 1e3) / 1e3 << endl
// << round(b * 1e3) / 1e3 << endl;
if (op == "mb")
{
cout << round(m * 1e3) / 1e3 << endl
<< round(b * 1e3) / 1e3 << endl;
}
else if (op == "func")
{
cout << "y = ";
if (m == 1 && b != 0)
cout << "x ";
else if (m == -1 && b != 0)
cout << "-x ";
else if (m != 0 && b != 0)
cout << round(m * 1e3) / 1e3 << "x ";
else if (m == -1 && b == 0)
cout << "-x ";
else if (m != 0 && b == 0)
cout << "x ";
if ((m == 0 && b != 0) || b != 0)
{
if (b < 0)
cout << "- ";
if (b > 0)
cout << "+ ";
cout << abs(round(b * 1e3) / 1e3);
} else if (m == 0 && b == 0) {
cout << 0;
}
cout << endl;
}
} |
# 1197, 2024-11-02 11:22:16, PPPPPPPPPP-------------- (41%)
#include <stdio.h>
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <set>
#include <cctype>
#include <cmath>
using namespace std;
void printVec(vector<string> vec)
{
for (auto i : vec)
{
cout << i << ' ';
}
cout << endl;
}
void printSet(set<string> st)
{
for (auto i : st)
{
cout << i << ' ';
}
cout << endl;
}
void printMap(vector<pair<float, float>> mp)
{
for (auto i : mp)
{
cout << '(' << i.first << " : " << i.second << ')';
}
cout << endl;
}
float M(float n, vector<pair<float, float>> vec)
{
float s1, s2, s3, s4, s5;
float sum1 = 0;
for (int i = 1; i <= vec.size(); i++)
{
int idx = i - 1;
sum1 += vec[idx].first * vec[idx].second;
}
s1 = sum1 * n;
float sum2 = 0;
for (int i = 1; i <= vec.size(); i++)
{
int idx = i - 1;
sum2 += vec[idx].first;
}
s2 = sum2;
float sum3 = 0;
for (int i = 1; i <= vec.size(); i++)
{
int idx = i - 1;
sum3 += vec[idx].second;
}
s3 = sum3;
float sum4 = 0;
for (int i = 1; i <= vec.size(); i++)
{
int idx = i - 1;
sum4 += pow(vec[idx].first, 2);
}
s4 = sum4 * n;
float sum5 = 0;
for (int i = 1; i <= vec.size(); i++)
{
int idx = i - 1;
sum5 += vec[idx].first;
}
s5 = pow(sum5, 2);
return (s1 - (s2 * s3)) / (s4 - s5);
}
float B(float m, float n, vector<pair<float, float>> vec)
{
float s1, s2;
float sum1 = 0;
for (int i = 1; i <= vec.size(); i++)
{
int idx = i - 1;
sum1 += vec[idx].second;
}
s1 = sum1;
float sum2 = 0;
for (int i = 1; i <= vec.size(); i++)
{
int idx = i - 1;
sum2 += vec[idx].first;
}
s2 = m * sum2;
return (s1 - s2) / n;
}
int main()
{
vector<pair<float, float>> vec;
string str;
float n;
cin >> n;
cin >> str;
for (int i = 0; i < n; i++)
{
/* code */
float x, y;
cin >> x >> y;
vec.push_back(pair<float, float>(x, y));
}
// printMap(vec);
if (str == "mb")
{
/* code */
float m = M(n, vec);
float b = B(m, n, vec);
cout << round(m * 1e3) / 1e3 << endl;
cout << round(b * 1e3) / 1e3 << endl;
}
} | # 1198, 2024-11-02 11:25:05, PPPPPPPPPP-------------- (41%)
#include <stdio.h>
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <set>
#include <cctype>
#include <cmath>
using namespace std;
void printVec(vector<string> vec)
{
for (auto i : vec)
{
cout << i << ' ';
}
cout << endl;
}
void printSet(set<string> st)
{
for (auto i : st)
{
cout << i << ' ';
}
cout << endl;
}
void printMap(vector<pair<float, float>> mp)
{
for (auto i : mp)
{
cout << '(' << i.first << " : " << i.second << ')';
}
cout << endl;
}
float M(float n, vector<pair<float, float>> vec)
{
float s1, s2, s3, s4, s5;
float sum1 = 0;
for (int i = 1; i <= vec.size(); i++)
{
int idx = i - 1;
sum1 += vec[idx].first * vec[idx].second;
}
s1 = sum1 * n;
float sum2 = 0;
for (int i = 1; i <= vec.size(); i++)
{
int idx = i - 1;
sum2 += vec[idx].first;
}
s2 = sum2;
float sum3 = 0;
for (int i = 1; i <= vec.size(); i++)
{
int idx = i - 1;
sum3 += vec[idx].second;
}
s3 = sum3;
float sum4 = 0;
for (int i = 1; i <= vec.size(); i++)
{
int idx = i - 1;
sum4 += pow(vec[idx].first, 2);
}
s4 = sum4 * n;
float sum5 = 0;
for (int i = 1; i <= vec.size(); i++)
{
int idx = i - 1;
sum5 += vec[idx].first;
}
s5 = pow(sum5, 2);
return (s1 - (s2 * s3)) / (s4 - s5);
}
float B(float m, float n, vector<pair<float, float>> vec)
{
float s1, s2;
float sum1 = 0;
for (int i = 1; i <= vec.size(); i++)
{
int idx = i - 1;
sum1 += vec[idx].second;
}
s1 = sum1;
float sum2 = 0;
for (int i = 1; i <= vec.size(); i++)
{
int idx = i - 1;
sum2 += vec[idx].first;
}
s2 = m * sum2;
return (s1 - s2) / n;
}
int main()
{
vector<pair<float, float>> vec;
string str;
float n;
cin >> n;
cin >> str;
for (int i = 0; i < n; i++)
{
/* code */
float x, y;
cin >> x >> y;
vec.push_back(pair<float, float>(x, y));
}
// printMap(vec);
if (str == "mb")
{
/* code */
float m = M(n, vec);
float b = B(m, n, vec);
cout << round(m * 1e3) / 1e3 << endl;
cout << round(b * 1e3) / 1e3 << endl;
}
else
{
float m = M(n, vec);
float b = B(m, n, vec);
cout << "y = " << m << "x + " << b << endl;
}
} | # 1199, 2024-11-02 11:55:29, PPPPPPPPPPPPPPPP--PP---- (75%)
#include <stdio.h>
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <set>
#include <cctype>
#include <cmath>
using namespace std;
void printVec(vector<string> vec)
{
for (auto i : vec)
{
cout << i << ' ';
}
cout << endl;
}
void printSet(set<string> st)
{
for (auto i : st)
{
cout << i << ' ';
}
cout << endl;
}
void printMap(vector<pair<float, float>> mp)
{
for (auto i : mp)
{
cout << '(' << i.first << " : " << i.second << ')';
}
cout << endl;
}
float M(float n, vector<pair<float, float>> vec)
{
float s1, s2, s3, s4, s5;
float sum1 = 0;
for (int i = 1; i <= vec.size(); i++)
{
int idx = i - 1;
sum1 += vec[idx].first * vec[idx].second;
}
s1 = sum1 * n;
float sum2 = 0;
for (int i = 1; i <= vec.size(); i++)
{
int idx = i - 1;
sum2 += vec[idx].first;
}
s2 = sum2;
float sum3 = 0;
for (int i = 1; i <= vec.size(); i++)
{
int idx = i - 1;
sum3 += vec[idx].second;
}
s3 = sum3;
float sum4 = 0;
for (int i = 1; i <= vec.size(); i++)
{
int idx = i - 1;
sum4 += pow(vec[idx].first, 2);
}
s4 = sum4 * n;
float sum5 = 0;
for (int i = 1; i <= vec.size(); i++)
{
int idx = i - 1;
sum5 += vec[idx].first;
}
s5 = pow(sum5, 2);
return (s1 - (s2 * s3)) / (s4 - s5);
}
float B(float m, float n, vector<pair<float, float>> vec)
{
float s1, s2;
float sum1 = 0;
for (int i = 1; i <= vec.size(); i++)
{
int idx = i - 1;
sum1 += vec[idx].second;
}
s1 = sum1;
float sum2 = 0;
for (int i = 1; i <= vec.size(); i++)
{
int idx = i - 1;
sum2 += vec[idx].first;
}
s2 = m * sum2;
return (s1 - s2) / n;
}
void printMX(float m)
{
if (m == 0)
{
}
else if (m == 1)
{
cout << 'x';
}
else if (m == -1)
{
cout << "-x";
}
else
{
cout << round(m * 1e3) / 1e3 << 'x';
}
}
void printB(float b)
{
if (b == 0)
{
/* code */
}
else if (b < 0)
{
/* code */
cout << " - " << abs(round(b * 1e3) / 1e3);
}
else if (b > 0)
{
cout << " + " << abs(round(b * 1e3) / 1e3);
}
}
int main()
{
vector<pair<float, float>> vec;
string str;
float n;
cin >> n;
cin >> str;
for (int i = 0; i < n; i++)
{
/* code */
float x, y;
cin >> x >> y;
vec.push_back(pair<float, float>(x, y));
}
// printMap(vec);
if (str == "mb")
{
/* code */
float m = M(n, vec);
float b = B(m, n, vec);
cout << round(m * 1e3) / 1e3 << endl;
cout << round(b * 1e3) / 1e3 << endl;
}
else
{
float m = M(n, vec);
float b = B(m, n, vec);
if (m == 0 && b == 0)
{
cout << "y = 0" << endl;
return 0;
}
else
{
cout << "y = ";
printMX(m);
printB(b);
cout << endl;
}
}
}
// cout << "y = " << m << "x + " << b << endl; | # 1200, 2024-11-02 12:11:54, PPPPPPPPPPPPPPPP--PP---- (75%)
#include <stdio.h>
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <set>
#include <cctype>
#include <cmath>
using namespace std;
void printVec(vector<string> vec)
{
for (auto i : vec)
{
cout << i << ' ';
}
cout << endl;
}
void printSet(set<string> st)
{
for (auto i : st)
{
cout << i << ' ';
}
cout << endl;
}
void printMap(vector<pair<float, float>> mp)
{
for (auto i : mp)
{
cout << '(' << i.first << " : " << i.second << ')';
}
cout << endl;
}
float M(float n, vector<pair<float, float>> vec)
{
float s1, s2, s3, s4, s5;
float sum1 = 0;
for (int i = 1; i <= vec.size(); i++)
{
int idx = i - 1;
sum1 += vec[idx].first * vec[idx].second;
}
s1 = sum1 * n;
float sum2 = 0;
for (int i = 1; i <= vec.size(); i++)
{
int idx = i - 1;
sum2 += vec[idx].first;
}
s2 = sum2;
float sum3 = 0;
for (int i = 1; i <= vec.size(); i++)
{
int idx = i - 1;
sum3 += vec[idx].second;
}
s3 = sum3;
float sum4 = 0;
for (int i = 1; i <= vec.size(); i++)
{
int idx = i - 1;
sum4 += pow(vec[idx].first, 2);
}
s4 = sum4 * n;
float sum5 = 0;
for (int i = 1; i <= vec.size(); i++)
{
int idx = i - 1;
sum5 += vec[idx].first;
}
s5 = pow(sum5, 2);
return (s1 - (s2 * s3)) / (s4 - s5);
}
float B(float m, float n, vector<pair<float, float>> vec)
{
float s1, s2;
float sum1 = 0;
for (int i = 1; i <= vec.size(); i++)
{
int idx = i - 1;
sum1 += vec[idx].second;
}
s1 = sum1;
float sum2 = 0;
for (int i = 1; i <= vec.size(); i++)
{
int idx = i - 1;
sum2 += vec[idx].first;
}
s2 = m * sum2;
return (s1 - s2) / n;
}
void printMX(float m, float b)
{
if (m == 0)
{
}
else if (m == 1)
{
cout << 'x';
}
else if (m == -1)
{
cout << "-x";
}
else if (m > 1)
{
cout << round(m * 1e3) / 1e3 << 'x';
}
else if (m < 1)
{
cout << round(m * 1e3) / 1e3 << 'x';
}
}
void printB(float b, float m)
{
if (b == 0)
{
/* code */
}
else if (b < 0)
{
/* code */
cout << " - " << abs(round(b * 1e3) / 1e3);
}
else if (b > 0)
{
cout << " + " << abs(round(b * 1e3) / 1e3);
}
}
int main()
{
vector<pair<float, float>> vec;
string str;
float n;
cin >> n;
cin >> str;
for (int i = 0; i < n; i++)
{
/* code */
float x, y;
cin >> x >> y;
vec.push_back(pair<float, float>(x, y));
}
// printMap(vec);
if (str == "mb")
{
/* code */
float m = M(n, vec);
float b = B(m, n, vec);
cout << round(m * 1e3) / 1e3 << endl;
cout << round(b * 1e3) / 1e3 << endl;
}
else
{
float m = M(n, vec);
float b = B(m, n, vec);
if (m == 0 && b == 0)
{
cout << "y = 0" << endl;
return 0;
}
else if (m == 0)
{
if (b > 0)
{
cout << "y = ";
cout << "+ " << round(abs(b) * 1e3) / 1e3 << endl;
return 0;
}
if (b < 0)
{
/* code */
cout << "y = ";
cout << "- " << round(abs(b) * 1e3) / 1e3 << endl;
return 0;
}
}
else
{
// cout << m << endl;
// cout << "h1" << endl;
cout << "y = ";
printMX(m, b);
printB(b, m);
cout << endl;
}
}
} |
# 1201, 2024-11-02 13:03:42, PPPPPPPPPPP-P----------- (50%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
int n;
string instr;
cin >> n >> instr;
// cin.ignore();
vector<float> xf;;
vector<float> yf;
for(int i=0; i<n; ++i){
float tmx, tmy;
cin >> tmx >> tmy;
xf.push_back(tmx);
yf.push_back(tmy);
}
// find m
// m first term
float term1 = 0;
for(int i=0; i<n; ++i){
term1 += xf[i]*yf[i];
}
term1 *= n;
float term2_1 = 0;
float term2_2 = 0;
for(int i=0; i<n; ++i){
term2_1 += xf[i];
term2_2 += yf[i];
}
float term2 = term2_1 * term2_2;
float term3 = 0;
for(int i=0; i<n; ++i){
term3 += pow(xf[i], 2);
}
term3 *= n;
float term4 = 0;
for(int i=0; i<n; ++i){
term4 += xf[i];
}
term4 = pow(term4, 2);
float m = (term1-term2)/(term3-term4);
float derm1 = 0;
float derm2 = 0;
for(int i=0; i<n; ++i){
derm1 += yf[i];
derm2 += xf[i];
}
derm2 *= m;
float b = (derm1-derm2)/n;
if(instr=="mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 ;
}else{
if(m==1.0){
cout << "y = " << "x + " << round(b*1e3)/1e3;
}else if(m==-1.0){
cout << "y = " << "-x + " << round(b*1e3)/1e3;
}else {
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
}
}
//bmer | # 1202, 2024-11-02 13:05:21, PPPPPPPPPPPPPPP--------- (62%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
int n;
string instr;
cin >> n >> instr;
// cin.ignore();
vector<float> xf;;
vector<float> yf;
for(int i=0; i<n; ++i){
float tmx, tmy;
cin >> tmx >> tmy;
xf.push_back(tmx);
yf.push_back(tmy);
}
// find m
// m first term
float term1 = 0;
for(int i=0; i<n; ++i){
term1 += xf[i]*yf[i];
}
term1 *= n;
float term2_1 = 0;
float term2_2 = 0;
for(int i=0; i<n; ++i){
term2_1 += xf[i];
term2_2 += yf[i];
}
float term2 = term2_1 * term2_2;
float term3 = 0;
for(int i=0; i<n; ++i){
term3 += pow(xf[i], 2);
}
term3 *= n;
float term4 = 0;
for(int i=0; i<n; ++i){
term4 += xf[i];
}
term4 = pow(term4, 2);
float m = (term1-term2)/(term3-term4);
float derm1 = 0;
float derm2 = 0;
for(int i=0; i<n; ++i){
derm1 += yf[i];
derm2 += xf[i];
}
derm2 *= m;
float b = (derm1-derm2)/n;
if(instr=="mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 ;
}else{
if(m==1.0){
cout << "y = " << "x + " << round(b*1e3)/1e3;
}else if(m==-1.0){
cout << "y = " << "-x + " << round(b*1e3)/1e3;
}else if(b<0){
cout << "y = " << round(m*1e3)/1e3 << "x - " << abs(round(b*1e3)/1e3);
}
else {
cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
}
}
}
/*
3 mb
1.0 0.0
2.0 0.0
9.4 0.0
20 mb
1.1881 1.5293
1.7655 1.1602
1.8581 1.1016
2.2834 0.8302
2.7323 0.5438
3.0490 0.3426
3.2191 0.2325
3.5325 0.0332
3.7860 -0.1221
5.8511 -1.4411
6.0823 -1.5966
6.2641 -1.7018
6.6594 -1.9658
6.9622 -2.1554
7.5696 -2.5427
7.6285 -2.5792
7.9083 -2.7581
7.9242 -2.7681
9.6531 -3.8725
9.9108 -4.0347
*/
//bmer | # 1203, 2024-11-02 14:24:11, PPPPPPPPPPP----P-----P-- (54%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
int n;
string instr;
cin >> n >> instr;
// cin.ignore();
vector<float> xf;;
vector<float> yf;
for(int i=0; i<n; ++i){
float tmx, tmy;
cin >> tmx >> tmy;
xf.push_back(tmx);
yf.push_back(tmy);
}
// find m
// m first term
float term1 = 0;
for(int i=0; i<n; ++i){
term1 += xf[i]*yf[i];
}
term1 *= n;
float term2_1 = 0;
float term2_2 = 0;
for(int i=0; i<n; ++i){
term2_1 += xf[i];
term2_2 += yf[i];
}
float term2 = term2_1 * term2_2;
float term3 = 0;
for(int i=0; i<n; ++i){
term3 += pow(xf[i], 2);
}
term3 *= n;
float term4 = 0;
for(int i=0; i<n; ++i){
term4 += xf[i];
}
term4 = pow(term4, 2);
float m = (term1-term2)/(term3-term4);
float derm1 = 0;
float derm2 = 0;
for(int i=0; i<n; ++i){
derm1 += yf[i];
derm2 += xf[i];
}
derm2 *= m;
float b = (derm1-derm2)/n;
if(instr=="mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 ;
}else{
cout << "y = ";
if(m>0){
cout << round(m*1e3)/1e3 << "x ";
}else if(m==-1){
cout << "-x ";
}
else if(round(m*1e3)/1e3==0){
cout << "";
}
else if(round(m*1e3)/1e3<0){
cout << round(m*1e3)/1e3 << "x";
}
if(b > 0){
cout << "+ " << round(b*1e3)/1e3;
}else if(b<0){
cout << "" << round(b*1e3)/1e3;
}else if( round(b*1e3)/1e3==0){
cout << "0";
}
// if(m==1.0){
// cout << "y = " << "x + " << round(b*1e3)/1e3;
// }else if(m==-1.0 && b>=0){
// cout << "y = " << "-x + " << round(b*1e3)/1e3;
// }else if(b<0 ){
// cout << "y = " << round(m*1e3)/1e3 << "x - " << abs(round(b*1e3)/1e3);
// }
// else {
// cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
// }
}
}
/*
3 mb
1.0 0.0
2.0 0.0
9.4 0.0
20 mb
1.1881 1.5293
1.7655 1.1602
1.8581 1.1016
2.2834 0.8302
2.7323 0.5438
3.0490 0.3426
3.2191 0.2325
3.5325 0.0332
3.7860 -0.1221
5.8511 -1.4411
6.0823 -1.5966
6.2641 -1.7018
6.6594 -1.9658
6.9622 -2.1554
7.5696 -2.5427
7.6285 -2.5792
7.9083 -2.7581
7.9242 -2.7681
9.6531 -3.8725
9.9108 -4.0347
*/
//bmer | # 1204, 2024-11-02 14:30:57, PPPPPPPPPPPP---P-PPP-PP- (75%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
int n;
string instr;
cin >> n >> instr;
// cin.ignore();
vector<float> xf;;
vector<float> yf;
for(int i=0; i<n; ++i){
float tmx, tmy;
cin >> tmx >> tmy;
xf.push_back(tmx);
yf.push_back(tmy);
}
// find m
// m first term
float term1 = 0;
for(int i=0; i<n; ++i){
term1 += xf[i]*yf[i];
}
term1 *= n;
float term2_1 = 0;
float term2_2 = 0;
for(int i=0; i<n; ++i){
term2_1 += xf[i];
term2_2 += yf[i];
}
float term2 = term2_1 * term2_2;
float term3 = 0;
for(int i=0; i<n; ++i){
term3 += pow(xf[i], 2);
}
term3 *= n;
float term4 = 0;
for(int i=0; i<n; ++i){
term4 += xf[i];
}
term4 = pow(term4, 2);
float m = (term1-term2)/(term3-term4);
float derm1 = 0;
float derm2 = 0;
for(int i=0; i<n; ++i){
derm1 += yf[i];
derm2 += xf[i];
}
derm2 *= m;
float b = (derm1-derm2)/n;
if(instr=="mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 ;
}else{
cout << "y = ";
if(m>0 && round(m*1e3)/1e3!=1){
cout << round(m*1e3)/1e3 << "x ";
}else if(m==-1){
cout << "-x ";
}else if(round(m*1e3)/1e3==1){
cout << "x ";
}
else if(round(m*1e3)/1e3==0){
cout << "";
}
else if(round(m*1e3)/1e3<0){
cout << round(m*1e3)/1e3 << "x";
}
if(b > 0 && round(m*1e3)/1e3!=0){
cout << "+ " << round(b*1e3)/1e3;
}else if(b<0 && round(m*1e3)/1e3!=0){
cout << "- " << abs(round(b*1e3)/1e3);
}else if(round(m*1e3)/1e3==0 && round(b*1e3)/1e3==0){
cout << "0";
}else if(b>0){
cout << round(b*1e3)/1e3;
}else if(b<0){
cout << round(b*1e3)/1e3;
}
// if(m==1.0){
// cout << "y = " << "x + " << round(b*1e3)/1e3;
// }else if(m==-1.0 && b>=0){
// cout << "y = " << "-x + " << round(b*1e3)/1e3;
// }else if(b<0 ){
// cout << "y = " << round(m*1e3)/1e3 << "x - " << abs(round(b*1e3)/1e3);
// }
// else {
// cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
// }
}
}
/*
3 mb
1.0 0.0
2.0 0.0
9.4 0.0
20 mb
1.1881 1.5293
1.7655 1.1602
1.8581 1.1016
2.2834 0.8302
2.7323 0.5438
3.0490 0.3426
3.2191 0.2325
3.5325 0.0332
3.7860 -0.1221
5.8511 -1.4411
6.0823 -1.5966
6.2641 -1.7018
6.6594 -1.9658
6.9622 -2.1554
7.5696 -2.5427
7.6285 -2.5792
7.9083 -2.7581
7.9242 -2.7681
9.6531 -3.8725
9.9108 -4.0347
*/
//bmer |
# 1205, 2024-11-02 13:30:30, PPPPPPPPPP-P-PPP--PP-PP- (75%)
#include <iostream>
#include <map>
#include <math.h>
#include <cmath>
using namespace std;
int main(){
float c,d;
int n,N;
string s;
map<float,float> ma;
cin >> n>>s;
N=n;
while(n--){
cin>>c>>d;
ma[c]=d;
}
float m;
float b;
float sumxi=0;
float sumyi=0;
float sumxiyi=0;
float sumxito2=0;
for(auto &e:ma){
sumxi += e.first;
sumyi += e.second;
sumxiyi += e.first*e.second;
sumxito2 += pow(e.first,2);
}
m = (N*sumxiyi - sumxi*sumyi )/(N*sumxito2-pow(sumxi,2));
b= (sumyi - m*sumxi)/N;
if(s=="mb"){
cout << round(m*1e3)/1e3<< endl << round(b*1e3)/1e3 ;
} else{
if(m==0||m==-1||m==1){
if(m==0){
if(b==0) cout << "y = 0";
else if(b<0) cout << "y = -" << -round(b*1e3)/1e3;
else cout << "y = " << round(b*1e3)/1e3;
}
else if(m==1){
if(b==0) cout << "y = x";
else if(b<0) cout << "y = x - " << -round(b*1e3)/1e3;
else cout << "y = x + " << round(b*1e3)/1e3;
}
else {
if(b==0) cout << "y = -x";
else if(b<0) cout << "y = -x - " << -round(b*1e3)/1e3;
else cout << "y = -x + " << round(b*1e3)/1e3;
}
} else{
if (b==0) cout << "y = " << round(m*1e3)/1e3<< "x";
else if(b<0){
cout << "y = " << round(m*1e3)/1e3<< "x - " << -round(b*1e3)/1e3;
}else{
cout << "y = " << round(m*1e3)/1e3<< "x " << round(b*1e3)/1e3;
}
}
}
} | # 1206, 2024-11-02 13:41:49, PPPPPPPPPP-P---PP-P--PP- (66%)
#include <iostream>
#include <map>
#include <math.h>
#include <cmath>
using namespace std;
int main(){
float c,d;
int n,N;
string s;
map<float,float> ma;
cin >> n>>s;
N=n;
while(n--){
cin>>c>>d;
ma[c]=d;
}
float m;
float b;
float sumxi=0;
float sumyi=0;
float sumxiyi=0;
float sumxito2=0;
for(auto &e:ma){
sumxi += e.first;
sumyi += e.second;
sumxiyi += e.first*e.second;
sumxito2 += pow(e.first,2);
}
m = (N*sumxiyi - sumxi*sumyi )/(N*sumxito2-pow(sumxi,2));
b= (sumyi - m*sumxi)/N;
//cout << m << endl;
if(s=="mb"){
cout << round(m*1e3)/1e3<< endl << round(b*1e3)/1e3 ;
} else{
if(m==0||m==-1||m==1||m<1e-6){
if(m==0||m<1e-6){
if(b==0) cout << "y = 0";
else if(b<0) cout << "y = -" << -round(b*1e3)/1e3;
else cout << "y = " << round(b*1e3)/1e3;
}
else if(m==1){
if(b==0) cout << "y = x";
else if(b<0) cout << "y = x - " << -round(b*1e3)/1e3;
else cout << "y = x + " << round(b*1e3)/1e3;
}
else {
if(b==0) cout << "y = -x";
else if(b<0) cout << "y = -x - " << -round(b*1e3)/1e3;
else cout << "y = -x + " << round(b*1e3)/1e3;
}
} else{
if (b==0) cout << "y = " << round(m*1e3)/1e3<< "x";
else if(b<0){
cout << "y = " << round(m*1e3)/1e3<< "x - " << -round(b*1e3)/1e3;
}else{
cout << "y = " << round(m*1e3)/1e3<< "x " << round(b*1e3)/1e3;
}
}
}
} | # 1207, 2024-11-02 13:42:14, PPPPPPPPPP-P---P--P--PP- (62%)
#include <iostream>
#include <map>
#include <math.h>
#include <cmath>
using namespace std;
int main(){
float c,d;
int n,N;
string s;
map<float,float> ma;
cin >> n>>s;
N=n;
while(n--){
cin>>c>>d;
ma[c]=d;
}
float m;
float b;
float sumxi=0;
float sumyi=0;
float sumxiyi=0;
float sumxito2=0;
for(auto &e:ma){
sumxi += e.first;
sumyi += e.second;
sumxiyi += e.first*e.second;
sumxito2 += pow(e.first,2);
}
m = (N*sumxiyi - sumxi*sumyi )/(N*sumxito2-pow(sumxi,2));
b= (sumyi - m*sumxi)/N;
//cout << m << endl;
if(s=="mb"){
cout << round(m*1e3)/1e3<< endl << round(b*1e3)/1e3 ;
} else{
if(m==0||m==-1||m==1||m<1e-10){
if(m==0||m<1e-10){
if(b==0) cout << "y = 0";
else if(b<0) cout << "y = -" << -round(b*1e3)/1e3;
else cout << "y = " << round(b*1e3)/1e3;
}
else if(m==1){
if(b==0) cout << "y = x";
else if(b<0) cout << "y = x - " << -round(b*1e3)/1e3;
else cout << "y = x + " << round(b*1e3)/1e3;
}
else {
if(b==0) cout << "y = -x";
else if(b<0) cout << "y = -x - " << -round(b*1e3)/1e3;
else cout << "y = -x + " << round(b*1e3)/1e3;
}
} else{
if (b==0) cout << "y = " << round(m*1e3)/1e3<< "x";
else if(b<0){
cout << "y = " << round(m*1e3)/1e3<< "x - " << -round(b*1e3)/1e3;
}else{
cout << "y = " << round(m*1e3)/1e3<< "x " << round(b*1e3)/1e3;
}
}
}
} |
# 1208, 2024-11-02 09:37:49, ---------------P-------- (4%)
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <cmath>
using namespace std;
int main(){
int n;
string s;
cin >> n >> s;
float sumxy=0, sumx=01, sumy=0, sumx2=0;
int x, y;
for(int i=0; i < n; i++){
cin >> x >> y;
sumxy += x*y;
sumx += x;
sumy += y;
sumx2 += x*x;
}
float m, b;
m = (n*sumxy - sumx*sumy) / (n*sumx2 - sumx*sumx);
b = (sumy - m*sumx) / n;
if(s == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(s == "func"){
if(m == 0 && b == 0) cout << "y = 0";
else if(m == 0 && b > 0) cout << "y = " << round(b*1e3)/1e3;
else if(m == 0 && b < 0) cout << "y = " << abs(round(b*1e3)/1e3);
else if(m == 1 && b > 0) cout << "y = x + " << round(b*1e3)/1e3;
else if(m == 1 && b < 0) cout << "y = x - " << abs(round(b*1e3)/1e3);
else if(m == 1 && b == 0) cout << "y = x";
else if(m == -1 && b > 0) cout << "y = -x + " << round(b*1e3)/1e3;
else if(m == -1 && b < 0) cout << "y = -x - " << abs(round(b*1e3)/1e3);
else if(m == -1 && b == 0) cout << "y = -x";
else if(b > 0) cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
else if(b < 0) cout << "y = " << round(m*1e3)/1e3 << "x - " << abs(round(b*1e3)/1e3);
else if(b == 0) cout << "y = " << round(m*1e3)/1e3 << "x";
}
return 0;
} | # 1209, 2024-11-02 10:24:07, -----P---------P-------- (8%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n;
string s;
cin >> n >> s;
float sumxy=0, sumx=01, sumy=0, sumx2=0;
float x, y;
for(int i=0; i < n; i++){
cin >> x >> y;
sumxy += x*y;
sumx += x;
sumy += y;
sumx2 += x*x;
}
float m, b;
m = (n*sumxy - sumx*sumy) / (n*sumx2 - sumx*sumx);
b = (sumy - m*sumx) / n;
if(s == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(s == "func"){
if(m == 0 && b == 0) cout << "y = 0";
else if(m == 0 && b > 0) cout << "y = " << round(b*1e3)/1e3;
else if(m == 0 && b < 0) cout << "y = " << abs(round(b*1e3)/1e3);
else if(m == 1 && b > 0) cout << "y = x + " << round(b*1e3)/1e3;
else if(m == 1 && b < 0) cout << "y = x - " << abs(round(b*1e3)/1e3);
else if(m == 1 && b == 0) cout << "y = x";
else if(m == -1 && b > 0) cout << "y = -x + " << round(b*1e3)/1e3;
else if(m == -1 && b < 0) cout << "y = -x - " << abs(round(b*1e3)/1e3);
else if(m == -1 && b == 0) cout << "y = -x";
else if(b > 0) cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
else if(b < 0) cout << "y = " << round(m*1e3)/1e3 << "x - " << abs(round(b*1e3)/1e3);
else if(b == 0) cout << "y = " << round(m*1e3)/1e3 << "x";
}
} | # 1210, 2024-11-02 10:27:23, PPPPPPPPPPPPPPPP--PP---- (75%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n;
string s;
cin >> n >> s;
float sumxy=0, sumx=0, sumy=0, sumx2=0;
float x, y;
for(int i=0; i < n; i++){
cin >> x >> y;
sumxy += x*y;
sumx += x;
sumy += y;
sumx2 += x*x;
}
float m, b;
m = (n*sumxy - sumx*sumy) / (n*sumx2 - sumx*sumx);
b = (sumy - m*sumx) / n;
if(s == "mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}
else if(s == "func"){
if(m == 0 && b == 0) cout << "y = 0";
else if(m == 0 && b > 0) cout << "y = " << round(b*1e3)/1e3;
else if(m == 0 && b < 0) cout << "y = " << abs(round(b*1e3)/1e3);
else if(m == 1 && b > 0) cout << "y = x + " << round(b*1e3)/1e3;
else if(m == 1 && b < 0) cout << "y = x - " << abs(round(b*1e3)/1e3);
else if(m == 1 && b == 0) cout << "y = x";
else if(m == -1 && b > 0) cout << "y = -x + " << round(b*1e3)/1e3;
else if(m == -1 && b < 0) cout << "y = -x - " << abs(round(b*1e3)/1e3);
else if(m == -1 && b == 0) cout << "y = -x";
else if(b > 0) cout << "y = " << round(m*1e3)/1e3 << "x + " << round(b*1e3)/1e3;
else if(b < 0) cout << "y = " << round(m*1e3)/1e3 << "x - " << abs(round(b*1e3)/1e3);
else if(b == 0) cout << "y = " << round(m*1e3)/1e3 << "x";
}
} |
# 1211, 2024-11-02 09:33:56, ------------------------ (0%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int N = n;
string cmd;
cin>>cmd;
vector<float> x;
vector<float> y;
x.push_back(0);
y.push_back(0);
while (n--)
{
float a,b;
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
if(cmd == "mb"){
float m,b,sixma_x,sixma_y,sixma_xy,sixma_x2;
for (int i = 1; i <= N; i++)
{
sixma_x += x[i];
sixma_y += y[i];
sixma_xy += (x[i]*y[i]);
sixma_x2 += (x[i]*x[i]);
}
m = (n*sixma_xy)-(sixma_x*sixma_y)/((n*sixma_x2)-(pow(sixma_x,2)));
b = (sixma_y-(m*sixma_x))/N;
cout<<m<<endl<<b;
}
} | # 1212, 2024-11-02 09:34:53, ------PP---------------- (8%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int N = n;
string cmd;
cin>>cmd;
vector<float> x;
vector<float> y;
x.push_back(0);
y.push_back(0);
while (n--)
{
float a,b;
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
if(cmd == "mb"){
float m,b,sixma_x,sixma_y,sixma_xy,sixma_x2;
for (int i = 1; i <= N; i++)
{
sixma_x += x[i];
sixma_y += y[i];
sixma_xy += (x[i]*y[i]);
sixma_x2 += (x[i]*x[i]);
}
m = ((n*sixma_xy)-(sixma_x*sixma_y))/((n*sixma_x2)-(pow(sixma_x,2)));
b = (sixma_y-(m*sixma_x))/N;
cout<<m<<endl<<b;
}
} | # 1213, 2024-11-02 09:35:41, ------PP---------------- (8%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int N = n;
string cmd;
cin>>cmd;
vector<float> x;
vector<float> y;
//x.push_back(0);
//y.push_back(0);
while (n--)
{
float a,b;
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
if(cmd == "mb"){
float m,b,sixma_x,sixma_y,sixma_xy,sixma_x2;
for (int i = 0; i < N; i++)
{
sixma_x += x[i];
sixma_y += y[i];
sixma_xy += (x[i]*y[i]);
sixma_x2 += (x[i]*x[i]);
}
m = ((n*sixma_xy)-(sixma_x*sixma_y))/((n*sixma_x2)-(pow(sixma_x,2)));
b = (sixma_y-(m*sixma_x))/N;
cout<<m<<endl<<b;
}
} | # 1214, 2024-11-02 09:37:32, -----PPP---------------- (12%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int N = n;
string cmd;
cin>>cmd;
vector<float> x;
vector<float> y;
//x.push_back(0);
//y.push_back(0);
while (n--)
{
float a,b;
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
if(cmd == "mb"){
float m,b,sixma_x,sixma_y,sixma_xy,sixma_x2;
for (int i = 0; i < N; i++)
{
sixma_x += x[i];
sixma_y += y[i];
sixma_xy += (x[i]*y[i]);
sixma_x2 += (x[i]*x[i]);
}
m = ((n*sixma_xy)-(sixma_x*sixma_y))/((n*sixma_x2)-(pow(sixma_x,2)));
b = (sixma_y-(m*sixma_x))/N;
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
} | # 1215, 2024-11-02 09:38:43, -----P------------------ (4%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int N = n;
string cmd;
cin>>cmd;
vector<float> x;
vector<float> y;
//x.push_back(0);
//y.push_back(0);
while (n--)
{
float a,b;
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
if(cmd == "mb"){
float m,b,sixma_x,sixma_y,sixma_xy,sixma_x2;
for (int i = 0; i < N; i++)
{
sixma_x += x[i];
sixma_y += y[i];
sixma_xy += (x[i]*y[i]);
sixma_x2 += (x[i]*x[i]);
}
m = ((N*sixma_xy)-(sixma_x*sixma_y))/((n*sixma_x2)-(pow(sixma_x,2)));
b = (sixma_y-(m*sixma_x))/N;
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
} | # 1216, 2024-11-02 09:39:34, PPPPP-P-PP-------------- (33%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int N = n;
string cmd;
cin>>cmd;
vector<float> x;
vector<float> y;
//x.push_back(0);
//y.push_back(0);
while (n--)
{
float a,b;
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
if(cmd == "mb"){
float m,b,sixma_x,sixma_y,sixma_xy,sixma_x2;
for (int i = 0; i < N; i++)
{
sixma_x += x[i];
sixma_y += y[i];
sixma_xy += (x[i]*y[i]);
sixma_x2 += (x[i]*x[i]);
}
m = ((N*sixma_xy)-(sixma_x*sixma_y))/((N*sixma_x2)-(pow(sixma_x,2)));
b = (sixma_y-(m*sixma_x))/N;
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
} | # 1217, 2024-11-02 09:45:13, -----PP-PP-------------- (16%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int m,b;
int n;
cin>>n;
int N = n;
string cmd;
cin>>cmd;
vector<float> x;
vector<float> y;
//x.push_back(0);
//y.push_back(0);
while (n--)
{
float a,b;
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
if(cmd == "mb"){
float sixma_x,sixma_y,sixma_xy,sixma_x2;
for (int i = 0; i < N; i++)
{
sixma_x += x[i];
sixma_y += y[i];
sixma_xy += (x[i]*y[i]);
sixma_x2 += (x[i]*x[i]);
}
m = ((N*sixma_xy)-(sixma_x*sixma_y))/((N*sixma_x2)-(pow(sixma_x,2)));
b = (sixma_y-(m*sixma_x))/N;
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else{
string ans = "Y = ";
if(m == -1){
ans.push_back('-');
}else if(m != 0){
ans.push_back(m);
}
ans.push_back('x');
if(b < 0){
ans+= " - ";
ans+= b;
}else if(b > 0){
ans += " + ";
ans += b;
}
cout<<ans;
}
} | # 1218, 2024-11-02 09:46:51, -----PP-PP-------------- (16%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int m,b;
int n;
cin>>n;
int N = n;
string cmd;
cin>>cmd;
vector<float> x;
vector<float> y;
//x.push_back(0);
//y.push_back(0);
while (n--)
{
float a,b;
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
if(cmd == "mb"){
float sixma_x,sixma_y,sixma_xy,sixma_x2;
for (int i = 0; i < N; i++)
{
sixma_x += x[i];
sixma_y += y[i];
sixma_xy += (x[i]*y[i]);
sixma_x2 += (x[i]*x[i]);
}
m = ((N*sixma_xy)-(sixma_x*sixma_y))/((N*sixma_x2)-(pow(sixma_x,2)));
b = (sixma_y-(m*sixma_x))/N;
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else{
float sixma_x,sixma_y,sixma_xy,sixma_x2;
for (int i = 0; i < N; i++)
{
sixma_x += x[i];
sixma_y += y[i];
sixma_xy += (x[i]*y[i]);
sixma_x2 += (x[i]*x[i]);
}
m = ((N*sixma_xy)-(sixma_x*sixma_y))/((N*sixma_x2)-(pow(sixma_x,2)));
b = (sixma_y-(m*sixma_x))/N;
string ans = "Y = ";
if(m == -1){
ans.push_back('-');
}else if(m != 0){
ans.push_back(m);
}
ans.push_back('x');
if(b < 0){
ans+= " - ";
ans+= b;
}else if(b > 0){
ans += " + ";
ans += b;
}
cout<<ans;
}
} | # 1219, 2024-11-02 09:48:42, -----PP-PP-------------- (16%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int m,b;
int n;
cin>>n;
int N = n;
string cmd;
cin>>cmd;
vector<float> x;
vector<float> y;
x.push_back(0);
y.push_back(0);
while (n--)
{
float a,b;
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
float sixma_x,sixma_y,sixma_xy,sixma_x2;
for (int i = 1; i <= N; i++)
{
sixma_x += x[i];
sixma_y += y[i];
sixma_xy += (x[i]*y[i]);
sixma_x2 += (x[i]*x[i]);
}
m = ((N*sixma_xy)-(sixma_x*sixma_y))/((N*sixma_x2)-(pow(sixma_x,2)));
b = (sixma_y-(m*sixma_x))/N;
if(cmd == "mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else{
string ans = "Y = ";
if(m == -1){
ans.push_back('-');
}else if(m != 0){
ans.push_back(m);
}
ans.push_back('x');
if(b < 0){
ans+= " - ";
ans+= b;
}else if(b > 0){
ans += " + ";
ans += b;
}
cout<<ans;
}
} | # 1220, 2024-11-02 09:49:09, -----PP-PP-------------- (16%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int m,b;
int n;
cin>>n;
int N = n;
string cmd;
cin>>cmd;
vector<float> x;
vector<float> y;
x.push_back(0);
y.push_back(0);
while (n--)
{
float a,b;
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
float sixma_x = 0,sixma_y = 0,sixma_xy = 0,sixma_x2 = 0;
for (int i = 1; i <= N; i++)
{
sixma_x += x[i];
sixma_y += y[i];
sixma_xy += (x[i]*y[i]);
sixma_x2 += (x[i]*x[i]);
}
m = ((N*sixma_xy)-(sixma_x*sixma_y))/((N*sixma_x2)-(pow(sixma_x,2)));
b = (sixma_y-(m*sixma_x))/N;
if(cmd == "mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else{
string ans = "Y = ";
if(m == -1){
ans.push_back('-');
}else if(m != 0){
ans.push_back(m);
}
ans.push_back('x');
if(b < 0){
ans+= " - ";
ans+= b;
}else if(b > 0){
ans += " + ";
ans += b;
}
cout<<ans;
}
} | # 1221, 2024-11-02 09:51:56, PPPPP-P-PP-------------- (33%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int N = n;
string cmd;
cin>>cmd;
vector<float> x;
vector<float> y;
//x.push_back(0);
//y.push_back(0);
while (n--)
{
float a,b;
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
float m,b,sixma_x,sixma_y,sixma_xy,sixma_x2;
for (int i = 0; i < N; i++)
{
sixma_x += x[i];
sixma_y += y[i];
sixma_xy += (x[i]*y[i]);
sixma_x2 += (x[i]*x[i]);
}
m = ((N*sixma_xy)-(sixma_x*sixma_y))/((N*sixma_x2)-(pow(sixma_x,2)));
b = (sixma_y-(m*sixma_x))/N;
if(cmd == "mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}
} | # 1222, 2024-11-02 09:54:05, PPPPP-P-PP-----------P-- (37%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int N = n;
string cmd;
cin>>cmd;
vector<float> x;
vector<float> y;
//x.push_back(0);
//y.push_back(0);
while (n--)
{
float a,b;
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
float m,b,sixma_x,sixma_y,sixma_xy,sixma_x2;
for (int i = 0; i < N; i++)
{
sixma_x += x[i];
sixma_y += y[i];
sixma_xy += (x[i]*y[i]);
sixma_x2 += (x[i]*x[i]);
}
m = ((N*sixma_xy)-(sixma_x*sixma_y))/((N*sixma_x2)-(pow(sixma_x,2)));
b = (sixma_y-(m*sixma_x))/N;
if(cmd == "mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else{
string ans;
if(m==0 && b==0){
cout<<"y = 0";
return 0;
}
if(m==0 && b!=0){
cout<<"y = "<<b;
}
}
} | # 1223, 2024-11-02 09:58:13, PPPPP-P-PP-----------P-- (37%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int N = n;
string cmd;
cin>>cmd;
vector<float> x;
vector<float> y;
//x.push_back(0);
//y.push_back(0);
while (n--)
{
float a,b;
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
float m,b,sixma_x,sixma_y,sixma_xy,sixma_x2;
for (int i = 0; i < N; i++)
{
sixma_x += x[i];
sixma_y += y[i];
sixma_xy += (x[i]*y[i]);
sixma_x2 += (x[i]*x[i]);
}
m = ((N*sixma_xy)-(sixma_x*sixma_y))/((N*sixma_x2)-(pow(sixma_x,2)));
b = (sixma_y-(m*sixma_x))/N;
if(cmd == "mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else{
string ans = "y = ";
if(m==0 && b==0){
cout<<"y = 0";
return 0;
}
if(m==0 && b!=0){
cout<<"y = "<<b;
return 0;
}
if(m==1){
ans += 'x';
if(b > 0){
ans += " + ";
ans += b;
}else if(b < 0){
ans += " ";
ans += b;
}
}
}
} | # 1224, 2024-11-02 09:58:57, PPPPP-P-PP-----------P-- (37%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int N = n;
string cmd;
cin>>cmd;
vector<float> x;
vector<float> y;
//x.push_back(0);
//y.push_back(0);
while (n--)
{
float a,b;
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
float m,b,sixma_x,sixma_y,sixma_xy,sixma_x2;
for (int i = 0; i < N; i++)
{
sixma_x += x[i];
sixma_y += y[i];
sixma_xy += (x[i]*y[i]);
sixma_x2 += (x[i]*x[i]);
}
m = ((N*sixma_xy)-(sixma_x*sixma_y))/((N*sixma_x2)-(pow(sixma_x,2)));
b = (sixma_y-(m*sixma_x))/N;
if(cmd == "mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else{
string ans = "y = ";
if(m==0 && b==0){
cout<<"y = 0";
return 0;
}
if(m==0 && b!=0){
cout<<"y = "<<b;
return 0;
}
if(m==1){
ans += 'x';
if(b > 0){
ans += " + ";
ans += b;
}else if(b < 0){
ans += " ";
ans += b;
}
}else if(m==-1){
ans += '-x';
if(b > 0){
ans += " + ";
ans += b;
}else if(b < 0){
ans += " ";
ans += b;
}
}
}
} | # 1225, 2024-11-02 10:02:29, PPPPP-P-PP---------P-P-- (41%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int N = n;
string cmd;
cin>>cmd;
vector<float> x;
vector<float> y;
//x.push_back(0);
//y.push_back(0);
while (n--)
{
float a,b;
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
float m,b,sixma_x,sixma_y,sixma_xy,sixma_x2;
for (int i = 0; i < N; i++)
{
sixma_x += x[i];
sixma_y += y[i];
sixma_xy += (x[i]*y[i]);
sixma_x2 += (x[i]*x[i]);
}
m = ((N*sixma_xy)-(sixma_x*sixma_y))/((N*sixma_x2)-(pow(sixma_x,2)));
b = (sixma_y-(m*sixma_x))/N;
if(cmd == "mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else{
string ans = "y = ";
if(m==0 && b==0){
cout<<"y = 0";
return 0;
}
if(m==0 && b!=0){
cout<<"y = "<<b;
return 0;
}
if(m==1){
ans += 'x';
}else if(m==-1){
ans += "-x";
}else{
ans += m;
ans +="x";
}
if(b > 0){
ans += " + ";
ans += b;
}else if(b < 0){
ans += " - ";
ans += (b*-1);
}
cout<<ans;
}
} | # 1226, 2024-11-02 10:04:20, PPPPP-P-PP---------P-P-- (41%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int N = n;
string cmd;
cin>>cmd;
vector<float> x;
vector<float> y;
x.push_back(0);
y.push_back(0);
while (n--)
{
float a,b;
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
float m,b,sixma_x,sixma_y,sixma_xy,sixma_x2;
for (int i = 1; i <= N; i++)
{
sixma_x += x[i];
sixma_y += y[i];
sixma_xy += (x[i]*y[i]);
sixma_x2 += (x[i]*x[i]);
}
m = ((N*sixma_xy)-(sixma_x*sixma_y))/((N*sixma_x2)-(pow(sixma_x,2)));
b = (sixma_y-(m*sixma_x))/N;
if(cmd == "mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else{
string ans = "y = ";
if(m==0 && b==0){
cout<<"y = 0";
return 0;
}
if(m==0 && b!=0){
cout<<"y = "<<b;
return 0;
}
if(m==1){
ans += 'x';
}else if(m==-1){
ans += "-x";
}else{
ans += m;
ans +="x";
}
if(b > 0){
ans += " + ";
ans += b;
}else if(b < 0){
ans += " - ";
ans += (b*-1);
}
cout<<ans;
}
} | # 1227, 2024-11-02 10:07:34, PPPPP-PPPP--------PP-P-- (50%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int N = n;
string cmd;
cin>>cmd;
vector<float> x;
vector<float> y;
x.push_back(0);
y.push_back(0);
while (n--)
{
float a,b;
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
float m,b,sixma_x,sixma_y,sixma_xy,sixma_x2;
for (int i = 1; i <= N; i++)
{
sixma_x += x[i];
sixma_y += y[i];
sixma_xy += (x[i]*y[i]);
sixma_x2 += (x[i]*x[i]);
}
double upperm= (N*sixma_xy)-(sixma_x*sixma_y);
double lowerm = (N*sixma_x2)-(sixma_x*sixma_x);
m = upperm/lowerm;
b = (sixma_y-(m*sixma_x))/N;
if(cmd == "mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else{
string ans = "y = ";
if(m==0 && b==0){
cout<<"y = 0";
return 0;
}
if(m==0 && b!=0){
cout<<"y = "<<b;
return 0;
}
if(m==1){
ans += 'x';
}else if(m==-1){
ans += "-x";
}else{
ans += m;
ans +="x";
}
if(b > 0){
ans += " + ";
ans += b;
}else if(b < 0){
ans += " - ";
ans += (b*-1);
}
cout<<ans;
}
} | # 1228, 2024-11-02 10:34:34, PPPPPPPPPP-----P--PP-P-- (58%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int N = n;
string cmd;
cin>>cmd;
vector<float> x;
vector<float> y;
x.push_back(0);
y.push_back(0);
while (n--)
{
float a,b;
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
float m,b,sixma_x=0,sixma_y=0,sixma_xy=0,sixma_x2=0;
for (int i = 1; i <= N; i++)
{
sixma_x += x[i];
sixma_y += y[i];
sixma_xy += (x[i]*y[i]);
sixma_x2 += (x[i]*x[i]);
}
double upperm= (N*sixma_xy)-(sixma_x*sixma_y);
double lowerm = (N*sixma_x2)-(sixma_x*sixma_x);
m = upperm/lowerm;
b = (sixma_y-(m*sixma_x))/N;
if(cmd == "mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else{
string ans = "y = ";
if(m==0 && b==0){
cout<<"y = 0";
return 0;
}
if(m==0 && b!=0){
cout<<"y = "<<b;
return 0;
}
if(m==1){
ans += 'x';
}else if(m==-1){
ans += "-x";
}else{
ans += m;
ans +="x";
}
if(b > 0){
ans += " + ";
ans += b;
}else if(b < 0){
ans += " - ";
ans += (b*-1);
}
cout<<ans;
}
} | # 1229, 2024-11-02 10:35:56, PPPPPPPPPP-----P--PP-P-- (58%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int N = n;
string cmd;
cin>>cmd;
vector<float> x;
vector<float> y;
x.push_back(0);
y.push_back(0);
while (n--)
{
float a,b;
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
float m,b,sixma_x=0,sixma_y=0,sixma_xy=0,sixma_x2=0;
for (int i = 1; i <= N; i++)
{
sixma_x += x[i];
sixma_y += y[i];
sixma_xy += (x[i]*y[i]);
sixma_x2 += (x[i]*x[i]);
}
double upperm= (N*sixma_xy)-(sixma_x*sixma_y);
double lowerm = (N*sixma_x2)-(sixma_x*sixma_x);
m = upperm/lowerm;
double upperb= sixma_y-(m*sixma_x);
b = upperb/N;
if(cmd == "mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else{
string ans = "y = ";
if(m==0 && b==0){
cout<<"y = 0";
return 0;
}
if(m==0 && b!=0){
cout<<"y = "<<b;
return 0;
}
if(m==1){
ans += 'x';
}else if(m==-1){
ans += "-x";
}else{
ans += m;
ans +="x";
}
if(b > 0){
ans += " + ";
ans += b;
}else if(b < 0){
ans += " - ";
ans += (b*-1);
}
cout<<ans;
}
} | # 1230, 2024-11-02 10:39:18, PPPPPPPPPP-----P--PP-P-- (58%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int N = n;
string cmd;
cin>>cmd;
vector<float> x;
vector<float> y;
x.push_back(0);
y.push_back(0);
while (n--)
{
float a,b;
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
float m,b,sixma_x=0,sixma_y=0,sixma_xy=0,sixma_x2=0;
for (int i = 1; i <= N; i++)
{
sixma_x += x[i];
sixma_y += y[i];
sixma_xy += (x[i]*y[i]);
sixma_x2 += (x[i]*x[i]);
}
double upperm= (N*sixma_xy)-(sixma_x*sixma_y);
double lowerm = (N*sixma_x2)-(sixma_x*sixma_x);
m = upperm/lowerm;
double upperb= sixma_y-(m*sixma_x);
b = upperb/N;
if(cmd == "mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else{
string ans = "y = ";
if(m==0 && b==0){
cout<<"y = 0";
return 0;
}
if(m==0 && b!=0){
cout<<"y = "<<round(b*1e3)/1e3;
return 0;
}
if(m==1){
ans += 'x';
}else if(m==-1){
ans += "-x";
}else{
ans += round(m*1e3)/1e3;
ans +="x";
}
if(b > 0){
ans += " + ";
ans += round(b*1e3)/1e3;
}else if(b < 0){
ans += " - ";
ans += round((b*-1)*1e3)/1e3;
}
cout<<ans;
}
} | # 1231, 2024-11-02 10:41:25, PPPPPPPPPP-----P--PP-P-- (58%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int N = n;
string cmd;
cin>>cmd;
vector<float> x;
vector<float> y;
x.push_back(0);
y.push_back(0);
while (n--)
{
float a,b;
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
float m,b,sixma_x=0,sixma_y=0,sixma_xy=0,sixma_x2=0;
for (int i = 1; i <= N; i++)
{
sixma_x += x[i];
sixma_y += y[i];
sixma_xy += (x[i]*y[i]);
sixma_x2 += (x[i]*x[i]);
}
double upperm= (N*sixma_xy)-(sixma_x*sixma_y);
double lowerm = (N*sixma_x2)-(sixma_x*sixma_x);
m = upperm/lowerm;
double upperb= sixma_y-(m*sixma_x);
b = upperb/N;
if(cmd == "mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else{
string ans = "y = ";
if(m==0 && b==0){
cout<<"y = 0";
return 0;
}
if(m==0 && b!=0){
cout<<"y = "<<round(b*1e3)/1e3;
return 0;
}
if(m==1){
ans += 'x';
}else if(m==-1){
ans += "-x";
}else{
ans += round(m*1e3)/1e3;
ans +="x";
}
if(b > 0){
ans += " + ";
ans += to_string((b*1e3)/1e3);
}else if(b < 0){
ans += " - ";
ans += to_string(((b*-1)*1e3)/1e3);
}
cout<<ans;
}
} | # 1232, 2024-11-02 10:42:54, PPPPPPPPPP-----P--PP-P-- (58%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int N = n;
string cmd;
cin>>cmd;
vector<float> x;
vector<float> y;
x.push_back(0);
y.push_back(0);
while (n--)
{
float a,b;
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
float m,b,sixma_x=0,sixma_y=0,sixma_xy=0,sixma_x2=0;
for (int i = 1; i <= N; i++)
{
sixma_x += x[i];
sixma_y += y[i];
sixma_xy += (x[i]*y[i]);
sixma_x2 += (x[i]*x[i]);
}
double upperm= (N*sixma_xy)-(sixma_x*sixma_y);
double lowerm = (N*sixma_x2)-(sixma_x*sixma_x);
m = upperm/lowerm;
double upperb= sixma_y-(m*sixma_x);
b = upperb/N;
if(cmd == "mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else{
string ans = "y = ";
if(m==0 && b==0){
cout<<"y = 0";
return 0;
}
if(m==0 && b!=0){
cout<<"y = "<<round(b*1e3)/1e3;
return 0;
}
if(m==1){
ans += 'x';
}else if(m==-1){
ans += "-x";
}else{
ans += round(m*1e3)/1e3;
ans +="x";
}
if(b > 0){
ans += " + ";
ans += to_string(b);
}else if(b < 0){
ans += " - ";
ans += to_string((b*-1));
}
cout<<ans;
}
} | # 1233, 2024-11-02 10:43:56, PPPPPPPPPP-----P--PP-P-- (58%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int N = n;
string cmd;
cin>>cmd;
vector<float> x;
vector<float> y;
x.push_back(0);
y.push_back(0);
while (n--)
{
float a,b;
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
float m,b,sixma_x=0,sixma_y=0,sixma_xy=0,sixma_x2=0;
for (int i = 1; i <= N; i++)
{
sixma_x += x[i];
sixma_y += y[i];
sixma_xy += (x[i]*y[i]);
sixma_x2 += (x[i]*x[i]);
}
double upperm= (N*sixma_xy)-(sixma_x*sixma_y);
double lowerm = (N*sixma_x2)-(sixma_x*sixma_x);
m = upperm/lowerm;
double upperb= sixma_y-(m*sixma_x);
b = upperb/N;
if(cmd == "mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else{
string ans = "y = ";
if(m==0 && b==0){
cout<<"y = 0";
return 0;
}
if(m==0 && b!=0){
cout<<"y = "<<round(b*1e3)/1e3;
return 0;
}
if(m==1){
ans += 'x';
}else if(m==-1){
ans += "-x";
}else{
ans += round(m*1e3)/1e3;
ans +="x";
}
if(b > 0){
ans += " + ";
ans += to_string(round(b*1000)/1000);
}else if(b < 0){
ans += " - ";
ans += to_string(round((b*-1)*1000)/1000);
}
cout<<ans;
}
} | # 1234, 2024-11-02 10:45:06, PPPPPPPPPP-----P--PP-P-- (58%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int N = n;
string cmd;
cin>>cmd;
vector<float> x;
vector<float> y;
x.push_back(0);
y.push_back(0);
while (n--)
{
float a,b;
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
float m,b,sixma_x=0,sixma_y=0,sixma_xy=0,sixma_x2=0;
for (int i = 1; i <= N; i++)
{
sixma_x += x[i];
sixma_y += y[i];
sixma_xy += (x[i]*y[i]);
sixma_x2 += (x[i]*x[i]);
}
double upperm= (N*sixma_xy)-(sixma_x*sixma_y);
double lowerm = (N*sixma_x2)-(sixma_x*sixma_x);
m = upperm/lowerm;
double upperb= sixma_y-(m*sixma_x);
b = upperb/N;
if(cmd == "mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else{
string ans = "y = ";
double newm = round(m*1e3)/1e3;
double newb = round(b*1e3)/1e3;
if(m==0 && b==0){
cout<<"y = 0";
return 0;
}
if(m==0 && b!=0){
cout<<"y = "<<newb;
return 0;
}
if(m==1){
ans += 'x';
}else if(m==-1){
ans += "-x";
}else{
ans += newm;
ans +="x";
}
if(b > 0){
ans += " + ";
ans += newb;
}else if(b < 0){
ans += " - ";
ans += (newb*-1);
}
cout<<ans;
}
} | # 1235, 2024-11-02 10:47:51, PPPPPPPPPP-----P--PP-P-- (58%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int N = n;
string cmd;
cin>>cmd;
vector<float> x;
vector<float> y;
x.push_back(0);
y.push_back(0);
while (n--)
{
float a,b;
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
float m,b,sixma_x=0,sixma_y=0,sixma_xy=0,sixma_x2=0;
for (int i = 1; i <= N; i++)
{
sixma_x += x[i];
sixma_y += y[i];
sixma_xy += (x[i]*y[i]);
sixma_x2 += (x[i]*x[i]);
}
double upperm= (N*sixma_xy)-(sixma_x*sixma_y);
double lowerm = (N*sixma_x2)-(sixma_x*sixma_x);
m = upperm/lowerm;
double upperb= sixma_y-(m*sixma_x);
b = upperb/N;
if(cmd == "mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else{
string ans = "y = ";
if(m==0 && b==0){
cout<<"y = 0";
return 0;
}
if(m==0 && b!=0){
cout<<"y = "<<round(b*1e3)/1e3;
return 0;
}
if(m==1){
ans += 'x';
}else if(m==-1){
ans += "-x";
}else{
ans += round(m*1e3)/1e3;
ans +="x";
}
if(b > 0){
ans += " + ";
ans += to_string(round(b*1e3)/1e3);
}else if(b < 0){
ans += " - ";
ans += to_string(round((b*-1)*1e3)/1e3);
}
cout<<ans;
}
} | # 1236, 2024-11-02 10:53:17, PPPPPPPPPP-----PP----P-- (54%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int N = n;
string cmd;
cin>>cmd;
vector<float> x;
vector<float> y;
x.push_back(0);
y.push_back(0);
while (n--)
{
float a,b;
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
float m,b,sixma_x=0,sixma_y=0,sixma_xy=0,sixma_x2=0;
for (int i = 1; i <= N; i++)
{
sixma_x += x[i];
sixma_y += y[i];
sixma_xy += (x[i]*y[i]);
sixma_x2 += (x[i]*x[i]);
}
double upperm= (N*sixma_xy)-(sixma_x*sixma_y);
double lowerm = (N*sixma_x2)-(sixma_x*sixma_x);
m = upperm/lowerm;
double upperb= sixma_y-(m*sixma_x);
b = upperb/N;
if(cmd == "mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else{
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
string ans = "y = ";
double ansb;
if(m==0 && b==0){
cout<<"y = 0";
return 0;
}
if(m==0 && b!=0){
cout<<"y = "<<round(b*1e3)/1e3;
return 0;
}
if(m==1){
ans += 'x';
}else if(m==-1){
ans += "-x";
}else{
ans += round(m*1e3)/1e3;
ans +="x";
}
if(b > 0){
ans += " + ";
ansb = (round(b*1e3)/1e3);
}else if(b < 0){
ans += " - ";
ansb = (round((b * -1)*1e3)/1e3);
}
cout<<setprecision(3)<<ans<<ansb;
}
} | # 1237, 2024-11-02 10:53:38, PPPPPPPPPP-----PPP--PPPP (70%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int N = n;
string cmd;
cin>>cmd;
vector<float> x;
vector<float> y;
x.push_back(0);
y.push_back(0);
while (n--)
{
float a,b;
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
float m,b,sixma_x=0,sixma_y=0,sixma_xy=0,sixma_x2=0;
for (int i = 1; i <= N; i++)
{
sixma_x += x[i];
sixma_y += y[i];
sixma_xy += (x[i]*y[i]);
sixma_x2 += (x[i]*x[i]);
}
double upperm= (N*sixma_xy)-(sixma_x*sixma_y);
double lowerm = (N*sixma_x2)-(sixma_x*sixma_x);
m = upperm/lowerm;
double upperb= sixma_y-(m*sixma_x);
b = upperb/N;
if(cmd == "mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else{
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
string ans = "y = ";
double ansb;
if(m==0 && b==0){
cout<<"y = 0";
return 0;
}
if(m==0 && b!=0){
cout<<"y = "<<round(b*1e3)/1e3;
return 0;
}
if(m==1){
ans += 'x';
}else if(m==-1){
ans += "-x";
}else{
ans += round(m*1e3)/1e3;
ans +="x";
}
if(b > 0){
ans += " + ";
ansb = (round(b*1e3)/1e3);
}else if(b < 0){
ans += " - ";
ansb = (round((b * -1)*1e3)/1e3);
}
cout<<fixed<<setprecision(3)<<ans<<ansb;
}
} | # 1238, 2024-11-02 10:55:11, PPPPPPPPPP-----PPP--PPPP (70%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int N = n;
string cmd;
cin>>cmd;
vector<float> x;
vector<float> y;
x.push_back(0);
y.push_back(0);
while (n--)
{
float a,b;
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
float m,b,sixma_x=0,sixma_y=0,sixma_xy=0,sixma_x2=0;
for (int i = 1; i <= N; i++)
{
sixma_x += x[i];
sixma_y += y[i];
sixma_xy += (x[i]*y[i]);
sixma_x2 += (x[i]*x[i]);
}
double upperm= (N*sixma_xy)-(sixma_x*sixma_y);
double lowerm = (N*sixma_x2)-(sixma_x*sixma_x);
m = upperm/lowerm;
double upperb= sixma_y-(m*sixma_x);
b = upperb/N;
if(cmd == "mb"){
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
}else{
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
string ans = "y = ";
double ansb;
if(m==0 && b==0){
cout<<"y = 0";
return 0;
}
if(m==0 && b!=0){
cout<<"y = "<<round(b*1e3)/1e3;
return 0;
}
if(m==1){
ans += 'x';
}else if(m==-1){
ans += "-x";
}else{
ans += round(m*1e3)/1e3;
ans +="x";
}
if(b > 0){
ans += " + ";
ansb = (round(b*1e3)/1e3);
}else if(b < 0){
ans += " - ";
ansb = (round((b * -1)*1e3)/1e3);
}
if(ansb!=0){
cout<<fixed<<setprecision(3)<<ans<<ansb;
}else{
cout<<fixed<<setprecision(3)<<ans;
}
}
} |
# 1239, 2024-11-02 10:10:14, xxxxxxxxxxxxxxxxxxxxxxxx (0%)
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
string select[2] = {"mb","func"};
vector<float> x,y;
float m = 0,b = 0;
float m_up = 0;
float sum_x = 0,sum_xsqrt = 0,sum_y = 0,sum_xy = 0;
string s;
int n;
cin>>n>>s;
while(n--){
cin>>x[n]>>y[n];
if(n == 0) break;
}
for(int i = 0;i<n;i++){
b += y[i] - x[i];
}
b = b/n;
for(int j = 0;j<n;j++){
m_up += (x[j]*y[j]);
sum_x += x[j];
sum_y += y[j];
sum_xy += x[j]*y[j];
sum_xsqrt += pow(x[j],2);
}
m = (m_up - sum_xy)/(sum_xsqrt - pow(sum_x,2));
if(s == select[0]){
cout<<m<<endl;
cout<<b<<endl;
return 0;
}
if(s == select[1]){
cout<<"y ="<< round(m*1e3)/1e3 << "x" << "+" << round(b*1e3)/1e3;
return 0;
}
} | # 1240, 2024-11-02 10:10:54, xxxxxxxxxxxxxxxxxxxxxxxx (0%)
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
string select[2] = {"mb","func"};
vector<float> x,y;
float m = 0,b = 0;
float m_up = 0;
float sum_x = 0,sum_xsqrt = 0,sum_y = 0,sum_xy = 0;
string s;
int n;
cin>>n>>s;
while(n--){
cin>>x[n]>>y[n];
}
for(int i = 0;i<n;i++){
b += y[i] - x[i];
}
b = b/n;
for(int j = 0;j<n;j++){
m_up += (x[j]*y[j]);
sum_x += x[j];
sum_y += y[j];
sum_xy += x[j]*y[j];
sum_xsqrt += pow(x[j],2);
}
m = (m_up - sum_xy)/(sum_xsqrt - pow(sum_x,2));
if(s == select[0]){
cout<<m<<endl;
cout<<b<<endl;
return 0;
}
if(s == select[1]){
cout<<"y ="<< round(m*1e3)/1e3 << "x" << "+" << round(b*1e3)/1e3;
return 0;
}
} | # 1241, 2024-11-02 10:36:01, ------------------------ (0%)
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
string select[2] = {"mb","func"};
float m = 0,b = 0;
float m_up = 0;
float sum_x = 0,sum_xsqrt = 0,sum_y = 0,sum_xy = 0;
string s;
int n;
cin>>n>>s;
float x[n],y[n];
for(int k = 0;k<n;k++){
cin>>x[k]>>y[k];
}
for(int i = 0;i<n;i++){
b += y[i] - x[i];
}
b = b/n;
for(int j = 0;j<n;j++){
m_up += (x[j]*y[j]);
sum_x += x[j];
sum_y += y[j];
sum_xy += x[j]*y[j];
sum_xsqrt += pow(x[j],2);
}
m = (m_up - sum_xy)/(sum_xsqrt - pow(sum_x,2));
if(s == select[0]){
cout<<m<<endl;
cout<<b<<endl;
return 0;
}
if(s == select[1]){
cout<<"y ="<< round(m*1e3)/1e3 << "x" << "+" << round(b*1e3)/1e3;
return 0;
}
} | # 1242, 2024-11-02 10:36:24, ------------------------ (0%)
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
string select[2] = {"mb","func"};
float m = 0,b = 0;
float m_up = 0;
float sum_x = 0,sum_xsqrt = 0,sum_y = 0,sum_xy = 0;
string s;
int n;
cin>>n>>s;
float x[n],y[n];
for(int k = 0;k<n;k++){
cin>>x[k]>>y[k];
}
for(int i = 0;i<n;i++){
b += y[i] - x[i];
}
b = b/n;
for(int j = 0;j<n;j++){
m_up += (x[j]*y[j]);
sum_x += x[j];
sum_y += y[j];
sum_xy += x[j]*y[j];
sum_xsqrt += pow(x[j],2);
}
m = (m_up - sum_xy)/(sum_xsqrt - pow(sum_x,2));
if(s == select[0]){
cout<<m<<endl;
cout<<b<<endl;
return 0;
}
if(s == select[1]){
cout<<"y ="<< round(m*1e3)/1e3 << "x" << "+" << round(b*1e3)/1e3;
return 0;
}
} | # 1243, 2024-11-02 10:39:12, ------------------------ (0%)
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
string select[2] = {"mb","func"};
float m = 0,b = 0;
float m_up = 0;
float sum_x = 0,sum_xsqrt = 0,sum_y = 0,sum_xy = 0;
string s;
int n;
cin>>n>>s;
float x[n],y[n];
for(int k = 0;k<n;k++){
cin>>x[k]>>y[k];
}
for(int j = 0;j<n;j++){
m_up += (x[j]*y[j]);
sum_x += x[j];
sum_y += y[j];
sum_xy += x[j]*y[j];
sum_xsqrt += pow(x[j],2);
}
m = (m_up - sum_xy)/(sum_xsqrt - pow(sum_x,2));
for(int i = 0;i<n;i++){
b += y[i] - m*x[i];
}
b = b/n;
if(s == select[0]){
cout<<m<<endl;
cout<<b<<endl;
return 0;
}
if(s == select[1]){
cout<<"y ="<< round(m*1e3)/1e3 << "x" << "+" << round(b*1e3)/1e3;
return 0;
}
} | # 1244, 2024-11-02 10:49:27, -----P------------------ (4%)
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
string select[2] = {"mb","func"};
float m = 0,b = 0;
float m_up = 0;
float sum_x = 0,sum_xsqrt = 0,sum_y = 0,sum_xy = 0;
string s;
int n;
cin>>n>>s;
float x[n],y[n];
for(int k = 0;k<n;k++){
cin>>x[k]>>y[k];
}
for(int j = 0;j<n;j++){
m_up += (x[j]*y[j]);
sum_x += x[j];
sum_y += y[j];
sum_xsqrt += pow(x[j],2);
}
sum_xy = sum_x*sum_y;
m = (n*m_up - sum_xy)/(n*sum_xsqrt - pow(sum_x,2));
b = (sum_y - m*sum_x)/n;
if(s == select[0]){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(m*1e3)/1e3<<endl;
return 0;
}
if(s == select[1]){
cout<<"y ="<< round(m*1e3)/1e3 << "x" << "+" << round(b*1e3)/1e3;
return 0;
}
} | # 1245, 2024-11-02 11:00:04, -----P----P-P----------- (12%)
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
string select[2] = {"mb","func"};
float m = 0,b = 0;
float m_up = 0;
float sum_x = 0,sum_xsqrt = 0,sum_y = 0,sum_xy = 0;
string s;
int n;
cin>>n>>s;
float x[n],y[n];
for(int k = 0;k<n;k++){
cin>>x[k]>>y[k];
}
for(int j = 0;j<n;j++){
m_up += (x[j]*y[j]);
sum_x += x[j];
sum_y += y[j];
sum_xsqrt += pow(x[j],2);
}
sum_xy = sum_x*sum_y;
m = (n*m_up - sum_xy)/(n*sum_xsqrt - pow(sum_x,2));
b = (sum_y - m*sum_x)/n;
if(s == select[0]){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(m*1e3)/1e3<<endl;
return 0;
}
if(s == select[1]){
if(m == 1){
cout<<"y = "<< "x" << " " << "+" << " " << round(b*1e3)/1e3;
}
else
{cout<<"y = "<< round(m*1e3)/1e3 << "x" << " " << "+" << " " << round(b*1e3)/1e3;}
return 0;
}
} | # 1246, 2024-11-02 11:24:53, Compilation error (0%)
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
string select[2] = {"mb","func"};
float m = 0,b = 0;
float m_up = 0;
float sum_x = 0,sum_xsqrt = 0,sum_y = 0,sum_xy = 0;
string s;
int n;
cin>>n>>s;
float x[n],y[n];
for(int k = 0;k<n;k++){
cin>>x[k]>>y[k];
}
for(int j = 0;j<n;j++){
m_up += (x[j]*y[j]);
sum_x += x[j];
sum_y += y[j];
sum_xsqrt += pow(x[j],2);
}
sum_xy = sum_x*sum_y;
m = (n*m_up - sum_xy)/(n*sum_xsqrt - pow(sum_x,2));
b = (sum_y - m*sum_x)/n;
if(s == select[0]){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
return 0;
}
if(s == select[1]){
if(m == 0 && b == 0){
cout<<"y = 0"<<endl;
}
else if(m == 1 && b != 0){
cout<<"y = "<<"x"<<" "<<"+"<<" "<<round(b*1e3)/1e3<<endl;
}
else if(m == 1 && b == 0){
cout<<"y = x"<<endl;
}
else if(m == -1 && b != 0){
cout<<"y = "<<"-x"<<" "<<"+"<<" "<<round(b*1e3)/1e3<<endl;
}
else if(m == -1 && b == 0){
cout<<"y = -x"<<endl;
}
else if( m == 0 && b != 0){
cout<<" y = b"<<endl;
}
else{
cout<<"y = "<< round(m*1e3)/1e3 << "x" << " " << "+" << " " << round(b*1e3)/1e3<<endl;
}
/*if(m == 1){
cout<<"y = "<< "x" << " " << "+" << " " << round(b*1e3)/1e3;
}
else if(m ==-1)
{cout<<"y = "<< "-x" << " " << "+" << " " << round(b*1e3)/1e3;}
else
{cout<<"y = "<< round(m*1e3)/1e3 << "x" << " " << "+" << " " << round(b*1e3)/1e3;}*/
return 0;
} | # 1247, 2024-11-02 11:25:24, PPPPPPPPPPP-P--P--PP---- (62%)
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
string select[2] = {"mb","func"};
float m = 0,b = 0;
float m_up = 0;
float sum_x = 0,sum_xsqrt = 0,sum_y = 0,sum_xy = 0;
string s;
int n;
cin>>n>>s;
float x[n],y[n];
for(int k = 0;k<n;k++){
cin>>x[k]>>y[k];
}
for(int j = 0;j<n;j++){
m_up += (x[j]*y[j]);
sum_x += x[j];
sum_y += y[j];
sum_xsqrt += pow(x[j],2);
}
sum_xy = sum_x*sum_y;
m = (n*m_up - sum_xy)/(n*sum_xsqrt - pow(sum_x,2));
b = (sum_y - m*sum_x)/n;
if(s == select[0]){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
return 0;
}
if(s == select[1]){
if(m == 0 && b == 0){
cout<<"y = 0"<<endl;
}
else if(m == 1 && b != 0){
cout<<"y = "<<"x"<<" "<<"+"<<" "<<round(b*1e3)/1e3<<endl;
}
else if(m == 1 && b == 0){
cout<<"y = x"<<endl;
}
else if(m == -1 && b != 0){
cout<<"y = "<<"-x"<<" "<<"+"<<" "<<round(b*1e3)/1e3<<endl;
}
else if(m == -1 && b == 0){
cout<<"y = -x"<<endl;
}
else if( m == 0 && b != 0){
cout<<" y = b"<<endl;
}
else{
cout<<"y = "<< round(m*1e3)/1e3 << "x" << " " << "+" << " " << round(b*1e3)/1e3<<endl;
}
/*if(m == 1){
cout<<"y = "<< "x" << " " << "+" << " " << round(b*1e3)/1e3;
}
else if(m ==-1)
{cout<<"y = "<< "-x" << " " << "+" << " " << round(b*1e3)/1e3;}
else
{cout<<"y = "<< round(m*1e3)/1e3 << "x" << " " << "+" << " " << round(b*1e3)/1e3;}*/
return 0;
}
} | # 1248, 2024-11-02 11:48:37, PPPPPPPPPP-PPPPP--PP---- (70%)
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
string select[2] = {"mb","func"};
float m = 0,b = 0;
float m_up = 0;
float sum_x = 0,sum_xsqrt = 0,sum_y = 0,sum_xy = 0;
string s;
int n;
cin>>n>>s;
float x[n],y[n];
for(int k = 0;k<n;k++){
cin>>x[k]>>y[k];
}
for(int j = 0;j<n;j++){
m_up += (x[j]*y[j]);
sum_x += x[j];
sum_y += y[j];
sum_xsqrt += pow(x[j],2);
}
sum_xy = sum_x*sum_y;
m = (n*m_up - sum_xy)/(n*sum_xsqrt - pow(sum_x,2));
b = (sum_y - m*sum_x)/n;
if(s == select[0]){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
return 0;
}
if(s == select[1]){
if(m == 0 && b == 0){
cout<<"y = 0"<<endl;
}
else if(m>0 && b>0){
;
}
else if (m>0 && b<0){
cout<<"y = "<< round(m*1e3)/1e3 << "x" <<" "<< "-" << " " << abs(round(b*1e3)/1e3);
}
else if (m<0 && m != -1 && b<0){
cout<<"y = "<< round(m*1e3)/1e3 << "x" <<" "<< "-" << " " << abs(round(b*1e3)/1e3);
}
else if(m == 1 && b != 0){
cout<<"y = "<<"x"<<" "<<"+"<<" "<<round(b*1e3)/1e3<<endl;
}
else if(m == 1 && b == 0){
cout<<"y = x"<<endl;
}
else if(m == -1 && b != 0 && b != -1){
cout<<"y = "<<"-x"<<" "<<"+"<<" "<<round(b*1e3)/1e3<<endl;
}
else if(m == -1 && b != 0 && b == -1){
cout<<"y = "<<"-x"<<" "<<" "<<round(b*1e3)/1e3<<endl;
}
else if(m == -1 && b == 0){
cout<<"y = -x"<<endl;
}
else if( m == 0 && b == -1){
cout<<" y = -1"<<endl;
}
else if( m == 0 && b != 0){
cout<<" y = b"<<endl;
}
else{
cout<<"y = "<< round(m*1e3)/1e3 << "x" << " " << "+" << " " << round(b*1e3)/1e3;
}
/*else if(m == 1 && b != 0){
cout<<"y = "<<"x"<<" "<<"+"<<" "<<round(b*1e3)/1e3<<endl;
}
else if(m == 1 && b == 0){
cout<<"y = x"<<endl;
}
else if(m == -1 && b != 0 && b != -1){
cout<<"y = "<<"-x"<<" "<<"+"<<" "<<round(b*1e3)/1e3<<endl;
}
else if(m == -1 && b != 0 && b == -1){
cout<<"y = "<<"-x"<<" "<<" "<<round(b*1e3)/1e3<<endl;
}
else if(m == -1 && b == 0){
cout<<"y = -x"<<endl;
}
else if( m == 0 && b == -1){
cout<<" y = -1"<<endl;
}
else if( m == 0 && b != 0){
cout<<" y = b"<<endl;
}
else{
cout<<"y = "<< round(m*1e3)/1e3 << "x" << " " << "+" << " " << round(b*1e3)/1e3<<endl;
}*/
/*if(m == 1){
cout<<"y = "<< "x" << " " << "+" << " " << round(b*1e3)/1e3;
}
else if(m ==-1)
{cout<<"y = "<< "-x" << " " << "+" << " " << round(b*1e3)/1e3;}
else
{cout<<"y = "<< round(m*1e3)/1e3 << "x" << " " << "+" << " " << round(b*1e3)/1e3;}*/
return 0;
}
} | # 1249, 2024-11-02 11:54:47, PPPPPPPPPP-PP--P--PP---- (62%)
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
string select[2] = {"mb","func"};
float m = 0,b = 0;
float m_up = 0;
float sum_x = 0,sum_xsqrt = 0,sum_y = 0,sum_xy = 0;
string s;
int n;
cin>>n>>s;
float x[n],y[n];
for(int k = 0;k<n;k++){
cin>>x[k]>>y[k];
}
for(int j = 0;j<n;j++){
m_up += (x[j]*y[j]);
sum_x += x[j];
sum_y += y[j];
sum_xsqrt += pow(x[j],2);
}
sum_xy = sum_x*sum_y;
m = (n*m_up - sum_xy)/(n*sum_xsqrt - pow(sum_x,2));
b = (sum_y - m*sum_x)/n;
if(s == select[0]){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
return 0;
}
if(s == select[1]){
if(m == 0 && b == 0){
cout<<"y = 0"<<endl;
}
else if(m == 1 && b != 0){
cout<<"y = "<<"x"<<" "<<"+"<<" "<<round(b*1e3)/1e3<<endl;
}
else if (m == -1 && b<0){
cout<<"y = "<< "-x" <<" "<< "-" << " " << abs(round(b*1e3)/1e3);
}
else if(m == 1 && b == 0){
cout<<"y = x"<<endl;
}
else if(m == -1 && b != 0 && b != -1){
cout<<"y = "<<"-x"<<" "<<"+"<<" "<<round(b*1e3)/1e3<<endl;
}
else if(m == -1 && b != 0 && b == -1){
cout<<"y = "<<"-x"<<" "<<" "<<round(b*1e3)/1e3<<endl;
}
else if(m == -1 && b == 0){
cout<<"y = -x"<<endl;
}
else if( m == 0 && b == -1){
cout<<" y = -1"<<endl;
}
else if(m>0 && b>0){
;
}
else if (m>0 && b<0){
cout<<"y = "<< round(m*1e3)/1e3 << "x" <<" "<< "-" << " " << abs(round(b*1e3)/1e3);
}
else if( m == 0 && b != 0){
cout<<" y = b"<<endl;
}
else{
cout<<"y = "<< round(m*1e3)/1e3 << "x" << " " << "+" << " " << round(b*1e3)/1e3;
}
/*else if(m == 1 && b != 0){
cout<<"y = "<<"x"<<" "<<"+"<<" "<<round(b*1e3)/1e3<<endl;
}
else if(m == 1 && b == 0){
cout<<"y = x"<<endl;
}
else if(m == -1 && b != 0 && b != -1){
cout<<"y = "<<"-x"<<" "<<"+"<<" "<<round(b*1e3)/1e3<<endl;
}
else if(m == -1 && b != 0 && b == -1){
cout<<"y = "<<"-x"<<" "<<" "<<round(b*1e3)/1e3<<endl;
}
else if(m == -1 && b == 0){
cout<<"y = -x"<<endl;
}
else if( m == 0 && b == -1){
cout<<" y = -1"<<endl;
}
else if( m == 0 && b != 0){
cout<<" y = b"<<endl;
}
else{
cout<<"y = "<< round(m*1e3)/1e3 << "x" << " " << "+" << " " << round(b*1e3)/1e3<<endl;
}*/
/*if(m == 1){
cout<<"y = "<< "x" << " " << "+" << " " << round(b*1e3)/1e3;
}
else if(m ==-1)
{cout<<"y = "<< "-x" << " " << "+" << " " << round(b*1e3)/1e3;}
else
{cout<<"y = "<< round(m*1e3)/1e3 << "x" << " " << "+" << " " << round(b*1e3)/1e3;}*/
return 0;
}
} | # 1250, 2024-11-02 11:56:49, PPPPPPPPPP-PP--P--PP---- (62%)
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
string select[2] = {"mb","func"};
float m = 0,b = 0;
float m_up = 0;
float sum_x = 0,sum_xsqrt = 0,sum_y = 0,sum_xy = 0;
string s;
int n;
cin>>n>>s;
float x[n],y[n];
for(int k = 0;k<n;k++){
cin>>x[k]>>y[k];
}
for(int j = 0;j<n;j++){
m_up += (x[j]*y[j]);
sum_x += x[j];
sum_y += y[j];
sum_xsqrt += pow(x[j],2);
}
sum_xy = sum_x*sum_y;
m = (n*m_up - sum_xy)/(n*sum_xsqrt - pow(sum_x,2));
b = (sum_y - m*sum_x)/n;
if(s == select[0]){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
return 0;
}
if(s == select[1]){
if(m == 0 && b == 0){
cout<<"y = 0"<<endl;
}
else if( m == 0 && b != 0){
cout<<" y = b"<<endl;
}
else if(m == 1 && b != 0){
cout<<"y = "<<"x"<<" "<<"+"<<" "<<round(b*1e3)/1e3<<endl;
}
else if (m == -1 && b<0){
cout<<"y = "<< "-x" <<" "<< "-" << " " << abs(round(b*1e3)/1e3);
}
else if(m == 1 && b == 0){
cout<<"y = x"<<endl;
}
else if(m == -1 && b != 0 && b != -1){
cout<<"y = "<<"-x"<<" "<<"+"<<" "<<round(b*1e3)/1e3<<endl;
}
else if(m == -1 && b != 0 && b == -1){
cout<<"y = "<<"-x"<<" "<<" "<<round(b*1e3)/1e3<<endl;
}
else if(m == -1 && b == 0){
cout<<"y = -x"<<endl;
}
else if( m == 0 && b == -1){
cout<<" y = -1"<<endl;
}
else if(m>0 && b>0){
;
}
else if (m>0 && b<0){
cout<<"y = "<< round(m*1e3)/1e3 << "x" <<" "<< "-" << " " << abs(round(b*1e3)/1e3);
}
else{
cout<<"y = "<< round(m*1e3)/1e3 << "x" << " " << "+" << " " << round(b*1e3)/1e3;
}
/*else if(m == 1 && b != 0){
cout<<"y = "<<"x"<<" "<<"+"<<" "<<round(b*1e3)/1e3<<endl;
}
else if(m == 1 && b == 0){
cout<<"y = x"<<endl;
}
else if(m == -1 && b != 0 && b != -1){
cout<<"y = "<<"-x"<<" "<<"+"<<" "<<round(b*1e3)/1e3<<endl;
}
else if(m == -1 && b != 0 && b == -1){
cout<<"y = "<<"-x"<<" "<<" "<<round(b*1e3)/1e3<<endl;
}
else if(m == -1 && b == 0){
cout<<"y = -x"<<endl;
}
else if( m == 0 && b == -1){
cout<<" y = -1"<<endl;
}
else if( m == 0 && b != 0){
cout<<" y = b"<<endl;
}
else{
cout<<"y = "<< round(m*1e3)/1e3 << "x" << " " << "+" << " " << round(b*1e3)/1e3<<endl;
}*/
/*if(m == 1){
cout<<"y = "<< "x" << " " << "+" << " " << round(b*1e3)/1e3;
}
else if(m ==-1)
{cout<<"y = "<< "-x" << " " << "+" << " " << round(b*1e3)/1e3;}
else
{cout<<"y = "<< round(m*1e3)/1e3 << "x" << " " << "+" << " " << round(b*1e3)/1e3;}*/
return 0;
}
} | # 1251, 2024-11-02 12:04:47, PPPPPPPPPP-PP--P--PP---- (62%)
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
string select[2] = {"mb","func"};
float m = 0,b = 0;
float m_up = 0;
float sum_x = 0,sum_xsqrt = 0,sum_y = 0,sum_xy = 0;
string s;
int n;
cin>>n>>s;
float x[n],y[n];
for(int k = 0;k<n;k++){
cin>>x[k]>>y[k];
}
for(int j = 0;j<n;j++){
m_up += (x[j]*y[j]);
sum_x += x[j];
sum_y += y[j];
sum_xsqrt += pow(x[j],2);
}
sum_xy = sum_x*sum_y;
m = (n*m_up - sum_xy)/(n*sum_xsqrt - pow(sum_x,2));
b = (sum_y - m*sum_x)/n;
if(s == select[0]){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
return 0;
}
if(s == select[1]){
if(m == 0 && b == 0){
cout<<"y = 0"<<endl;
}
else if( m == 0 && b != 0){
cout<<"y = b"<<endl;
}
else if(m == 1 && b != 0){
cout<<"y = "<<"x"<<" "<<"+"<<" "<<round(b*1e3)/1e3<<endl;
}
else if (m == -1 && b<0){
cout<<"y = "<< "-x" <<" "<< "-" << " " << abs(round(b*1e3)/1e3);
}
else if(m == 1 && b == 0){
cout<<"y = x"<<endl;
}
else if(m == -1 && b != 0 && b != -1){
cout<<"y = "<<"-x"<<" "<<"+"<<" "<<round(b*1e3)/1e3<<endl;
}
else if(m == -1 && b != 0 && b == -1){
cout<<"y = "<<"-x"<<" "<<" "<<round(b*1e3)/1e3<<endl;
}
else if(m == -1 && b == 0){
cout<<"y = -x"<<endl;
}
else if( m == 0 && b == -1){
cout<<" y = -1"<<endl;
}
else if(m>0 && b>0){
;
}
else if (m>0 && b<0){
cout<<"y = "<< round(m*1e3)/1e3 << "x" <<" "<< "-" << " " << abs(round(b*1e3)/1e3);
}
else{
cout<<"y = "<< round(m*1e3)/1e3 << "x" << " " << "+" << " " << round(b*1e3)/1e3;
}
return 0;
}
} | # 1252, 2024-11-02 12:09:12, PPPPPPPPPPPP---P--PP---- (62%)
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
string select[2] = {"mb","func"};
float m = 0,b = 0;
float m_up = 0;
float sum_x = 0,sum_xsqrt = 0,sum_y = 0,sum_xy = 0;
string s;
int n;
cin>>n>>s;
float x[n],y[n];
for(int k = 0;k<n;k++){
cin>>x[k]>>y[k];
}
for(int j = 0;j<n;j++){
m_up += (x[j]*y[j]);
sum_x += x[j];
sum_y += y[j];
sum_xsqrt += pow(x[j],2);
}
sum_xy = sum_x*sum_y;
m = (n*m_up - sum_xy)/(n*sum_xsqrt - pow(sum_x,2));
b = (sum_y - m*sum_x)/n;
if(s == select[0]){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
return 0;
}
if(s == select[1]){
if(m>0 && b >0){
cout<<"y = "<< round(m*1e3)/1e3 << "x" << " " << "+" << " " << round(b*1e3)/1e3;
}
else if(m == 0 && b == 0){
cout<<"y = 0"<<endl;
}
else if(m == 1 && b != 0){
cout<<"y = "<<"x"<<" "<<"+"<<" "<<round(b*1e3)/1e3<<endl;
}
else if (m == -1 && b<0){
cout<<"y = "<< "-x" <<" "<< "-" << " " << abs(round(b*1e3)/1e3);
}
else if(m == 1 && b == 0){
cout<<"y = x"<<endl;
}
else if(m == -1 && b != 0 && b != -1){
cout<<"y = "<<"-x"<<" "<<"+"<<" "<<round(b*1e3)/1e3<<endl;
}
else if(m == -1 && b != 0 && b == -1){
cout<<"y = "<<"-x"<<" "<<" "<<round(b*1e3)/1e3<<endl;
}
else if(m == -1 && b == 0){
cout<<"y = -x"<<endl;
}
else if( m == 0 && b == -1){
cout<<" y = -1"<<endl;
}
else if(m>0 && b>0){
;
}
else if (m>0 && b<0){
cout<<"y = "<< round(m*1e3)/1e3 << "x" <<" "<< "-" << " " << abs(round(b*1e3)/1e3);
}
else{
cout<<"y = abs(round(b*1e3)/1e3)"<<endl;
}
return 0;
}
} | # 1253, 2024-11-02 12:09:49, PPPPPPPPPPPP---P--PP---- (62%)
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
string select[2] = {"mb","func"};
float m = 0,b = 0;
float m_up = 0;
float sum_x = 0,sum_xsqrt = 0,sum_y = 0,sum_xy = 0;
string s;
int n;
cin>>n>>s;
float x[n],y[n];
for(int k = 0;k<n;k++){
cin>>x[k]>>y[k];
}
for(int j = 0;j<n;j++){
m_up += (x[j]*y[j]);
sum_x += x[j];
sum_y += y[j];
sum_xsqrt += pow(x[j],2);
}
sum_xy = sum_x*sum_y;
m = (n*m_up - sum_xy)/(n*sum_xsqrt - pow(sum_x,2));
b = (sum_y - m*sum_x)/n;
if(s == select[0]){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
return 0;
}
if(s == select[1]){
if(m>0 && b >0){
cout<<"y = "<< round(m*1e3)/1e3 << "x" << " " << "+" << " " << round(b*1e3)/1e3;
}
else if(m == 0 && b == 0){
cout<<"y = 0"<<endl;
}
else if(m == 1 && b != 0){
cout<<"y = "<<"x"<<" "<<"+"<<" "<<round(b*1e3)/1e3<<endl;
}
else if (m == -1 && b<0){
cout<<"y = "<< "-x" <<" "<< "-" << " " << abs(round(b*1e3)/1e3);
}
else if(m == 1 && b == 0){
cout<<"y = x"<<endl;
}
else if(m == -1 && b != 0 && b != -1){
cout<<"y = "<<"-x"<<" "<<"+"<<" "<<round(b*1e3)/1e3<<endl;
}
else if(m == -1 && b != 0 && b == -1){
cout<<"y = "<<"-x"<<" "<<" "<<round(b*1e3)/1e3<<endl;
}
else if(m == -1 && b == 0){
cout<<"y = -x"<<endl;
}
else if( m == 0 && b == -1){
cout<<" y = -1"<<endl;
}
else if(m>0 && b>0){
;
}
else if (m>0 && b<0){
cout<<"y = "<< round(m*1e3)/1e3 << "x" <<" "<< "-" << " " << abs(round(b*1e3)/1e3);
}
else{
cout<<"y = "<<abs(round(b*1e3)/1e3)<<endl;
}
return 0;
}
} | # 1254, 2024-11-02 12:10:07, PPPPPPPPPPPP---P--PP-P-- (66%)
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
string select[2] = {"mb","func"};
float m = 0,b = 0;
float m_up = 0;
float sum_x = 0,sum_xsqrt = 0,sum_y = 0,sum_xy = 0;
string s;
int n;
cin>>n>>s;
float x[n],y[n];
for(int k = 0;k<n;k++){
cin>>x[k]>>y[k];
}
for(int j = 0;j<n;j++){
m_up += (x[j]*y[j]);
sum_x += x[j];
sum_y += y[j];
sum_xsqrt += pow(x[j],2);
}
sum_xy = sum_x*sum_y;
m = (n*m_up - sum_xy)/(n*sum_xsqrt - pow(sum_x,2));
b = (sum_y - m*sum_x)/n;
if(s == select[0]){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
return 0;
}
if(s == select[1]){
if(m>0 && b >0){
cout<<"y = "<< round(m*1e3)/1e3 << "x" << " " << "+" << " " << round(b*1e3)/1e3;
}
else if(m == 0 && b == 0){
cout<<"y = 0"<<endl;
}
else if(m == 1 && b != 0){
cout<<"y = "<<"x"<<" "<<"+"<<" "<<round(b*1e3)/1e3<<endl;
}
else if (m == -1 && b<0){
cout<<"y = "<< "-x" <<" "<< "-" << " " << abs(round(b*1e3)/1e3);
}
else if(m == 1 && b == 0){
cout<<"y = x"<<endl;
}
else if(m == -1 && b != 0 && b != -1){
cout<<"y = "<<"-x"<<" "<<"+"<<" "<<round(b*1e3)/1e3<<endl;
}
else if(m == -1 && b != 0 && b == -1){
cout<<"y = "<<"-x"<<" "<<" "<<round(b*1e3)/1e3<<endl;
}
else if(m == -1 && b == 0){
cout<<"y = -x"<<endl;
}
else if( m == 0 && b == -1){
cout<<" y = -1"<<endl;
}
else if(m>0 && b>0){
;
}
else if (m>0 && b<0){
cout<<"y = "<< round(m*1e3)/1e3 << "x" <<" "<< "-" << " " << abs(round(b*1e3)/1e3);
}
else{
cout<<"y = "<<round(b*1e3)/1e3<<endl;
}
return 0;
}
} |
# 1255, 2024-11-02 11:12:55, ------------------------ (0%)
#include<iostream>
#include<utility>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
int n,x,y;
string trash;
cin >> n >> trash;
while(n--){
cin >> x>>y;
}
cout << "y=x";
} | # 1256, 2024-11-02 11:13:21, ------------------P----- (4%)
#include<iostream>
#include<utility>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
int n,x,y;
string trash;
cin >> n >> trash;
while(n--){
cin >> x>>y;
}
cout << "y = x";
} | # 1257, 2024-11-02 11:14:15, -------------------P---- (4%)
#include<iostream>
#include<utility>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
int n,x,y;
string trash;
cin >> n >> trash;
while(n--){
cin >> x>>y;
}
cout << "y = -x";
} | # 1258, 2024-11-02 11:14:35, ------------------P----- (4%)
#include<iostream>
#include<utility>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
int n,x,y;
string trash;
cin >> n >> trash;
while(n--){
cin >> x>>y;
}
cout << "y = x";
} | # 1259, 2024-11-02 11:49:50, PPPPPPPPPP-------------- (41%)
#include<iostream>
#include<utility>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
float n=0,x=0,y=0;
string fnc;
cin >> n >> fnc;
float box = n;
float box1=0,box2=0,box3=0,box4=0,box5=0,box6=0,box7=0;
while(box--){
cin >> x>>y;
box1+= x*y;
box2 +=x;
box3+=y;
box4+= x*x;
box5+=x;
box6+=y;
box7+=x;
}
float m = ((n*box1)-(box2*box3))/((n*box4)-(box5*box5));
float b = (box6-(m*box7))/n;
cout << round(m*1e3)/1e3<<endl;
cout << round(b*1e3)/1e3 << endl;
} | # 1260, 2024-11-02 12:04:58, PPPPPPPPPP--------PP---- (50%)
#include<iostream>
#include<utility>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
float n=0,x=0,y=0;
string fnc;
cin >> n >> fnc;
float box = n;
float box1=0,box2=0,box3=0,box4=0,box5=0,box6=0,box7=0;
while(box--){
cin >> x>>y;
box1+= x*y;
box2 +=x;
box3+=y;
box4+= x*x;
box5+=x;
box6+=y;
box7+=x;
}
float m = ((n*box1)-(box2*box3))/((n*box4)-(box5*box5));
float b = (box6-(m*box7))/n;
bool have_x = false;
if(fnc=="mb"){
cout << round(m*1e3)/1e3<<endl;
cout << round(b*1e3)/1e3 << endl;
}
else{
cout<<"y = ";
if(m!=1&&m!=-1&&m!=0){
cout <<m;
have_x = true;
}else{
if(m==-1) cout<<"-";
have_x = true;
}
if(have_x){
cout<<"x";
}
if(have_x && b>0){
cout <<" + "<<b<<endl;
}else if(!have_x){
cout <<b<<endl;
}else if(have_x && b<0){
cout<<" - "<<b<<endl;
}
}
} | # 1261, 2024-11-02 12:07:24, PPPPPPPPPP--------PP---- (50%)
#include<iostream>
#include<utility>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
float n=0,x=0,y=0;
string fnc;
cin >> n >> fnc;
float box = n;
float box1=0,box2=0,box3=0,box4=0,box5=0,box6=0,box7=0;
while(box--){
cin >> x>>y;
box1+= x*y;
box2 +=x;
box3+=y;
box4+= x*x;
box5+=x;
box6+=y;
box7+=x;
}
float m = ((n*box1)-(box2*box3))/((n*box4)-(box5*box5));
float b = (box6-(m*box7))/n;
bool have_x = false;
if(fnc=="mb"){
cout << round(m*1e3)/1e3<<endl;
cout << round(b*1e3)/1e3 << endl;
}
else{
cout<<"y = ";
if(m!=1&&m!=-1&&m!=0){
cout <<m;
have_x = true;
}else{
if(m==-1) cout<<"-";
have_x = true;
}
if(have_x){
cout<<"x";
}
if(have_x && b>0){
cout <<" + "<<b<<endl;
}else if(!have_x){
cout <<b<<endl;
}else if(have_x && b<0){
cout<<" - "<<-b<<endl;
}
}
} | # 1262, 2024-11-02 12:09:01, Compilation error (0%)
#include<iostream>
#include<utility>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
float n=0,x=0,y=0;
string fnc;
cin >> n >> fnc;
float box = n;
float box1=0,box2=0,box3=0,box4=0,box5=0,box6=0,box7=0;
while(box--){
cin >> x>>y;
box1+= x*y;
box2 +=x;
box3+=y;
box4+= x*x;
box5+=x;
box6+=y;
box7+=x;
}
float m = ((n*box1)-(box2*box3))/((n*box4)-(box5*box5));
float b = (box6-(m*box7))/n;
bool have_x = false;
if(fnc=="mb"){
cout << round(m*1e3)/1e3<<endl;
cout << round(b*1e3)/1e3 << endl;
}
else{
cout<<"y = ";
if(m!=1&&m!=-1&&m!=0){
cout <<round(m*1e3)/1e3<;
have_x = true;
}else{
if(m==-1) cout<<"-";
have_x = true;
}
if(have_x){
cout<<"x";
}
if(have_x && b>0){
cout <<" + "<<round(b*1e3)/1e3<<endl;
}else if(!have_x){
cout <<b<<endl;
}else if(have_x && b<0){
cout<<" - "<<-round(b*1e3)/1e3<<endl;
}
}
} | # 1263, 2024-11-02 12:09:16, Compilation error (0%)
#include<iostream>
#include<utility>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
float n=0,x=0,y=0;
string fnc;
cin >> n >> fnc;
float box = n;
float box1=0,box2=0,box3=0,box4=0,box5=0,box6=0,box7=0;
while(box--){
cin >> x>>y;
box1+= x*y;
box2 +=x;
box3+=y;
box4+= x*x;
box5+=x;
box6+=y;
box7+=x;
}
float m = ((n*box1)-(box2*box3))/((n*box4)-(box5*box5));
float b = (box6-(m*box7))/n;
bool have_x = false;
if(fnc=="mb"){
cout << round(m*1e3)/1e3<<endl;
cout << round(b*1e3)/1e3 << endl;
}
else{
cout<<"y = ";
if(m!=1&&m!=-1&&m!=0){
cout <<round(m*1e3)/1e3<;
have_x = true;
}else{
if(m==-1) cout<<"-";
have_x = true;
}
if(have_x){
cout<<"x";
}
if(have_x && b>0){
cout <<" + "<<round(b*1e3)/1e3<<endl;
}else if(!have_x){
cout <<b<<endl;
}else if(have_x && b<0){
cout<<" - "<<round(b*1e3)/1e3<<endl;
}
}
} | # 1264, 2024-11-02 12:09:37, PPPPPPPPPPPPPPP---PP---- (70%)
#include<iostream>
#include<utility>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
float n=0,x=0,y=0;
string fnc;
cin >> n >> fnc;
float box = n;
float box1=0,box2=0,box3=0,box4=0,box5=0,box6=0,box7=0;
while(box--){
cin >> x>>y;
box1+= x*y;
box2 +=x;
box3+=y;
box4+= x*x;
box5+=x;
box6+=y;
box7+=x;
}
float m = ((n*box1)-(box2*box3))/((n*box4)-(box5*box5));
float b = (box6-(m*box7))/n;
bool have_x = false;
if(fnc=="mb"){
cout << round(m*1e3)/1e3<<endl;
cout << round(b*1e3)/1e3 << endl;
}
else{
cout<<"y = ";
if(m!=1&&m!=-1&&m!=0){
cout <<round(m*1e3)/1e3;
have_x = true;
}else{
if(m==-1) cout<<"-";
have_x = true;
}
if(have_x){
cout<<"x";
}
if(have_x && b>0){
cout <<" + "<<round(b*1e3)/1e3<<endl;
}else if(!have_x){
cout <<b<<endl;
}else if(have_x && b<0){
cout<<" - "<<-round(b*1e3)/1e3<<endl;
}
}
} |
# 1265, 2024-11-02 13:32:03, ------------------------ (0%)
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
vector<int> xq1,xq2,xq3,xq4,yq1,yq2,yq3,yq4;
int n,x,y;cin>>n;
for(int i=0;i<n;i++){
cin>>x>>y;
if(x>0&&y>0){
xq1.push_back(x);
yq1.push_back(y);
// q1.push_back(make_pair(x,y));
}else if(x<0&&y>0){
xq2.push_back(x);
yq2.push_back(y);
// q2.push_back(make_pair(x,y));
}else if(x<0&&y<0){
xq3.push_back(x);
yq3.push_back(y);
// q3.push_back(make_pair(x,y));
}else if(x>0&&y<0){
xq4.push_back(x);
yq4.push_back(y);
// q4.push_back(make_pair(x,y));
}
}
sort(xq1.begin(),xq1.end());
sort(xq2.begin(),xq2.end());
sort(xq3.begin(),xq3.end());
sort(xq4.begin(),xq4.end());
sort(yq1.begin(),yq1.end());
sort(yq2.begin(),yq2.end());
sort(yq3.begin(),yq3.end());
sort(yq4.begin(),yq4.end());
// cout<<"Q1";
// for(auto c:xq1){
// cout<<c;
// }
// cout<< "\n , ";
// for(auto c:yq1){
// cout<<c;
// }
// cout<<"q2";
// for(auto c:xq2){
// cout<<c;
// }
// cout<< "\n , ";
// for(auto c:yq2){
// cout<<c;
// }
if(xq1.empty()&&xq2.empty()&&xq3.empty()&&xq4.empty()){
cout<<"No point in any quadrant";
}
if(!xq1.empty()){
cout<<"Q1: ("<<xq1[0]<<", "<<yq1[0]<<") ("<<xq1.back()<<", ";
cout<<yq1.back()<<") "<<abs(xq1[0]-xq1.back()) * abs(yq1[0]-yq1.back()) ;
cout<<endl;
}
if(!xq2.empty()){
cout<<"Q2: ("<<xq2[0]<<", "<<yq2[0]<<") ("<<xq2.back()<<", ";
cout<<yq2.back()<<") "<<abs(xq2[0]-xq2.back()) * abs(yq2[0]-yq2.back()) ;
cout<<endl;
}
if(!xq3.empty()){
cout<<"Q3: ("<<xq3[0]<<", "<<yq3[0]<<") ("<<xq3.back()<<", ";
cout<<yq3.back()<<") "<<abs(xq3[0]-xq3.back()) * abs(yq3[0]-yq3.back()) ;
cout<<endl;
}
if(!xq4.empty()){
cout<<"Q4: ("<<xq4[0]<<", "<<yq4[0]<<") ("<<xq4.back()<<", ";
cout<<yq4.back()<<") "<<abs(xq4[0]-xq4.back()) * abs(yq4[0]-yq4.back()) ;
}
return 0;
} | # 1266, 2024-11-02 14:32:25, ------------------------ (0%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int N;cin>>N;
string nn;cin>>nn;
float m,b;
float x,y,m1=0,m2b2=0,m3b1=0,m4=0;
for(int i=0;i<N;i++){
cin>>x>>y;
m1+=x*y;
m2b2+=x;
m3b1+=y;
m4+=x*x;
}
m = ((N*m1) - (m2b2*m3b1))/((N*m4)-((m2b2*m2b2)));
b = ((m3b1)-(m*(m2b2)))/N;
//cout<<round(m*1e3)/1e3<<"\n"<<round(b*1e3)/1e3;
// cout<<m<<" "<<x<<" "<<b<<" "<< (m*x)+b;
cout<<m<<" "<<x<<" "<<b<<endl;
if(nn=="mb"){
cout<<round(m*1e3)/1e3<<"\n"<<round(b*1e3)/1e3;
}else{
if(m==0||x==0){cout<<"y = "<<b;}
if(m>1&&x!=0&&b==0){cout<<"y = "<<round(m*1e3)/1e3<<"x";}
if(m<-1&&x!=0&&b==0){cout<<"y = -"<<round(m*1e3)/1e3<<"x";}
if(m>1&&x>0&&b>0){cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
if(m>1&&x>0&&b<0){cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
if(m<-1&&x>0&&b>0){cout<<"y = -"<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
if(m<-1&&x>0&&b<0){cout<<"y = -"<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
if(m>1&&x<0&&b>0){cout<<"y = -"<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
if(m>1&&x<0&&b<0){cout<<"y = -"<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
if(m<-1&&x<0&&b>0){cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
if(m<-1&&x<0&&b<0){cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
if(m==1&&x>0&&b>0){cout<<"y = "<<"x + "<<round(b*1e3)/1e3;}
if(m==1&&x>0&&b<0){cout<<"y = "<<"x - "<<round(b*1e3)/1e3;}
if(m==1&&x<0&&b>0){cout<<"y = -"<<"x + "<<round(b*1e3)/1e3;}
if(m==1&&x<0&&b<0){cout<<"y = -"<<"x - "<<round(b*1e3)/1e3;}
if(m==1&&x>0&&b==0){cout<<"y = "<<"x";}
if(m==1&&x<0&&b==0){cout<<"y = -"<<"x";}
if(m==-1&&b<0){cout<<"y = -x - "<<abs(b);}
if(m==-1&&b>0){cout<<"y = -x + "<<b;}
if(m==-1&&b==0){cout<<"y = -x";}
}
return 0;
} | # 1267, 2024-11-02 14:33:47, PPPPPPPPPPPP---P--PP-P-- (66%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int N;cin>>N;
string nn;cin>>nn;
float m,b;
float x,y,m1=0,m2b2=0,m3b1=0,m4=0;
for(int i=0;i<N;i++){
cin>>x>>y;
m1+=x*y;
m2b2+=x;
m3b1+=y;
m4+=x*x;
}
m = ((N*m1) - (m2b2*m3b1))/((N*m4)-((m2b2*m2b2)));
b = ((m3b1)-(m*(m2b2)))/N;
//cout<<round(m*1e3)/1e3<<"\n"<<round(b*1e3)/1e3;
// cout<<m<<" "<<x<<" "<<b<<" "<< (m*x)+b;
// cout<<m<<" "<<x<<" "<<b<<endl;
if(nn=="mb"){
cout<<round(m*1e3)/1e3<<"\n"<<round(b*1e3)/1e3;
}else{
if(m==0||x==0){cout<<"y = "<<b;}
if(m>1&&x!=0&&b==0){cout<<"y = "<<round(m*1e3)/1e3<<"x";}
if(m<-1&&x!=0&&b==0){cout<<"y = -"<<round(m*1e3)/1e3<<"x";}
if(m>1&&x>0&&b>0){cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
if(m>1&&x>0&&b<0){cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
if(m<-1&&x>0&&b>0){cout<<"y = -"<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
if(m<-1&&x>0&&b<0){cout<<"y = -"<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
if(m>1&&x<0&&b>0){cout<<"y = -"<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
if(m>1&&x<0&&b<0){cout<<"y = -"<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
if(m<-1&&x<0&&b>0){cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
if(m<-1&&x<0&&b<0){cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
if(m==1&&x>0&&b>0){cout<<"y = "<<"x + "<<round(b*1e3)/1e3;}
if(m==1&&x>0&&b<0){cout<<"y = "<<"x - "<<round(b*1e3)/1e3;}
if(m==1&&x<0&&b>0){cout<<"y = -"<<"x + "<<round(b*1e3)/1e3;}
if(m==1&&x<0&&b<0){cout<<"y = -"<<"x - "<<round(b*1e3)/1e3;}
if(m==1&&x>0&&b==0){cout<<"y = "<<"x";}
if(m==1&&x<0&&b==0){cout<<"y = -"<<"x";}
if(m==-1&&b<0){cout<<"y = -x - "<<abs(b);}
if(m==-1&&b>0){cout<<"y = -x + "<<b;}
if(m==-1&&b==0){cout<<"y = -x";}
}
return 0;
} | # 1268, 2024-11-02 14:40:16, PPPPPPPPPPPP---P--P--P-- (62%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int N;cin>>N;
string nn;cin>>nn;
float m,b;
float x,y,m1=0,m2b2=0,m3b1=0,m4=0;
for(int i=0;i<N;i++){
cin>>x>>y;
m1+=x*y;
m2b2+=x;
m3b1+=y;
m4+=x*x;
}
m = ((N*m1) - (m2b2*m3b1))/((N*m4)-((m2b2*m2b2)));
b = ((m3b1)-(m*(m2b2)))/N;
//cout<<round(m*1e3)/1e3<<"\n"<<round(b*1e3)/1e3;
// cout<<m<<" "<<x<<" "<<b<<" "<< (m*x)+b;
// cout<<m<<" "<<x<<" "<<b<<endl;
if(nn=="mb"){
cout<<round(m*1e3)/1e3<<"\n"<<round(b*1e3)/1e3;
}else{
if(m==0||x==0){cout<<"y = "<<b;}
if(m>1&&x!=0&&b==0){cout<<"y = "<<round(m*1e3)/1e3<<"x";}
if(m<-1&&x!=0&&b==0){cout<<"y = -"<<round(m*1e3)/1e3<<"x";}
if(m>1&&x>0&&b>0){cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
if(m>1&&x>0&&b<0){cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
if(m<-1&&x>0&&b>0){cout<<"y = -"<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
if(m<-1&&x>0&&b<0){cout<<"y = -"<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
if(m>1&&x<0&&b>0){cout<<"y = -"<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
if(m>1&&x<0&&b<0){cout<<"y = -"<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
if(m<-1&&x<0&&b>0){cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
if(m<-1&&x<0&&b<0){cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
if(m==1&&x>0&&b>0){cout<<"y = "<<"x + "<<round(b*1e3)/1e3;}
if(m==1&&x>0&&b<0){cout<<"y = "<<"x - "<<round(b*1e3)/1e3;}
if(m==1&&x<0&&b>0){cout<<"y = -"<<"x + "<<round(b*1e3)/1e3;}
if(m==1&&x<0&&b<0){cout<<"y = -"<<"x - "<<round(b*1e3)/1e3;}
if(m==1&&x>0&&b==0){cout<<"y = "<<"x";}
if(m==1&&x<0&&b==0){cout<<"y = -"<<"x";}
if(m=-0){cout<<"y = "<<b;}
if(m==-1&&b<0){cout<<"y = -x - "<<abs(b);}
if(m==-1&&b>0){cout<<"y = -x + "<<b;}
if(m==-1&&b==0){cout<<"y = -x";}
}
return 0;
} | # 1269, 2024-11-02 14:44:57, PPPPPPPPPPPP---P--P--P-- (62%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int N;cin>>N;
string nn;cin>>nn;
float m,b;
float x,y,m1=0,m2b2=0,m3b1=0,m4=0;
for(int i=0;i<N;i++){
cin>>x>>y;
m1+=x*y;
m2b2+=x;
m3b1+=y;
m4+=x*x;
}
m = ((N*m1) - (m2b2*m3b1))/((N*m4)-((m2b2*m2b2)));
b = ((m3b1)-(m*(m2b2)))/N;
//cout<<round(m*1e3)/1e3<<"\n"<<round(b*1e3)/1e3;
// cout<<m<<" "<<x<<" "<<b<<" "<< (m*x)+b;
// cout<<m<<" "<<x<<" "<<b<<endl;
if(nn=="mb"){
cout<<round(m*1e3)/1e3<<"\n"<<round(b*1e3)/1e3;
}else{
if(m==0||x==0){cout<<"y = "<<b;}
if(m>1&&x!=0&&b==0){cout<<"y = "<<round(m*1e3)/1e3<<"x";}
if(m<-1&&x!=0&&b==0){cout<<"y = -"<<round(m*1e3)/1e3<<"x";}
if(m>1&&x>0&&b>0){cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
if(m>1&&x>0&&b<0){cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
if(m<-1&&x>0&&b>0){cout<<"y = -"<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
if(m<-1&&x>0&&b<0){cout<<"y = -"<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
if(m>1&&x<0&&b>0){cout<<"y = -"<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
if(m>1&&x<0&&b<0){cout<<"y = -"<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
if(m<-1&&x<0&&b>0){cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
if(m<-1&&x<0&&b<0){cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
if(m==1&&x>0&&b>0){cout<<"y = "<<"x + "<<round(b*1e3)/1e3;}
if(m==1&&x>0&&b<0){cout<<"y = "<<"x - "<<round(b*1e3)/1e3;}
if(m==1&&x<0&&b>0){cout<<"y = -"<<"x + "<<round(b*1e3)/1e3;}
if(m==1&&x<0&&b<0){cout<<"y = -"<<"x - "<<round(b*1e3)/1e3;}
if(m==1&&x>0&&b==0){cout<<"y = "<<"x";}
if(m==1&&x<0&&b==0){cout<<"y = -"<<"x";}
if(m==-1&&b<0){cout<<"y = -x - "<<abs(round(b*1e3)/1e3);}
if(m==-1&&b>0){cout<<"y = -x + "<<round(b*1e3)/1e3;}
if(m==-1&&b==0){cout<<"sdsd";cout<<"y = -x";}
if(m=-0){cout<<"y = "<<b;}
}
return 0;
} | # 1270, 2024-11-02 14:48:34, PPPPPPPPPPPP---P--PP-P-- (66%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int N;cin>>N;
string nn;cin>>nn;
float m,b;
float x,y,m1=0,m2b2=0,m3b1=0,m4=0;
for(int i=0;i<N;i++){
cin>>x>>y;
m1+=x*y;
m2b2+=x;
m3b1+=y;
m4+=x*x;
}
m = ((N*m1) - (m2b2*m3b1))/((N*m4)-((m2b2*m2b2)));
b = ((m3b1)-(m*(m2b2)))/N;
//cout<<round(m*1e3)/1e3<<"\n"<<round(b*1e3)/1e3;
// cout<<m<<" "<<x<<" "<<b<<" "<< (m*x)+b;
// cout<<m<<" "<<x<<" "<<b<<endl;
if(nn=="mb"){
cout<<round(m*1e3)/1e3<<"\n"<<round(b*1e3)/1e3;
}else{
if(m==0||x==0){cout<<"y = "<<b;}
if(m>1&&x!=0&&b==0){cout<<"y = "<<round(m*1e3)/1e3<<"x";}
if(m<-1&&x!=0&&b==0){cout<<"y = -"<<round(m*1e3)/1e3<<"x";}
if(m>1&&x>0&&b>0){cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
if(m>1&&x>0&&b<0){cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
if(m<-1&&x>0&&b>0){cout<<"y = -"<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
if(m<-1&&x>0&&b<0){cout<<"y = -"<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
if(m>1&&x<0&&b>0){cout<<"y = -"<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
if(m>1&&x<0&&b<0){cout<<"y = -"<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
if(m<-1&&x<0&&b>0){cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
if(m<-1&&x<0&&b<0){cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
if(m==1&&x>0&&b>0){cout<<"y = "<<"x + "<<round(b*1e3)/1e3;}
if(m==1&&x>0&&b<0){cout<<"y = "<<"x - "<<round(b*1e3)/1e3;}
if(m==1&&x<0&&b>0){cout<<"y = -"<<"x + "<<round(b*1e3)/1e3;}
if(m==1&&x<0&&b<0){cout<<"y = -"<<"x - "<<round(b*1e3)/1e3;}
if(m==1&&x>0&&b==0){cout<<"y = "<<"x";}
if(m==1&&x<0&&b==0){cout<<"y = -"<<"x";}
if(m==-1&&b<0){cout<<"y = -x - "<<abs(round(b*1e3)/1e3);}
if(m==-1&&b>0){cout<<"y = -x + "<<round(b*1e3)/1e3;}
if(m==-1&&b==0){cout<<"y = -x";}
if(m=-0){cout<<"y = "<<b;}
}
return 0;
} | # 1271, 2024-11-02 14:50:28, PPPPPPPPPPPP---PP-PP-P-- (70%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int N;cin>>N;
string nn;cin>>nn;
float m,b;
float x,y,m1=0,m2b2=0,m3b1=0,m4=0;
for(int i=0;i<N;i++){
cin>>x>>y;
m1+=x*y;
m2b2+=x;
m3b1+=y;
m4+=x*x;
}
m = ((N*m1) - (m2b2*m3b1))/((N*m4)-((m2b2*m2b2)));
b = ((m3b1)-(m*(m2b2)))/N;
//cout<<round(m*1e3)/1e3<<"\n"<<round(b*1e3)/1e3;
// cout<<m<<" "<<x<<" "<<b<<" "<< (m*x)+b;
// cout<<m<<" "<<x<<" "<<b<<endl;
if(nn=="mb"){
cout<<round(m*1e3)/1e3<<"\n"<<round(b*1e3)/1e3;
}else{
if(m==0||x==0){cout<<"y = "<<b;}
else if(m>1&&x!=0&&b==0){cout<<"y = "<<round(m*1e3)/1e3<<"x";}
else if(m<-1&&x!=0&&b==0){cout<<"y = -"<<round(m*1e3)/1e3<<"x";}
else if(m>1&&x>0&&b>0){cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
else if(m>1&&x>0&&b<0){cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
else if(m<-1&&x>0&&b>0){cout<<"y = -"<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
else if(m<-1&&x>0&&b<0){cout<<"y = -"<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
else if(m>1&&x<0&&b>0){cout<<"y = -"<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
else if(m>1&&x<0&&b<0){cout<<"y = -"<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
else if(m<-1&&x<0&&b>0){cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
else if(m<-1&&x<0&&b<0){cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
else if(m==1&&x>0&&b>0){cout<<"y = "<<"x + "<<round(b*1e3)/1e3;}
else if(m==1&&x>0&&b<0){cout<<"y = "<<"x - "<<round(b*1e3)/1e3;}
else if(m==1&&x<0&&b>0){cout<<"y = -"<<"x + "<<round(b*1e3)/1e3;}
else if(m==1&&x<0&&b<0){cout<<"y = -"<<"x - "<<round(b*1e3)/1e3;}
else if(m==1&&x>0&&b==0){cout<<"y = "<<"x";}
else if(m==1&&x<0&&b==0){cout<<"y = -"<<"x";}
else if(m==-1&&b<0){cout<<"y = -x - "<<abs(round(b*1e3)/1e3);}
else if(m==-1&&b>0){cout<<"y = -x + "<<round(b*1e3)/1e3;}
else if(m==-1&&b==0){cout<<"y = -x";}
else{cout<<"y = "<<b;}
}
return 0;
} | # 1272, 2024-11-02 15:23:23, PPPPPPPPPPPP---PP-PP-P-- (70%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int N;cin>>N;
string nn;cin>>nn;
float m,b;
float x,y,m1=0,m2b2=0,m3b1=0,m4=0;
for(int i=0;i<N;i++){
cin>>x>>y;
m1+=x*y;
m2b2+=x;
m3b1+=y;
m4+=x*x;
}
m = ((N*m1) - (m2b2*m3b1))/((N*m4)-((m2b2*m2b2)));
b = ((m3b1)-(m*(m2b2)))/N;
//cout<<round(m*1e3)/1e3<<"\n"<<round(b*1e3)/1e3;
// cout<<m<<" "<<x<<" "<<b<<" "<< (m*x)+b;
// cout<<m<<" "<<x<<" "<<b<<endl;
if(nn=="mb"){
cout<<round(m*1e3)/1e3<<"\n"<<round(b*1e3)/1e3;
}else{
if(m==0||x==0){cout<<"y = "<<b;}
else if(m>1&&x!=0&&b==0){cout<<"y = "<<round(m*1e3)/1e3<<"x";}
else if(m<-1&&x!=0&&b==0){cout<<"y = -"<<round(m*1e3)/1e3<<"x";}
else if(m>1&&x>0&&b>0){cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
else if(m>1&&x>0&&b<0){cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
else if(m<-1&&x>0&&b>0){cout<<"y = -"<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
else if(m<-1&&x>0&&b<0){cout<<"y = -"<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
else if(m>1&&x<0&&b>0){cout<<"y = -"<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
else if(m>1&&x<0&&b<0){cout<<"y = -"<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
else if(m<-1&&x<0&&b>0){cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
else if(m<-1&&x<0&&b<0){cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
else if(m==1&&x>0&&b>0){cout<<"y = "<<"x + "<<round(b*1e3)/1e3;}
else if(m==1&&x>0&&b<0){cout<<"y = "<<"x - "<<round(b*1e3)/1e3;}
else if(m==1&&x<0&&b>0){cout<<"y = -"<<"x + "<<round(b*1e3)/1e3;}
else if(m==1&&x<0&&b<0){cout<<"y = -"<<"x - "<<round(b*1e3)/1e3;}
else if(m==1&&x>0&&b==0){cout<<"y = "<<"x";}
else if(m==1&&x<0&&b==0){cout<<"y = -"<<"x";}
else if(m==-1&&b<0){cout<<"y = -x - "<<abs(round(b*1e3)/1e3);}
else if(m==-1&&b>0){cout<<"y = -x + "<<round(b*1e3)/1e3;}
else if(m==-1&&b==0){cout<<"y = -x";}
else if((m*x)+b==0 ){cout<<"y = 0";}
else{cout<<"y = "<<b;}
}
return 0;
} | # 1273, 2024-11-02 15:25:10, PPPPPPPPPPPP---PP-PP-P-- (70%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int N;cin>>N;
string nn;cin>>nn;
float m,b;
float x,y,m1=0,m2b2=0,m3b1=0,m4=0;
for(int i=0;i<N;i++){
cin>>x>>y;
m1+=x*y;
m2b2+=x;
m3b1+=y;
m4+=x*x;
}
m = ((N*m1) - (m2b2*m3b1))/((N*m4)-((m2b2*m2b2)));
b = ((m3b1)-(m*(m2b2)))/N;
//cout<<round(m*1e3)/1e3<<"\n"<<round(b*1e3)/1e3;
// cout<<m<<" "<<x<<" "<<b<<" "<< (m*x)+b;
// cout<<m<<" "<<x<<" "<<b<<endl;
if(nn=="mb"){
cout<<round(m*1e3)/1e3<<"\n"<<round(b*1e3)/1e3;
}else{
if(m==0||x==0){cout<<"y = "<<b;}
else if(m>1&&x!=0&&b==0){cout<<"y = "<<round(m*1e3)/1e3<<"x";}
else if(m<-1&&x!=0&&b==0){cout<<"y = -"<<round(m*1e3)/1e3<<"x";}
else if(m>1&&x>0&&b>0){cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
else if(m>1&&x>0&&b<0){cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
else if(m<-1&&x>0&&b>0){cout<<"y = -"<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
else if(m<-1&&x>0&&b<0){cout<<"y = -"<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
else if(m>1&&x<0&&b>0){cout<<"y = -"<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
else if(m>1&&x<0&&b<0){cout<<"y = -"<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
else if(m<-1&&x<0&&b>0){cout<<"y = "<<round(m*1e3)/1e3<<"x + "<<round(b*1e3)/1e3;}
else if(m<-1&&x<0&&b<0){cout<<"y = "<<round(m*1e3)/1e3<<"x - "<<abs(round(b*1e3)/1e3);}
else if(m==1&&x>0&&b>0){cout<<"y = "<<"x + "<<round(b*1e3)/1e3;}
else if(m==1&&x>0&&b<0){cout<<"y = "<<"x - "<<round(b*1e3)/1e3;}
else if(m==1&&x<0&&b>0){cout<<"y = -"<<"x + "<<round(b*1e3)/1e3;}
else if(m==1&&x<0&&b<0){cout<<"y = -"<<"x - "<<round(b*1e3)/1e3;}
else if(m==1&&x>0&&b==0){cout<<"y = "<<"x";}
else if(m==1&&x<0&&b==0){cout<<"y = -"<<"x";}
else if(m==-1&&b<0){cout<<"y = -x - "<<abs(round(b*1e3)/1e3);}
else if(m==-1&&b>0){cout<<"y = -x + "<<round(b*1e3)/1e3;}
else if(m==-1&&b==0){cout<<"y = -x";}
else if(m==0&&x==0&&b==0 ){cout<<"y = 0";}
else{cout<<"y = "<<b;}
}
return 0;
} |
# 1274, 2024-11-02 10:54:28, ------------------------ (0%)
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int n;
double xi,yi,m,b,f1=0,f2=0;
double sumx,sumy,sumxx=0;
string s;
cin >> n >> s;
while(n--){
cin >> xi >> yi;
if(s=="mb"){
sumx+=xi;
sumy+=yi;
sumxx+=xi*xi;
}
else if(s=="func"){
}
}
if(s=="mb"){
double m=((n*sumx*sumy)-(sumx*sumy))/((n*sumxx)-(sumx*sumx));
double b=(sumy-sumx)/n;
cout << m << endl << b;
}
else if(s=="func"){
if(m==-1){
if(b==0){
cout << "y = -x" ;
}
else if(b<0){
cout << "y = -";
}
}
else if(m==1){
if(b==0){
cout << "y = x";
}
}
}
} | # 1275, 2024-11-02 11:19:08, -----P------------------ (4%)
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int n;
double xi,yi,m,b,f1=0,f2=0;
double sumx=0,sumy=0,sumxx=0;
string s;
cin >> n >> s;
for(int i=0; i<n; i++){
cin >> xi >> yi;
if(s=="mb"){
sumx+=xi;
sumy+=yi;
sumxx+=(xi*xi);
//cout << sumx << ":"<<sumy << ":"<< sumxx << endl;
}
}
//cout << sumx << ":"<<sumy << ":"<< sumxx << endl;
if(s=="mb"){
double m=((n*sumx*sumy)-(sumx*sumy))/((n*sumxx)-(sumx*sumx));
double b=(sumy-(m*sumx))/n;
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 ;
}
// else if(s=="func"){
// if(m==-1){
// if(b==0){
// cout << "y = -x" ;
// }
// else if(b<0){
// cout << "y = -";
// }
// }
// else if(m==1){
// if(b==0){
// cout << "y = x";
// }
// }
// }
} | # 1276, 2024-11-02 11:27:03, ------------------------ (0%)
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int n;
double xi,yi,m,b,f1=0,f2=0;
double sumx=0,sumy=0,sumxx,sumxy=0;
string s;
cin >> n >> s;
for(int i=0; i<n; i++){
cin >> xi >> yi;
if(s=="mb"){
sumx+=xi;
sumy+=yi;
sumxx+=(xi*xi);
sumxy+=(xi*yi);
cout << sumx << ":"<<sumy << ":"<< sumxx << ":"<< sumxy << endl;
}
}
//cout << sumx << ":"<<sumy << ":"<< sumxx << endl;
if(s=="mb"){
double m=((n*sumxy)-(sumx*sumy))/((n*sumxx)-(sumx*sumx));
double b=(sumy-(m*sumx))/n;
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 ;
}
// else if(s=="func"){
// if(m==-1){
// if(b==0){
// cout << "y = -x" ;
// }
// else if(b<0){
// cout << "y = -";
// }
// }
// else if(m==1){
// if(b==0){
// cout << "y = x";
// }
// }
// }
} | # 1277, 2024-11-02 11:28:27, PPPPPPPPPP-------------- (41%)
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int n;
double xi,yi,m,b,f1=0,f2=0;
double sumx=0,sumy=0,sumxx,sumxy=0;
string s;
cin >> n >> s;
for(int i=0; i<n; i++){
cin >> xi >> yi;
if(s=="mb"){
sumx+=xi;
sumy+=yi;
sumxx+=(xi*xi);
sumxy+=(xi*yi);
//cout << sumx << ":"<<sumy << ":"<< sumxx << ":"<< sumxy << endl;
}
}
//cout << sumx << ":"<<sumy << ":"<< sumxx << endl;
if(s=="mb"){
double m=((n*sumxy)-(sumx*sumy))/((n*sumxx)-(sumx*sumx));
double b=(sumy-(m*sumx))/n;
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 ;
}
// else if(s=="func"){
// if(m==-1){
// if(b==0){
// cout << "y = -x" ;
// }
// else if(b<0){
// cout << "y = -";
// }
// }
// else if(m==1){
// if(b==0){
// cout << "y = x";
// }
// }
// }
} | # 1278, 2024-11-02 11:56:01, PPPPPPPPPP-----P--PP-P-- (58%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int n;
double xi,yi,m,b,f1=0,f2=0;
double sumx=0,sumy=0,sumxx,sumxy=0;
vector<double> vx,vy;
string s;
cin >> n >> s;
for(int i=0; i<n; i++){
cin >> xi >> yi;
if(s=="mb"){
sumx+=xi;
sumy+=yi;
sumxx+=(xi*xi);
sumxy+=(xi*yi);
//cout << sumx << ":"<<sumy << ":"<< sumxx << ":"<< sumxy << endl;
}
if(s=="func"){
vx.push_back(xi);
vy.push_back(yi);
}
}
// for(auto e: vy){
// cout << e;
// }
//cout << sumx << ":"<<sumy << ":"<< sumxx << endl;
if(s=="mb"){
double m=((n*sumxy)-(sumx*sumy))/((n*sumxx)-(sumx*sumx));
double b=(sumy-(m*sumx))/n;
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 ;
}
else if(s=="func"){
f1=(vy[0]-vy[1])/(vx[0]-vx[1]);
f2=vy[1]-(f1*vx[1]);
//cout << f1 << f2;
if(f1==-1){
if(f2==0){
cout << "y = -x" ;
}
else if(b<0){
cout << "y = -x - " << (-1)*f2;
}
else if(b>0){
cout << "y = -x + "<< f2;
}
}
else if(f1==0){
if(f2==0){
cout << "y = 0";
}
else if(f2<0){
cout << "y = " << f2;
}
}
else if(f1==1){
if(f2==0){
cout << "y = x";
}
else if(b<0){
cout << "y = -x -" << (-1)*f2;
}
else if(b>0){
cout << "y = x + "<< f2;
}
}
else {
cout << "y = " << f1 << "+" << f2;
}
}
} | # 1279, 2024-11-02 12:05:48, PPPPPPPPPP-----P-PPPPP-P (70%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int n;
double xi,yi,m,b,f1=0,f2=0;
double sumx=0,sumy=0,sumxx,sumxy=0;
vector<double> vx,vy;
string s;
cin >> n >> s;
for(int i=0; i<n; i++){
cin >> xi >> yi;
if(s=="mb"){
sumx+=xi;
sumy+=yi;
sumxx+=(xi*xi);
sumxy+=(xi*yi);
//cout << sumx << ":"<<sumy << ":"<< sumxx << ":"<< sumxy << endl;
}
if(s=="func"){
vx.push_back(xi);
vy.push_back(yi);
}
}
// for(auto e: vy){
// cout << e;
// }
//cout << sumx << ":"<<sumy << ":"<< sumxx << endl;
if(s=="mb"){
double m=((n*sumxy)-(sumx*sumy))/((n*sumxx)-(sumx*sumx));
double b=(sumy-(m*sumx))/n;
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 ;
}
else if(s=="func"){
f1=(vy[0]-vy[1])/(vx[0]-vx[1]);
f2=vy[1]-(f1*vx[1]);
f1=round(f1*1e3)/1e3 ;
f2=round(f2*1e3)/1e3 ;
//cout << f1 << f2;
if(f1==-1){
if(f2==0){
cout << "y = -x" ;
}
else if(f2<0){
cout << "y = -x - " << (-1)*f2;
}
else if(f2>0){
cout << "y = -x + "<< f2;
}
}
else if(f1==0){
if(f2==0){
cout << "y = 0";
}
else if(f2<0){
cout << "y = " << f2;
}
}
else if(f1==1){
if(f2==0){
cout << "y = x";
}
else if(f2<0){
cout << "y = -x -" << (-1)*f2;
}
else if(f2>0){
cout << "y = x + "<< f2;
}
}
else {
if(f2>0){
cout << "y = " << f1 << "x" << " + " << f2;
}
else if(f2<0){
cout << "y = " << f1 << "x" << "-" << (-1)*f2;
}
}
}
} | # 1280, 2024-11-02 12:11:37, PPPPPPPPPP-----P-PPPPP-P (70%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int n;
float xi,yi,m,b,f1=0,f2=0;
float sumx=0,sumy=0,sumxx,sumxy=0;
vector<float> vx,vy;
string s;
cin >> n >> s;
for(int i=0; i<n; i++){
cin >> xi >> yi;
if(s=="mb"){
sumx+=xi;
sumy+=yi;
sumxx+=(xi*xi);
sumxy+=(xi*yi);
//cout << sumx << ":"<<sumy << ":"<< sumxx << ":"<< sumxy << endl;
}
if(s=="func"){
vx.push_back(xi);
vy.push_back(yi);
}
}
// for(auto e: vy){
// cout << e;
// }
//cout << sumx << ":"<<sumy << ":"<< sumxx << endl;
if(s=="mb"){
float m=((n*sumxy)-(sumx*sumy))/((n*sumxx)-(sumx*sumx));
float b=(sumy-(m*sumx))/n;
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 ;
}
else if(s=="func"){
f1=(vy[0]-vy[1])/(vx[0]-vx[1]);
f2=vy[1]-(f1*vx[1]);
f1=round(f1*1e3)/1e3 ;
f2=round(f2*1e3)/1e3 ;
//cout << f1 << f2;
if(f1==-1){
if(f2==0){
cout << "y = -x" ;
}
else if(f2<0){
cout << "y = -x - " << (-1)*f2;
}
else if(f2>0){
cout << "y = -x + "<< f2;
}
}
else if(f1==0){
if(f2==0){
cout << "y = 0";
}
else if(f2<0){
cout << "y = " << f2;
}
}
else if(f1==1){
if(f2==0){
cout << "y = x";
}
else if(f2<0){
cout << "y = -x -" << (-1)*f2;
}
else if(f2>0){
cout << "y = x + "<< f2;
}
}
else {
if(f2>0){
cout << "y = " << f1 << "x" << " + " << f2;
}
else if(f2<0){
cout << "y = " << f1 << "x" << "-" << (-1)*f2;
}
}
}
} |
# 1281, 2024-11-02 13:20:22, PPPPPPPPPP---------P---- (45%)
#include <iostream>
#include <cmath>
#include <vector>
int main(){
float n;
std::string cmd;
std::cin >> n >> cmd;
float sumx = 0 , sumy = 0 , sumxy = 0 , sumxx = 0;
for(int i = 0 ; i< n ; ++i){
float x , y ;
std::cin >> x >> y;
sumx += x;
sumy += y;
sumxy += x*y;
sumxx += x*x;
}
std::string g = std::to_string(n);
// float l = std::stof(g);
// std::cout << l <<std::endl;
float m = ((n*sumxy)-(sumx*sumy))/(n*sumxx - sumx*sumx);
float b = (sumy -(sumx*m))/n;
if(cmd == "mb"){
std::cout << round(m*1e3)/1e3 <<std::endl;
std::cout << round(b*1e3)/1e3 <<std::endl;
}else if(cmd == "func"){
std::cout << "y = ";
if(m==-1){
std::cout << "-x ";
}else if(m==0){
}else{
std::cout << round(m*1e3)/1e3 << "x ";
}
if(b == 0){
}else if(b < 0){
std::cout << "- "<< abs(round(b*1e3)/1e3);
}else{
std::cout << "+ "<< abs(round(b*1e3)/1e3);
}
}
} | # 1282, 2024-11-02 14:19:52, PPPPPPPPPPPPPPP----P---- (66%)
#include <iostream>
#include <cmath>
#include <vector>
int main(){
float n;
std::string cmd;
std::cin >> n >> cmd;
float sumx = 0 , sumy = 0 , sumxy = 0 , sumxx = 0;
for(int i = 0 ; i< n ; ++i){
float x , y ;
std::cin >> x >> y;
sumx += x;
sumy += y;
sumxy += x*y;
sumxx += x*x;
}
// std::string g = std::to_string(n);
// double l = std::stod(g+"1");
// std::cout << g <<std::endl;
float m = ((n*sumxy)-(sumx*sumy))/(n*sumxx - sumx*sumx);
float b = (sumy -(sumx*m))/n;
if(cmd == "mb"){
std::cout << round(m*1e3)/1e3 <<std::endl;
std::cout << round(b*1e3)/1e3 <<std::endl;
}else if(cmd == "func"){
std::cout << "y = ";
if(m==-1){
std::cout << "-x ";
}else if(m==0){
}else{
std::cout << round(m*1e3)/1e3 << "x ";
}
if(b == 0){
}else if(b < 0){
std::cout << "- "<< -round(b*1e3)/1e3;
}else{
std::cout << "+ "<< round(b*1e3)/1e3;
}
}
} | # 1283, 2024-11-02 15:26:39, PPPPPPPPPPPPPPP---PP---- (70%)
#include <iostream>
#include <cmath>
#include <vector>
int main(){
float n;
std::string cmd;
std::cin >> n >> cmd;
float sumx = 0 , sumy = 0 , sumxy = 0 , sumxx = 0;
for(int i = 0 ; i< n ; ++i){
float x , y ;
std::cin >> x >> y;
sumx += x;
sumy += y;
sumxy += (x*y);
sumxx += (x*x);
}
// std::string g = std::to_string(n);
// double l = std::stod(g+"1");
// std::cout << g <<std::endl;
float m = ((n*sumxy)-(sumx*sumy))/(n*sumxx - sumx*sumx);
float b = (sumy -(sumx*m))/n;
if(cmd == "mb"){
std::cout << round(m*1e3)/1e3 <<std::endl;
std::cout << round(b*1e3)/1e3 <<std::endl;
}else if(cmd == "func"){
std::cout << "y = ";
if(m==-1){
std::cout << "-x ";
}else if(m==1){
std::cout << "x ";
}else if(m==0){
}else{
std::cout << round(m*1e3)/1e3 << "x ";
}
if(b == 0){
}else if(b < 0){
std::cout << "- "<< -round(b*1e3)/1e3;
}else{
std::cout << "+ "<< round(b*1e3)/1e3;
}
}
} | # 1284, 2024-11-02 15:32:24, PPPPPPPPPP-----PP-P--P-- (58%)
#include <iostream>
#include <cmath>
#include <vector>
int main(){
float n;
std::string cmd;
std::cin >> n >> cmd;
float sumx = 0 , sumy = 0 , sumxy = 0 , sumxx = 0;
for(int i = 0 ; i< n ; ++i){
float x , y ;
std::cin >> x >> y;
sumx += x;
sumy += y;
sumxy += (x*y);
sumxx += (x*x);
}
// std::string g = std::to_string(n);
// double l = std::stod(g+"1");
// std::cout << g <<std::endl;
float m = ((n*sumxy)-(sumx*sumy))/(n*sumxx - sumx*sumx);
float b = (sumy -(sumx*m))/n;
if(cmd == "mb"){
std::cout << round(m*1e3)/1e3 <<std::endl;
std::cout << round(b*1e3)/1e3 <<std::endl;
}else if(cmd == "func"){
std::cout << "y = ";
if(m>1 || m<1
){
std::cout << round(b*1e3)/1e3;
return 0;
}else if(m==1){
std::cout << "x ";
}else if(m==-1){
std::cout << "-x ";
}else if(m> 0||m<0){
std::cout << round(m*1e3)/1e3 << "x ";
}
if(b == 0){
}else if(b < 0){
std::cout << "- "<< -round(b*1e3)/1e3;
}else{
std::cout << "+ "<< round(b*1e3)/1e3;
}
}
} | # 1285, 2024-11-02 15:32:44, PPPPPPPPPP-----PP-P--P-- (58%)
#include <iostream>
#include <cmath>
#include <vector>
int main(){
float n;
std::string cmd;
std::cin >> n >> cmd;
float sumx = 0 , sumy = 0 , sumxy = 0 , sumxx = 0;
for(int i = 0 ; i< n ; ++i){
float x , y ;
std::cin >> x >> y;
sumx += x;
sumy += y;
sumxy += (x*y);
sumxx += (x*x);
}
// std::string g = std::to_string(n);
// double l = std::stod(g+"1");
// std::cout << g <<std::endl;
float m = ((n*sumxy)-(sumx*sumy))/(n*sumxx - sumx*sumx);
float b = (sumy -(sumx*m))/n;
if(cmd == "mb"){
std::cout << round(m*1e3)/1e3 <<std::endl;
std::cout << round(b*1e3)/1e3 <<std::endl;
}else if(cmd == "func"){
std::cout << "y = ";
if(m>1 || m<1){
std::cout << round(b*1e3)/1e3;
return 0;
}else if(m==1){
std::cout << "x ";
}else if(m==-1){
std::cout << "-x ";
}else {
std::cout << round(m*1e3)/1e3 << "x ";
}
if(b == 0){
}else if(b < 0){
std::cout << "- "<< -round(b*1e3)/1e3;
}else{
std::cout << "+ "<< round(b*1e3)/1e3;
}
}
} |
# 1286, 2024-11-02 10:34:00, ------------------------ (0%)
#include<bits/stdc++.h>
using namespace std ;
int main(){
vector<float> X ;
vector<float> Y ;
int n ,n1; cin >> n ;
n1 = n ;
string name ; cin >> name ;
float Xn , Yn ;
while (n--) {
cin >> Xn >> Yn ;
X.push_back(Xn) ;
Y.push_back(Yn) ;
}
float m , b ;
if(name == "mb"){
float ans1 = 0 ; float ans2 = 0 ;
float ans3 = 0 ; float ans4 = 0 ;
float ans5 = 0 ;
for (int i = 0; i < Y.size() ; i++) {
ans1 += X[i]*Y[i] ; ans2 += X[i] ;
ans3 += Y[i] ; ans4 += X[i]*X[i] ;
ans5 += X[i] ;
}
cout << ans1 <<" " <<ans2<< " " <<ans3 << " " <<ans4 << " " <<ans5 <<endl;
m = ((n1*ans1)-(ans2*ans3))/((n1*ans4)-(ans5*ans5)) ;
b = (ans3 - (m*ans5))/n1 ;
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
string last_ans ;
if(name == "func"){
float ans1 = 0 ; float ans2 = 0 ;
float ans3 = 0 ; float ans4 = 0 ;
float ans5 = 0 ;
for (int i = 0; i < Y.size() ; i++) {
ans1 += X[i]*Y[i] ; ans2 += X[i] ;
ans3 += Y[i] ; ans4 += X[i]*X[i] ;
ans5 += X[i] ;
}
cout << ans1 <<" " <<ans2<< " " <<ans3 << " " <<ans4 << " " <<ans5 <<endl;
m = ((n1*ans1)-(ans2*ans3))/((n1*ans4)-(ans5*ans5)) ;
b = (ans3 - (m*ans5))/n1 ;
if(m == 0 && b == 0) cout << "y = 0" ;
else if(m == 0 && b != 0) cout << "y = " + to_string(b) ;
else if(b == 0 && m != 0) cout << "y = " + to_string(m) +"x" ;
else if(m == -1 && b == 0) cout << "y = -x " ;
else if(m == -1 && b != 0) cout << "y = -x + " + to_string(b) ;
else{
cout << "y = " + to_string(m) + "x + " + to_string(b) ;
}
}
} | # 1287, 2024-11-02 10:36:30, PPPPPPPPPP-------------- (41%)
#include<bits/stdc++.h>
using namespace std ;
int main(){
vector<float> X ;
vector<float> Y ;
int n ,n1; cin >> n ;
n1 = n ;
string name ; cin >> name ;
float Xn , Yn ;
while (n--) {
cin >> Xn >> Yn ;
X.push_back(Xn) ;
Y.push_back(Yn) ;
}
float m , b ;
if(name == "mb"){
float ans1 = 0 ; float ans2 = 0 ;
float ans3 = 0 ; float ans4 = 0 ;
float ans5 = 0 ;
for (int i = 0; i < Y.size() ; i++) {
ans1 += X[i]*Y[i] ; ans2 += X[i] ;
ans3 += Y[i] ; ans4 += X[i]*X[i] ;
ans5 += X[i] ;
}
m = ((n1*ans1)-(ans2*ans3))/((n1*ans4)-(ans5*ans5)) ;
b = (ans3 - (m*ans5))/n1 ;
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
string last_ans ;
if(name == "func"){
float ans1 = 0 ; float ans2 = 0 ;
float ans3 = 0 ; float ans4 = 0 ;
float ans5 = 0 ;
for (int i = 0; i < Y.size() ; i++) {
ans1 += X[i]*Y[i] ; ans2 += X[i] ;
ans3 += Y[i] ; ans4 += X[i]*X[i] ;
ans5 += X[i] ;
}
cout << ans1 <<" " <<ans2<< " " <<ans3 << " " <<ans4 << " " <<ans5 <<endl;
m = ((n1*ans1)-(ans2*ans3))/((n1*ans4)-(ans5*ans5)) ;
b = (ans3 - (m*ans5))/n1 ;
if(m == 0 && b == 0) cout << "y = 0" ;
else if(m == 0 && b != 0) cout << "y = " + to_string(b) ;
else if(b == 0 && m != 0) cout << "y = " + to_string(m) +"x" ;
else if(m == -1 && b == 0) cout << "y = -x " ;
else if(m == -1 && b != 0) cout << "y = -x + " + to_string(b) ;
else{
cout << "y = " + to_string(m) + "x + " + to_string(b) ;
}
}
} | # 1288, 2024-11-02 10:39:28, PPPPPPPPPP-----P-------- (45%)
#include<bits/stdc++.h>
using namespace std ;
int main(){
vector<float> X ;
vector<float> Y ;
int n ,n1; cin >> n ;
n1 = n ;
string name ; cin >> name ;
float Xn , Yn ;
while (n--) {
cin >> Xn >> Yn ;
X.push_back(Xn) ;
Y.push_back(Yn) ;
}
float m , b ;
if(name == "mb"){
float ans1 = 0 ; float ans2 = 0 ;
float ans3 = 0 ; float ans4 = 0 ;
float ans5 = 0 ;
for (int i = 0; i < Y.size() ; i++) {
ans1 += X[i]*Y[i] ; ans2 += X[i] ;
ans3 += Y[i] ; ans4 += X[i]*X[i] ;
ans5 += X[i] ;
}
m = ((n1*ans1)-(ans2*ans3))/((n1*ans4)-(ans5*ans5)) ;
b = (ans3 - (m*ans5))/n1 ;
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
string last_ans ;
if(name == "func"){
float ans1 = 0 ; float ans2 = 0 ;
float ans3 = 0 ; float ans4 = 0 ;
float ans5 = 0 ;
for (int i = 0; i < Y.size() ; i++) {
ans1 += X[i]*Y[i] ; ans2 += X[i] ;
ans3 += Y[i] ; ans4 += X[i]*X[i] ;
ans5 += X[i] ;
}
m = ((n1*ans1)-(ans2*ans3))/((n1*ans4)-(ans5*ans5)) ;
b = (ans3 - (m*ans5))/n1 ;
last_ans = "y = " + to_string(m) + "x " + to_string(b) ;
if(m == 0 && b == 0) cout << "y = 0" ;
else if(m == 0 && b != 0) cout << "y = " + to_string(b) ;
else if(b == 0 && m != 0) cout << "y = " + to_string(m) +"x" ;
else if(m == -1 && b == 0) cout << "y = -x " ;
else if(m == -1 && b != 0) cout << "y = -x + " + to_string(b) ;
else{
cout << "y = " + to_string(m) + "x + " + to_string(b) ;
}
}
} | # 1289, 2024-11-02 10:43:33, PPPPPPPPPPP-P--P-----P-- (58%)
#include<bits/stdc++.h>
using namespace std ;
int main(){
vector<float> X ;
vector<float> Y ;
int n ,n1; cin >> n ;
n1 = n ;
string name ; cin >> name ;
float Xn , Yn ;
while (n--) {
cin >> Xn >> Yn ;
X.push_back(Xn) ;
Y.push_back(Yn) ;
}
float m , b ;
if(name == "mb"){
float ans1 = 0 ; float ans2 = 0 ;
float ans3 = 0 ; float ans4 = 0 ;
float ans5 = 0 ;
for (int i = 0; i < Y.size() ; i++) {
ans1 += X[i]*Y[i] ; ans2 += X[i] ;
ans3 += Y[i] ; ans4 += X[i]*X[i] ;
ans5 += X[i] ;
}
m = ((n1*ans1)-(ans2*ans3))/((n1*ans4)-(ans5*ans5)) ;
b = (ans3 - (m*ans5))/n1 ;
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
string last_ans ;
if(name == "func"){
float ans1 = 0 ; float ans2 = 0 ;
float ans3 = 0 ; float ans4 = 0 ;
float ans5 = 0 ;
for (int i = 0; i < Y.size() ; i++) {
ans1 += X[i]*Y[i] ; ans2 += X[i] ;
ans3 += Y[i] ; ans4 += X[i]*X[i] ;
ans5 += X[i] ;
}
m = ((n1*ans1)-(ans2*ans3))/((n1*ans4)-(ans5*ans5)) ;
b = (ans3 - (m*ans5))/n1 ;
float ans_m = round(m*1e3)/1e3 ;;
float ans_b = round(b*1e3)/1e3 ;
if(m == 0 && b == 0) cout << "y = 0" ;
else if(m == 0 && b != 0) cout << "y = " << ans_b ;
else if(b == 0 && m != 0) cout << "y = " << ans_m << "x" ;
else if(m == -1 && b == 0) cout << "y = -x " ;
else if(m == -1 && b != 0) cout << "y = -x + " << ans_b ;
else{
cout << "y = " << ans_m << "x + " << ans_b ;
}
}
} | # 1290, 2024-11-02 10:46:39, PPPPPPPPPPP-P--PPP--PP-- (70%)
#include<bits/stdc++.h>
using namespace std ;
int main(){
vector<float> X ;
vector<float> Y ;
int n ,n1; cin >> n ;
n1 = n ;
string name ; cin >> name ;
float Xn , Yn ;
while (n--) {
cin >> Xn >> Yn ;
X.push_back(Xn) ;
Y.push_back(Yn) ;
}
float m , b ;
if(name == "mb"){
float ans1 = 0 ; float ans2 = 0 ;
float ans3 = 0 ; float ans4 = 0 ;
float ans5 = 0 ;
for (int i = 0; i < Y.size() ; i++) {
ans1 += X[i]*Y[i] ; ans2 += X[i] ;
ans3 += Y[i] ; ans4 += X[i]*X[i] ;
ans5 += X[i] ;
}
m = ((n1*ans1)-(ans2*ans3))/((n1*ans4)-(ans5*ans5)) ;
b = (ans3 - (m*ans5))/n1 ;
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
string last_ans ;
if(name == "func"){
float ans1 = 0 ; float ans2 = 0 ;
float ans3 = 0 ; float ans4 = 0 ;
float ans5 = 0 ;
for (int i = 0; i < Y.size() ; i++) {
ans1 += X[i]*Y[i] ; ans2 += X[i] ;
ans3 += Y[i] ; ans4 += X[i]*X[i] ;
ans5 += X[i] ;
}
m = ((n1*ans1)-(ans2*ans3))/((n1*ans4)-(ans5*ans5)) ;
b = (ans3 - (m*ans5))/n1 ;
float ans_m = round(m*1e3)/1e3 ;;
float ans_b = round(b*1e3)/1e3 ;
if(ans_m == 0 && ans_b == 0) cout << "y = 0" ;
else if(ans_m == 0 && ans_b != 0) cout << "y = " << ans_b ;
else if(ans_b == 0 && ans_m != 0) cout << "y = " << ans_m << "x" ;
else if (ans_m == 1 && ans_b == 0) cout << "y = x" ;
else if (ans_m == 1 && ans_b != 0) cout << "y = x + " << ans_b ;
else if(ans_m == -1 && ans_b == 0) cout << "y = -x " ;
else if(ans_m == -1 && ans_b != 0) cout << "y = -x + " << ans_b ;
else{
cout << "y = " << ans_m << "x + " << ans_b ;
}
}
} |
# 1291, 2024-11-02 11:53:20, ------PPPP-------------- (16%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n ;
string ask ;
cin >> n >> ask ;
float x, y , m ,b ,b1 ,b2 , m1 , m2 ,m2x , m2y , m3 , m4 ;
for(int a=0 ; a <n ; a++){
cin >> x >> y ;
m1 += x*y ;
m2x += x ;
m2y += y ;
m3 += pow(x,2) ;
m4 += x ;
b1 += y ;
b2 += x ;
}
m1 = m1 * n ;
m2 = m2x * m2y;
m3 = m3 * n ;
m4 = pow(m4 , 2);
m = (m1 - m2 ) / (m3 - m4) ;
b2 = b2*m ;
b = (b1-b2) / n ;
cout << m << endl;
cout << b << endl;
} | # 1292, 2024-11-02 11:55:13, PPPPP-PP---------------- (29%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n ;
string ask ;
cin >> n >> ask ;
float x, y , m ,b ,b1 ,b2 , m1 , m2 ,m2x , m2y , m3 , m4 ;
for(int a=0 ; a <n ; a++){
cin >> x >> y ;
if(y==0) continue;
m1 += x*y ;
m2x += x ;
m2y += y ;
m3 += pow(x,2) ;
m4 += x ;
b1 += y ;
b2 += x ;
}
m1 = m1 * n ;
m2 = m2x * m2y;
m3 = m3 * n ;
m4 = pow(m4 , 2);
m = (m1 - m2 ) / (m3 - m4) ;
b2 = b2*m ;
b = (b1-b2) / n ;
if(m==0) b=0 ;
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
} | # 1293, 2024-11-02 11:59:22, PPPPP-PP----------PP---- (37%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n ;
string ask ;
cin >> n >> ask ;
float x, y , m ,b ,b1 ,b2 , m1 , m2 ,m2x , m2y , m3 , m4 ;
for(int a=0 ; a <n ; a++){
cin >> x >> y ;
if(y==0) continue;
m1 += x*y ;
m2x += x ;
m2y += y ;
m3 += pow(x,2) ;
m4 += x ;
b1 += y ;
b2 += x ;
}
m1 = m1 * n ;
m2 = m2x * m2y;
m3 = m3 * n ;
m4 = pow(m4 , 2);
m = (m1 - m2 ) / (m3 - m4) ;
b2 = b2*m ;
b = (b1-b2) / n ;
if(m==0) b=0 ;
if(ask == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(ask == "func"){
if(m ==0) cout << "y = 0 ";
if(m==1 && b == 0) cout << "y = x";
if(m==-1 && b == 0) cout << "y = -x";
if(m==-1 && b != 0) cout << "y = -x + " << b ;
if(m==1 && b != 0) cout << "y = x + " << b ;
}
} | # 1294, 2024-11-02 12:00:55, PPPPP-PP----------PP---- (37%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n ;
string ask ;
cin >> n >> ask ;
float x, y , m ,b ,b1 ,b2 , m1 , m2 ,m2x , m2y , m3 , m4 ;
for(int a=0 ; a <n ; a++){
cin >> x >> y ;
if(y==0) continue;
m1 += x*y ;
m2x += x ;
m2y += y ;
m3 += pow(x,2) ;
m4 += x ;
b1 += y ;
b2 += x ;
}
m1 = m1 * n ;
m2 = m2x * m2y;
m3 = m3 * n ;
m4 = pow(m4 , 2);
m = (m1 - m2 ) / (m3 - m4) ;
b2 = b2*m ;
b = (b1-b2) / n ;
if(m==0) b=0 ;
if(ask == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(ask == "func"){
if(m ==0) cout << "y = 0 ";
if(m==1 && b == 0) cout << "y = x";
if(m==-1 && b == 0) cout << "y = -x";
if(m==-1 && b > 0) cout << "y = -x + " << b ;
if(m==1 && b > 0) cout << "y = x + " << b ;
if(m==1 && b < 0) cout << "y = x - " << -b ;
if(m==-1 && b < 0) cout << "y = -x - " << -b ;
}
} | # 1295, 2024-11-02 12:03:07, PPPPP-PP----------PP---- (37%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n ;
string ask ;
cin >> n >> ask ;
float x, y , m ,b ,b1 ,b2 , m1 , m2 ,m2x , m2y , m3 , m4 ;
for(int a=0 ; a <n ; a++){
cin >> x >> y ;
if(y==0) continue;
m1 += x*y ;
m2x += x ;
m2y += y ;
m3 += pow(x,2) ;
m4 += x ;
b1 += y ;
b2 += x ;
}
m1 = m1 * n ;
m2 = m2x * m2y;
m3 = m3 * n ;
m4 = pow(m4 , 2);
m = (m1 - m2 ) / (m3 - m4) ;
b2 = b2*m ;
b = (b1-b2) / n ;
if(m==0) b=0 ;
if(ask == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(ask == "func"){
if(m ==0) cout << "y = 0 ";
if(m==1 && b == 0) cout << "y = x";
if(m==-1 && b == 0) cout << "y = -x";
if(m==-1 && b > 0) cout << "y = -x + " << b ;
if(m==1 && b > 0) cout << "y = x + " << b ;
if(m==1 && b < 0) cout << "y = x - " << -b ;
if(m==-1 && b < 0) cout << "y = -x - " << -b ;
if(m != 1 && m !=-1 && b == 0) cout << "y = " << x ;
}
} | # 1296, 2024-11-02 12:05:39, PPPPP-PP----------PP---- (37%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n ;
string ask ;
cin >> n >> ask ;
float x, y , m ,b ,b1 ,b2 , m1 , m2 ,m2x , m2y , m3 , m4 ;
for(int a=0 ; a <n ; a++){
cin >> x >> y ;
if(y==0) continue;
m1 += x*y ;
m2x += x ;
m2y += y ;
m3 += pow(x,2) ;
m4 += x ;
b1 += y ;
b2 += x ;
}
m1 = m1 * n ;
m2 = m2x * m2y;
m3 = m3 * n ;
m4 = pow(m4 , 2);
m = (m1 - m2 ) / (m3 - m4) ;
b2 = b2*m ;
b = (b1-b2) / n ;
if(m==0) b=0 ;
if(ask == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(ask == "func"){
if(m ==0) cout << "y = 0 ";
else if(m==1 && b == 0) cout << "y = x";
else if(m==-1 && b == 0) cout << "y = -x";
else if(m==-1 && b > 0) cout << "y = -x + " << b ;
else if(m==1 && b > 0) cout << "y = x + " << b ;
else if(m==1 && b < 0) cout << "y = x - " << -b ;
else if(m==-1 && b < 0) cout << "y = -x - " << -b ;
else if(m != 1 && m !=-1 && b == 0) cout << "y = " << m ;
else cout << "y = " << m << "x " << "+ " << b ;
}
} | # 1297, 2024-11-02 12:07:02, PPPPPPPP--P-P--P--PP---- (54%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n ;
string ask ;
cin >> n >> ask ;
float x, y , m ,b ,b1 ,b2 , m1 , m2 ,m2x , m2y , m3 , m4 ;
for(int a=0 ; a <n ; a++){
cin >> x >> y ;
if(y==0) continue;
m1 += x*y ;
m2x += x ;
m2y += y ;
m3 += pow(x,2) ;
m4 += x ;
b1 += y ;
b2 += x ;
}
m1 = m1 * n ;
m2 = m2x * m2y;
m3 = m3 * n ;
m4 = pow(m4 , 2);
m = (m1 - m2 ) / (m3 - m4) ;
b2 = b2*m ;
b = (b1-b2) / n ;
if(m==0) b=0 ;
if(ask == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(ask == "func"){
if(m ==0) cout << "y = 0 ";
else if(m==1 && b == 0) cout << "y = x";
else if(m==-1 && b == 0) cout << "y = -x";
else if(m==-1 && b > 0) cout << "y = -x + " << b ;
else if(m==1 && b > 0) cout << "y = x + " << b ;
else if(m==1 && b < 0) cout << "y = x - " << -b ;
else if(m==-1 && b < 0) cout << "y = -x - " << -b ;
else if(m != 1 && m !=-1 && b == 0) cout << "y = " << m ;
else cout << "y = " << round(m*1e3)/1e3 << "x " << "+ " << round(b*1e3)/1e3 ;
}
} | # 1298, 2024-11-02 12:08:24, PPPPPPPP--PPPPPP--PP---- (66%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n ;
string ask ;
cin >> n >> ask ;
float x, y , m ,b ,b1 ,b2 , m1 , m2 ,m2x , m2y , m3 , m4 ;
for(int a=0 ; a <n ; a++){
cin >> x >> y ;
if(y==0) continue;
m1 += x*y ;
m2x += x ;
m2y += y ;
m3 += pow(x,2) ;
m4 += x ;
b1 += y ;
b2 += x ;
}
m1 = m1 * n ;
m2 = m2x * m2y;
m3 = m3 * n ;
m4 = pow(m4 , 2);
m = (m1 - m2 ) / (m3 - m4) ;
b2 = b2*m ;
b = (b1-b2) / n ;
if(m==0) b=0 ;
if(ask == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(ask == "func"){
if(m ==0) cout << "y = 0 ";
else if(m==1 && b == 0) cout << "y = x";
else if(m==-1 && b == 0) cout << "y = -x";
else if(m==-1 && b > 0) cout << "y = -x + " << round(b*1e3)/1e3 ;
else if(m==1 && b > 0) cout << "y = x + " << round(b*1e3)/1e3 ;
else if(m==1 && b < 0) cout << "y = x - " << -round(b*1e3)/1e3 ;
else if(m==-1 && b < 0) cout << "y = -x - " << -round(b*1e3)/1e3;
else if(m != 1 && m !=-1 && b == 0) cout << "y = " << m ;
else if(m != 1 && m !=-1 && b < 0) cout << "y = " << round(m*1e3)/1e3 << "x " << "- " << -round(b*1e3)/1e3 ;
else cout << "y = " << round(m*1e3)/1e3 << "x " << "+ " << round(b*1e3)/1e3 ;
}
} | # 1299, 2024-11-02 12:10:57, PPPPPPPP--PPPPPP--PP---- (66%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n ;
string ask ;
cin >> n >> ask ;
float x, y , m ,b ,b1 ,b2 , m1 , m2 ,m2x , m2y , m3 , m4 ;
for(int a=0 ; a <n ; a++){
cin >> x >> y ;
if(y==0) continue;
m1 += x*y ;
m2x += x ;
m2y += y ;
m3 += pow(x,2) ;
m4 += x ;
b1 += y ;
b2 += x ;
}
m1 = m1 * n ;
m2 = m2x * m2y;
m3 = m3 * n ;
m4 = pow(m4 , 2);
m = (m1 - m2 ) / (m3 - m4) ;
b2 = b2*m ;
b = (b1-b2) / n ;
if(m==0) b=0 ;
if(ask == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(ask == "func"){
if(m ==0) cout << "y = 0 ";
else if(m==1 && b == 0) cout << "y = x";
else if(m==-1 && b == 0) cout << "y = -x";
else if(m==-1 && b > 0) cout << "y = -x + " << round(b*1e3)/1e3 ;
else if(m==-1 && b < 0) cout << "y = -x - " << -round(b*1e3)/1e3 ;
else if(m==1 && b > 0) cout << "y = x + " << round(b*1e3)/1e3 ;
else if(m==1 && b < 0) cout << "y = x - " << -round(b*1e3)/1e3 ;
else if(m==-1 && b < 0) cout << "y = -x - " << -round(b*1e3)/1e3;
else if(m != 1 && m !=-1 && b == 0) cout << "y = " << m ;
else if(m != 1 && m !=-1 && b < 0) cout << "y = " << round(m*1e3)/1e3 << "x " << "- " << -round(b*1e3)/1e3 ;
else cout << "y = " << round(m*1e3)/1e3 << "x " << "+ " << round(b*1e3)/1e3 ;
}
} |
# 1300, 2024-11-02 09:56:15, -----PPPPPP-P--P--P--P-- (41%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n;
string s;
cin >> n >> s;
float x[n] , y[n] , m , b , sumxy = 0 , sumx = 0 , sumy = 0 , sumx2 = 0;
for(int i = 0 ; i < n ; i++)
{
cin >> x[i] >> y[i];
}
for(int i = 0 ; i < n ; i++)
{
sumxy = sumxy + x[i] * y[i];
sumx = sumx + x[i];
sumy = sumy + y[i];
sumx2 = sumx2 + x[i] * x[i];
}
m = ((n * sumxy) - (sumx * sumy)) / ((n * sumx2) - (sumx * sumx));
b = (sumy - (m * sumx)) / n;
if(s == "mb")
{
cout << m << endl << b;
}
else if(s == "func")
{
cout << "y = ";
if(m == 0 && b == 0)
{
cout << "0";
}
else if(m == 0)
{
cout << round(b * 1e3) / 1e3;
}
else if(b == 0 && m != 1)
{
cout << round(m * 1e3) / 1e3 << "x";
}
else if(m == 1 && b == 0)
{
cout << "x";
}
else if(m == -1 && b == 0)
{
cout << "-x";
}
else if(b > 0 && m == 1)
{
cout << "x + " << round(b * 1e3) / 1e3;
}
else if(b > 0 && m == -1)
{
cout << "-x + " << round(b * 1e3) / 1e3;
}
else if(b < 0 && m == 1)
{
cout << "x " << round(b * 1e3) / 1e3;
}
else if(b < 0 && m == -1)
{
cout << "-x " << round(b * 1e3) / 1e3;
}
else if(b < 0 && m != 1)
{
cout << round(m * 1e3) / 1e3 << "x" << round(b * 1e3) / 1e3;
}
else if(b > 0 && m != 1)
{
cout << round(m * 1e3) / 1e3 << "x + " << round(b * 1e3) / 1e3;
}
}
return 0;
} | # 1301, 2024-11-02 10:48:44, PPPPPPPPPPP-P--P--P--P-- (62%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n;
string s;
cin >> n >> s;
float x[n] , y[n] , m , b , sumxy = 0 , sumx = 0 , sumy = 0 , sumx2 = 0;
for(int i = 0 ; i < n ; i++)
{
cin >> x[i] >> y[i];
}
for(int i = 0 ; i < n ; i++)
{
sumxy = sumxy + x[i] * y[i];
sumx = sumx + x[i];
sumy = sumy + y[i];
sumx2 = sumx2 + x[i] * x[i];
}
m = ((n * sumxy) - (sumx * sumy)) / ((n * sumx2) - (sumx * sumx));
b = (sumy - (m * sumx)) / n;
if(s == "mb")
{
cout << round(m * 1e3) / 1e3 << endl << round(b * 1e3) / 1e3;
}
else if(s == "func")
{
cout << "y = ";
if(m == 0 && b == 0)
{
cout << "0";
}
else if(m == 0)
{
cout << round(b * 1e3) / 1e3;
}
else if(b == 0 && m != 1)
{
cout << round(m * 1e3) / 1e3 << "x";
}
else if(m == 1 && b == 0)
{
cout << "x";
}
else if(m == -1 && b == 0)
{
cout << "-x";
}
else if(b > 0 && m == 1)
{
cout << "x + " << round(b * 1e3) / 1e3;
}
else if(b > 0 && m == -1)
{
cout << "-x + " << round(b * 1e3) / 1e3;
}
else if(b < 0 && m == 1)
{
cout << "x " << round(b * 1e3) / 1e3;
}
else if(b < 0 && m == -1)
{
cout << "-x " << round(b * 1e3) / 1e3;
}
else if(b < 0 && m != 1)
{
cout << round(m * 1e3) / 1e3 << "x" << round(b * 1e3) / 1e3;
}
else if(b > 0 && m != 1)
{
cout << round(m * 1e3) / 1e3 << "x + " << round(b * 1e3) / 1e3;
}
}
return 0;
} | # 1302, 2024-11-02 10:59:53, Compilation error (0%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n;
string s;
cin >> n >> s;
float x[n] , y[n] , m , b , sumxy = 0 , sumx = 0 , sumy = 0 , sumx2 = 0;
for(int i = 0 ; i < n ; i++)
{
cin >> x[i] >> y[i];
}
for(int i = 0 ; i < n ; i++)
{
sumxy = sumxy + x[i] * y[i];
sumx = sumx + x[i];
sumy = sumy + y[i];
sumx2 = sumx2 + x[i] * x[i];
}
m = ((n * sumxy) - (sumx * sumy)) / ((n * sumx2) - (sumx * sumx));
b = (sumy - (m * sumx)) / n;
if(s == "mb")
{
cout << round(m * 1e3) / 1e3 << endl << round(b * 1e3) / 1e3;
}
else if(s == "func")
{
cout << "y = ";
if(m == 0 && b == 0)
{
cout << "0";
}
else if(m == 0)
{
cout << round(b * 1e3) / 1e3;
}
else if(m == 1 && b == 0)
{
cout << "x";
}
else if(m == 1 && b > 0)
{
cout << "x + " << round(b * 1e3) / 1e3;
}
else if(m == 1 && b < 0)
{
cout << "x " << round(b * 1e3) / 1e3;
}
else if(m == -1 && b == 0)
{
cout << "-x ";
}
else if(m == -1 && b > 0)
{
cout << "-x + " << round(b * 1e3) / 1e3;
}
else if(m == - 1 && b < 0)
{
cout << "-x " << round(b * 1e3) / 1e3;
}
else if(b == 0)
{
cout << round(m * 1e3) / 1e3 << "x";
}
else if(b > 0)
{
cout << round(m * 1e3) / 1e3 << "x + " << round(b * 1e3) / 1e3;
}
else if(b < 0)
{
cout << round(m * 1e3) / 1e3 << "x " << round(b * 1e3) / 1e3;
}
}
round(m * 1e3) / 1e3
return 0;
} | # 1303, 2024-11-02 10:59:59, Compilation error (0%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n;
string s;
cin >> n >> s;
float x[n] , y[n] , m , b , sumxy = 0 , sumx = 0 , sumy = 0 , sumx2 = 0;
for(int i = 0 ; i < n ; i++)
{
cin >> x[i] >> y[i];
}
for(int i = 0 ; i < n ; i++)
{
sumxy = sumxy + x[i] * y[i];
sumx = sumx + x[i];
sumy = sumy + y[i];
sumx2 = sumx2 + x[i] * x[i];
}
m = ((n * sumxy) - (sumx * sumy)) / ((n * sumx2) - (sumx * sumx));
b = (sumy - (m * sumx)) / n;
if(s == "mb")
{
cout << round(m * 1e3) / 1e3 << endl << round(b * 1e3) / 1e3;
}
else if(s == "func")
{
cout << "y = ";
if(m == 0 && b == 0)
{
cout << "0";
}
else if(m == 0)
{
cout << round(b * 1e3) / 1e3;
}
else if(m == 1 && b == 0)
{
cout << "x";
}
else if(m == 1 && b > 0)
{
cout << "x + " << round(b * 1e3) / 1e3;
}
else if(m == 1 && b < 0)
{
cout << "x " << round(b * 1e3) / 1e3;
}
else if(m == -1 && b == 0)
{
cout << "-x ";
}
else if(m == -1 && b > 0)
{
cout << "-x + " << round(b * 1e3) / 1e3;
}
else if(m == - 1 && b < 0)
{
cout << "-x " << round(b * 1e3) / 1e3;
}
else if(b == 0)
{
cout << round(m * 1e3) / 1e3 << "x";
}
else if(b > 0)
{
cout << round(m * 1e3) / 1e3 << "x + " << round(b * 1e3) / 1e3;
}
else if(b < 0)
{
cout << round(m * 1e3) / 1e3 << "x " << round(b * 1e3) / 1e3;
}
}
round(m * 1e3) / 1e3
return 0;
} | # 1304, 2024-11-02 11:00:24, PPPPPPPPPPP-P--P--PP-P-- (66%)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n;
string s;
cin >> n >> s;
float x[n] , y[n] , m , b , sumxy = 0 , sumx = 0 , sumy = 0 , sumx2 = 0;
for(int i = 0 ; i < n ; i++)
{
cin >> x[i] >> y[i];
}
for(int i = 0 ; i < n ; i++)
{
sumxy = sumxy + x[i] * y[i];
sumx = sumx + x[i];
sumy = sumy + y[i];
sumx2 = sumx2 + x[i] * x[i];
}
m = ((n * sumxy) - (sumx * sumy)) / ((n * sumx2) - (sumx * sumx));
b = (sumy - (m * sumx)) / n;
if(s == "mb")
{
cout << round(m * 1e3) / 1e3 << endl << round(b * 1e3) / 1e3;
}
else if(s == "func")
{
cout << "y = ";
if(m == 0 && b == 0)
{
cout << "0";
}
else if(m == 0)
{
cout << round(b * 1e3) / 1e3;
}
else if(m == 1 && b == 0)
{
cout << "x";
}
else if(m == 1 && b > 0)
{
cout << "x + " << round(b * 1e3) / 1e3;
}
else if(m == 1 && b < 0)
{
cout << "x " << round(b * 1e3) / 1e3;
}
else if(m == -1 && b == 0)
{
cout << "-x ";
}
else if(m == -1 && b > 0)
{
cout << "-x + " << round(b * 1e3) / 1e3;
}
else if(m == - 1 && b < 0)
{
cout << "-x " << round(b * 1e3) / 1e3;
}
else if(b == 0)
{
cout << round(m * 1e3) / 1e3 << "x";
}
else if(b > 0)
{
cout << round(m * 1e3) / 1e3 << "x + " << round(b * 1e3) / 1e3;
}
else if(b < 0)
{
cout << round(m * 1e3) / 1e3 << "x " << round(b * 1e3) / 1e3;
}
}
return 0;
} |
# 1305, 2024-11-02 11:33:44, PPPPPPPPPP-------PPPP-PP (66%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main() {
int n ;
float x,y;
string sec;
cin>>n>>sec;
int r = n;
vector<pair<float,float>> v;
while(n--){
cin>>x>>y;
v.push_back(make_pair(x,y));
}
float m = 0,b = 0,s1 = 0,s2 = 0,s3 = 0,s4 = 0,s5 = 0;
for(int i = 0;i<r;i++){
s1 += v[i].first*v[i].second;
s2 += v[i].first;
s3 += v[i].second;
s4 += pow(v[i].first,2);
s5 += v[i].first;
}
m = (r*s1 - s2*s3)/(r*s4 - pow(s5,2));
b = (s3 - m*s2)/r;
m = round(m * 1000)/1000;
b = round(b * 1000)/1000;
if(sec == "mb"){
cout<<m<<endl<<b;
}else if (sec == "func"){
string nm;
if(m==-1){
nm = "-";
}
else if(m==1){
nm = "";
}else{
nm = m;
}
if(x==0){
cout<<"y = "<<b;
}else{
if(b<0){
cout<<"y = "<<nm<<"x - "<<abs(b);
}else if(b>0){
cout<<"y = "<<nm<<"x + "<<b;
}else{
cout<<"y = "<<nm<<"x";
}
}
}
} | # 1306, 2024-11-02 11:42:40, PPPPPPPPPP-------PPPP-PP (66%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main() {
int n ;
float x,y;
string sec;
cin>>n>>sec;
int r = n;
vector<pair<float,float>> v;
while(n--){
cin>>x>>y;
v.push_back(make_pair(x,y));
}
float m = 0,b = 0,s1 = 0,s2 = 0,s3 = 0,s4 = 0,s5 = 0;
for(int i = 0;i<r;i++){
s1 += v[i].first*v[i].second;
s2 += v[i].first;
s3 += v[i].second;
s4 += pow(v[i].first,2);
s5 += v[i].first;
}
m = (r*s1 - s2*s3)/(r*s4 - pow(s5,2));
b = (s3 - m*s2)/r;
m = round(m * 1000)/1000;
b = round(b * 1000)/1000;
if(sec == "mb"){
cout<<m<<endl<<b;
}else if (sec == "func"){
string nm;
if(m==-1){
nm = "-";
}
else if(m==1){
nm = "";
}else{
nm = m;
cout<<nm;
}
if(m==0){
cout<<"y = "<<b;
}else if(abs(m)==1){
if(b<0){
cout<<"y = "<<nm<<"x - "<<abs(b);
}else if(b>0){
cout<<"y = "<<nm<<"x + "<<b;
}else{
cout<<"y = "<<nm<<"x";
}
}else{
if(b<0){
cout<<"y = "<<m<<"x - "<<abs(b);
}else if(b>0){
cout<<"y = "<<m<<"x + "<<b;
}else{
cout<<"y = "<<m<<"x";
}
}
}
} | # 1307, 2024-11-02 11:52:26, PPPPPPPPPP-------PPPP-PP (66%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main() {
int n ;
float x,y;
string sec;
cin>>n>>sec;
int r = n;
vector<pair<float,float>> v;
while(n--){
cin>>x>>y;
v.push_back(make_pair(x,y));
}
float m = 0,b = 0,s1 = 0,s2 = 0,s3 = 0,s4 = 0,s5 = 0;
for(int i = 0;i<r;i++){
s1 += v[i].first*v[i].second;
s2 += v[i].first;
s3 += v[i].second;
s4 += pow(v[i].first,2);
s5 += v[i].first;
}
m = (r*s1 - s2*s3)/(r*s4 - pow(s5,2));
b = (s3 - m*s2)/r;
m = round(m * 1000)/1000;
b = round(b * 1000)/1000;
if(sec == "mb"){
cout<<m<<endl<<b;
}else if (sec == "func"){
string nm;
if(m==-1){
nm = "-";
}
else if(m==1){
nm = "";
}else{
nm = m;
cout<<nm;
}
if(m==0){
cout<<"y = "<<b;
}else if(abs(m)==1){
if(b<0){
cout<<"y = "<<nm<<"x - "<<abs(b);
}else if(b>0){
cout<<"y = "<<nm<<"x + "<<b;
}else{
cout<<"y = "<<nm<<"x";
}
}else{
if(b<0){
cout<<"y = "<<m<<"x - "<<abs(b);
}else if(b>0){
cout<<"y = "<<m<<"x + "<<b;
}else{
cout<<"y = "<<m<<"x";
}
}
}else{
cout<<"";
}
} |
# 1308, 2024-11-02 13:18:07, ---------------P--PP---- (12%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
string cmd;
vector<float> x,y;
cin>>n>>cmd;
float m,b,sumx=0,sumy=0,sumxy=0,sumpx=0;
while(n--){
float xi,yi;
cin>>xi>>yi;
x.push_back(xi);
y.push_back(yi);
}
for(int i=0;i<x.size();i++){
sumx+=x[i];
sumy+=y[i];
sumxy+=x[i]*y[i];
sumpx+=x[i]*x[i];
}
m=(n*sumxy-sumx*sumy)/(n*sumpx-sumx*sumx);
b=(sumy-m*sumx)/n;
if(cmd=="mb") cout<<m<<endl<<b;
if(cmd=="func"){
cout<<"y = ";
if(m==0&&b==0)cout<<"0";
else{
if(m!=0){
if(m==1);
else if(m==-1) cout<<"-";
else cout<<round(m*1e3)/1e3;
cout<<"x ";
if(b!=0){
if(b>0) cout<<"+ "<<round(b*1e3)/1e3;
else cout<<"- "<<round(b*1e3)/1e3;
}
}
else{
if(b>0) cout<<"+ "<<round(b*1e3)/1e3;
else cout<<"- "<<round(b*1e3)/1e3;
}
}
}
} | # 1309, 2024-11-02 13:35:27, ---------------P--PP---- (12%)
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main(){
float n;
string cmd;
map<float,float> p;
cin>>n>>cmd;
float m,b,sumx=0,sumy=0,sumxy=0,sumpx=0;
while(n--){
float xi,yi;
cin>>xi>>yi;
p[xi]=yi;
}
for(pair e:p){
sumx+=e.first;
sumy+=e.second;
sumxy+=e.first*e.second;
sumpx+=e.first*e.first;
}
m=((n*sumxy)-(sumx*sumy))/((n*sumpx)-(sumx*sumx));
b=(sumy-(m*sumx))/n;
if(cmd=="mb") cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3<<endl;
if(cmd=="func"){
cout<<"y = ";
if(m==0&&b==0)cout<<"0";
else{
if(m!=0){
if(m==1);
else if(m==-1) cout<<"-";
else cout<<round(m*1e3)/1e3;
cout<<"x ";
if(b!=0){
if(b>0) cout<<"+ "<<round(b*1e3)/1e3;
else cout<<"- "<<round(b*1e3)/1e3;
}
}
else{
if(b>0) cout<<"+ "<<round(b*1e3)/1e3;
else cout<<"- "<<-round(b*1e3)/1e3;
}
}
}
} | # 1310, 2024-11-02 15:22:08, PPPPPPPPPPP-P--P--PP---- (62%)
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main(){
float n;
string cmd;
map<float,float> p;
cin>>n>>cmd;
float m=0,b=0,sumx=0,sumy=0,sumxy=0,sumpx=0;
float nn=n;
while(n--){
float xi,yi;
cin>>xi>>yi;
p[xi]=yi;
}
for(pair e:p){
sumx+=e.first;
sumy+=e.second;
sumxy+=e.first*e.second;
sumpx+=e.first*e.first;
}
n=nn;
m=((n*sumxy)-(sumx*sumy))/((n*sumpx)-(sumx*sumx));
b=(sumy-(m*sumx))/n;
if(cmd=="mb") cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3<<endl;
if(cmd=="func"){
cout<<"y = ";
if(m==0&&b==0)cout<<"0";
else{
if(m!=0){
if(m==1);
else if(m==-1) cout<<"-";
else cout<<round(m*1e3)/1e3;
cout<<"x ";
if(b!=0){
if(b>0) cout<<"+ "<<round(b*1e3)/1e3;
else cout<<"- "<<round(b*1e3)/1e3;
}
}
else{
if(b>0) cout<<"+ "<<round(b*1e3)/1e3;
else cout<<"- "<<-round(b*1e3)/1e3;
}
}
}
} | # 1311, 2024-11-02 15:26:10, PPPPPPPPPPP-P--P--PP---- (62%)
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main(){
float n;
string cmd;
map<float,float> p;
cin>>n>>cmd;
float m=0,b=0,sumx=0,sumy=0,sumxy=0,sumpx=0;
float nn=n;
while(n--){
float xi,yi;
cin>>xi>>yi;
p[xi]=yi;
}
for(pair e:p){
sumx+=e.first;
sumy+=e.second;
sumxy+=e.first*e.second;
sumpx+=e.first*e.first;
}
n=nn;
m=((n*sumxy)-(sumx*sumy))/((n*sumpx)-(sumx*sumx));
b=(sumy-(m*sumx))/n;
if(cmd=="mb") cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3<<endl;
if(cmd=="func"){
cout<<"y = ";
if(m==0&&b==0)cout<<"0";
else{
if(m==0){
if(b>0) cout<<"+ "<<round(b*1e3)/1e3;
else cout<<"- "<<-round(b*1e3)/1e3;
}
else{
if(m==1);
else if(m==-1) cout<<"-";
else cout<<round(m*1e3)/1e3;
cout<<"x ";
if(b!=0){
if(b>0) cout<<"+ "<<round(b*1e3)/1e3;
else cout<<"- "<<round(b*1e3)/1e3;
}
}
}
}
} | # 1312, 2024-11-02 15:30:48, Compilation error (0%)
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main(){
float n;
string cmd;
map<float,float> p;
cin>>n>>cmd;
float m=0,b=0,sumx=0,sumy=0,sumxy=0,sumpx=0;
float nn=n;
while(n--){
float xi,yi;
cin>>xi>>yi;
p[xi]=yi;
}
for(pair e:p){
sumx+=e.first;
sumy+=e.second;
sumxy+=e.first*e.second;
sumpx+=e.first*e.first;
}
n=nn;
m=((n*sumxy)-(sumx*sumy))/((n*sumpx)-(sumx*sumx));
b=(sumy-(m*sumx))/n;
if(cmd=="mb") cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3<<endl;
if(cmd=="func"){
cout<<"y = ";
if(m==0&&b==0)cout<<"0";
else if(m==0&&b!=0){
cout<<b;
}
else if(m!=0&&b==0){
if(m==1);
else if(m==-1) cout<<"-";
else cout<<m;
cout<<"x";
}
else{
if(m==1);
else if(m==-1) cout<<"-";
else cout<<m;
cout<<"x + ";
}
}
}
} | # 1313, 2024-11-02 15:31:37, PPPPPPPPPP-----P--PP-P-- (58%)
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main(){
float n;
string cmd;
map<float,float> p;
cin>>n>>cmd;
float m=0,b=0,sumx=0,sumy=0,sumxy=0,sumpx=0;
float nn=n;
while(n--){
float xi,yi;
cin>>xi>>yi;
p[xi]=yi;
}
for(pair e:p){
sumx+=e.first;
sumy+=e.second;
sumxy+=e.first*e.second;
sumpx+=e.first*e.first;
}
n=nn;
m=((n*sumxy)-(sumx*sumy))/((n*sumpx)-(sumx*sumx));
b=(sumy-(m*sumx))/n;
if(cmd=="mb") cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3<<endl;
if(cmd=="func"){
cout<<"y = ";
if(m==0&&b==0)cout<<"0";
else if(m==0&&b!=0){
cout<<b;
}
else if(m!=0&&b==0){
if(m==1);
else if(m==-1) cout<<"-";
else cout<<m;
cout<<"x";
}
else{
if(m==1);
else if(m==-1) cout<<"-";
else cout<<m;
cout<<"x + ";
}
}
} | # 1314, 2024-11-02 15:32:15, PPPPPPPPPP-----P--PP-P-- (58%)
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main(){
float n;
string cmd;
map<float,float> p;
cin>>n>>cmd;
float m=0,b=0,sumx=0,sumy=0,sumxy=0,sumpx=0;
float nn=n;
while(n--){
float xi,yi;
cin>>xi>>yi;
p[xi]=yi;
}
for(pair e:p){
sumx+=e.first;
sumy+=e.second;
sumxy+=e.first*e.second;
sumpx+=e.first*e.first;
}
n=nn;
m=((n*sumxy)-(sumx*sumy))/((n*sumpx)-(sumx*sumx));
b=(sumy-(m*sumx))/n;
if(cmd=="mb") cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3<<endl;
if(cmd=="func"){
cout<<"y = ";
if(m==0&&b==0)cout<<"0";
else if(m==0&&b!=0){
cout<<b;
}
else if(m!=0&&b==0){
if(m==1);
else if(m==-1) cout<<"-";
else cout<<m;
cout<<"x";
}
else{
if(m==1);
else if(m==-1) cout<<"-";
else cout<<m;
cout<<"x + ";
cout<<b;
}
}
} |
# 1315, 2024-11-02 14:56:43, ------------------------ (0%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main() {
vector<pair<float, float>> s;
int a1;
cin >> a1;
string order;
cin >> order;
for (int i=0; i < a1; ++i) {
float x, y;
cin >> x >> y;
s.push_back({x,y});
}
int size_s = s.size();
float cal_xy = 0;
for (int i=0; i < size_s; ++i) {
cal_xy += s[i].first * s[i].second;
}
float cal_x = 0;
for (int i=0; i < size_s; ++i) {
cal_x += s[i].first;
}
float cal_y = 0;
for (int i=0; i < size_s; ++i) {
cal_y += s[i].second;
}
float cal_x2 = 0;
for (int i=0; i < size_s; ++i) {
cal_x2 += s[i].first * s[i].first;
}
float cal_y2 = 0;
for (int i=0; i < size_s; ++i) {
cal_y2 += s[i].second * s[i].second;
}
float m = ((size_s * cal_xy) - (cal_x*cal_y)) / (size_s * cal_x2) - (cal_x * cal_x);
float b = (cal_y - cal_x) / size_s;
if (order == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
} else {
cout << "y = " << round(m*1e3)/1e3 << " - " << round(b*1e3)/1e3 << endl;
}
} | # 1316, 2024-11-02 15:03:31, PPPPPPPPPP-------------- (41%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main() {
vector<pair<float, float>> s;
int a1;
cin >> a1;
string order;
cin >> order;
for (int i=0; i < a1; ++i) {
float x, y;
cin >> x >> y;
s.push_back({x,y});
}
int size_s = s.size();
float cal_xy = 0;
for (int i=0; i < size_s; ++i) {
cal_xy += s[i].first * s[i].second;
}
//cout << cal_xy << endl;
float cal_x = 0;
for (int i=0; i < size_s; ++i) {
cal_x += s[i].first;
}
//cout << cal_x << endl;
float cal_y = 0;
for (int i=0; i < size_s; ++i) {
cal_y += s[i].second;
}
//cout << cal_y << endl;
float cal_x2 = 0;
for (int i=0; i < size_s; ++i) {
cal_x2 += s[i].first * s[i].first;
}
//cout << cal_x2 << endl;
float cal_y2 = 0;
for (int i=0; i < size_s; ++i) {
cal_y2 += s[i].second * s[i].second;
}
//cout << cal_y2 << endl;
float m = ((size_s * cal_xy) - (cal_x*cal_y)) / ((size_s * cal_x2) - (cal_x * cal_x));
//cout << (size_s * cal_xy) - (cal_x*cal_y) << endl;
float b = (cal_y - (m*cal_x)) / size_s;
if (order == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
} else {
cout << "y = " << round(m*1e3)/1e3 << " - " << round(b*1e3)/1e3 << endl;
}
} | # 1317, 2024-11-02 15:12:55, PPPPPPPPPP-----P-------- (45%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main() {
vector<pair<float, float>> s;
int a1;
cin >> a1;
string order;
cin >> order;
for (int i=0; i < a1; ++i) {
float x, y;
cin >> x >> y;
s.push_back({x,y});
}
int size_s = s.size();
float cal_xy = 0;
for (int i=0; i < size_s; ++i) {
cal_xy += s[i].first * s[i].second;
}
//cout << cal_xy << endl;
float cal_x = 0;
for (int i=0; i < size_s; ++i) {
cal_x += s[i].first;
}
//cout << cal_x << endl;
float cal_y = 0;
for (int i=0; i < size_s; ++i) {
cal_y += s[i].second;
}
//cout << cal_y << endl;
float cal_x2 = 0;
for (int i=0; i < size_s; ++i) {
cal_x2 += s[i].first * s[i].first;
}
//cout << cal_x2 << endl;
float cal_y2 = 0;
for (int i=0; i < size_s; ++i) {
cal_y2 += s[i].second * s[i].second;
}
//cout << cal_y2 << endl;
float m = ((size_s * cal_xy) - (cal_x*cal_y)) / ((size_s * cal_x2) - (cal_x * cal_x));
//cout << (size_s * cal_xy) - (cal_x*cal_y) << endl;
float b = (cal_y - (m*cal_x)) / size_s;
if (order == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
} else {
if ((m != 0 && b != 0) || (b == 0 && m!=0)) {
if (m == 1) {
cout << "y = " << "x" << " - " << 0-round(b*1e3)/1e3 << endl;
} else if (m == -1) {
cout << "y = " << "-x" << " - " << 0-round(b*1e3)/1e3 << endl;
} else {
cout << "y = " << round(m*1e3)/1e3 << " - " << 0-round(b*1e3)/1e3 << endl;
}
} else if (m == 0) {
cout << "y = " << 0-round(b*1e3)/1e3 << endl;
} else {
cout << "y = 0";
}
}
} | # 1318, 2024-11-02 15:29:36, PPPPPPPPPP-P-PPP--P----- (62%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main() {
vector<pair<float, float>> s;
int a1;
cin >> a1;
string order;
cin >> order;
for (int i=0; i < a1; ++i) {
float x, y;
cin >> x >> y;
s.push_back({x,y});
}
int size_s = s.size();
float cal_xy = 0;
for (int i=0; i < size_s; ++i) {
cal_xy += s[i].first * s[i].second;
}
//cout << cal_xy << endl;
float cal_x = 0;
for (int i=0; i < size_s; ++i) {
cal_x += s[i].first;
}
//cout << cal_x << endl;
float cal_y = 0;
for (int i=0; i < size_s; ++i) {
cal_y += s[i].second;
}
//cout << cal_y << endl;
float cal_x2 = 0;
for (int i=0; i < size_s; ++i) {
cal_x2 += s[i].first * s[i].first;
}
//cout << cal_x2 << endl;
float cal_y2 = 0;
for (int i=0; i < size_s; ++i) {
cal_y2 += s[i].second * s[i].second;
}
//cout << cal_y2 << endl;
float m = ((size_s * cal_xy) - (cal_x*cal_y)) / ((size_s * cal_x2) - (cal_x * cal_x));
//cout << (size_s * cal_xy) - (cal_x*cal_y) << endl;
float b = (cal_y - (m*cal_x)) / size_s;
if (order == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
} else {
if (m == 0 && b == 0) {
cout << "y = 0" << endl;
} else if (m > 0 && b == 0) {
if (m == 1) {
cout << "y = " << "x" << endl;
} else if (m == -1) {
cout << "y = " << "-x" << endl;
} else {
cout << "y = " << round(m*1e3)/1e3 << "x" << endl;
}
} else {
cout << "y = " << round(m*1e3)/1e3 << "x" <<" - " << 0-round(b*1e3)/1e3 << endl;
}
}
} | # 1319, 2024-11-02 15:31:25, PPPPPPPPPP-----P--P----- (50%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main() {
vector<pair<float, float>> s;
int a1;
cin >> a1;
string order;
cin >> order;
for (int i=0; i < a1; ++i) {
float x, y;
cin >> x >> y;
s.push_back({x,y});
}
int size_s = s.size();
float cal_xy = 0;
for (int i=0; i < size_s; ++i) {
cal_xy += s[i].first * s[i].second;
}
//cout << cal_xy << endl;
float cal_x = 0;
for (int i=0; i < size_s; ++i) {
cal_x += s[i].first;
}
//cout << cal_x << endl;
float cal_y = 0;
for (int i=0; i < size_s; ++i) {
cal_y += s[i].second;
}
//cout << cal_y << endl;
float cal_x2 = 0;
for (int i=0; i < size_s; ++i) {
cal_x2 += s[i].first * s[i].first;
}
//cout << cal_x2 << endl;
float cal_y2 = 0;
for (int i=0; i < size_s; ++i) {
cal_y2 += s[i].second * s[i].second;
}
//cout << cal_y2 << endl;
float m = ((size_s * cal_xy) - (cal_x*cal_y)) / ((size_s * cal_x2) - (cal_x * cal_x));
//cout << (size_s * cal_xy) - (cal_x*cal_y) << endl;
float b = (cal_y - (m*cal_x)) / size_s;
if (order == "mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
} else {
if (m == 0 && b == 0) {
cout << "y = 0" << endl;
} else if (m > 0 && b == 0) {
if (m == 1) {
cout << "y = " << "x" << endl;
} else if (m == -1) {
cout << "y = " << "-x" << endl;
} else {
cout << "y = " << round(m*1e3)/1e3 << "x" << endl;
}
} else {
if (b < 0) {
cout << "y = " << round(m*1e3)/1e3 << "x" << " + " << abs(round(b*1e3)/1e3) << endl;
} else {
cout << "y = " << round(m*1e3)/1e3 << "x" << " - " << round(b*1e3)/1e3 << endl;
}
}
}
} |
# 1320, 2024-11-02 13:43:34, PPPPPPPPPP-----P-P---P-- (54%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string call;
cin >> N >> call;
map<int,pair<float,float>> point;
float x,y;
for(int i=1;i<=N;i++){
cin >> x>>y;
point[i]={x,y};
}
float sumx=0,sumy=0,sumall=0,m,b,powsumx;
for(int i=1;i<=N;i++){
// cout <<point[i].first <<" + " <<point[i].second;
sumx+=point[i].first;
sumy+=point[i].second;
sumall+=point[i].first*point[i].second;
powsumx += pow(point[i].first,2);
}
m=((N*sumall)-(sumx*sumy))/(N*powsumx-pow(sumx,2));
b= (sumy-m*sumx)/N;
if(call =="mb"){
cout << round(m*1e3)/1e3 <<endl<<round(b*1e3)/1e3;
}else if(call=="func"){
cout << "y = " ;
if(m==-1)cout << "-";
if(m==1) cout <<"";
if(m!=0) cout<<"x + ";
cout << b;
}
} | # 1321, 2024-11-02 13:47:33, PPPPPPPPPPPPPPP--------- (62%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string call;
cin >> N >> call;
map<int,pair<float,float>> point;
float x,y;
for(int i=1;i<=N;i++){
cin >> x>>y;
point[i]={x,y};
}
float sumx=0,sumy=0,sumall=0,m,b,powsumx;
for(int i=1;i<=N;i++){
// cout <<point[i].first <<" + " <<point[i].second;
sumx+=point[i].first;
sumy+=point[i].second;
sumall+=point[i].first*point[i].second;
powsumx += pow(point[i].first,2);
}
m=((N*sumall)-(sumx*sumy))/(N*powsumx-pow(sumx,2));
b= (sumy-m*sumx)/N;
if(call =="mb"){
cout << round(m*1e3)/1e3 <<endl<<round(b*1e3)/1e3;
}else if(call=="func"){
cout << "y = " ;
if(m==-1)cout << "-";
if(m==1) cout <<"";
if(m!=0) cout<<round(m*1e3)/1e3 <<"x ";
if(b<0) cout <<"- ";
if (b>0) cout << "+ ";
if (b!=0) cout << abs(round(b*1e3)/1e3);
}
} | # 1322, 2024-11-02 13:48:35, PPPPPPPPPPPP------------ (50%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string call;
cin >> N >> call;
map<int,pair<float,float>> point;
float x,y;
for(int i=1;i<=N;i++){
cin >> x>>y;
point[i]={x,y};
}
float sumx=0,sumy=0,sumall=0,m,b,powsumx;
for(int i=1;i<=N;i++){
// cout <<point[i].first <<" + " <<point[i].second;
sumx+=point[i].first;
sumy+=point[i].second;
sumall+=point[i].first*point[i].second;
powsumx += pow(point[i].first,2);
}
m=((N*sumall)-(sumx*sumy))/(N*powsumx-pow(sumx,2));
b= (sumy-m*sumx)/N;
if(call =="mb"){
cout << round(m*1e3)/1e3 <<endl<<round(b*1e3)/1e3;
}else if(call=="func"){
cout << "y = " ;
if(m==-1)cout << "-";
if(m==1) cout <<"";
if(m!=0) cout<<abs(round(m*1e3)/1e3) <<"x ";
if(b<0) cout <<"- ";
if (b>0) cout << "+ ";
if (b!=0) cout << abs(round(b*1e3)/1e3);
}
} | # 1323, 2024-11-02 13:54:06, PPPPPPPPPPPP------PP--P- (62%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string call;
cin >> N >> call;
map<int,pair<float,float>> point;
float x,y;
for(int i=1;i<=N;i++){
cin >> x>>y;
point[i]={x,y};
}
float sumx=0,sumy=0,sumall=0,m,b,powsumx;
for(int i=1;i<=N;i++){
// cout <<point[i].first <<" + " <<point[i].second;
sumx+=point[i].first;
sumy+=point[i].second;
sumall+=point[i].first*point[i].second;
powsumx += pow(point[i].first,2);
}
m=((N*sumall)-(sumx*sumy))/(N*powsumx-pow(sumx,2));
b= (sumy-m*sumx)/N;
if(call =="mb"){
cout << round(m*1e3)/1e3 <<endl<<round(b*1e3)/1e3;
}else if(call=="func"){
cout << "y = " ;
if(m==-1)cout << "-x ";
else if(m==1) cout <<"x ";
else if(m!=0) cout<<abs(round(m*1e3)/1e3) <<"x ";
if(b<0) cout <<"- ";
if (b>0) cout << "+ ";
if (b!=0) cout << abs(round(b*1e3)/1e3);
}
} |
# 1324, 2024-11-02 15:18:04, PPPPP-PPPP------------P- (41%)
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
int main(){
int n;
string s;
float x;
float y;
float m,b, d,e,f,g,h;
cin>>n;
cin>>s;
for(int i=0;i<n ;i++){
cin>> x>> y;
d+=x*y;
e+=x;
f+=y;
g+=pow(x,2);
h+=x;
}
m=(n*d-e*f)/(n*g-pow(e,2));
b=(f-m*e)/n;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
}
if(s=="func"){
string s_m ="";
string ope ="";
if(m==1){
s_m="";
if(b/abs(b)==1){
ope="+";
}
else{
ope="-";
}
cout<<"y = "<<s_m<<"x "<<ope<<" "<<abs(round(b*1e3)/1e3);
}
else if(m==-1){
s_m="-";
if(b/abs(b)==1){
ope="+";
}
else{
ope="-";
}
cout<<"y = "<<s_m<<"x "<<ope<<" "<<abs(round(b*1e3)/1e3);
}
else{
if(b/abs(b)==1){
ope="+";
}
else{
ope="-";
}
cout<<"y = "<<round(m*1e3)/1e3<<endl<<"x "<<ope<<" "<<abs(round(b*1e3)/1e3);
}
}
} | # 1325, 2024-11-02 15:23:26, PPPPP-PPPP-----P------P- (45%)
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
int main(){
int n;
string s;
float x;
float y;
float m,b, d,e,f,g,h;
cin>>n;
cin>>s;
for(int i=0;i<n ;i++){
cin>> x>> y;
d+=x*y;
e+=x;
f+=y;
g+=pow(x,2);
h+=x;
}
m=(n*d-e*f)/(n*g-pow(e,2));
b=(f-m*e)/n;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
}
if(s=="func"){
string s_m ="";
string ope ="";
if(y==0){
cout<< "y = 0";
}
else{
if(m==0){
cout<< "y = "<< abs(round(b*1e3)/1e3);
cout<<"kkk";
}
else if(m==1){
s_m="";
if(b/abs(b)==1){
ope="+";
}
else{
ope="-";
}
cout<<"y = "<<s_m<<"x "<<ope<<" "<<abs(round(b*1e3)/1e3);
}
else if(m==-1){
s_m="-";
if(b/abs(b)==1){
ope="+";
}
else{
ope="-";
}
cout<<"y = "<<s_m<<"x "<<ope<<" "<<abs(round(b*1e3)/1e3);
}
else{
if(b/abs(b)==1){
ope="+";
}
else{
ope="-";
}
cout<<"y = "<<round(m*1e3)/1e3<<endl<<"x "<<ope<<" "<<abs(round(b*1e3)/1e3);
}
}
}
} | # 1326, 2024-11-02 15:30:16, PPPPP-PPPP-----PPP--P-PP (62%)
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
int main(){
int n;
string s;
float x;
float y;
float m,b, d,e,f,g,h;
cin>>n;
cin>>s;
for(int i=0;i<n ;i++){
cin>> x>> y;
d+=x*y;
e+=x;
f+=y;
g+=pow(x,2);
h+=x;
}
m=(n*d-e*f)/(n*g-pow(e,2));
b=(f-m*e)/n;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
}
if(s=="func"){
string s_m ="";
string ope ="";
if(y==0){
cout<< "y = 0";
}
else{
if(abs(round(m*1e3)/1e3-0)<pow(10,-8)){
cout<< "y = "<< abs(round(b*1e3)/1e3);
}
else if(round(m*1e3)/1e3==1){
s_m="";
if(b/abs(b)==1){
ope="+";
}
else{
ope="-";
}
cout<<"y = "<<s_m<<"x "<<ope<<" "<<abs(round(b*1e3)/1e3);
}
else if(round(m*1e3)/1e3==-1){
s_m="-";
if(b/abs(b)==1){
ope="+";
}
else{
ope="-";
}
cout<<"y = "<<s_m<<"x "<<ope<<" "<<abs(round(b*1e3)/1e3);
}
else{
if(b/abs(b)==1){
ope="+";
}
else{
ope="-";
}
cout<<"y = "<<round(m*1e3)/1e3<<endl<<"x "<<ope<<" "<<abs(round(b*1e3)/1e3);
}
}
}
} | # 1327, 2024-11-02 15:30:50, PPPPP-PPPP-----PPP--P-PP (62%)
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
int main(){
int n;
string s;
float x;
float y;
float m,b, d,e,f,g,h;
cin>>n;
cin>>s;
for(int i=0;i<n ;i++){
cin>> x>> y;
d+=x*y;
e+=x;
f+=y;
g+=pow(x,2);
h+=x;
}
m=(n*d-e*f)/(n*g-pow(e,2));
b=(f-m*e)/n;
if(s=="mb"){
cout<<round(m*1e3)/1e3<<endl;
cout<<round(b*1e3)/1e3<<endl;
}
if(s=="func"){
string s_m ="";
string ope ="";
if(y==0){
cout<< "y = 0";
}
else{
if(round(m*1e3)/1e3==0){
cout<< "y = "<< abs(round(b*1e3)/1e3);
}
else if(round(m*1e3)/1e3==1){
s_m="";
if(b/abs(b)==1){
ope="+";
}
else{
ope="-";
}
cout<<"y = "<<s_m<<"x "<<ope<<" "<<abs(round(b*1e3)/1e3);
}
else if(round(m*1e3)/1e3==-1){
s_m="-";
if(b/abs(b)==1){
ope="+";
}
else{
ope="-";
}
cout<<"y = "<<s_m<<"x "<<ope<<" "<<abs(round(b*1e3)/1e3);
}
else{
if(b/abs(b)==1){
ope="+";
}
else{
ope="-";
}
cout<<"y = "<<round(m*1e3)/1e3<<endl<<"x "<<ope<<" "<<abs(round(b*1e3)/1e3);
}
}
}
} |
# 1328, 2024-11-02 09:34:39, -----PPPPP---------PP--P (33%)
#include <iostream>
#include <map>
#include <cmath>
using namespace std;
float xiyi(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.first*i.second;
}
return sum;
}
float eachxi(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.first;
}
return sum;
}
float eachyi(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.second;
}
return sum;
}
float powereach(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.first*i.first;
}
return sum;
}
int main(){
int i,n;
map<float,float> store;
float xi,yi,m,b;
string type;
cin >> n >> type;
for(i=0;i<n;++i){
cin >> xi >> yi;
store[xi]=yi;
}
xi=eachxi(store);
yi=eachyi(store);
float xiyinum,pxi;
xiyinum = xiyi(store);
pxi= powereach(store);
m=((n*xiyinum)-(xi*yi))/((n*pxi)-(xi*xi));
m=round(m*1e3)/1e3;
b=(yi-(m*xi))/n;
b=round(b*1e3)/1e3;
if(type=="mb"){
cout << m << endl;
cout << b << endl;
}else{
cout << "y = ";
if(m!=0&&m!=-1){
cout << m <<"x";
}else if(m==-1){
cout << "-x";
}
if(b!=0&&b>0){
cout << " + " << b;
}else if(b<0){
cout << " - " << b*(-1);
}
}
} | # 1329, 2024-11-02 09:37:20, -----PPPPP-----P---PP--P (37%)
#include <iostream>
#include <map>
#include <cmath>
using namespace std;
float xiyi(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.first*i.second;
}
return sum;
}
float eachxi(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.first;
}
return sum;
}
float eachyi(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.second;
}
return sum;
}
float powereach(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.first*i.first;
}
return sum;
}
int main(){
int i,n;
map<float,float> store;
float xi,yi,m,b;
string type;
cin >> n >> type;
for(i=0;i<n;++i){
cin >> xi >> yi;
store[xi]=yi;
}
xi=eachxi(store);
yi=eachyi(store);
float xiyinum,pxi;
xiyinum = xiyi(store);
pxi= powereach(store);
m=((n*xiyinum)-(xi*yi))/((n*pxi)-(xi*xi));
m=round(m*1e3)/1e3;
b=(yi-(m*xi))/n;
b=round(b*1e3)/1e3;
if(type=="mb"){
cout << m << endl;
cout << b << endl;
}else{
cout << "y = ";
if(m!=0&&m!=-1){
cout << m <<"x";
}else if(m==-1){
cout << "-x";
}
if(b!=0&&b>0){
cout << " + " << b;
}else if(b<0){
cout << " - " << b*(-1);
}
if(m==0&&b==0){
cout << "0";
}
}
} | # 1330, 2024-11-02 09:38:52, -----PPPPP-----P-PPPP-PP (50%)
#include <iostream>
#include <map>
#include <cmath>
using namespace std;
float xiyi(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.first*i.second;
}
return sum;
}
float eachxi(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.first;
}
return sum;
}
float eachyi(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.second;
}
return sum;
}
float powereach(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.first*i.first;
}
return sum;
}
int main(){
int i,n;
map<float,float> store;
float xi,yi,m,b;
string type;
cin >> n >> type;
for(i=0;i<n;++i){
cin >> xi >> yi;
store[xi]=yi;
}
xi=eachxi(store);
yi=eachyi(store);
float xiyinum,pxi;
xiyinum = xiyi(store);
pxi= powereach(store);
m=((n*xiyinum)-(xi*yi))/((n*pxi)-(xi*xi));
m=round(m*1e3)/1e3;
b=(yi-(m*xi))/n;
b=round(b*1e3)/1e3;
if(type=="mb"){
cout << m << endl;
cout << b << endl;
}else{
cout << "y = ";
if(m==1){
cout << "x";
}else if(m!=0&&m!=-1){
cout << m <<"x";
}else if(m==-1){
cout << "-x";
}
if(b!=0&&b>0){
cout << " + " << b;
}else if(b<0){
cout << " - " << b*(-1);
}
if(m==0&&b==0){
cout << "0";
}
}
} | # 1331, 2024-11-02 11:34:32, -----PPPPP-----P-PPPPPPP (54%)
#include <iostream>
#include <map>
#include <cmath>
using namespace std;
float xiyi(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.first*i.second;
}
return sum;
}
float eachxi(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.first;
}
return sum;
}
float eachyi(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.second;
}
return sum;
}
float powereach(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.first*i.first;
}
return sum;
}
int main(){
int i,n;
map<float,float> store;
float xi,yi,m,b;
string type;
cin >> n >> type;
for(i=0;i<n;++i){
cin >> xi >> yi;
store[xi]=yi;
}
xi=eachxi(store);
yi=eachyi(store);
float xiyinum,pxi;
xiyinum = xiyi(store);
pxi= powereach(store);
m=((n*xiyinum)-(xi*yi))/((n*pxi)-(xi*xi));
m+=0.0001;
m=round(m*1e3)/1e3;
b=(yi-(m*xi))/n;
b=round(b*1e3)/1e3;
if(type=="mb"){
cout << m << endl;
cout << b << endl;
}else{
cout << "y = ";
if(m==1){
cout << "x ";
}else if(m!=0&&m!=-1){
cout << m <<"x ";
}else if(m==-1){
cout << "-x ";
}
if(b!=0&&b>0){
cout << "+ " << b;
}else if(b<0){
if(m==0){
cout << "-";
}else{
cout << "- ";
}
cout << b*(-1);
}
if(m==0&&b==0){
cout << "0";
}
}
} | # 1332, 2024-11-02 11:39:14, -----PPPPP-----P-PPPPPPP (54%)
#include <iostream>
#include <map>
#include <cmath>
using namespace std;
float xiyi(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.first*i.second;
}
return sum;
}
float eachxi(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.first;
}
return sum;
}
float eachyi(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.second;
}
return sum;
}
float powereach(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.first*i.first;
}
return sum;
}
int main(){
int i,n;
map<float,float> store;
float xi,yi,m,b;
string type;
cin >> n >> type;
for(i=0;i<n;++i){
cin >> xi >> yi;
store[xi]=yi;
}
xi=eachxi(store);
yi=eachyi(store);
float xiyinum,pxi;
xiyinum = xiyi(store);
pxi= powereach(store);
m=((n*xiyinum)-(xi*yi))/((n*pxi)-(xi*xi));
m=round(m*1e3)/1e3;
b=(yi-(m*xi))/n;
b=round(b*1e3)/1e3;
if(type=="mb"){
cout << m << endl;
cout << b << endl;
}else{
cout << "y = ";
if(m==1){
cout << "x ";
}else if(m!=0&&m!=-1){
cout << m <<"x ";
}else if(m==-1){
cout << "-x ";
}
if(b!=0&&b>0){
cout << "+ " << b;
}else if(b<0){
if(m==0){
cout << "-";
}else{
cout << "- ";
}
cout << b*(-1);
}
if(m==0&&b==0){
cout << "0";
}
}
} | # 1333, 2024-11-02 11:44:48, -----PPPPP-----P-PPPPPPP (54%)
#include <iostream>
#include <map>
#include <cmath>
using namespace std;
float xiyi(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.first*i.second;
}
return sum;
}
float eachxi(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.first;
}
return sum;
}
float eachyi(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.second;
}
return sum;
}
float powereach(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.first*i.first;
}
return sum;
}
int main(){
int i,n;
map<float,float> store;
float xi,yi,m,b;
string type;
cin >> n >> type;
for(i=0;i<n;++i){
cin >> xi >> yi;
store[xi]=yi;
}
xi=eachxi(store);
yi=eachyi(store);
float xiyinum,pxi;
bool ne1=0,ne2=0;
xiyinum = xiyi(store);
pxi= powereach(store);
m=((n*xiyinum)-(xi*yi))/((n*pxi)-(xi*xi));
if(m<0) ne1=1;
m = abs(m);
m=round(m*1e3)/1e3;
if(ne1) m*=-1;
b=(yi-(m*xi))/n;
if(b<0) ne2=1;
b= abs(b);
b=round(b*1e3)/1e3;
if(ne2) b*=-1;
if(type=="mb"){
cout << m << endl;
cout << b << endl;
}else{
cout << "y = ";
if(m==1){
cout << "x ";
}else if(m!=0&&m!=-1){
cout << m <<"x ";
}else if(m==-1){
cout << "-x ";
}
if(b!=0&&b>0){
cout << "+ " << b;
}else if(b<0){
if(m==0){
cout << "-";
}else{
cout << "- ";
}
cout << b*(-1);
}
if(m==0&&b==0){
cout << "0";
}
}
} | # 1334, 2024-11-02 11:48:21, -----PPPPP-----P-PPPPPPP (54%)
#include <iostream>
#include <map>
#include <cmath>
using namespace std;
float xiyi(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.first*i.second;
}
return sum;
}
float eachxi(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.first;
}
return sum;
}
float eachyi(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.second;
}
return sum;
}
float powereach(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.first*i.first;
}
return sum;
}
int main(){
int i,n;
map<float,float> store;
float xi,yi,m,b;
string type;
cin >> n >> type;
for(i=0;i<n;++i){
cin >> xi >> yi;
store[xi]=yi;
}
xi=eachxi(store);
yi=eachyi(store);
float xiyinum,pxi;
bool ne1=0,ne2=0;
xiyinum = xiyi(store);
pxi= powereach(store);
m=((n*xiyinum)-(xi*yi))/((n*pxi)-(xi*xi));
if(m<0) ne1=1;
m = abs(m);
m+=0.0003;
m = round(m*1e3)/1e3;
if(ne1) m*=-1;
b=(yi-(m*xi))/n;
if(b<0) ne2=1;
b= abs(b);
b+=0.0003;
b=round(b*1e3)/1e3;
if(ne2) b*=-1;
if(type=="mb"){
cout << m << endl;
cout << b << endl;
}else{
cout << "y = ";
if(m==1){
cout << "x ";
}else if(m!=0&&m!=-1){
cout << m <<"x ";
}else if(m==-1){
cout << "-x ";
}
if(b!=0&&b>0){
cout << "+ " << b;
}else if(b<0){
if(m==0){
cout << "-";
}else{
cout << "- ";
}
cout << b*(-1);
}
if(m==0&&b==0){
cout << "0";
}
}
} | # 1335, 2024-11-02 11:51:09, -----PPPPP-----P-PPPPPPP (54%)
#include <iostream>
#include <map>
#include <cmath>
using namespace std;
float xiyi(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.first*i.second;
}
return sum;
}
float eachxi(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.first;
}
return sum;
}
float eachyi(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.second;
}
return sum;
}
float powereach(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.first*i.first;
}
return sum;
}
int main(){
int i,n;
map<float,float> store;
float xi,yi,m,b;
string type;
cin >> n >> type;
for(i=0;i<n;++i){
cin >> xi >> yi;
store[xi]=yi;
}
xi=eachxi(store);
yi=eachyi(store);
float xiyinum,pxi;
bool ne1=0,ne2=0;
xiyinum = xiyi(store);
pxi= powereach(store);
m=((n*xiyinum)-(xi*yi))/((n*pxi)-(xi*xi));
if(m<0) ne1=1;
m = abs(m);
m = round(m*1e3)/1e3;
if(ne1) m*=-1;
b=(yi-(m*xi))/n;
if(b<0) ne2=1;
b= abs(b);
b+=0.0003;
b=round(b*1e3)/1e3;
if(ne2) b*=-1;
if(type=="mb"){
cout << m << endl;
cout << b << endl;
}else{
cout << "y = ";
if(m==1){
cout << "x ";
}else if(m!=0&&m!=-1){
cout << m <<"x ";
}else if(m==-1){
cout << "-x ";
}
if(b!=0&&b>0){
cout << "+ " << b;
}else if(b<0){
if(m==0){
cout << "-";
}else{
cout << "- ";
}
cout << b*(-1);
}
if(m==0&&b==0){
cout << "0";
}
}
} | # 1336, 2024-11-02 11:52:53, -----PPPPP-----P-PPPPPPP (54%)
#include <iostream>
#include <map>
#include <cmath>
using namespace std;
float xiyi(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.first*i.second;
}
return sum;
}
float eachxi(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.first;
}
return sum;
}
float eachyi(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.second;
}
return sum;
}
float powereach(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.first*i.first;
}
return sum;
}
int main(){
int i,n;
map<float,float> store;
float xi,yi,m,b;
string type;
cin >> n >> type;
for(i=0;i<n;++i){
cin >> xi >> yi;
store[xi]=yi;
}
xi=eachxi(store);
yi=eachyi(store);
float xiyinum,pxi;
bool ne1=0,ne2=0;
xiyinum = xiyi(store);
pxi= powereach(store);
m=((n*xiyinum)-(xi*yi))/((n*pxi)-(xi*xi));
if(m<0) ne1=1;
m = abs(m);
m = round(m*1e3)/1e3;
if(ne1) m*=-1;
b=(yi-(m*xi))/n;
if(b<0) ne2=1;
b= abs(b);
b=round(b*1e3)/1e3;
if(ne2) b*=-1;
if(type=="mb"){
cout << m << endl;
cout << b << endl;
}else{
cout << "y = ";
if(m==1){
cout << "x ";
}else if(m!=0&&m!=-1){
cout << m <<"x ";
}else if(m==-1){
cout << "-x ";
}
if(b!=0&&b>0){
cout << "+ " << b;
}else if(b<0){
if(m==0){
cout << "-";
}else{
cout << "- ";
}
cout << b*(-1);
}
if(m==0&&b==0){
cout << "0";
}
}
} | # 1337, 2024-11-02 11:56:00, -----PPPPP-----P-PPPPPPP (54%)
#include <iostream>
#include <map>
#include <cmath>
using namespace std;
float xiyi(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.first*i.second;
}
return sum;
}
float eachxi(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.first;
}
return sum;
}
float eachyi(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.second;
}
return sum;
}
float powereach(map<float,float> s){
float sum=0;
for(auto i : s){
sum += i.first*i.first;
}
return sum;
}
int main(){
int i,num;
map<float,float> store;
float xi,yi,m,b;
string type;
cin >> num >> type;
for(i=0;i<num;++i){
cin >> xi >> yi;
store[xi]=yi;
}
xi=eachxi(store);
yi=eachyi(store);
float xiyinum,pxi;
bool ne1=0,ne2=0;
xiyinum = xiyi(store);
pxi= powereach(store);
float n=store.size();
m=((n*xiyinum)-(xi*yi))/((n*pxi)-(xi*xi));
if(m<0) ne1=1;
m = abs(m);
m = round(m*1e3)/1e3;
if(ne1) m*=-1;
b=(yi-(m*xi))/n;
if(b<0) ne2=1;
b= abs(b);
b=round(b*1e3)/1e3;
if(ne2) b*=-1;
if(type=="mb"){
cout << m << endl;
cout << b << endl;
}else{
cout << "y = ";
if(m==1){
cout << "x ";
}else if(m!=0&&m!=-1){
cout << m <<"x ";
}else if(m==-1){
cout << "-x ";
}
if(b!=0&&b>0){
cout << "+ " << b;
}else if(b<0){
if(m==0){
cout << "-";
}else{
cout << "- ";
}
cout << b*(-1);
}
if(m==0&&b==0){
cout << "0";
}
}
} | # 1338, 2024-11-02 11:58:31, -----PPPPP-----P-PPPPPPP (54%)
#include <iostream>
#include <map>
#include <set>
#include <cmath>
using namespace std;
float xiyi(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.first*i.second;
}
return sum;
}
float eachxi(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.first;
}
return sum;
}
float eachyi(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.second;
}
return sum;
}
float powereach(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.first*i.first;
}
return sum;
}
int main(){
int i,num;
set<pair<float,float>> store;
float xi,yi,m,b;
string type;
cin >> num >> type;
for(i=0;i<num;++i){
cin >> xi >> yi;
store.insert(make_pair(xi,yi));
}
xi=eachxi(store);
yi=eachyi(store);
float xiyinum,pxi;
bool ne1=0,ne2=0;
xiyinum = xiyi(store);
pxi= powereach(store);
float n=store.size();
m=((n*xiyinum)-(xi*yi))/((n*pxi)-(xi*xi));
if(m<0) ne1=1;
m = abs(m);
m = round(m*1e3)/1e3;
if(ne1) m*=-1;
b=(yi-(m*xi))/n;
if(b<0) ne2=1;
b= abs(b);
b=round(b*1e3)/1e3;
if(ne2) b*=-1;
if(type=="mb"){
cout << m << endl;
cout << b << endl;
}else{
cout << "y = ";
if(m==1){
cout << "x ";
}else if(m!=0&&m!=-1){
cout << m <<"x ";
}else if(m==-1){
cout << "-x ";
}
if(b!=0&&b>0){
cout << "+ " << b;
}else if(b<0){
if(m==0){
cout << "-";
}else{
cout << "- ";
}
cout << b*(-1);
}
if(m==0&&b==0){
cout << "0";
}
}
} | # 1339, 2024-11-02 11:59:52, -----PPPPP-----P-PPPPPPP (54%)
#include <iostream>
#include <map>
#include <set>
#include <cmath>
using namespace std;
float xiyi(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.first*i.second;
}
return sum;
}
float eachxi(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.first;
}
return sum;
}
float eachyi(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.second;
}
return sum;
}
float powereach(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.first*i.first;
}
return sum;
}
int main(){
int i,num;
set<pair<float,float>> store;
float xi,yi,m,b;
string type;
cin >> num >> type;
for(i=0;i<num;++i){
cin >> xi >> yi;
store.insert(make_pair(xi,yi));
}
xi=eachxi(store);
yi=eachyi(store);
float xiyinum,pxi;
bool ne1=0,ne2=0;
xiyinum = xiyi(store);
pxi= powereach(store);
float n = store.size();
m=((n*xiyinum)-(xi*yi))/((n*pxi)-(xi*xi));
if(m<0) ne1=1;
m = abs(m);
m = round(m*1e3)/1e3;
if(ne1) m*=-1;
b=(yi-(m*xi))/n;
if(b<0) ne2=1;
b= abs(b);
b=round(b*1e3)/1e3;
if(ne2) b*=-1;
if(type=="mb"){
cout << m << endl;
cout << b << endl;
}else{
cout << "y = ";
if(m==1){
cout << "x ";
}else if(m!=0&&m!=-1){
cout << m <<"x ";
}else if(m==-1){
cout << "-x ";
}
if(b!=0&&b>0){
cout << "+ " << b;
}else if(b<0){
if(m==0){
cout << "-";
}else{
cout << "- ";
}
cout << b*(-1);
}
if(m==0&&b==0){
cout << "0";
}
}
} | # 1340, 2024-11-02 12:01:08, -----PPPPP-----P-PPPPPPP (54%)
#include <iostream>
#include <map>
#include <set>
#include <cmath>
using namespace std;
float xiyi(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.first*i.second;
}
return sum;
}
float eachxi(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.first;
}
return sum;
}
float eachyi(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.second;
}
return sum;
}
float powereach(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.first*i.first;
}
return sum;
}
int main(){
int i,num;
set<pair<float,float>> store;
float xi,yi,m,b;
string type;
cin >> num >> type;
for(i=0;i<num;++i){
cin >> xi >> yi;
store.insert(make_pair(xi,yi));
}
xi=eachxi(store);
yi=eachyi(store);
float xiyinum,pxi;
bool ne1=0,ne2=0;
xiyinum = xiyi(store);
pxi= powereach(store);
float n = store.size();
m=((n*xiyinum)-(xi*yi))/((n*pxi)-(xi*xi));
if(m<0) ne1=1;
m = abs(m);
m += 0.0003;
m = round(m*1e3)/1e3;
if(ne1) m*=-1;
b=(yi-(m*xi))/n;
if(b<0) ne2=1;
b= abs(b);
b+=0.0003;
b=round(b*1e3)/1e3;
if(ne2) b*=-1;
if(type=="mb"){
cout << m << endl;
cout << b << endl;
}else{
cout << "y = ";
if(m==1){
cout << "x ";
}else if(m!=0&&m!=-1){
cout << m <<"x ";
}else if(m==-1){
cout << "-x ";
}
if(b!=0&&b>0){
cout << "+ " << b;
}else if(b<0){
if(m==0){
cout << "-";
}else{
cout << "- ";
}
cout << b*(-1);
}
if(m==0&&b==0){
cout << "0";
}
}
} | # 1341, 2024-11-02 12:04:01, -----PPPPP-----PP-PP-PPP (50%)
#include <iostream>
#include <map>
#include <set>
#include <cmath>
using namespace std;
float xiyi(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.first*i.second;
}
return sum;
}
float eachxi(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.first;
}
return sum;
}
float eachyi(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.second;
}
return sum;
}
float powereach(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.first*i.first;
}
return sum;
}
int main(){
int i,num;
set<pair<float,float>> store;
float xi,yi,m,b;
string type;
cin >> num >> type;
for(i=0;i<num;++i){
cin >> xi >> yi;
store.insert(make_pair(xi,yi));
}
xi=eachxi(store);
yi=eachyi(store);
float xiyinum,pxi;
bool ne1=0,ne2=0;
xiyinum = xiyi(store);
pxi= powereach(store);
float n = store.size();
m=((n*xiyinum)-(xi*yi))/((n*pxi)-(xi*xi));
if(m<0) ne1=1;
m = abs(m);
m += 0.0003;
m = round(m*1e3)/1e3;
if(ne1) m*=-1;
b=(yi-(m*xi))/n;
if(b<0) ne2=1;
b= abs(b);
b+=0.0003;
b=round(b*1e3)/1e3;
if(ne2) b*=-1;
if(type=="mb"){
cout << m << endl;
cout << b << endl;
}else{
cout << "y = ";
if(m==1){
cout << "x ";
}else if(m!=0&&m!=-1){
cout << m <<"x ";
}else if(m==-1){
cout << "-x ";
}
if(b!=0&&b>0){
if(m==0){
}else{
cout << "- ";
}
cout << b;
}else if(b<0){
if(m==0){
cout << "-";
}else{
cout << "- ";
}
cout << b*(-1);
}
if(m==0&&b==0){
cout << "0";
}
}
} | # 1342, 2024-11-02 12:04:28, -----PPPPP-----PPPPPPPPP (58%)
#include <iostream>
#include <map>
#include <set>
#include <cmath>
using namespace std;
float xiyi(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.first*i.second;
}
return sum;
}
float eachxi(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.first;
}
return sum;
}
float eachyi(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.second;
}
return sum;
}
float powereach(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.first*i.first;
}
return sum;
}
int main(){
int i,num;
set<pair<float,float>> store;
float xi,yi,m,b;
string type;
cin >> num >> type;
for(i=0;i<num;++i){
cin >> xi >> yi;
store.insert(make_pair(xi,yi));
}
xi=eachxi(store);
yi=eachyi(store);
float xiyinum,pxi;
bool ne1=0,ne2=0;
xiyinum = xiyi(store);
pxi= powereach(store);
float n = store.size();
m=((n*xiyinum)-(xi*yi))/((n*pxi)-(xi*xi));
if(m<0) ne1=1;
m = abs(m);
m += 0.0003;
m = round(m*1e3)/1e3;
if(ne1) m*=-1;
b=(yi-(m*xi))/n;
if(b<0) ne2=1;
b= abs(b);
b+=0.0003;
b=round(b*1e3)/1e3;
if(ne2) b*=-1;
if(type=="mb"){
cout << m << endl;
cout << b << endl;
}else{
cout << "y = ";
if(m==1){
cout << "x ";
}else if(m!=0&&m!=-1){
cout << m <<"x ";
}else if(m==-1){
cout << "-x ";
}
if(b!=0&&b>0){
if(m==0){
}else{
cout << "+ ";
}
cout << b;
}else if(b<0){
if(m==0){
cout << "-";
}else{
cout << "- ";
}
cout << b*(-1);
}
if(m==0&&b==0){
cout << "0";
}
}
} | # 1343, 2024-11-02 12:04:48, -----PPPPP-----PPPPPPPPP (58%)
#include <iostream>
#include <map>
#include <set>
#include <cmath>
using namespace std;
float xiyi(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.first*i.second;
}
return sum;
}
float eachxi(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.first;
}
return sum;
}
float eachyi(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.second;
}
return sum;
}
float powereach(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.first*i.first;
}
return sum;
}
int main(){
int i,num;
set<pair<float,float>> store;
float xi,yi,m,b;
string type;
cin >> num >> type;
for(i=0;i<num;++i){
cin >> xi >> yi;
store.insert(make_pair(xi,yi));
}
xi=eachxi(store);
yi=eachyi(store);
float xiyinum,pxi;
bool ne1=0,ne2=0;
xiyinum = xiyi(store);
pxi= powereach(store);
float n = store.size();
m=((n*xiyinum)-(xi*yi))/((n*pxi)-(xi*xi));
if(m<0) ne1=1;
m = abs(m);
m = round(m*1e3)/1e3;
if(ne1) m*=-1;
b=(yi-(m*xi))/n;
if(b<0) ne2=1;
b= abs(b);
b=round(b*1e3)/1e3;
if(ne2) b*=-1;
if(type=="mb"){
cout << m << endl;
cout << b << endl;
}else{
cout << "y = ";
if(m==1){
cout << "x ";
}else if(m!=0&&m!=-1){
cout << m <<"x ";
}else if(m==-1){
cout << "-x ";
}
if(b!=0&&b>0){
if(m==0){
}else{
cout << "+ ";
}
cout << b;
}else if(b<0){
if(m==0){
cout << "-";
}else{
cout << "- ";
}
cout << b*(-1);
}
if(m==0&&b==0){
cout << "0";
}
}
} | # 1344, 2024-11-02 12:07:01, -----PPPPP-----PPPPPPPPP (58%)
#include <iostream>
#include <map>
#include <set>
#include <cmath>
using namespace std;
float xiyi(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.first*i.second;
}
return sum;
}
float eachxi(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.first;
}
return sum;
}
float eachyi(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.second;
}
return sum;
}
float powereach(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.first*i.first;
}
return sum;
}
int main(){
int i,num;
set<pair<float,float>> store;
float xi,yi,m,b;
string type;
cin >> num >> type;
for(i=0;i<num;++i){
cin >> xi >> yi;
store.insert(make_pair(xi,yi));
}
xi=eachxi(store);
yi=eachyi(store);
float xiyinum,pxi;
bool ne1=0,ne2=0;
xiyinum = xiyi(store);
pxi= powereach(store);
float n = store.size();
m=((n*xiyinum)-(xi*yi))/((n*pxi)-(xi*xi));
if(m<0) ne1=1;
m = abs(m);
m = round(m*1e3)/1e3;
if(ne1) m*=-1;
b=(yi-(m*xi))/n;
if(b<0) ne2=1;
b= abs(b);
b=round(b*1e3)/1e3;
if(ne2) b*=-1;
if(type=="mb"){
cout << m << endl;
cout << b;
}else{
cout << "y = ";
if(m==1){
cout << "x ";
}else if(m!=0&&m!=-1){
cout << m <<"x ";
}else if(m==-1){
cout << "-x ";
}
if(b!=0&&b>0){
if(m==0){
}else{
cout << "+ ";
}
cout << b;
}else if(b<0){
if(m==0){
cout << "-";
}else{
cout << "- ";
}
cout << b*(-1);
}
if(m==0&&b==0){
cout << "0";
}
}
} | # 1345, 2024-11-02 12:07:31, ---------------PPPPPPPPP (37%)
#include <iostream>
#include <map>
#include <set>
#include <cmath>
using namespace std;
float xiyi(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.first*i.second;
}
return sum;
}
float eachxi(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.first;
}
return sum;
}
float eachyi(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.second;
}
return sum;
}
float powereach(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.first*i.first;
}
return sum;
}
int main(){
int i,num;
set<pair<float,float>> store;
float xi,yi,m,b;
string type;
cin >> num >> type;
for(i=0;i<num;++i){
cin >> xi >> yi;
store.insert(make_pair(xi,yi));
}
xi=eachxi(store);
yi=eachyi(store);
float xiyinum,pxi;
bool ne1=0,ne2=0;
xiyinum = xiyi(store);
pxi= powereach(store);
float n = store.size();
m=((n*xiyinum)-(xi*yi))/((n*pxi)-(xi*xi));
if(m<0) ne1=1;
m = abs(m);
m = round(m*1e3)/1e3;
if(ne1) m*=-1;
b=(yi-(m*xi))/n;
if(b<0) ne2=1;
b= abs(b);
b=round(b*1e3)/1e3;
if(ne2) b*=-1;
if(type=="mb"){
cout << m << " " << b << endl;
//cout << b;
}else{
cout << "y = ";
if(m==1){
cout << "x ";
}else if(m!=0&&m!=-1){
cout << m <<"x ";
}else if(m==-1){
cout << "-x ";
}
if(b!=0&&b>0){
if(m==0){
}else{
cout << "+ ";
}
cout << b;
}else if(b<0){
if(m==0){
cout << "-";
}else{
cout << "- ";
}
cout << b*(-1);
}
if(m==0&&b==0){
cout << "0";
}
}
} | # 1346, 2024-11-02 12:08:04, -----PPPPP-----PPPPPPPPP (58%)
#include <iostream>
#include <map>
#include <set>
#include <cmath>
using namespace std;
float xiyi(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.first*i.second;
}
return sum;
}
float eachxi(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.first;
}
return sum;
}
float eachyi(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.second;
}
return sum;
}
float powereach(set<pair<float,float>> s){
float sum=0;
for(auto i : s){
sum += i.first*i.first;
}
return sum;
}
int main(){
int i,num;
set<pair<float,float>> store;
float xi,yi,m,b;
string type;
cin >> num >> type;
for(i=0;i<num;++i){
cin >> xi >> yi;
store.insert(make_pair(xi,yi));
}
xi=eachxi(store);
yi=eachyi(store);
float xiyinum,pxi;
bool ne1=0,ne2=0;
xiyinum = xiyi(store);
pxi= powereach(store);
float n = store.size();
m=((n*xiyinum)-(xi*yi))/((n*pxi)-(xi*xi));
if(m<0) ne1=1;
m = abs(m);
m = round(m*1e3)/1e3;
if(ne1) m*=-1;
b=(yi-(m*xi))/n;
if(b<0) ne2=1;
b= abs(b);
b=round(b*1e3)/1e3;
if(ne2) b*=-1;
if(type=="mb"){
cout << m << endl;
cout << b << endl;
}else{
cout << "y = ";
if(m==1){
cout << "x ";
}else if(m!=0&&m!=-1){
cout << m <<"x ";
}else if(m==-1){
cout << "-x ";
}
if(b!=0&&b>0){
if(m==0){
}else{
cout << "+ ";
}
cout << b;
}else if(b<0){
if(m==0){
cout << "-";
}else{
cout << "- ";
}
cout << b*(-1);
}
if(m==0&&b==0){
cout << "0";
}
}
} |
# 1347, 2024-11-02 14:11:11, -----PPPPP-------------- (20%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int N;
string op;
cin >> N >> op;
vector<pair<float, float>> xy;
float x, y;
for(int i=0; i<N; i++) {
cin >> x >> y;
xy.push_back(make_pair(x,y));
}
float m=0,b=0;
float m1=0,m2=0,m3=0,m4=0;
for(int i=0; i<N; i++) {
m1 += xy[i].first * xy[i].second;
}
m1*=N;
for(int i=0; i<N; i++) {
m2 += xy[i].first;
}
for(int i=0; i<N; i++) {
m3 += xy[i].second;
}
for(int i=0; i<N; i++) {
m4 += xy[i].first * xy[i].first;
}
m4*=N;
m = (m1 - m2*m3) / (m4-(m2*m2));
m = round(m*1e3)/1e3;
cout << m << endl;
float b1=0, b2=0;
for(int i=0; i<N; i++) {
b1 += xy[i].second;
}
for(int i=0; i<N; i++) {
b2 += xy[i].first;
}
b2 *= m;
b = (b1 - b2)/N;
b = round(b*1e3)/1e3;
cout << b;
} | # 1348, 2024-11-02 14:14:19, -----PPPPP-------------- (20%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int N;
string op;
cin >> N >> op;
vector<pair<float, float>> xy;
float x, y;
for(int i=0; i<N; i++) {
cin >> x >> y;
xy.push_back(make_pair(x,y));
}
float m=0,b=0;
float m1=0,m2=0,m3=0,m4=0;
for(int i=0; i<N; i++) {
m1 += xy[i].first * xy[i].second;
}
m1*=N;
for(int i=0; i<N; i++) {
m2 += xy[i].first;
}
for(int i=0; i<N; i++) {
m3 += xy[i].second;
}
for(int i=0; i<N; i++) {
m4 += xy[i].first * xy[i].first;
}
m4*=N;
m = (m1 - m2*m3) / (m4-(m2*m2));
m = round(m*1e3)/1e3;
float b1=0, b2=0;
for(int i=0; i<N; i++) {
b1 += xy[i].second;
}
for(int i=0; i<N; i++) {
b2 += xy[i].first;
}
b2 *= m;
b = (b1 - b2)/N;
b = round(b*1e3)/1e3;
if(op == "mb") {
cout << m << endl << b;
}else {
cout << "y = " << m << "x + " << b;
}
} | # 1349, 2024-11-02 14:18:02, -----PPPPP-------P------ (25%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int N;
string op;
cin >> N >> op;
vector<pair<float, float>> xy;
float x, y;
for(int i=0; i<N; i++) {
cin >> x >> y;
xy.push_back(make_pair(x,y));
}
float m=0,b=0;
float m1=0,m2=0,m3=0,m4=0;
for(int i=0; i<N; i++) {
m1 += xy[i].first * xy[i].second;
}
m1*=N;
for(int i=0; i<N; i++) {
m2 += xy[i].first;
}
for(int i=0; i<N; i++) {
m3 += xy[i].second;
}
for(int i=0; i<N; i++) {
m4 += xy[i].first * xy[i].first;
}
m4*=N;
m = (m1 - m2*m3) / (m4-(m2*m2));
m = round(m*1e3)/1e3;
float b1=0, b2=0;
for(int i=0; i<N; i++) {
b1 += xy[i].second;
}
for(int i=0; i<N; i++) {
b2 += xy[i].first;
}
b2 *= m;
b = (b1 - b2)/N;
b = round(b*1e3)/1e3;
if(op == "mb") {
cout << m << endl << b;
}else if(m>0 && b>0 && m!=1) {
cout << "y = " << m << "x + " << b;
}else if(m==1 && b>0) {
cout << "y = x + " << b;
}
} | # 1350, 2024-11-02 14:25:53, -----PPPPP-------PPPP-PP (45%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int N;
string op;
cin >> N >> op;
vector<pair<float, float>> xy;
float x, y;
for(int i=0; i<N; i++) {
cin >> x >> y;
xy.push_back(make_pair(x,y));
}
float m=0,b=0;
float m1=0,m2=0,m3=0,m4=0;
for(int i=0; i<N; i++) {
m1 += xy[i].first * xy[i].second;
}
m1*=N;
for(int i=0; i<N; i++) {
m2 += xy[i].first;
}
for(int i=0; i<N; i++) {
m3 += xy[i].second;
}
for(int i=0; i<N; i++) {
m4 += xy[i].first * xy[i].first;
}
m4*=N;
m = (m1 - m2*m3) / (m4-(m2*m2));
m = round(m*1e3)/1e3;
float b1=0, b2=0;
for(int i=0; i<N; i++) {
b1 += xy[i].second;
}
for(int i=0; i<N; i++) {
b2 += xy[i].first;
}
b2 *= m;
b = (b1 - b2)/N;
b = round(b*1e3)/1e3;
if(op == "mb") {
cout << m << endl << b;
}else {
cout << "y = ";
if(m==1) cout << "x ";
else if(m==-1) cout << "-x ";
else if(m!=1 && m!=0) cout << m << "x ";
if(b>0) cout << "+ " << b;
else if(b<0) cout << "- " << -b;
}
} | # 1351, 2024-11-02 14:28:50, -----PPPPP-----P-PPPPPPP (54%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int N;
string op;
cin >> N >> op;
vector<pair<float, float>> xy;
float x, y;
for(int i=0; i<N; i++) {
cin >> x >> y;
xy.push_back(make_pair(x,y));
}
float m=0,b=0;
float m1=0,m2=0,m3=0,m4=0;
for(int i=0; i<N; i++) {
m1 += xy[i].first * xy[i].second;
}
m1*=N;
for(int i=0; i<N; i++) {
m2 += xy[i].first;
}
for(int i=0; i<N; i++) {
m3 += xy[i].second;
}
for(int i=0; i<N; i++) {
m4 += xy[i].first * xy[i].first;
}
m4*=N;
m = (m1 - m2*m3) / (m4-(m2*m2));
m = round(m*1e3)/1e3;
float b1=0, b2=0;
for(int i=0; i<N; i++) {
b1 += xy[i].second;
}
for(int i=0; i<N; i++) {
b2 += xy[i].first;
}
b2 *= m;
b = (b1 - b2)/N;
b = round(b*1e3)/1e3;
if(op == "mb") {
cout << m << endl << b;
}else {
cout << "y = ";
if(m==1) cout << "x ";
else if(m==-1) cout << "-x ";
else if(m!=1 && m!=0) cout << m << "x ";
if(b>0) cout << "+ " << b;
else if(b<0 && m!=0) cout << "- " << -b;
else if(b<0 && m==0) cout << b;
else if(b==0 && m==0) cout << "0";
}
} | # 1352, 2024-11-02 14:33:08, -----PPPPP-----P-PPPPPPP (54%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int N;
string op;
cin >> N >> op;
vector<pair<float, float>> xy;
float x, y;
for(int i=0; i<N; i++) {
cin >> x >> y;
xy.push_back(make_pair(x,y));
}
float m=0,b=0;
float m1=0,m2=0,m3=0,m4=0;
for(int i=0; i<N; i++) {
m1 += xy[i].first * xy[i].second;
}
m1*=N;
for(int i=0; i<N; i++) {
m2 += xy[i].first;
}
for(int i=0; i<N; i++) {
m3 += xy[i].second;
}
for(int i=0; i<N; i++) {
m4 += xy[i].first * xy[i].first;
}
m4*=N;
m = (m1 - m2*m3) / (m4-(m2*m2));
m = round(m*1e3)/1e3;
float b1=0, b2=0;
for(int i=0; i<N; i++) {
b1 += xy[i].second;
}
for(int i=0; i<N; i++) {
b2 += xy[i].first;
}
b2 *= m;
b = (b1 - b2)/N;
b = round(b*1e3)/1e3;
if(op == "mb") {
cout << m << endl << b;
}else {
cout << "y = ";
if(m==1) cout << "x ";
else if(m==-1) cout << "-x ";
else if(m!=1 && m!=0) cout << m << "x ";
if(b>0) cout << "+ " << b;
else if(b<0 && m!=0) cout << "- " << -b;
else if(b<0 && m==0) cout << b;
else if(b==0 && m==0) cout << "0";
}
} | # 1353, 2024-11-02 14:35:07, -----PPPPP-----P-PPPPPPP (54%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int N;
string op;
cin >> N >> op;
vector<pair<float, float>> xy;
float x, y;
for(int i=0; i<N; i++) {
cin >> x >> y;
xy.push_back(make_pair(x,y));
}
float m=0,b=0;
float m1=0,m2=0,m3=0,m4=0;
for(int i=0; i<N; i++) {
m1 += xy[i].first * xy[i].second;
}
m1*=N;
for(int i=0; i<N; i++) {
m2 += xy[i].first;
}
for(int i=0; i<N; i++) {
m3 += xy[i].second;
}
for(int i=0; i<N; i++) {
m4 += xy[i].first * xy[i].first;
}
m4*=N;
m = (m1 - m2*m3) / (m4-(m2*m2));
m = round(m*1e3)/1e3;
float b1=0, b2=0;
for(int i=0; i<N; i++) {
b1 += xy[i].second;
}
for(int i=0; i<N; i++) {
b2 += xy[i].first;
}
b2 *= m;
b = (b1 - b2)/N;
b = round(b*1e3)/1e3;
if(op == "mb") {
cout << m << endl << b;
}else {
cout << "y = ";
if(m==1) cout << "x";
else if(m==-1) cout << "-x";
else if(m!=1 && m!=0) cout << m << "x";
if(b>0) cout << " + " << b;
else if(b<0 && m!=0) cout << " - " << -b;
else if(b<0 && m==0) cout << b;
else if(b==0 && m==0) cout << "0";
}
} | # 1354, 2024-11-02 14:57:46, -----PPPPP-----P-PPPPPPP (54%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int N;
string op;
cin >> N >> op;
vector<pair<float, float>> xy;
float x, y;
for(int i=0; i<N; i++) {
cin >> x >> y;
xy.push_back(make_pair(x,y));
}
float m=0,b=0;
float m1=0,m2=0,m3=0,m4=0;
for(int i=0; i<N; i++) {
m1 += xy[i].first * xy[i].second;
}
m1*=N;
for(int i=0; i<N; i++) {
m2 += xy[i].first;
}
for(int i=0; i<N; i++) {
m3 += xy[i].second;
}
for(int i=0; i<N; i++) {
m4 += xy[i].first * xy[i].first;
}
m4*=N;
m = (m1 - m2*m3) / (m4-(m2*m2));
m = round(m*1e3)/1e3;
float b1=0, b2=0;
for(int i=0; i<N; i++) {
b1 += xy[i].second;
}
for(int i=0; i<N; i++) {
b2 += xy[i].first;
}
b2 *= m;
b = (b1 - b2)/N;
b = round(b*1e3)/1e3;
if(op == "mb") {
cout << m << endl << b;
}else if(op == "func") {
cout << "y = ";
if(m==1) cout << "x";
else if(m==-1) cout << "-x";
else if(m!=1 && m!=0) cout << m << "x";
if(b>0) cout << " + " << b;
else if(b<0 && m!=0) cout << " - " << -b;
else if(b<0 && m==0) cout << b;
else if(b==0 && m==0) cout << "0";
}
} | # 1355, 2024-11-02 15:02:47, -----PPPPP-----PPPPPPPPP (58%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int N;
string op;
cin >> N >> op;
vector<pair<float, float>> xy;
float x, y;
for(int i=0; i<N; i++) {
cin >> x >> y;
xy.push_back(make_pair(x,y));
}
float m=0,b=0;
float m1=0,m2=0,m3=0,m4=0;
for(int i=0; i<N; i++) {
m1 += xy[i].first * xy[i].second;
}
m1*=N;
for(int i=0; i<N; i++) {
m2 += xy[i].first;
}
for(int i=0; i<N; i++) {
m3 += xy[i].second;
}
for(int i=0; i<N; i++) {
m4 += xy[i].first * xy[i].first;
}
m4*=N;
m = (m1 - m2*m3) / (m4-(m2*m2));
m = round(m*1e3)/1e3;
float b1=0, b2=0;
for(int i=0; i<N; i++) {
b1 += xy[i].second;
}
for(int i=0; i<N; i++) {
b2 += xy[i].first;
}
b2 *= m;
b = (b1 - b2)/N;
b = round(b*1e3)/1e3;
if(op == "mb") {
cout << m << endl << b;
}else if(op == "func") {
cout << "y = ";
if(m==1) cout << "x";
else if(m==-1) cout << "-x";
else if(m!=1 && m!=0) cout << m << "x";
if(b>0 && m!=0) cout << " + " << b;
else if(b>0 && m==0) cout << b;
else if(b<0 && m!=0) cout << " - " << -b;
else if(b<0 && m==0) cout << b;
else if(b==0 && m==0) cout << "0";
}
} | # 1356, 2024-11-02 15:05:24, -----PPPPP-----PPPPPPPPP (58%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int N;
string op;
cin >> N >> op;
vector<pair<float, float>> xy;
float x, y;
for(int i=0; i<N; i++) {
cin >> x >> y;
xy.push_back(make_pair(x,y));
}
float m=0,b=0;
float m1=0,m2=0,m3=0,m4=0;
for(int i=0; i<N; i++) {
m1 += xy[i].first * xy[i].second;
}
m1*=N;
for(int i=0; i<N; i++) {
m2 += xy[i].first;
}
for(int i=0; i<N; i++) {
m3 += xy[i].second;
}
for(int i=0; i<N; i++) {
m4 += xy[i].first * xy[i].first;
}
m4*=N;
m = (m1 - m2*m3) / (m4-(m2*m2));
m = round(m*1e3)/1e3;
float b1=0, b2=0;
for(int i=0; i<N; i++) {
b1 += xy[i].second;
}
for(int i=0; i<N; i++) {
b2 += xy[i].first;
}
b2 *= m;
b = (b1 - b2)/N;
b = round(b*1e3)/1e3;
if(op == "mb") {
cout << m << endl << b << endl;
}else if(op == "func") {
cout << "y = ";
if(m==1) cout << "x";
else if(m==-1) cout << "-x";
else if(m!=1 && m!=0) cout << m << "x";
if(b>0 && m!=0) cout << " + " << b;
else if(b>0 && m==0) cout << b;
else if(b<0 && m!=0) cout << " - " << -b;
else if(b<0 && m==0) cout << b;
else if(b==0 && m==0) cout << "0";
}
} | # 1357, 2024-11-02 15:06:11, -----P---------PPPPPPPPP (41%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int N;
string op;
cin >> N >> op;
vector<pair<float, float>> xy;
float x, y;
for(int i=0; i<N; i++) {
cin >> x >> y;
xy.push_back(make_pair(x,y));
}
float m=0,b=0;
float m1=0,m2=0,m3=0,m4=0;
for(int i=0; i<N; i++) {
m1 += xy[i].first * xy[i].second;
}
m1*=N;
for(int i=0; i<N; i++) {
m2 += xy[i].first;
}
for(int i=0; i<N; i++) {
m3 += xy[i].second;
}
for(int i=0; i<N; i++) {
m4 += xy[i].first * xy[i].first;
}
m4*=N;
m = (m1 - m2*m3) / (m4-(m2*m2));
m = round(m*1e3)/1e3;
float b1=0, b2=0;
for(int i=0; i<N; i++) {
b1 += xy[i].second;
}
for(int i=0; i<N; i++) {
b2 += xy[i].first;
}
b2 *= m;
b = (b1 - b2)/N;
b = round(b*1e3)/1e3;
if(op == "mb") {
cout << b << endl << m << endl;
}else if(op == "func") {
cout << "y = ";
if(m==1) cout << "x";
else if(m==-1) cout << "-x";
else if(m!=1 && m!=0) cout << m << "x";
if(b>0 && m!=0) cout << " + " << b;
else if(b>0 && m==0) cout << b;
else if(b<0 && m!=0) cout << " - " << -b;
else if(b<0 && m==0) cout << b;
else if(b==0 && m==0) cout << "0";
}
} | # 1358, 2024-11-02 15:06:33, -----PPPPP-----PPPPPPPPP (58%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int N;
string op;
cin >> N >> op;
vector<pair<float, float>> xy;
float x, y;
for(int i=0; i<N; i++) {
cin >> x >> y;
xy.push_back(make_pair(x,y));
}
float m=0,b=0;
float m1=0,m2=0,m3=0,m4=0;
for(int i=0; i<N; i++) {
m1 += xy[i].first * xy[i].second;
}
m1*=N;
for(int i=0; i<N; i++) {
m2 += xy[i].first;
}
for(int i=0; i<N; i++) {
m3 += xy[i].second;
}
for(int i=0; i<N; i++) {
m4 += xy[i].first * xy[i].first;
}
m4*=N;
m = (m1 - m2*m3) / (m4-(m2*m2));
m = round(m*1e3)/1e3;
float b1=0, b2=0;
for(int i=0; i<N; i++) {
b1 += xy[i].second;
}
for(int i=0; i<N; i++) {
b2 += xy[i].first;
}
b2 *= m;
b = (b1 - b2)/N;
b = round(b*1e3)/1e3;
if(op == "mb") {
cout << m << endl << b << endl;
}else if(op == "func") {
cout << "y = ";
if(m==1) cout << "x";
else if(m==-1) cout << "-x";
else if(m!=1 && m!=0) cout << m << "x";
if(b>0 && m!=0) cout << " + " << b;
else if(b>0 && m==0) cout << b;
else if(b<0 && m!=0) cout << " - " << -b;
else if(b<0 && m==0) cout << b;
else if(b==0 && m==0) cout << "0";
}
} |
# 1359, 2024-11-02 10:02:03, -----PPPPP-------------- (20%)
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
using namespace std;
int main(){
int n;
string str;
cin >> n >> str;
float x, y;
vector <pair <float, float>> v;
// x0, y0 dont have
v.push_back(make_pair(0, 0));
for(int i = 0; i < n; i++){
cin >> x >> y;
v.push_back(make_pair(x, y));
}
if(str == "mb"){
float m1 = 0;
float m2 = 0, m2x = 0, m2y = 0;
float m3 = 0;
float m4 = 0;
for(int i = 1; i <= n; i++){
// m1
m1 += (v[i].first * v[i].second);
//m2x, m2y
m2x += v[i].first;
m2y += v[i].second;
// m3
m3 += (v[i].first * v[i].first);
}
m1 *= n;
m2 = m2x * m2y;
m3 *= n;
m4 = m2x * m2x;
float m = 0;
m = (m1 - m2) / (m3 - m4);
m = round(m * 1e3)/1e3;
float b = 0;
b = (m2y - (m * m2x)) / n;
b = round(b * 1e3)/1e3;
cout << m << endl << b;
}
} | # 1360, 2024-11-02 10:06:19, -----PPPPP-----PP----P-- (33%)
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <set>
using namespace std;
int main(){
int n;
string str;
cin >> n >> str;
float x, y;
vector <pair <float, float>> v;
set <float> sy;
// x0, y0 dont have
v.push_back(make_pair(0, 0));
for(int i = 0; i < n; i++){
cin >> x >> y;
v.push_back(make_pair(x, y));
sy.insert(y);
}
if(str == "mb"){
float m1 = 0;
float m2 = 0, m2x = 0, m2y = 0;
float m3 = 0;
float m4 = 0;
for(int i = 1; i <= n; i++){
// m1
m1 += (v[i].first * v[i].second);
//m2x, m2y
m2x += v[i].first;
m2y += v[i].second;
// m3
m3 += (v[i].first * v[i].first);
}
m1 *= n;
m2 = m2x * m2y;
m3 *= n;
m4 = m2x * m2x;
float m = 0;
m = (m1 - m2) / (m3 - m4);
m = round(m * 1e3)/1e3;
float b = 0;
b = (m2y - (m * m2x)) / n;
b = round(b * 1e3)/1e3;
cout << m << endl << b;
}
else{
cout << "y = ";
if(sy.size() == 1)
for(auto ans : sy)
cout << ans;
}
} | # 1361, 2024-11-02 10:10:40, -----PPPPP-----PP-P--P-- (37%)
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <set>
using namespace std;
int main(){
int n;
string str;
cin >> n >> str;
float x, y;
vector <pair <float, float>> v;
set <float> sy;
// x0, y0 dont have
v.push_back(make_pair(0, 0));
for(int i = 0; i < n; i++){
cin >> x >> y;
v.push_back(make_pair(x, y));
sy.insert(y);
}
if(str == "mb"){
float m1 = 0;
float m2 = 0, m2x = 0, m2y = 0;
float m3 = 0;
float m4 = 0;
for(int i = 1; i <= n; i++){
// m1
m1 += (v[i].first * v[i].second);
//m2x, m2y
m2x += v[i].first;
m2y += v[i].second;
// m3
m3 += (v[i].first * v[i].first);
}
m1 *= n;
m2 = m2x * m2y;
m3 *= n;
m4 = m2x * m2x;
float m = 0;
m = (m1 - m2) / (m3 - m4);
m = round(m * 1e3)/1e3;
float b = 0;
b = (m2y - (m * m2x)) / n;
b = round(b * 1e3)/1e3;
cout << m << endl << b;
}
else{
cout << "y = ";
if(sy.size() == 1)
for(auto ans : sy)
cout << ans;
else{
bool xEQy = true;
for(int i = 0; i < v.size(); i++){
if(v[i].first == v[i].second)
xEQy = true;
else{
xEQy = false;
break;
}
}
if(xEQy)
cout << "x";
}
}
} | # 1362, 2024-11-02 10:19:31, -----PPPPP-----PPPP--P-- (41%)
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <set>
using namespace std;
int main(){
int n;
string str;
cin >> n >> str;
float x, y;
vector <pair <float, float>> v;
set <float> sy;
// x0, y0 dont have
v.push_back(make_pair(0, 0));
for(int i = 0; i < n; i++){
cin >> x >> y;
v.push_back(make_pair(x, y));
sy.insert(y);
}
if(str == "mb"){
float m1 = 0;
float m2 = 0, m2x = 0, m2y = 0;
float m3 = 0;
float m4 = 0;
for(int i = 1; i <= n; i++){
// m1
m1 += (v[i].first * v[i].second);
//m2x, m2y
m2x += v[i].first;
m2y += v[i].second;
// m3
m3 += (v[i].first * v[i].first);
}
m1 *= n;
m2 = m2x * m2y;
m3 *= n;
m4 = m2x * m2x;
float m = 0;
m = (m1 - m2) / (m3 - m4);
m = round(m * 1e3)/1e3;
float b = 0;
b = (m2y - (m * m2x)) / n;
b = round(b * 1e3)/1e3;
cout << m << endl << b;
}
else{
cout << "y = ";
if(sy.size() == 1)
for(auto ans : sy)
cout << ans;
else{
bool xEQy = true;
float sub = 0;
for(int i = 1; i < n+1; i++){
if(v[i].first == v[i].second)
xEQy = true;
else{
xEQy = false;
break;
}
}
if(xEQy)
cout << "x";
else{
sub = v[1].second - v[1].first;
bool subEQ = true;
for(int i = 1; i < n+1; i++){
if(v[i].second - v[i].first == sub)
subEQ = true;
else{
subEQ = false;
break;
}
}
if(subEQ)
cout << "x + " << sub;
}
}
}
} | # 1363, 2024-11-02 10:25:51, -----PPPPP-----PPPPPPP-P (54%)
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <set>
using namespace std;
int main(){
int n;
string str;
cin >> n >> str;
float x, y;
vector <pair <float, float>> v;
set <float> sy;
// x0, y0 dont have
v.push_back(make_pair(0, 0));
for(int i = 0; i < n; i++){
cin >> x >> y;
v.push_back(make_pair(x, y));
sy.insert(y);
}
if(str == "mb"){
float m1 = 0;
float m2 = 0, m2x = 0, m2y = 0;
float m3 = 0;
float m4 = 0;
for(int i = 1; i <= n; i++){
// m1
m1 += (v[i].first * v[i].second);
//m2x, m2y
m2x += v[i].first;
m2y += v[i].second;
// m3
m3 += (v[i].first * v[i].first);
}
m1 *= n;
m2 = m2x * m2y;
m3 *= n;
m4 = m2x * m2x;
float m = 0;
m = (m1 - m2) / (m3 - m4);
m = round(m * 1e3)/1e3;
float b = 0;
b = (m2y - (m * m2x)) / n;
b = round(b * 1e3)/1e3;
cout << m << endl << b;
}
else{
cout << "y = ";
if(sy.size() == 1)
for(auto ans : sy)
cout << ans;
else{
bool xEQy = true;
float sub = 0;
for(int i = 1; i < n+1; i++){
if(v[i].first == v[i].second)
xEQy = true;
else{
xEQy = false;
break;
}
}
if(xEQy)
cout << "x";
else{
sub = v[1].second - v[1].first;
bool subEQ = true;
for(int i = 1; i < n+1; i++){
if(v[i].second - v[i].first == sub)
subEQ = true;
else{
subEQ = false;
break;
}
}
if(subEQ)
cout << "x + " << sub;
else{
float add = v[1].second + v[1].first;
bool addEQ = true;
for(int i = 1; i < n+1; i++){
if(v[i].second + v[i].first == add)
addEQ = true;
else{
addEQ = false;
break;
}
}
if(addEQ){
cout << "-x";
if(add > 0)
cout << " + " << add;
else if(add < 0)
cout << " - " << abs(add);
}
}
}
}
}
} | # 1364, 2024-11-02 11:45:22, -----PPPPP-----PPPPPPPPP (58%)
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <set>
using namespace std;
int main(){
int n;
string str;
cin >> n >> str;
float x, y;
vector <pair <float, float>> v;
set <float> sy;
// x0, y0 dont have
v.push_back(make_pair(0, 0));
for(int i = 0; i < n; i++){
cin >> x >> y;
v.push_back(make_pair(x, y));
sy.insert(y);
}
float m1 = 0;
float m2 = 0, m2x = 0, m2y = 0;
float m3 = 0;
float m4 = 0;
for(int i = 1; i <= n; i++){
// m1
m1 += (v[i].first * v[i].second);
//m2x, m2y
m2x += v[i].first;
m2y += v[i].second;
// m3
m3 += (v[i].first * v[i].first);
}
m1 *= n;
m2 = m2x * m2y;
m3 *= n;
m4 = m2x * m2x;
float m = 0;
m = (m1 - m2) / (m3 - m4);
m = round(m * 1e3)/1e3;
float b = 0;
b = (m2y - (m * m2x)) / n;
b = round(b * 1e3)/1e3;
if(str == "mb"){
cout << m << endl << b;
}
else{
cout << "y = ";
if(m == 0){
cout << b;
}
else{
if(m != 1){
if(m == -1)
cout << "-";
else cout << m;
}
if(b > 0)
cout << "x + " << b;
else if(b < 0)
cout << "x - " << abs(b);
else cout << "x";
}
}
} | # 1365, 2024-11-02 11:53:02, -----PPPPP-----PPPPPPPPP (58%)
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <set>
using namespace std;
int main(){
int n;
string str;
cin >> n >> str;
float x, y;
vector <pair <float, float>> v;
// x0, y0 dont have
v.push_back(make_pair(0, 0));
for(int i = 1; i <= n; i++){
cin >> x >> y;
v.push_back(make_pair(x, y));
}
float m1 = 0;
float m2 = 0, m2x = 0, m2y = 0;
float m3 = 0;
float m4 = 0;
for(int i = 1; i <= n; i++){
// m1
m1 += (v[i].first * v[i].second);
//m2x, m2y
m2x += v[i].first;
m2y += v[i].second;
// m3
m3 += (v[i].first * v[i].first);
}
m1 *= n;
m2 = m2x * m2y;
m3 *= n;
m4 = m2x * m2x;
float m = 0;
m = (m1 - m2) / (m3 - m4);
m = round(m * 1e3)/1e3;
float b = 0;
b = (m2y - (m * m2x)) / n;
b = round(b * 1e3)/1e3;
if(str == "mb"){
cout << m << endl << b;
}
else{
cout << "y = ";
if(m == 0){
cout << b;
}
else{
if(m != 1){
if(m == -1)
cout << "-";
else cout << m;
}
if(b > 0)
cout << "x + " << b;
else if(b < 0)
cout << "x - " << abs(b);
else cout << "x";
}
}
} |
# 1366, 2024-11-02 11:46:22, ------P----------------- (4%)
#include "bits/stdc++.h"
using namespace std;
vector<pair<float, float>> vt;
float calm(int N)
{
float a = 0, b = 0, c = 0, d = 0, e = 0;
for (int i = 0; i < N; i++)
{
a += vt[i].first * vt[i].second;
b += vt[i].first;
c += vt[i].second;
d += vt[i].first * vt[i].first;
}
a *= N;
d *= N;
e = b * b;
return (a - (b * c)) / (d - e);
}
float calb(int N)
{
float a = 0, b = 0;
for (int i = 0; i < N; i++)
{
a += vt[i].second;
b += vt[i].first;
}
return (a-b) / N;
}
int main()
{
int n;
string ip;
cin >> n >> ip;
for (int i = 0; i < n; i++)
{
float x, y;
cin >> x >> y;
vt.push_back({x, y});
}
if(ip == "mb"){
cout << calm(n) << "\n";
cout << calb(n) << "\n";
}
return 0;
} | # 1367, 2024-11-02 11:50:39, -----PPPPP-------------- (20%)
#include "bits/stdc++.h"
using namespace std;
vector<pair<float, float>> vt;
float calm(int N)
{
float a = 0, b = 0, c = 0, d = 0, e = 0;
for (int i = 0; i < N; i++)
{
a += vt[i].first * vt[i].second;
b += vt[i].first;
c += vt[i].second;
d += vt[i].first * vt[i].first;
}
a *= N;
d *= N;
e = b * b;
return (a - (b * c)) / (d - e);
}
float calb(int N, int m)
{
float a = 0, b = 0;
for (int i = 0; i < N; i++)
{
a += vt[i].second;
b += vt[i].first;
}
b *= m;
return (a - b) / N;
}
int main()
{
int n;
string ip;
cin >> n >> ip;
for (int i = 0; i < n; i++)
{
float x, y;
cin >> x >> y;
vt.push_back({x, y});
}
float a = calm(n);
float b = calb(n, a);
a = round(a * 1e3) / 1e3;
b = round(b * 1e3) / 1e3;
if (ip == "mb")
{
cout << a << "\n";
cout << b << "\n";
}
return 0;
} | # 1368, 2024-11-02 11:52:47, PPPPPPPPPP-------------- (41%)
#include "bits/stdc++.h"
using namespace std;
vector<pair<float, float>> vt;
float calm(int N)
{
float a = 0, b = 0, c = 0, d = 0, e = 0;
for (int i = 0; i < N; i++)
{
a += vt[i].first * vt[i].second;
b += vt[i].first;
c += vt[i].second;
d += vt[i].first * vt[i].first;
}
a *= N;
d *= N;
e = b * b;
return (a - (b * c)) / (d - e);
}
float calb(int N)
{
float a = 0, b = 0;
for (int i = 0; i < N; i++)
{
a += vt[i].second;
b += vt[i].first;
}
b *= calm(N);
return (a - b) / N;
}
int main()
{
int n;
string ip;
cin >> n >> ip;
for (int i = 0; i < n; i++)
{
float x, y;
cin >> x >> y;
vt.push_back({x, y});
}
float a = calm(n);
float b = calb(n);
a = round(a * 1e3) / 1e3;
b = round(b * 1e3) / 1e3;
if (ip == "mb")
{
cout << a << "\n";
cout << b << "\n";
}
return 0;
} | # 1369, 2024-11-02 11:56:22, PPPPPPPPPPP-P----------- (50%)
#include "bits/stdc++.h"
using namespace std;
vector<pair<float, float>> vt;
float calm(int N)
{
float a = 0, b = 0, c = 0, d = 0, e = 0;
for (int i = 0; i < N; i++)
{
a += vt[i].first * vt[i].second;
b += vt[i].first;
c += vt[i].second;
d += vt[i].first * vt[i].first;
}
a *= N;
d *= N;
e = b * b;
return (a - (b * c)) / (d - e);
}
float calb(int N)
{
float a = 0, b = 0;
for (int i = 0; i < N; i++)
{
a += vt[i].second;
b += vt[i].first;
}
b *= calm(N);
return (a - b) / N;
}
int main()
{
int n;
string ip;
cin >> n >> ip;
for (int i = 0; i < n; i++)
{
float x, y;
cin >> x >> y;
vt.push_back({x, y});
}
float a = calm(n);
float b = calb(n);
a = round(a * 1e3) / 1e3;
b = round(b * 1e3) / 1e3;
if (ip == "mb")
{
cout << a << "\n";
cout << b << "\n";
return 0;
}
cout << "y = " << a << "x + " << b;
return 0;
} | # 1370, 2024-11-02 11:58:01, Compilation error (0%)
#include "bits/stdc++.h"
using namespace std;
vector<pair<float, float>> vt;
float calm(int N)
{
float a = 0, b = 0, c = 0, d = 0, e = 0;
for (int i = 0; i < N; i++)
{
a += vt[i].first * vt[i].second;
b += vt[i].first;
c += vt[i].second;
d += vt[i].first * vt[i].first;
}
a *= N;
d *= N;
e = b * b;
return (a - (b * c)) / (d - e);
}
float calb(int N)
{
float a = 0, b = 0;
for (int i = 0; i < N; i++)
{
a += vt[i].second;
b += vt[i].first;
}
b *= calm(N);
return (a - b) / N;
}
int main()
{
int n;
string ip;
cin >> n >> ip;
for (int i = 0; i < n; i++)
{
float x, y;
cin >> x >> y;
vt.push_back({x, y});
}
float a = calm(n);
float b = calb(n);
a = round(a * 1e3) / 1e3;
b = round(b * 1e3) / 1e3;
if (ip == "mb")
{
cout << a << "\n";
cout << b << "\n";
return 0;
}
if(x==y&&y=0) cout << "y = 0";
cout << "y = " << a << "x + " << b;
return 0;
} | # 1371, 2024-11-02 11:58:24, Compilation error (0%)
#include "bits/stdc++.h"
using namespace std;
vector<pair<float, float>> vt;
float calm(int N)
{
float a = 0, b = 0, c = 0, d = 0, e = 0;
for (int i = 0; i < N; i++)
{
a += vt[i].first * vt[i].second;
b += vt[i].first;
c += vt[i].second;
d += vt[i].first * vt[i].first;
}
a *= N;
d *= N;
e = b * b;
return (a - (b * c)) / (d - e);
}
float calb(int N)
{
float a = 0, b = 0;
for (int i = 0; i < N; i++)
{
a += vt[i].second;
b += vt[i].first;
}
b *= calm(N);
return (a - b) / N;
}
int main()
{
int n;
string ip;
cin >> n >> ip;
for (int i = 0; i < n; i++)
{
float x, y;
cin >> x >> y;
vt.push_back({x, y});
}
float a = calm(n);
float b = calb(n);
a = round(a * 1e3) / 1e3;
b = round(b * 1e3) / 1e3;
if (ip == "mb")
{
cout << a << "\n";
cout << b << "\n";
return 0;
}
if(a==0&&b=0) cout << "y = 0";
cout << "y = " << a << "x + " << b;
return 0;
} | # 1372, 2024-11-02 11:58:59, PPPPPPPPPPP-P--P-------- (54%)
#include "bits/stdc++.h"
using namespace std;
vector<pair<float, float>> vt;
float calm(int N)
{
float a = 0, b = 0, c = 0, d = 0, e = 0;
for (int i = 0; i < N; i++)
{
a += vt[i].first * vt[i].second;
b += vt[i].first;
c += vt[i].second;
d += vt[i].first * vt[i].first;
}
a *= N;
d *= N;
e = b * b;
return (a - (b * c)) / (d - e);
}
float calb(int N)
{
float a = 0, b = 0;
for (int i = 0; i < N; i++)
{
a += vt[i].second;
b += vt[i].first;
}
b *= calm(N);
return (a - b) / N;
}
int main()
{
int n;
string ip;
cin >> n >> ip;
for (int i = 0; i < n; i++)
{
float x, y;
cin >> x >> y;
vt.push_back({x, y});
}
float a = calm(n);
float b = calb(n);
a = round(a * 1e3) / 1e3;
b = round(b * 1e3) / 1e3;
if (ip == "mb")
{
cout << a << "\n";
cout << b << "\n";
return 0;
}
if (a == 0 &&b == 0)
{
cout << "y = 0";
return 0;
}
cout << "y = " << a << "x + " << b;
return 0;
} | # 1373, 2024-11-02 12:00:08, Compilation error (0%)
#include "bits/stdc++.h"
using namespace std;
vector<pair<float, float>> vt;
float calm(int N)
{
float a = 0, b = 0, c = 0, d = 0, e = 0;
for (int i = 0; i < N; i++)
{
a += vt[i].first * vt[i].second;
b += vt[i].first;
c += vt[i].second;
d += vt[i].first * vt[i].first;
}
a *= N;
d *= N;
e = b * b;
return (a - (b * c)) / (d - e);
}
float calb(int N)
{
float a = 0, b = 0;
for (int i = 0; i < N; i++)
{
a += vt[i].second;
b += vt[i].first;
}
b *= calm(N);
return (a - b) / N;
}
int main()
{
int n;
string ip;
cin >> n >> ip;
for (int i = 0; i < n; i++)
{
float x, y;
cin >> x >> y;
vt.push_back({x, y});
}
float a = calm(n);
float b = calb(n);
a = round(a * 1e3) / 1e3;
b = round(b * 1e3) / 1e3;
if (ip == "mb")
{
cout << a << "\n";
cout << b << "\n";
return 0;
}
if (a == 0 &&b == 0)
{
cout << "y = 0";
return 0;
}
if(m==1){
out << "y = " << "x + " << b;
}
if(m==-1){
out << "y = " << "-x + " << b;
}
cout << "y = " << a << "x + " << b;
return 0;
} | # 1374, 2024-11-02 12:00:31, Compilation error (0%)
#include "bits/stdc++.h"
using namespace std;
vector<pair<float, float>> vt;
float calm(int N)
{
float a = 0, b = 0, c = 0, d = 0, e = 0;
for (int i = 0; i < N; i++)
{
a += vt[i].first * vt[i].second;
b += vt[i].first;
c += vt[i].second;
d += vt[i].first * vt[i].first;
}
a *= N;
d *= N;
e = b * b;
return (a - (b * c)) / (d - e);
}
float calb(int N)
{
float a = 0, b = 0;
for (int i = 0; i < N; i++)
{
a += vt[i].second;
b += vt[i].first;
}
b *= calm(N);
return (a - b) / N;
}
int main()
{
int n;
string ip;
cin >> n >> ip;
for (int i = 0; i < n; i++)
{
float x, y;
cin >> x >> y;
vt.push_back({x, y});
}
float a = calm(n);
float b = calb(n);
a = round(a * 1e3) / 1e3;
b = round(b * 1e3) / 1e3;
if (ip == "mb")
{
cout << a << "\n";
cout << b << "\n";
return 0;
}
if (a == 0 &&b == 0)
{
cout << "y = 0";
return 0;
}
if(m==1){
cout << "y = " << "x + " << b;
}
if(m==-1){
cout << "y = " << "-x + " << b;
}
cout << "y = " << a << "x + " << b;
return 0;
} | # 1375, 2024-11-02 12:00:52, Compilation error (0%)
#include "bits/stdc++.h"
using namespace std;
vector<pair<float, float>> vt;
float calm(int N)
{
float a = 0, b = 0, c = 0, d = 0, e = 0;
for (int i = 0; i < N; i++)
{
a += vt[i].first * vt[i].second;
b += vt[i].first;
c += vt[i].second;
d += vt[i].first * vt[i].first;
}
a *= N;
d *= N;
e = b * b;
return (a - (b * c)) / (d - e);
}
float calb(int N)
{
float a = 0, b = 0;
for (int i = 0; i < N; i++)
{
a += vt[i].second;
b += vt[i].first;
}
b *= calm(N);
return (a - b) / N;
}
int main()
{
int n;
string ip;
cin >> n >> ip;
for (int i = 0; i < n; i++)
{
float x, y;
cin >> x >> y;
vt.push_back({x, y});
}
float a = calm(n);
float b = calb(n);
a = round(a * 1e3) / 1e3;
b = round(b * 1e3) / 1e3;
if (ip == "mb")
{
cout << a << "\n";
cout << b << "\n";
return 0;
}
if (a == 0 &&b == 0)
{
cout << "y = 0";
return 0;
}
if(m==1){
cout << "y = " << "x + " << b;
}
if(m==-1){
cout << "y = " << "-x + " << b;
}
cout << "y = " << a << "x + " << b;
return 0;
} | # 1376, 2024-11-02 12:01:04, PPPPPPPPPPP-P--P-------- (54%)
#include "bits/stdc++.h"
using namespace std;
vector<pair<float, float>> vt;
float calm(int N)
{
float a = 0, b = 0, c = 0, d = 0, e = 0;
for (int i = 0; i < N; i++)
{
a += vt[i].first * vt[i].second;
b += vt[i].first;
c += vt[i].second;
d += vt[i].first * vt[i].first;
}
a *= N;
d *= N;
e = b * b;
return (a - (b * c)) / (d - e);
}
float calb(int N)
{
float a = 0, b = 0;
for (int i = 0; i < N; i++)
{
a += vt[i].second;
b += vt[i].first;
}
b *= calm(N);
return (a - b) / N;
}
int main()
{
int n;
string ip;
cin >> n >> ip;
for (int i = 0; i < n; i++)
{
float x, y;
cin >> x >> y;
vt.push_back({x, y});
}
float a = calm(n);
float b = calb(n);
a = round(a * 1e3) / 1e3;
b = round(b * 1e3) / 1e3;
if (ip == "mb")
{
cout << a << "\n";
cout << b << "\n";
return 0;
}
if (a == 0 &&b == 0)
{
cout << "y = 0";
return 0;
}
if(a==1){
cout << "y = " << "x + " << b;
}
if(a==-1){
cout << "y = " << "-x + " << b;
}
cout << "y = " << a << "x + " << b;
return 0;
} |
# 1377, 2024-11-02 10:18:27, -----PPPP------PP--PP--P (37%)
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
int main () {
float n = 0 , xi = 0 , yi = 0 , m = 0 , b = 0 , sumxi = 0 , sumyi = 0 , sumxiyi = 0 , sumxipow = 0 ;
std::string typef ;
std::vector<float> x ;
std::vector<float> y ;
std::cin >> n >> typef ;
//input
for ( float i = 0 ; i < n ; i++ ){
std::cin >> xi >> yi ;
sumxi += xi ;
sumyi += yi ;
sumxiyi += ( xi * yi ) ;
sumxipow += pow( xi , 2 ) ;
x.push_back( xi ) ;
y.push_back( yi ) ;
}
//find m
float upm = 0 , lowm = 0 ;
upm = ( n * sumxiyi ) - ( sumxi * sumyi ) ;
lowm = ( sumxipow * n) - ( pow( sumxi , 2 ) ) ;
m = upm / lowm ;
m = round(m*1e3)/1e3 ;
//find b
b = ( sumyi - ( m*sumxi )) / n ;
b = round(b*1e3)/1e3 ;
bool bminues = b < 0 ;
if ( b < 0 ){
b = b * -1 ;
}
//output
if ( typef == "mb" ){
std::cout << m << std::endl ;
std::cout << b << std::endl ;
}else if ( typef == "func"){
//b not 0 and m = -1
if ( m == -1 && b != 0 ){
if ( bminues ){
std::cout << "y = -x - " << b ;
}else std::cout << "y = -x + " << b ;
}else if ( m == -1 && b == 0 ){
// b = 0 and m = -1
std::cout << "y = -x" ;
}else if ( m == 0 ){
// m == 0 and b != 0 or b == 0
std::cout << "y = " << b ;
}else {
if ( bminues ){
std::cout << "y = " << m << "x - " << b ;
}else std::cout << "y = " << m << "x + " << b ;
}
}
} | # 1378, 2024-11-02 10:30:33, -----PPPP------PP--PPP-P (41%)
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
int main () {
float n = 0 , xi = 0 , yi = 0 , m = 0 , b = 0 , sumxi = 0 , sumyi = 0 , sumxiyi = 0 , sumxipow = 0 ;
std::string typef ;
std::cin >> n >> typef ;
//input
for ( float i = 0 ; i < n ; i++ ){
std::cin >> xi >> yi ;
sumxi += xi ;
sumyi += yi ;
sumxiyi += ( xi * yi ) ;
sumxipow += pow( xi , 2 ) ;
}
//find m
float upm = 0 , lowm = 0 ;
upm = ( n * sumxiyi ) - ( sumxi * sumyi ) ;
lowm = ( sumxipow * n) - ( pow( sumxi , 2 ) ) ;
m = upm / lowm ;
m = round(m*1e3)/1e3 ;
//find b
b = ( sumyi - ( m*sumxi )) / n ;
bool bminues = b < 0 ;
if ( b < 0 ){
b = b * -1 ;
}
b = round(b*1e3)/1e3 ;
//output
if ( typef == "mb" ){
std::cout << m << std::endl ;
std::cout << b << std::endl ;
}else if ( typef == "func"){
//b not 0 and m = -1
if ( m == -1 && b != 0 ){
if ( bminues ){
std::cout << "y = -x - " << b ;
}else std::cout << "y = -x + " << b ;
}else if ( m == -1 && b == 0 ){
// b = 0 and m = -1
std::cout << "y = -x" ;
}else if ( m == 0 ){
// m == 0 and b != 0 or b == 0
if ( bminues ){
std::cout << "y = -" << b ;
}else std::cout << "y = " << b ;
}else {
if ( bminues ){
std::cout << "y = " << m << "x - " << b ;
}else std::cout << "y = " << m << "x + " << b ;
}
}
} | # 1379, 2024-11-02 10:34:35, -----PPPP------PPPPPPPPP (54%)
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
int main () {
float n = 0 , xi = 0 , yi = 0 , m = 0 , b = 0 , sumxi = 0 , sumyi = 0 , sumxiyi = 0 , sumxipow = 0 ;
std::string typef ;
std::cin >> n >> typef ;
//input
for ( float i = 0 ; i < n ; i++ ){
std::cin >> xi >> yi ;
sumxi += xi ;
sumyi += yi ;
sumxiyi += ( xi * yi ) ;
sumxipow += pow( xi , 2 ) ;
}
//find m
float upm = 0 , lowm = 0 ;
upm = ( n * sumxiyi ) - ( sumxi * sumyi ) ;
lowm = ( sumxipow * n) - ( pow( sumxi , 2 ) ) ;
m = upm / lowm ;
m = round(m*1e3)/1e3 ;
//find b
b = ( sumyi - ( m*sumxi )) / n ;
bool bminues = b < 0 ;
if ( b < 0 ){
b = b * -1 ;
}
b = round(b*1e3)/1e3 ;
//output
if ( typef == "mb" ){
std::cout << m << std::endl ;
std::cout << b << std::endl ;
}else if ( typef == "func"){
//b not 0 and m = -1
if ( m == -1 && b != 0 ){
if ( bminues ){
std::cout << "y = -x - " << b ;
}else std::cout << "y = -x + " << b ;
}else if ( m == -1 && b == 0 ){
// b = 0 and m = -1
std::cout << "y = -x" ;
}else if ( m == 0 ){
// m == 0 and b != 0 or b == 0
if ( bminues ){
std::cout << "y = -" << b ;
}else std::cout << "y = " << b ;
}else if ( m == 1 && b != 0 ){
if ( bminues ){
std::cout << "y = x - " << b ;
}else std::cout << "y = x + " << b ;
}else if ( m == 1 && b == 0 ){
// b = 0 and m = 1
std::cout << "y = x" ;
}else{
if ( bminues ){
std::cout << "y = " << m << "x - " << b ;
}else std::cout << "y = " << m << "x + " << b ;
}
}
} | # 1380, 2024-11-02 10:36:15, -----PPPP------PPPPPPPPP (54%)
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
int main () {
float n = 0 , xi = 0 , yi = 0 , m = 0 , b = 0 , sumxi = 0 , sumyi = 0 , sumxiyi = 0 , sumxipow = 0 ;
std::string typef ;
std::cin >> n >> typef ;
//input
for ( float i = 0 ; i < n ; i++ ){
std::cin >> xi >> yi ;
sumxi += xi ;
sumyi += yi ;
sumxiyi += ( xi * yi ) ;
sumxipow += pow( xi , 2 ) ;
}
//find m
float upm = 0 , lowm = 0 ;
upm = ( n * sumxiyi ) - ( sumxi * sumyi ) ;
lowm = ( sumxipow * n) - ( pow( sumxi , 2 ) ) ;
m = upm / lowm ;
m = round(m*1e3)/1e3 ;
//find b
b = ( sumyi - ( m*sumxi )) / n ;
bool bminues = b < 0 ;
if ( b < 0 ){
b = b * -1 ;
}
b = round(b*1e3)/1e3 ;
//output
if ( typef == "mb" ){
std::cout << m << std::endl ;
std::cout << b ;
}else if ( typef == "func"){
//b not 0 and m = -1
if ( m == -1 && b != 0 ){
if ( bminues ){
std::cout << "y = -x - " << b ;
}else std::cout << "y = -x + " << b ;
}else if ( m == -1 && b == 0 ){
// b = 0 and m = -1
std::cout << "y = -x" ;
}else if ( m == 0 ){
// m == 0 and b != 0 or b == 0
if ( bminues ){
std::cout << "y = -" << b ;
}else std::cout << "y = " << b ;
}else if ( m == 1 && b != 0 ){
if ( bminues ){
std::cout << "y = x - " << b ;
}else std::cout << "y = x + " << b ;
}else if ( m == 1 && b == 0 ){
// b = 0 and m = 1
std::cout << "y = x" ;
}else{
if ( bminues ){
std::cout << "y = " << m << "x - " << b ;
}else std::cout << "y = " << m << "x + " << b ;
}
}
} | # 1381, 2024-11-02 10:41:27, -----PPPP------PPPPPPPPP (54%)
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
int main () {
float n = 0 , xi = 0 , yi = 0 , m = 0 , b = 0 , sumxi = 0 , sumyi = 0 , sumxiyi = 0 , sumxipow = 0 ;
std::string typef = "";
std::cin >> n >> typef ;
//input
for ( float i = 0 ; i < n ; i++ ){
std::cin >> xi >> yi ;
sumxi += xi ;
sumyi += yi ;
sumxiyi += ( xi * yi ) ;
sumxipow += pow( xi , 2 ) ;
}
//find m
float upm = 0 , lowm = 0 ;
upm = ( n * sumxiyi ) - ( sumxi * sumyi ) ;
lowm = ( sumxipow * n) - ( pow( sumxi , 2 ) ) ;
m = upm / lowm ;
m = round(m*1e3)/1e3 ;
//find b
b = ( sumyi - ( m*sumxi )) / n ;
bool bminues = b < 0 ;
if ( b < 0 ){
b = b * -1 ;
}
b = round(b*1e3)/1e3 ;
//output
if ( typef == "mb" ){
std::cout << m << std::endl ;
std::cout << b ;
}else if ( typef == "func"){
//b not 0 and m = -1
if ( m == -1 && b != 0 ){
if ( bminues ){
std::cout << "y = -x - " << b ;
}else std::cout << "y = -x + " << b ;
}else if ( m == -1 && b == 0 ){
// b = 0 and m = -1
std::cout << "y = -x" ;
}else if ( m == 0 ){
// m == 0 and b != 0 or b == 0
if ( bminues ){
std::cout << "y = -" << b ;
}else std::cout << "y = " << b ;
}else if ( m == 1 && b != 0 ){
if ( bminues ){
std::cout << "y = x - " << b ;
}else std::cout << "y = x + " << b ;
}else if ( m == 1 && b == 0 ){
// b = 0 and m = 1
std::cout << "y = x" ;
}else{
if ( bminues ){
std::cout << "y = " << m << "x - " << b ;
}else std::cout << "y = " << m << "x + " << b ;
}
}
} | # 1382, 2024-11-02 10:43:18, -----PPPP------PPPPPPPPP (54%)
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
int main () {
float n = 0 , xi = 0 , yi = 0 , m = 0 , b = 0 , sumxi = 0 , sumyi = 0 , sumxiyi = 0 , sumxipow = 0 ;
std::string typef = "" ;
std::cin >> n >> typef ;
//input
for ( float i = 0 ; i < n ; i++ ){
std::cin >> xi >> yi ;
sumxi += xi ;
sumyi += yi ;
sumxiyi += ( xi * yi ) ;
sumxipow += ( xi * xi ) ;
}
//find m
float upm = 0 , lowm = 0 ;
upm = ( n * sumxiyi ) - ( sumxi * sumyi ) ;
lowm = ( sumxipow * n) - ( sumxi * sumxi ) ;
m = upm / lowm ;
m = round(m*1e3)/1e3 ;
//find b
b = ( sumyi - ( m*sumxi )) / n ;
bool bminues = b < 0 ;
if ( b < 0 ){
b = b * -1 ;
}
b = round(b*1e3)/1e3 ;
//output
if ( typef == "mb" ){
std::cout << m << std::endl ;
std::cout << b << std::endl ;
}else if ( typef == "func"){
//b not 0 and m = -1
if ( m == -1 && b != 0 ){
if ( bminues ){
std::cout << "y = -x - " << b ;
}else std::cout << "y = -x + " << b ;
}else if ( m == -1 && b == 0 ){
// b = 0 and m = -1
std::cout << "y = -x" ;
}else if ( m == 0 ){
// m == 0 and b != 0 or b == 0
if ( bminues ){
std::cout << "y = -" << b ;
}else std::cout << "y = " << b ;
}else if ( m == 1 && b != 0 ){
if ( bminues ){
std::cout << "y = x - " << b ;
}else std::cout << "y = x + " << b ;
}else if ( m == 1 && b == 0 ){
// b = 0 and m = 1
std::cout << "y = x" ;
}else{
if ( bminues ){
std::cout << "y = " << m << "x - " << b ;
}else std::cout << "y = " << m << "x + " << b ;
}
}
} | # 1383, 2024-11-02 10:47:01, -----PPPP------PPPPPPPPP (54%)
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
int main () {
float n = 0 , xi = 0 , yi = 0 , m = 0 , b = 0 , sumxi = 0 , sumyi = 0 , sumxiyi = 0 , sumxipow = 0 ;
std::string typef ;
std::cin >> n >> typef ;
//input
for ( float i = 0 ; i < n ; i++ ){
std::cin >> xi >> yi ;
sumxi += xi ;
sumyi += yi ;
sumxiyi += ( xi * yi ) ;
sumxipow += pow( xi , 2 ) ;
}
//find m
float upm = 0 , lowm = 0 ;
upm = ( n * sumxiyi ) - ( sumxi * sumyi ) ;
lowm = ( sumxipow * n) - ( pow( sumxi , 2 ) ) ;
m = upm / lowm ;
m = round(m*1e3)/1e3 ;
//find b
b = ( sumyi - ( m*sumxi )) / n ;
bool bminues = b < 0 ;
if ( b < 0 ){
b = b * -1 ;
}
b = round(b*1e3)/1e3 ;
//output
if ( typef == "mb" ){
std::cout << m << std::endl ;
std::cout << b << std::endl ;
}else if ( typef == "func"){
//b not 0 and m = -1
if ( m == -1 && b != 0 ){
if ( bminues ){
std::cout << "y = -x - " << b ;
}else std::cout << "y = -x + " << b ;
}else if ( m == -1 && b == 0 ){
// b = 0 and m = -1
std::cout << "y = -x" ;
}else if ( m == 0 ){
// m == 0 and b != 0 or b == 0
if ( bminues ){
std::cout << "y = -" << b ;
}else std::cout << "y = " << b ;
}else if ( m == 1 && b != 0 ){
if ( bminues ){
std::cout << "y = x - " << b ;
}else std::cout << "y = x + " << b ;
}else if ( m == 1 && b == 0 ){
// b = 0 and m = 1
std::cout << "y = x" ;
}else{
if ( bminues ){
std::cout << "y = " << m << "x - " << b ;
}else std::cout << "y = " << m << "x + " << b ;
}
}
} | # 1384, 2024-11-02 11:46:48, -----PPPP------PPPPPPPPP (54%)
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
int main () {
float n = 0 , xi = 0 , yi = 0 , m = 0 , b = 0 , sumxi = 0 , sumyi = 0 , sumxiyi = 0 , sumxipow = 0 ;
std::string typef ;
std::cin >> n >> typef ;
//input
for ( float i = 0 ; i < n ; i++ ){
std::cin >> xi >> yi ;
sumxi += xi ;
sumyi += yi ;
sumxiyi += ( xi * yi ) ;
sumxipow += pow( xi , 2 ) ;
}
//find m
float upm = 0 , lowm = 0 ;
upm = ( n * sumxiyi ) - ( sumxi * sumyi ) ;
lowm = ( sumxipow * n) - ( pow( sumxi , 2 ) ) ;
m = upm / lowm ;
m = round(m*1e3)/1e3 ;
//find b
b = ( sumyi - ( m*sumxi )) / n ;
bool bminues = b < 0 ;
if ( b < 0 ){
b = b * -1.000 ;
}
b = round(b*1e3)/1e3 ;
//output
if ( typef == "mb" ){
std::cout << m << std::endl ;
std::cout << b << std::endl ;
}else if ( typef == "func"){
//b not 0 and m = -1
if ( m == -1 && b != 0 ){
if ( bminues ){
std::cout << "y = -x - " << b ;
}else std::cout << "y = -x + " << b ;
}else if ( m == -1 && b == 0 ){
// b = 0 and m = -1
std::cout << "y = -x" ;
}else if ( m == 0 ){
// m == 0 and b != 0 or b == 0
if ( bminues ){
std::cout << "y = -" << b ;
}else std::cout << "y = " << b ;
}else if ( m == 1 && b != 0 ){
if ( bminues ){
std::cout << "y = x - " << b ;
}else std::cout << "y = x + " << b ;
}else if ( m == 1 && b == 0 ){
// b = 0 and m = 1
std::cout << "y = x" ;
}else{
if ( bminues ){
std::cout << "y = " << m << "x - " << b ;
}else std::cout << "y = " << m << "x + " << b ;
}
}
} | # 1385, 2024-11-02 11:50:28, -----PPPP------PPPPPPPPP (54%)
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
int main () {
float n = 0 , xi = 0 , yi = 0 , m = 0 , b = 0 , sumxi = 0 , sumyi = 0 , sumxiyi = 0 , sumxipow = 0 ;
std::string typef = "" ;
std::cin >> n >> typef ;
//input
for ( float i = 0 ; i < n ; i++ ){
std::cin >> xi >> yi ;
sumxi += xi ;
sumyi += yi ;
sumxiyi += ( xi * yi ) ;
sumxipow += ( xi * xi ) ;
}
//find m
float upm = 0 , lowm = 0 ;
upm = ( n * sumxiyi ) - ( sumxi * sumyi ) ;
lowm = ( sumxipow * n) - ( sumxi * sumxi ) ;
m = upm / lowm ;
m = round(m*1e3)/1e3 ;
//find b
b = ( sumyi - ( m*sumxi )) / n ;
bool bminues = b < 0 ; float c = b ;
if ( b < 0 ){
b = b * -1 ;
}
c = round(c*1e3)/1e3 ;
b = round(b*1e3)/1e3 ;
//output
if ( typef == "mb" ){
std::cout << m << std::endl ;
std::cout << b << std::endl ;
}else if ( typef == "func"){
//b not 0 and m = -1
if ( m == -1 && b != 0 ){
if ( bminues ){
std::cout << "y = -x - " << b ;
}else std::cout << "y = -x + " << b ;
}else if ( m == -1 && b == 0 ){
// b = 0 and m = -1
std::cout << "y = -x" ;
}else if ( m == 0 ){
// m == 0 and b != 0 or b == 0
std::cout << "y = " << c ;
}else if ( m == 1 && b != 0 ){
if ( bminues ){
std::cout << "y = x - " << b ;
}else std::cout << "y = x + " << b ;
}else if ( m == 1 && b == 0 ){
// b = 0 and m = 1
std::cout << "y = x" ;
}else{
if ( bminues ){
std::cout << "y = " << m << "x - " << b ;
}else std::cout << "y = " << m << "x + " << b ;
}
}
} | # 1386, 2024-11-02 11:58:21, -----PPPP------PP-PP-P-- (37%)
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
int main () {
float n = 0 , xi = 0 , yi = 0 , m = 0 , b = 0 , sumxi = 0 , sumyi = 0 , sumxiyi = 0 , sumxipow = 0 ;
std::string typef = "" ;
std::cin >> n >> typef ;
//input
for ( float i = 0 ; i < n ; i++ ){
std::cin >> xi >> yi ;
sumxi += xi ;
sumyi += yi ;
sumxiyi += ( xi * yi ) ;
sumxipow += ( xi * xi ) ;
}
//find m
float upm = 0 , lowm = 0 ;
upm = ( n * sumxiyi ) - ( sumxi * sumyi ) ;
lowm = ( sumxipow * n) - ( sumxi * sumxi ) ;
m = upm / lowm ;
m = round(m*1e3)/1e3 ;
//find b
b = ( sumyi - ( m*sumxi )) / n ;
bool bminues = b < 0 ; float c = b ;
b = abs(b) ;
c = round(c*1e3)/1e3 ;
b = round(b*1e3)/1e3 ;
//output
if ( typef == "mb" ){
std::cout << m << std::endl ;
std::cout << b << std::endl ;
}else if ( typef == "func"){
//b not 0 and m = -1
if ( m == -1 && b != 0 ){
if ( bminues ){
std::cout << "y = -x - " << b ;
}else std::cout << "y = -x + " << b ;
}else if ( m == -1 && b == 0 ){
// b = 0 and m = -1
std::cout << "y = -x" ;
}else if ( m == 0 ){
// m == 0 and b != 0 or b == 0
std::cout << "y = " << c ;
}else if ( m == 1 && b != 0 ){
if ( bminues ){
std::cout << "y = x - " << b ;
}else std::cout << "y = x + " << b ;
}else if ( m == 1 && b == 0 ){
// b = 0 and m = 1
std::cout << "y = x" ;
}else{
if ( bminues ){
std::cout << "y = " << m << "x - " << b ;
}else std::cout << "y = " << m << "x + " << b ;
}
}
} | # 1387, 2024-11-02 12:10:57, -----PPPP------PPPPPPPPP (54%)
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
int main () {
int n = 0 ;
float xi = 0 , yi = 0 , m = 0 , b = 0 , sumxi = 0 , sumyi = 0 , sumxiyi = 0 , sumxipow = 0 ;
std::string typef = "" ;
std::cin >> n >> typef ;
//input
for ( int i = 0 ; i < n ; i++ ){
std::cin >> xi >> yi ;
sumxi += xi ;
sumyi += yi ;
sumxiyi += ( xi * yi ) ;
sumxipow += ( xi * xi ) ;
}
//find m
float upm = 0 , lowm = 0 ;
upm = ( sumxiyi * n ) - ( sumxi * sumyi ) ;
lowm = ( sumxipow * n) - ( sumxi * sumxi ) ;
m = upm / lowm ;
m = round(m*1e3)/1e3 ;
//find b
b = ( sumyi - ( m*sumxi )) / n ;
bool bminues = b < 0 ; float c = b ;
if ( b < 0 ){
b = b * -1.000 ;
}
c = float(round(c*1e3)/1e3) ;
b = float(round(b*1e3)/1e3);
//output
if ( typef == "mb" ){
std::cout << m << std::endl ;
std::cout << b << std::endl ;
}else if ( typef == "func"){
//b not 0 and m = -1
if ( m == -1 && b != 0 ){
if ( bminues ){
std::cout << "y = -x - " << b ;
}else std::cout << "y = -x + " << b ;
}else if ( m == -1 && b == 0 ){
// b = 0 and m = -1
std::cout << "y = -x" ;
}else if ( m == 0 ){
// m == 0 and b != 0 or b == 0
std::cout << "y = " << c ;
}else if ( m == 1 && b != 0 ){
if ( bminues ){
std::cout << "y = x - " << b ;
}else std::cout << "y = x + " << b ;
}else if ( m == 1 && b == 0 ){
// b = 0 and m = 1
std::cout << "y = x" ;
}else{
if ( bminues ){
std::cout << "y = " << m << "x - " << b ;
}else std::cout << "y = " << m << "x + " << b ;
}
}
} |
# 1388, 2024-11-02 15:03:29, -----PPPPP-------P--P--- (29%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string f;
cin>>n>>f;
float a,b,M,B;
vector<pair<float,float>> num;
for(int i=0;i<n;i++){
cin>>a>>b;
num.push_back(make_pair(a,b));
}
double sxy=0,sx=0,sy=0,sxx=0;
for(auto d:num){
sxy+=d.first*d.second;
sx+=d.first;
sy+=d.second;
sxx+=pow(d.first,2);
}
M=((n*sxy)-(sx*sy))/(n*sxx-(pow(sx,2)));
M=round(M*1000)/1000;
B=(sy-M*sx)/n;
B=round(B*1000)/1000;
if(f=="mb"){
cout<<M<<endl;
cout<<B;
}
if(f=="func"){
if(M==1){
cout<<"y = "<<"x + "<<B;
}
else if(M==-1){
cout<<"y = "<<"-x + "<<B;
}
else
cout<<"y = "<<M<<"x + "<<B;
}
} | # 1389, 2024-11-02 15:10:15, -----PPPPP------PP--PP-- (37%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string f;
cin>>n>>f;
float a,b,M,B;
vector<pair<float,float>> num;
for(int i=0;i<n;i++){
cin>>a>>b;
num.push_back(make_pair(a,b));
}
double sxy=0,sx=0,sy=0,sxx=0;
for(auto d:num){
sxy+=d.first*d.second;
sx+=d.first;
sy+=d.second;
sxx+=pow(d.first,2);
}
M=((n*sxy)-(sx*sy))/(n*sxx-(pow(sx,2)));
M=round(M*1000)/1000;
B=(sy-M*sx)/n;
B=round(B*1000)/1000;
if(f=="mb"){
cout<<M<<endl;
cout<<B;
}
if(f=="func"){
if(M==1){
cout<<"y = "<<"x + "<<B;
}
else if(M==-1){
cout<<"y = "<<"-x + "<<B;
}
else if(M=0&&B==0){
cout<<"y = 0";
}
else if(M==0&&B!=0){
cout<<"y = "<<B;
}
else if(B==0&&M!=0){
cout<<"y = "<<M<<"x";
}
else if(M==-1&&B==0){
cout<<"y = -x";
}
else if(M==0&&B==-1){
cout<<"y = -"<<B;
}
else
cout<<"y = "<<M<<"x + "<<B;
}
} | # 1390, 2024-11-02 15:13:40, -----PPPPP-----PPP--PP-- (41%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string f;
cin>>n>>f;
float a,b,M,B;
vector<pair<float,float>> num;
for(int i=0;i<n;i++){
cin>>a>>b;
num.push_back(make_pair(a,b));
}
double sxy=0,sx=0,sy=0,sxx=0;
for(auto d:num){
sxy+=d.first*d.second;
sx+=d.first;
sy+=d.second;
sxx+=pow(d.first,2);
}
M=((n*sxy)-(sx*sy))/(n*sxx-(pow(sx,2)));
M=round(M*1000)/1000;
B=(sy-M*sx)/n;
B=round(B*1000)/1000;
if(f=="mb"){
cout<<M<<endl;
cout<<B;
}
if(f=="func"){
if(M==1&&B!=0){
cout<<"y = "<<"x + "<<B;
}
else if(M==-1&&B!=0){
cout<<"y = "<<"-x + "<<B;
}
else if(M==0&&B==0){
cout<<"y = 0";
}
else if(M==0&&B!=0){
cout<<"y = "<<B;
}
else if(B==0&&M!=0){
cout<<"y = "<<M<<"x";
}
else if(M==-1&&B==0){
cout<<"y = -x";
}
else if(M==0&&B==-1){
cout<<"y = -"<<B;
}
else
cout<<"y = "<<M<<"x + "<<B;
}
} | # 1391, 2024-11-02 15:19:18, -----PPPPP-----PPPPPPP-- (50%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string f;
cin>>n>>f;
float a,b,M,B;
vector<pair<float,float>> num;
for(int i=0;i<n;i++){
cin>>a>>b;
num.push_back(make_pair(a,b));
}
double sxy=0,sx=0,sy=0,sxx=0;
for(auto d:num){
sxy+=d.first*d.second;
sx+=d.first;
sy+=d.second;
sxx+=pow(d.first,2);
}
M=((n*sxy)-(sx*sy))/(n*sxx-(pow(sx,2)));
M=round(M*1000)/1000;
B=(sy-M*sx)/n;
B=round(B*1000)/1000;
if(f=="mb"){
cout<<M<<endl;
cout<<B;
}
if(f=="func"){
if(M==1&&B!=0){
cout<<"y = "<<"x + "<<B;
}
else if(M==-1&&B==0){
cout<<"y = -x";
}
else if(M==0&&B==0){
cout<<"y = 0";
}
else if(M==1&&B==0){
cout<<"y = x";
}
else if(M==-1&&B!=0){
cout<<"y = "<<"-x + "<<B;
}
else if(M==0&&B==-1){
cout<<"y = -"<<B;
}
else if(M==0&&B!=0){
cout<<"y = "<<B;
}
else if(B==0&&M!=0){
cout<<"y = "<<M<<"x";
}
else
cout<<"y = "<<M<<"x + "<<B;
}
} | # 1392, 2024-11-02 15:23:34, -----PPPPP-----PP-PPPPPP (54%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string f;
cin>>n>>f;
float a,b,M,B;
vector<pair<float,float>> num;
for(int i=0;i<n;i++){
cin>>a>>b;
num.push_back(make_pair(a,b));
}
double sxy=0,sx=0,sy=0,sxx=0;
for(auto d:num){
sxy+=d.first*d.second;
sx+=d.first;
sy+=d.second;
sxx+=pow(d.first,2);
}
M=((n*sxy)-(sx*sy))/(n*sxx-(pow(sx,2)));
M=round(M*1000)/1000;
B=(sy-M*sx)/n;
B=round(B*1000)/1000;
if(f=="mb"){
cout<<M<<endl;
cout<<B;
}
if(f=="func"){
if(M==1&&B>0){
cout<<"y = "<<"x + "<<B;
}
if(M==1&&B<0){
cout<<"y = "<<"x - "<<-B;
}
else if(M==-1&&B==0){
cout<<"y = -x";
}
else if(M==0&&B==0){
cout<<"y = 0";
}
else if(M==1&&B==0){
cout<<"y = x";
}
else if(M==-1&&B>0){
cout<<"y = "<<"-x + "<<B;
}
else if(M==-1&&B<0){
cout<<"y = "<<"-x - "<<-B;
}
else if(M==0&&B==-1){
cout<<"y = -"<<B;
}
else if(M==0&&B!=0){
cout<<"y = "<<B;
}
else if(B==0&&M!=0){
cout<<"y = "<<M<<"x";
}
else
cout<<"y = "<<M<<"x + "<<B;
}
} | # 1393, 2024-11-02 15:27:47, -----PPPPP-----PP-PPPPPP (54%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string f;
cin>>n>>f;
float a,b,M,B;
vector<pair<float,float>> num;
for(int i=0;i<n;i++){
cin>>a>>b;
num.push_back(make_pair(a,b));
}
float sxy=0,sx=0,sy=0,sxx=0;
for(auto d:num){
sxy+=d.first*d.second;
sx+=d.first;
sy+=d.second;
sxx+=pow(d.first,2);
}
M=((n*sxy)-(sx*sy))/(n*sxx-(pow(sx,2)));
M=round(M*1e3)/1e3;
B=(sy-M*sx)/n;
B=round(B*1e3)/1e3;
if(f=="mb"){
cout<<M<<endl;
cout<<B;
}
if(f=="func"){
if(M==1&&B>0){
cout<<"y = "<<"x + "<<B;
}
if(M==1&&B<0){
cout<<"y = "<<"x - "<<-B;
}
else if(M==-1&&B==0){
cout<<"y = -x";
}
else if(M==0&&B==0){
cout<<"y = 0";
}
else if(M==1&&B==0){
cout<<"y = x";
}
else if(M==-1&&B>0){
cout<<"y = "<<"-x + "<<B;
}
else if(M==-1&&B<0){
cout<<"y = "<<"-x - "<<-B;
}
else if(M==0&&B==-1){
cout<<"y = -"<<B;
}
else if(M==0&&B!=0){
cout<<"y = "<<B;
}
else if(B==0&&M!=0){
cout<<"y = "<<M<<"x";
}
else if(M!=0&&B>0)
cout<<"y = "<<M<<"x + "<<B;
else if(M!=0&&B<0)
cout<<"y = "<<M<<"x - "<<B;
}
} | # 1394, 2024-11-02 15:28:57, -----PPPPP-----PP-PPPPPP (54%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string f;
cin>>n>>f;
float a,b,M,B;
vector<pair<float,float>> num;
for(int i=0;i<n;i++){
cin>>a>>b;
num.push_back(make_pair(a,b));
}
float sxy=0,sx=0,sy=0,sxx=0;
for(auto d:num){
sxy+=d.first*d.second;
sx+=d.first;
sy+=d.second;
sxx+=pow(d.first,2);
}
M=((n*sxy)-(sx*sy))/(n*sxx-(pow(sx,2)));
M=round(M*1e3)/1e3;
B=(sy-M*sx)/n;
B=round(B*1e3)/1e3;
if(f=="mb"){
cout<<M<<endl;
cout<<B;
}
if(f=="func"){
if(M==1&&B>0){
cout<<"y = "<<"x + "<<B;
}
if(M==1&&B<0){
cout<<"y = "<<"x - "<<-B;
}
else if(M==-1&&B==0){
cout<<"y = -x";
}
else if(M==0&&B==0){
cout<<"y = 0";
}
else if(M==1&&B==0){
cout<<"y = x";
}
else if(M==-1&&B>0){
cout<<"y = "<<"-x + "<<B;
}
else if(M==-1&&B<0){
cout<<"y = "<<"-x - "<<-B;
}
else if(M==0&&B==-1){
cout<<"y = -"<<B;
}
else if(M==0&&B!=0){
cout<<"y = "<<B;
}
else if(B==0&&M!=0){
cout<<"y = "<<M<<"x";
}
else if(M!=0&&B>0)
cout<<"y = "<<M<<"x + "<<B;
else if(M!=0&&B<0)
cout<<"y = "<<M<<"x - "<<-B;
}
} |
# 1395, 2024-11-02 10:06:22, -----PPP---------------- (12%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string sth;
vector<float> x;
vector<float> y;
float xi, yi;
cin >> n >> sth;
for (int i = 0; i < n; i++) {
cin >> xi >> yi;
x.push_back(xi);
y.push_back(yi);
}
if (sth == "mb") {
float a = 0, b = 0, c = 0, d = 0, e = 0;
for (int i = 1; i <= n; i++) {
a += x[i]*y[i];
b += x[i];
c += y[i];
d += x[i]*x[i];
e += y[i]*y[i];
}
float m = ((n*a) - (b*c)) / ((n*d) - pow(b,2));
float ae = (c - (m*b)) / n;
cout << round(m*1e3)/1e3 << endl << round(ae*1e3)/1e3;
}
} | # 1396, 2024-11-02 10:08:51, PPPPPPP-PP-------------- (37%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string sth;
vector<float> x;
vector<float> y;
float xi, yi;
cin >> n >> sth;
for (int i = 0; i < n; i++) {
cin >> xi >> yi;
x.push_back(xi);
y.push_back(yi);
}
if (sth == "mb") {
float a = 0, b = 0, c = 0, d = 0, e = 0;
for (int i = 1; i <= n; i++) {
a += x[i-1]*y[i-1];
b += x[i-1];
c += y[i-1];
d += x[i-1]*x[i-1];
e += y[i-1]*y[i-1];
}
float m = ((n*a) - (b*c)) / ((n*d) - pow(b,2));
float ae = (c - (m*b)) / n;
cout << round(m*1e3)/1e3 << endl << round(ae*1e3)/1e3;
}
} | # 1397, 2024-11-02 10:28:25, PPPPPPP-PP-----P---P-PP- (54%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string sth;
vector<float> x;
vector<float> y;
float xi, yi;
cin >> n >> sth;
for (int i = 0; i < n; i++) {
cin >> xi >> yi;
x.push_back(xi);
y.push_back(yi);
}
float a = 0, b = 0, c = 0, d = 0, e = 0;
for (int i = 1; i <= n; i++) {
a += x[i-1]*y[i-1];
b += x[i-1];
c += y[i-1];
d += x[i-1]*x[i-1];
e += y[i-1]*y[i-1];
}
float m = ((n*a) - (b*c)) / ((n*d) - pow(b,2));
float ae = (c - (m*b)) / n;
if (sth == "mb") {
cout << round(m*1e3)/1e3 << endl << round(ae*1e3)/1e3;
}
else if (sth == "func") {
if ( m == 0) cout << "y = " << ae;
else if (m == 1) {
cout << "y = x ";
if (ae < 0) {
cout << "- " << ae*-1;
}
else if (ae > 0) {
cout << "+ " << ae;
}
else if (ae == 0) {
cout << endl;
}
}
else if (m == -1) {
cout << "y = -x ";
if (ae < 0) {
cout << "- " << ae*-1;
}
else if (ae > 0) {
cout << "+ " << ae;
}
else if (ae == 0) {
cout << endl;
}
}
else if (m > 1) {
cout << m << "x ";
if (ae < 0) {
cout << "- " << ae*-1;
}
else if (ae > 0) {
cout << "+ " << ae;
}
else if (ae == 0) {
cout << endl;
}
}
else if (m < -1) {
cout << "-" << m << "x ";
if (ae < 0) {
cout << "- " << ae*-1;
}
else if (ae > 0) {
cout << "+ " << ae;
}
else if (ae == 0) {
cout << endl;
}
}
}
} | # 1398, 2024-11-02 10:30:40, PPPPPPP-PP-----P---P-PP- (54%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string sth;
vector<float> x;
vector<float> y;
float xi, yi;
cin >> n >> sth;
for (int i = 0; i < n; i++) {
cin >> xi >> yi;
x.push_back(xi);
y.push_back(yi);
}
float a = 0, b = 0, c = 0, d = 0, e = 0;
for (int i = 1; i <= n; i++) {
a += x[i-1]*y[i-1];
b += x[i-1];
c += y[i-1];
d += x[i-1]*x[i-1];
e += y[i-1]*y[i-1];
}
float m = ((n*a) - (b*c)) / ((n*d) - pow(b,2));
float ae = (c - (m*b)) / n;
if (sth == "mb") {
cout << round(m*1e3)/1e3 << endl << round(ae*1e3)/1e3;
}
else if (sth == "func") {
if ( m == 0) cout << "y = " << ae;
else if (m == 1) {
cout << "y = x ";
if (ae < 0) {
cout << "- " << ae*-1;
}
else if (ae > 0) {
cout << "+ " << ae;
}
else if (ae == 0) {
cout << endl;
}
}
else if (m == -1) {
cout << "y = -x ";
if (ae < 0) {
cout << "- " << ae*-1;
}
else if (ae > 0) {
cout << "+ " << ae;
}
else if (ae == 0) {
cout << endl;
}
}
else if (m > 1) {
cout << "y = " << m << "x ";
if (ae < 0) {
cout << "- " << ae*-1;
}
else if (ae > 0) {
cout << "+ " << ae;
}
else if (ae == 0) {
cout << endl;
}
}
else if (m < -1) {
cout << "y = " << "-" << m << "x ";
if (ae < 0) {
cout << "- " << ae*-1;
}
else if (ae > 0) {
cout << "+ " << ae;
}
else if (ae == 0) {
cout << endl;
}
}
}
} | # 1399, 2024-11-02 10:32:48, PPPPPPP-PP-----P---P-PP- (54%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string sth;
vector<float> x;
vector<float> y;
float xi, yi;
cin >> n >> sth;
for (int i = 0; i < n; i++) {
cin >> xi >> yi;
x.push_back(xi);
y.push_back(yi);
}
float a = 0, b = 0, c = 0, d = 0, e = 0;
for (int i = 1; i <= n; i++) {
a += x[i-1]*y[i-1];
b += x[i-1];
c += y[i-1];
d += x[i-1]*x[i-1];
e += y[i-1]*y[i-1];
}
float m = ((n*a) - (b*c)) / ((n*d) - pow(b,2));
float ae = (c - (m*b)) / n;
if (sth == "mb") {
cout << round(m*1e3)/1e3 << endl << round(ae*1e3)/1e3;
}
else if (sth == "func") {
if ( m == 0) cout << "y = " << ae;
else if (m == 1) {
cout << "y = x ";
if (ae < 0) {
cout << "- " << ae*-1;
}
else if (ae > 0) {
cout << "+ " << ae;
}
else if (ae == 0) {
cout << endl;
}
}
else if (m == -1) {
cout << "y = -x ";
if (ae < 0) {
cout << "- " << ae*-1;
}
else if (ae > 0) {
cout << "+ " << ae;
}
else if (ae == 0) {
cout << endl;
}
}
else if (m > 1) {
cout << "y = " << m << "x ";
if (ae < 0) {
cout << "- " << ae*-1;
}
else if (ae > 0) {
cout << "+ " << ae;
}
else if (ae == 0) {
cout << endl;
}
}
else if (m < -1) {
cout << "y = " << "-" << m << "x ";
if (ae < 0) {
cout << "- " << ae*-1;
}
else if (ae > 0) {
cout << "+ " << ae;
}
else if (ae == 0) {
cout << endl;
}
}
}
} | # 1400, 2024-11-02 12:10:21, PPPPPPP-PP-----P---P-PP- (54%)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string sth;
vector<float> x;
vector<float> y;
float xi, yi;
cin >> n >> sth;
for (int i = 0; i < n; i++) {
cin >> xi >> yi;
x.push_back(xi);
y.push_back(yi);
}
float a = 0, b = 0, c = 0, d = 0, e = 0;
for (int i = 1; i <= n; i++) {
a += x[i-1]*y[i-1];
b += x[i-1];
c += y[i-1];
d += x[i-1]*x[i-1];
e += y[i-1]*y[i-1];
}
float m = ((n*a) - (b*c)) / ((n*d) - pow(b,2));
float ae = (c - (m*b)) / n;
if (sth == "mb") {
cout << round(m*1e3)/1e3 << endl << round(ae*1e3)/1e3;
}
else if (sth == "func") {
if ( m == 0) cout << "y = " << ae;
else if (m == 1) {
cout << "y = x ";
if (ae < 0) {
cout << "- " << ae*-1;
}
else if (ae > 0) {
cout << "+ " << ae;
}
else if (ae == 0) {
cout << endl;
}
}
else if (m == -1) {
cout << "y = -x ";
if (ae < 0) {
cout << "- " << ae*-1;
}
else if (ae > 0) {
cout << "+ " << ae;
}
else if (ae == 0) {
cout << endl;
}
}
else if (m > 1) {
cout << "y = " << m << "x ";
if (ae < 0) {
cout << "- " << ae*-1;
}
else if (ae > 0) {
cout << "+ " << ae;
}
else if (ae == 0) {
cout << endl;
}
}
else if (m < -1) {
cout << "y = " << "-" << m << "x ";
if (ae < 0) {
cout << "- " << ae*-1;
}
else if (ae > 0) {
cout << "+ " << ae;
}
else if (ae == 0) {
cout << endl;
}
}
else if (m == 0 && ae == 0) {
cout << "y = 0";
}
}
} |
# 1401, 2024-11-02 11:39:51, -----P-P---------------- (8%)
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string cmd;
cin >> cmd;
vector<pair<float,float>> point;
float x,y;
for(int i=0 ; i<n ;i++) {
cin >> x >> y;
point.push_back(make_pair(x,y));
}
float m=0;
float b =0;
float m1=0;
float m2=0;
float m3=0;
float m4=0;
float m5=0;
int count=1;
for(auto e : point) {
m1+= (e.first*e.second)*n;
m2+= e.first;
m3+= e.second;
m4+= pow(e.first,2)*n;
// count++;
}
m5=m2*m2;
m=(m1-(m2*m3))/(m4-m5);
b=(m3-(m*m2))/n;
//cout << m1 << " " << m2 << " " << m3 << " " << m4 << " " << m5 << endl;
if(cmd=="mb") {
cout << m << endl;
cout << b << endl;
}
} | # 1402, 2024-11-02 11:47:36, -----P-P-------P--P--P-- (20%)
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string cmd;
cin >> cmd;
vector<pair<float,float>> point;
float x,y;
for(int i=0 ; i<n ;i++) {
cin >> x >> y;
point.push_back(make_pair(x,y));
}
float m=0;
float b =0;
float m1=0;
float m2=0;
float m3=0;
float m4=0;
float m5=0;
int count=1;
for(auto e : point) {
m1+= (e.first*e.second)*n;
m2+= e.first;
m3+= e.second;
m4+= pow(e.first,2)*n;
// count++;
}
m5=m2*m2;
m=(m1-(m2*m3))/(m4-m5);
b=(m3-(m*m2))/n;
round(m*1e3)/1e3;
round(b*1e3)/1e3;
//cout << m1 << " " << m2 << " " << m3 << " " << m4 << " " << m5 << endl;
if(cmd=="mb") {
cout << m << endl;
cout << b << endl;
}
if(cmd=="func") {
float y=0;
if(m==1) {
if(b!=0) {
cout << "y = " << "x +" << b << endl;
} else {
cout << "y = x" << endl;
}
}
if(m==0) {
if(b!=0) {
cout << "y = " << b << endl;
} else {
cout << "y = 0" << endl;
}
}
if(m>1) {
if(b!=0) {
cout << "y = " << m << "x" << " + " << b;
} else {
cout << "y = " << m << "x" << endl;
}
}
}
} | # 1403, 2024-11-02 12:00:37, PPPPPPPPP-P-P-----P----- (50%)
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string cmd;
cin >> cmd;
vector<pair<float,float>> point;
float x,y;
for(int i=0 ; i<n ;i++) {
cin >> x >> y;
point.push_back(make_pair(x,y));
}
float m=0;
float b =0;
float m1=0;
float m2=0;
float m3=0;
float m4=0;
float m5=0;
int count=1;
for(auto e : point) {
m1+= (e.first*e.second)*n;
m2+= e.first;
m3+= e.second;
m4+= pow(e.first,2)*n;
// count++;
}
m5=m2*m2;
m=(m1-(m2*m3))/(m4-m5);
b=(m3-(m*m2))/n;
//cout << m1 << " " << m2 << " " << m3 << " " << m4 << " " << m5 << endl;
if(cmd=="mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(cmd=="func") {
float y=0;
if(m==1) {
if(b!=0) {
cout << "y = " << "x +" << round(b*1e3)/1e3 << endl;
} else {
cout << "y = x" << endl;
}
}
if(m==0) {
if(b!=0) {
cout << "y = " << round(b*1e3)/1e3 << endl;
} else {
cout << "y = 0" << endl;
}
}
if(m>1) {
if(b!=0) {
cout << "y = " << round(m*1e3)/1e3 << "x" << " + " << round(b*1e3)/1e3;
} else {
cout << "y = " << round(m*1e3)/1e3 << "x" << endl;
}
}
if(m<0) {
if(b!=0) {
cout << "y = " << round(m*1e3)/1e3 << "x" << " + " << round(b*1e3)/1e3;;
} else {
cout << "y = " << round(m*1e3)/1e3 << "x" << endl;
}
}
if(m==-0) {
if(b!=0) {
cout << "y = " << round(b*1e3)/1e3 << endl;
} else {
cout << "y = 0" << endl;
}
}
}
} | # 1404, 2024-11-02 12:04:12, PPPPPPPPP-P-------P----- (45%)
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string cmd;
cin >> cmd;
vector<pair<float,float>> point;
float x,y;
for(int i=0 ; i<n ;i++) {
cin >> x >> y;
point.push_back(make_pair(x,y));
}
float m=0;
float b =0;
float m1=0;
float m2=0;
float m3=0;
float m4=0;
float m5=0;
int count=1;
for(auto e : point) {
m1+= (e.first*e.second)*n;
m2+= e.first;
m3+= e.second;
m4+= pow(e.first,2)*n;
// count++;
}
m5=m2*m2;
m=(m1-(m2*m3))/(m4-m5);
b=(m3-(m*m2))/n;
//cout << m1 << " " << m2 << " " << m3 << " " << m4 << " " << m5 << endl;
if(cmd=="mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(cmd=="func") {
float y=0;
if(m==1) {
if(b!=0) {
cout << "y = " << "x +" << round(b*1e3)/1e3 << endl;
} else {
cout << "y = x" << endl;
}
}
if(m==0) {
if(b!=0) {
cout << "y = " << round(b*1e3)/1e3 << endl;
} else {
cout << "y = 0" << endl;
}
}
if(m>1) {
if(b!=0) {
cout << "y = " << round(m*1e3)/1e3 << "x" << " + " << round(b*1e3)/1e3;
} else {
cout << "y = " << round(m*1e3)/1e3 << "x" << endl;
}
}
if(m<0) {
if(b!=0) {
cout << "y = " << (-1)*(round(m*1e3)/1e3) << "x" << " + " << round(b*1e3)/1e3;;
} else {
cout << "y = " << (-1)*round(m*1e3)/1e3 << "x" << endl;
}
}
if(m==-1) {
if(b!=0) {
cout << "y = "<< "-x" << " + " << round(b*1e3)/1e3;;
} else {
cout << "y = "<< "-x" << endl;
}
}
if(m==-0) {
if(b!=0) {
cout << "y = " << round(b*1e3)/1e3 << endl;
} else {
cout << "y = 0" << endl;
}
}
}
} | # 1405, 2024-11-02 12:07:14, PPPPPPPPP-P-------P-P--- (50%)
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string cmd;
cin >> cmd;
vector<pair<float,float>> point;
float x,y;
for(int i=0 ; i<n ;i++) {
cin >> x >> y;
point.push_back(make_pair(x,y));
}
float m=0;
float b =0;
float m1=0;
float m2=0;
float m3=0;
float m4=0;
float m5=0;
int count=1;
for(auto e : point) {
m1+= (e.first*e.second)*n;
m2+= e.first;
m3+= e.second;
m4+= pow(e.first,2)*n;
// count++;
}
m5=m2*m2;
m=(m1-(m2*m3))/(m4-m5);
b=(m3-(m*m2))/n;
//cout << m1 << " " << m2 << " " << m3 << " " << m4 << " " << m5 << endl;
if(cmd=="mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(cmd=="func") {
float y=0;
if(m==1) {
if(b!=0) {
cout << "y = " << "x +" << round(b*1e3)/1e3 << endl;
} else {
cout << "y = x" << endl;
}
}
if(m==0) {
if(b!=0) {
cout << "y = " << round(b*1e3)/1e3 << endl;
} else {
cout << "y = 0" << endl;
}
}
if(m>1) {
if(b!=0) {
cout << "y = " << round(m*1e3)/1e3 << "x" << " + " << round(b*1e3)/1e3;
} else {
cout << "y = " << round(m*1e3)/1e3 << "x" << endl;
}
}
if(m<0 && m!=-1) {
if(b!=0) {
cout << "y = " << (-1)*(round(m*1e3)/1e3) << "x" << " + " << round(b*1e3)/1e3;;
} else {
cout << "y = " << (-1)*round(m*1e3)/1e3 << "x" << endl;
}
}
if(m==-1) {
if(b!=0) {
cout << "y = "<< "-x" << " + " << round(b*1e3)/1e3;;
} else {
cout << "y = "<< "-x" << endl;
}
}
if(m==-0) {
if(b!=0) {
cout << "y = " << round(b*1e3)/1e3 << endl;
} else {
cout << "y = 0" << endl;
}
}
}
} | # 1406, 2024-11-02 12:09:25, PPPPPPPPP-P-------P-P--- (50%)
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string cmd;
cin >> cmd;
vector<pair<float,float>> point;
float x,y;
for(int i=0 ; i<n ;i++) {
cin >> x >> y;
point.push_back(make_pair(x,y));
}
float m=0;
float b =0;
float m1=0;
float m2=0;
float m3=0;
float m4=0;
float m5=0;
int count=1;
for(auto e : point) {
m1+= (e.first*e.second)*n;
m2+= e.first;
m3+= e.second;
m4+= pow(e.first,2)*n;
// count++;
}
m5=m2*m2;
m=(m1-(m2*m3))/(m4-m5);
b=(m3-(m*m2))/n;
//cout << m1 << " " << m2 << " " << m3 << " " << m4 << " " << m5 << endl;
if(cmd=="mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(cmd=="func") {
float y=0;
if(m==1) {
if(b!=0) {
cout << "y = " << "x +" << round(b*1e3)/1e3 << endl;
} else {
cout << "y = x" << endl;
}
}
if(m==0) {
if(b!=0) {
cout << "y = " << round(b*1e3)/1e3 << endl;
} else {
cout << "y = 0" << endl;
}
}
if(m>1) {
if(b!=0) {
cout << "y = " << round(m*1e3)/1e3 << "x" << " + " << round(b*1e3)/1e3;
} else {
cout << "y = " << round(m*1e3)/1e3 << "x" << endl;
}
}
if(m<0 && m!=-1) {
if(b!=0) {
cout << "y = " << (-1)*(round(m*1e3)/1e3) << "x" << " + " << round(b*1e3)/1e3;;
} else {
cout << "y = " << (-1)*round(m*1e3)/1e3 << "x" << endl;
}
}
if(m==-1) {
if(b>0) {
cout << "y = "<< "-x" << " + " << round(b*1e3)/1e3;
} else {
cout << "y = "<< "-x" << endl;
}
if(b<1) {
cout << "y = "<< "-x" << round(b*1e3)/1e3;;
}
}
if(m==-0) {
if(b!=0) {
cout << "y = " << round(b*1e3)/1e3 << endl;
} else {
cout << "y = 0" << endl;
}
}
}
} | # 1407, 2024-11-02 12:10:42, PPPPPPPPP-P-------P-P--- (50%)
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string cmd;
cin >> cmd;
vector<pair<float,float>> point;
float x,y;
for(int i=0 ; i<n ;i++) {
cin >> x >> y;
point.push_back(make_pair(x,y));
}
float m=0;
float b =0;
float m1=0;
float m2=0;
float m3=0;
float m4=0;
float m5=0;
int count=1;
for(auto e : point) {
m1+= (e.first*e.second)*n;
m2+= e.first;
m3+= e.second;
m4+= pow(e.first,2)*n;
// count++;
}
m5=m2*m2;
m=(m1-(m2*m3))/(m4-m5);
b=(m3-(m*m2))/n;
//cout << m1 << " " << m2 << " " << m3 << " " << m4 << " " << m5 << endl;
if(cmd=="mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(cmd=="func") {
float y=0;
if(m==1) {
if(b!=0) {
cout << "y = " << "x +" << round(b*1e3)/1e3 << endl;
} else {
cout << "y = x" << endl;
}
}
if(m==0) {
if(b!=0) {
cout << "y = " << round(b*1e3)/1e3 << endl;
} else {
cout << "y = 0" << endl;
}
}
if(m>1) {
if(b!=0) {
cout << "y = " << round(m*1e3)/1e3 << "x" << " + " << round(b*1e3)/1e3;
} else {
cout << "y = " << round(m*1e3)/1e3 << "x" << endl;
}
}
if(m<0 && m!=-1) {
if(b!=0) {
cout << "y = " << (-1)*(round(m*1e3)/1e3) << "x" << " + " << round(b*1e3)/1e3;;
} else {
cout << "y = " << (-1)*round(m*1e3)/1e3 << "x" << endl;
}
}
if(m==-1) {
if(b>0) {
cout << "y = "<< "-x" << " + " << round(b*1e3)/1e3;
}
if(b==0) {
cout << "y = "<< "-x" << endl;
}
if(b<0) {
cout << "y = "<< "-x" << round(b*1e3)/1e3;;
}
}
if(m==-0) {
if(b!=0) {
cout << "y = " << round(b*1e3)/1e3 << endl;
} else {
cout << "y = 0" << endl;
}
}
}
} | # 1408, 2024-11-02 12:11:24, PPPPPPPPP---------P-P--- (45%)
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string cmd;
cin >> cmd;
vector<pair<float,float>> point;
float x,y;
for(int i=0 ; i<n ;i++) {
cin >> x >> y;
point.push_back(make_pair(x,y));
}
float m=0;
float b =0;
float m1=0;
float m2=0;
float m3=0;
float m4=0;
float m5=0;
int count=1;
for(auto e : point) {
m1+= (e.first*e.second)*n;
m2+= e.first;
m3+= e.second;
m4+= pow(e.first,2)*n;
// count++;
}
m5=m2*m2;
m=(m1-(m2*m3))/(m4-m5);
b=(m3-(m*m2))/n;
//cout << m1 << " " << m2 << " " << m3 << " " << m4 << " " << m5 << endl;
if(cmd=="mb") {
cout << round(m*1e3)/1e3 << endl;
cout << round(b*1e3)/1e3 << endl;
}
if(cmd=="func") {
float y=0;
if(m==1) {
if(b!=0) {
cout << "y = " << "x +" << round(b*1e3)/1e3 << endl;
} else {
cout << "y = x" << endl;
}
}
if(m==0) {
if(b!=0) {
cout << "y = " << round(b*1e3)/1e3 << endl;
} else {
cout << "y = 0" << endl;
}
}
if(m>1) {
if(b>0) {
cout << "y = "<< "x" << " + " << round(b*1e3)/1e3;
}
if(b==0) {
cout << "y = "<< "x" << endl;
}
if(b<0) {
cout << "y = "<< "x" << round(b*1e3)/1e3;;
}
}
if(m<0 && m!=-1) {
if(b!=0) {
cout << "y = " << (-1)*(round(m*1e3)/1e3) << "x" << " + " << round(b*1e3)/1e3;;
} else {
cout << "y = " << (-1)*round(m*1e3)/1e3 << "x" << endl;
}
}
if(m==-1) {
if(b>0) {
cout << "y = "<< "-x" << " + " << round(b*1e3)/1e3;
}
if(b==0) {
cout << "y = "<< "-x" << endl;
}
if(b<0) {
cout << "y = "<< "-x" << round(b*1e3)/1e3;;
}
}
if(m==-0) {
if(b!=0) {
cout << "y = " << round(b*1e3)/1e3 << endl;
} else {
cout << "y = 0" << endl;
}
}
}
} |
# 1409, 2024-11-02 10:12:26, PPPPPPPPPP-------------- (41%)
#include <bits/stdc++.h>
using namespace std;
float M(long int n, vector<pair<float,float>> v) {
float a = 0;
float b = 0;
float c = 0;
float d = 0;
for (int i = 0; i < n; i++) {
a += (v[i].first*v[i].second);
b += v[i].first;
c += v[i].second;
d += (pow((v[i].first),2));
}
float m = (((n*a) - (b*c))/((n*d) - (pow(b,2))));
// float m = ((n*a) - (b*c));
// if (m == -0) {
// m *= -1;
// }
return m;
}
float b(long int n, vector<pair<float,float>> v) {
float a = 0;
float b = 0;
for (int i = 0; i < n; i++) {
a += v[i].first;
b += v[i].second;
}
float B = (b-((M(n,v))*a))/n;
return B;
}
int main() {
long int n;
string how;
cin >> n >> how;
vector<pair<float,float>> collect;
for (long int i = 0; i < n; i++) {
float a, b;
cin >> a >> b;
pair<float,float> p = make_pair(a,b);
collect.push_back(p);
}
if (how == "mb") {
float x, y;
x = M(n,collect);
y = b(n,collect);
cout << round(x*1e3)/1e3 << endl;
cout << round(y*1e3)/1e3 << endl;
}
if (how == "func") {
float w, z;
w = M(n,collect);
z = b(n,collect);
cout << "y = ";
if ((w == 0) && (z == 0)) {
cout << "0";
} else {
if (w == 1) {
cout << "x";
} else {
if (w == -1) {
cout << "-x";
} else {
if (w != 0) {
//cout << round(w*1e3)/1e3 << "x";
cout << w << "x";
}
}
}
}
if ((z != 0) && (w == 0)) {
cout << round(z*1e3)/1e3;
} else {
if ((z > 0) && (w != 0)) {
cout << " + " << round(z*1e3)/1e3;
} else {
if ((z < 0) && (w != 0)) {
cout << " - " << -(round(z*1e3)/1e3);
}
}
}
cout << endl;
cout << w << " " << z;
}
} |
# 1410, 2024-11-02 10:09:17, P------PPPP----P---P---- (29%)
#include <bits/stdc++.h>
using namespace std ;
int main () {
float m,b = 0 ;
float A,B1,B2,C,D,E,F = 0 ;
// input
float x,y1 = 0 ;
int n = 0 ;
string op ;
vector< pair <float,float> > point ;
cin >> n >> op ;
for ( int i = 0 ; i<n ; i++ ) {
cin >> x >> y1 ;
point.push_back( make_pair ( x , y1 ) ) ;
}
// process
// find m
// find A,B1,B2,C,D,E
for ( int i = 0 ; i < n ; i++ ) {
A += (point[i].first)*(point[i].second) ;
B1 += point[i].first ;
B2 += point[i].second ;
C += pow( point[i].first , 2 ) ;
E += point[i].second ;
}
D = pow( B1 , 2 ) ;
m = ((n*A)-(B1*B2))/((n*C)-D) ;
//find b
// find F
F = m*B1 ;
b = (E-F)/n ;
// output
m = round(m*1e3)/1e3 ;
b = round(b*1e3)/1e3 ;
if ( op == "mb" ) {
cout << m << endl ;
cout << b << endl ;
} else if ( op == "func" ) {
cout << "y" << " =" ;
// if m,b == 0
if ( (m==0) && (b==0)) {
cout << " 0" << endl ;
} else {
// cout m
if ( m == 1 ) {
cout << " x " ;
} else if ( m == -1 ) {
cout << " -" << "x " ;
} else if ( m == 0 ) {
cout << " " ;
} else {
cout << " " << m << "x " ;
}
// cout b
if ( b > 0 ) {
cout << "+ " << b << endl ;
} else if ( b < 0 ) {
cout << "- " << (b*-1) << endl ;
}
}
}
} | # 1411, 2024-11-02 10:18:15, P--------P--PPPP-------- (25%)
#include <bits/stdc++.h>
using namespace std ;
int main () {
float m,b = 0 ;
float A,B1,B2,C,D,E,F = 0 ;
// input
float x,y1 = 0 ;
int n = 0 ;
string op ;
vector< pair <float,float> > point ;
cin >> n >> op ;
for ( int i = 0 ; i<n ; i++ ) {
cin >> x >> y1 ;
point.push_back( make_pair ( x , y1 ) ) ;
}
// process
// find m
// find A,B1,B2,C,D,
for ( int i = 0 ; i < n ; i++ ) {
A += (point[i].first)*(point[i].second) ;
B1 += point[i].first ;
B2 += point[i].second ;
C += pow( point[i].first , 2 ) ;
}
D = pow( B1 , 2 ) ;
m = ((n*A)-(B1*B2))/((n*C)-D) ;
//find b
// find E,F
E = B2 ;
F = m*B1 ;
b = (E-F)/n ;
// output
m = round(m*1e3)/1e3 ;
b = round(b*1e3)/1e3 ;
if ( op == "mb" ) {
cout << m << endl ;
cout << b << endl ;
} else if ( op == "func" ) {
cout << "y" << " =" ;
// if m,b == 0
if ( (m==0) && (b==0)) {
cout << " 0" << endl ;
} else {
// cout m
if ( m == 1 ) {
cout << " x " ;
} else if ( m == -1 ) {
cout << " -x " ;
} else if ( m == 0 ) {
cout << " " ;
} else {
cout << " " << m << "x " ;
}
// cout b
if ( b >= 0 ) {
cout << "+ " << b << endl ;
} else if ( b < 0 ) {
cout << "- " << (b*-1) << endl ;
}
}
}
} | # 1412, 2024-11-02 10:19:17, ----P----P--P-PP-------- (20%)
#include <bits/stdc++.h>
using namespace std ;
int main () {
float m,b = 0 ;
float A,B1,B2,C,D,E,F = 0 ;
// input
float x,y1 = 0 ;
int n = 0 ;
string op ;
vector< pair <float,float> > point ;
cin >> n >> op ;
for ( int i = 0 ; i<n ; i++ ) {
cin >> x >> y1 ;
point.push_back( make_pair ( x , y1 ) ) ;
}
// process
// find m
// find A,B1,B2,C,D,
for ( int i = 0 ; i < n ; i++ ) {
A += (point[i].first)*(point[i].second) ;
B1 += point[i].first ;
B2 += point[i].second ;
C += pow( point[i].first , 2 ) ;
}
D = pow( B1 , 2 ) ;
m = ((n*A)-(B1*B2))/((n*C)-D) ;
//find b
// find E,F
E = B2 ;
F = m*B1 ;
b = (E-F)/n ;
// output
m = round(m*1e3)/1e3 ;
b = round(b*1e3)/1e3 ;
if ( op == "mb" ) {
cout << m << endl ;
cout << b << endl ;
} else if ( op == "func" ) {
cout << "y" << " =" ;
// if m,b == 0
if ( (m==0) && (b==0)) {
cout << " 0" << endl ;
} else {
// cout m
if ( m == 1 ) {
cout << " x " ;
} else if ( m == -1 ) {
cout << " -" << "x " ;
} else if ( m == 0 ) {
cout << " " ;
} else {
cout << " " << m << "x " ;
}
// cout b
if ( b > 0 ) {
cout << "+ " << b << endl ;
} else if ( b < 0 ) {
cout << "- " << (b*-1) << endl ;
}
}
}
} | # 1413, 2024-11-02 10:21:20, P--P--P-----------P----- (16%)
#include <bits/stdc++.h>
using namespace std ;
int main () {
float m,b = 0 ;
float A,B1,B2,C,D,E,F = 0 ;
// input
float x,y1 = 0 ;
int n = 0 ;
string op ;
vector< pair <float,float> > point ;
cin >> n >> op ;
for ( int i = 0 ; i<n ; i++ ) {
cin >> x >> y1 ;
point.push_back( make_pair ( x , y1 ) ) ;
}
// process
// find m
// find A,B1,B2,C,D,E
for ( int i = 0 ; i < n ; i++ ) {
A += (point[i].first)*(point[i].second) ;
B1 += point[i].first ;
B2 += point[i].second ;
C += pow( point[i].first , 2 ) ;
E += point[i].second ;
}
D = pow( B1 , 2 ) ;
m = ((n*A)-(B1*B2))/((n*C)-D) ;
//find b
// find F
F = m*B1 ;
b = (E-F)/n ;
// output
if ( op == "mb" ) {
cout << round(m*1e3)/1e3 << endl ;
cout << round(b*1e3)/1e3 << endl ;
} else if ( op == "func" ) {
cout << "y" << " =" ;
// if m,b == 0
if ( (m==0) && (b==0)) {
cout << " 0" << endl ;
} else {
// cout m
if ( m == 1 ) {
cout << " x " ;
} else if ( m == -1 ) {
cout << " -" << "x " ;
} else if ( m == 0 ) {
cout << " " ;
} else {
cout << " " << round(m*1e3)/1e3 << "x " ;
}
// cout b
if ( b > 0 ) {
cout << "+ " << round(b*1e3)/1e3 << endl ;
} else if ( b < 0 ) {
b *= -1 ;
cout << "- " << round(b*1e3)/1e3 << endl ;
}
}
}
} | # 1414, 2024-11-02 10:21:54, PP-P-P------------------ (16%)
#include <bits/stdc++.h>
using namespace std ;
int main () {
float m,b = 0 ;
float A,B1,B2,C,D,E,F = 0 ;
// input
float x,y1 = 0 ;
int n = 0 ;
string op ;
vector< pair <float,float> > point ;
cin >> n >> op ;
for ( int i = 0 ; i<n ; i++ ) {
cin >> x >> y1 ;
point.push_back( make_pair ( x , y1 ) ) ;
}
// process
// find m
// find A,B1,B2,C,D,E
for ( int i = 0 ; i < n ; i++ ) {
A += (point[i].first)*(point[i].second) ;
B1 += point[i].first ;
B2 += point[i].second ;
C += pow( point[i].first , 2 ) ;
E += point[i].second ;
}
D = pow( B1 , 2 ) ;
m = ((n*A)-(B1*B2))/((n*C)-D) ;
//find b
// find F
F = m*B1 ;
b = (E-F)/n ;
// output
if ( op == "mb" ) {
cout << round(m*1e3)/1e3 << endl ;
cout << round(b*1e3)/1e3 << endl ;
} else if ( op == "func" ) {
cout << "y" << " =" ;
// if m,b == 0
if ( (m==0) && (b==0)) {
cout << " 0" << endl ;
} else {
// cout m
if ( m == 1 ) {
cout << " x " ;
} else if ( m == -1 ) {
cout << " -" << "x " ;
} else if ( m == 0 ) {
cout << " " ;
} else {
cout << " " << m << "x " ;
}
// cout b
if ( b > 0 ) {
cout << "+ " << b << endl ;
} else if ( b < 0 ) {
cout << "- " << (b*-1) << endl ;
}
}
}
} | # 1415, 2024-11-02 10:30:08, ----P--PP---PP---------- (20%)
#include <bits/stdc++.h>
using namespace std ;
int main () {
float m,b = 0 ;
float A,B1,B2,C,D,E,F = 0 ;
// input
float x,y1 = 0 ;
int n = 0 ;
string op ;
vector< pair <float,float> > point ;
cin >> n >> op ;
for ( int i = 0 ; i<n ; i++ ) {
cin >> x >> y1 ;
point.push_back( make_pair ( x , y1 ) ) ;
}
// process
// find m
// find A,B1,B2,C,D,E
for ( int i = 0 ; i < n ; i++ ) {
A += (point[i].first)*(point[i].second) ;
B1 += point[i].first ;
B2 += point[i].second ;
C += pow( point[i].first , 2 ) ;
E += point[i].second ;
}
D = pow( B1 , 2 ) ;
m = ((n*A)-(B1*B2))/((n*C)-D) ;
//find b
// find F
F = m*B1 ;
b = (E-F)/n ;
// output
if ( op == "mb" ) {
cout << round(m*1e3)/1e3 << endl ;
cout << round(b*1e3)/1e3 << endl ;
} else if ( op == "func" ) {
cout << "y =" ;
// if m,b == 0
if ( (m==0) && (b==0)) {
cout << " 0" << endl ;
} else {
// cout m
if ( m == 1 ) {
cout << " x " ;
} else if ( m == (-1) ) {
cout << " -x " ;
} else if ( m == 0 ) {
cout << " " ;
} else {
cout << " " << round(m*1e3)/1e3 << "x " ;
}
// cout b
if ( b > 0 ) {
cout << "+ " << round(b*1e3)/1e3 << endl ;
} else if ( b < 0 ) {
float j = -1 ;
cout << "- " << (round(b*1e3)/1e3*j) << endl ;
}
}
}
} | # 1416, 2024-11-02 12:07:18, ----P----P-P-P-P-------- (20%)
#include <bits/stdc++.h>
using namespace std ;
int main () {
float m,b = 0 ;
float A,B1,B2,C,D,E,F = 0 ;
float x,y1 = 0 ;
int n = 0 ;
string op ;
vector< pair <float,float> > point ;
// input
cin >> n >> op ;
for ( int i = 0 ; i<n ; i++ ) {
cin >> x >> y1 ;
point.push_back( make_pair ( x , y1 ) ) ;
}
// process
// find m
// find A,B1,B2,C,D,E
for ( int i = 0 ; i < n ; i++ ) {
A += (point[i].first)*(point[i].second) ;
B1 += point[i].first ;
B2 += point[i].second ;
C += pow(point[i].first , 2) ;
}
E = B2 ;
D = pow( B1 , 2 ) ;
m = ((n*A)-(B1*B2))/((n*C)-D) ;
//find b
// find F
F = m*B1 ;
b = (E-F)/n ;
// output
float M = round(m*1e3)/1e3 ;
float B = round(b*1e3)/1e3 ;
if (op == "mb" ) {
cout << M << endl ;
cout << B << endl ;
} else if ( op == "func" ) {
cout << "y =" ;
// if m,b == 0
if ( (M==0) && (B==0)) {
cout << " 0" << endl ;
} else {
// cout m
if ( M == 1 ) {
cout << " x " ;
} else if ( M == (-1) ) {
cout << " -x " ;
} else if ( M == 0 ) {
cout << " " ;
} else {
cout << " " << M << "x " ;
}
// cout b
if ( B > 0 ) {
cout << "+ " << B << endl ;
} else if ( B < 0 ) {
float j = -1 ;
cout << "- " << B*j << endl ;
}
}
}
} |
# 1417, 2024-11-02 10:05:36, ------------------------ (0%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
string code;
cin >> N >> code;
int n=N;
float xin,yin;
vector<pair<float,float>> xy;
//input,keep
while(N--){
cin >> xin >> yin;
xy.push_back(make_pair(xin,yin));
}
//calulate
//calM
float m=0,b=0;
float m1=0,m2=0,m3=0,m4=0;
//m1
for(int i=1;i<n;i++){
m1+=(xy[i].first)*(xy[i].second);
}
m1*=n;
//m2
for(int i=1;i<n;i++){
m2+=(xy[i].first);
}
//m3
for(int i=1;i<n;i++){
m3+=(xy[i].second);
}
//m4
for(int i=1;i<n;i++){
m4+=pow(xy[i].first,2);
}
m4*=n;
m=(m1-(m2*m3))/m4-(m2*m2);
//calB
float b1=0,b2=0;
//b1
for(int i=1;i<n;i++){
b1+=(xy[i].second);
}
//b2
for(int i=1;i<n;i++){
b2+=(xy[i].first);
}
b2*=m;
b=(b1-b2)/n;
//out
if(code=="mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}else if(code=="func"){
cout << "y = ";
if(m==0){
cout << round(b*1e3)/1e3;
}else if(b==0){
if(m==1){
cout << "x";
}else if(m==-1){
cout << "-x";
}else{
cout << round(m*1e3)/1e3 << "x";
}
}else{
if(b<0){
cout << round(m*1e3)/1e3 << "x" << " - " << (to_string(round(b*1e3)/1e3)).substr(1);
}else if(n>0){
cout << round(m*1e3)/1e3 << "x" << " + " << round(b*1e3)/1e3;
}
}
}
} | # 1418, 2024-11-02 10:17:18, -----P---------P-------- (8%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
string code;
cin >> N >> code;
int n=N;
float xin,yin;
vector<pair<float,float>> xy;
//input,keep
while(N--){
cin >> xin >> yin;
xy.push_back(make_pair(xin,yin));
}
//calulate
//calM
float m=0,b=0;
float m1=0,m2=0,m3=0,m4=0;
for(int i=1;i<n;i++){
m+=((n*(xy[i].first)*(xy[i].second))-((xy[i].first)*(xy[i].second)))/(n*pow(xy[i].first,2)-(xy[i].first*xy[i].first));
}
//calB
float b1=0,b2=0;
//b1
for(int i=1;i<n;i++){
b+=((xy[i].second)-(m*(xy[i].first)))/n;
}
//out
if(code=="mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}else if(code=="func"){
cout << "y = ";
if(m==0){
cout << round(b*1e3)/1e3;
}else if(b==0){
if(m==1){
cout << "x";
}else if(m==-1){
cout << "-x";
}else{
cout << round(m*1e3)/1e3 << "x";
}
}else{
if(b<0){
cout << round(m*1e3)/1e3 << "x" << " - " << (to_string(round(b*1e3)/1e3)).substr(1);
}else if(n>0){
cout << round(m*1e3)/1e3 << "x" << " + " << round(b*1e3)/1e3;
}
}
}
} | # 1419, 2024-11-02 11:49:45, ------------------------ (0%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
string code;
cin >> N >> code;
int n=N;
float xin,yin;
vector<pair<float,float>> xy;
//input,keep
while(N--){
cin >> xin >> yin;
xy.push_back(make_pair(xin,yin));
}
//calulate
//calM
float m=0,b=0;
float m1=0,m2=0,m3=0,m4=0;
//m1
for(int i=1;i<=n;i++){
m1+=(xy[i].first)*(xy[i].second);
}
m1*=n;
//m2
for(int i=1;i<=n;i++){
m2+=(xy[i].first);
}
//m3
for(int i=1;i<=n;i++){
m3+=(xy[i].second);
}
//m4
for(int i=1;i<=n;i++){
m4+=xy[i].first*xy[i].first;
}
m4*=n;
m+=(m1-(m2*m3))/m4-(m2*m2);
//calB
float b1=0,b2=0;
//b1
for(int i=1;i<=n;i++){
b1+=(xy[i].second);
}
//b2
for(int i=1;i<=n;i++){
b2+=(xy[i].first);
}
b2*=m;
b+=(b1-b2)/n;
//out
if(code=="mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}else if(code=="func"){
cout << "y = ";
if(m==0){
cout << round(b*1e3)/1e3;
}else if(b==0){
if(m==1){
cout << "x";
}else if(m==-1){
cout << "-x";
}else{
cout << round(m*1e3)/1e3 << "x";
}
}else{
if(b<0){
cout << round(m*1e3)/1e3 << "x" << " - " << (to_string(round(b*1e3)/1e3)).substr(1);
}else if(n>0){
cout << round(m*1e3)/1e3 << "x" << " + " << round(b*1e3)/1e3;
}
}
}
} | # 1420, 2024-11-02 11:49:58, -----P---------P-------- (8%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
string code;
cin >> N >> code;
int n=N;
float xin,yin;
vector<pair<float,float>> xy;
//input,keep
while(N--){
cin >> xin >> yin;
xy.push_back(make_pair(xin,yin));
}
//calulate
//calM
float m=0,b=0;
float m1=0,m2=0,m3=0,m4=0;
for(int i=1;i<n;i++){
m+=((n*(xy[i].first)*(xy[i].second))-((xy[i].first)*(xy[i].second)))/(n*pow(xy[i].first,2)-(xy[i].first*xy[i].first));
}
//calB
float b1=0,b2=0;
//b1
for(int i=1;i<n;i++){
b+=((xy[i].second)-(m*(xy[i].first)))/n;
}
//out
if(code=="mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}else if(code=="func"){
cout << "y = ";
if(m==0){
cout << round(b*1e3)/1e3;
}else if(b==0){
if(m==1){
cout << "x";
}else if(m==-1){
cout << "-x";
}else{
cout << round(m*1e3)/1e3 << "x";
}
}else{
if(b<0){
cout << round(m*1e3)/1e3 << "x" << " - " << (to_string(round(b*1e3)/1e3)).substr(1);
}else if(n>0){
cout << round(m*1e3)/1e3 << "x" << " + " << round(b*1e3)/1e3;
}
}
}
} | # 1421, 2024-11-02 11:52:54, ------------------------ (0%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
string code;
cin >> N >> code;
int n=N;
float xin,yin;
vector<pair<float,float>> xy;
//input,keep
while(N--){
cin >> xin >> yin;
xy.push_back(make_pair(0,0));
xy.push_back(make_pair(xin,yin));
}
//calulate
//calM
float m=0,b=0;
float m1=0,m2=0,m3=0,m4=0;
//m1
for(int i=1;i<=n;i++){
m1+=(xy[i].first)*(xy[i].second);
}
m1*=n;
//m2
for(int i=1;i<=n;i++){
m2+=(xy[i].first);
}
//m3
for(int i=1;i<=n;i++){
m3+=(xy[i].second);
}
//m4
for(int i=1;i<=n;i++){
m4+=xy[i].first*xy[i].first;
}
m4*=n;
m+=(m1-(m2*m3))/m4-(m2*m2);
//calB
float b1=0,b2=0;
//b1
for(int i=1;i<=n;i++){
b1+=(xy[i].second);
}
//b2
for(int i=1;i<=n;i++){
b2+=(xy[i].first);
}
b2*=m;
b+=(b1-b2)/n;
//out
if(code=="mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}else if(code=="func"){
cout << "y = ";
if(m==0){
cout << round(b*1e3)/1e3;
}else if(b==0){
if(m==1){
cout << "x";
}else if(m==-1){
cout << "-x";
}else{
cout << round(m*1e3)/1e3 << "x";
}
}else{
if(b<0){
cout << round(m*1e3)/1e3 << "x" << " - " << (to_string(round(b*1e3)/1e3)).substr(1);
}else if(n>0){
cout << round(m*1e3)/1e3 << "x" << " + " << round(b*1e3)/1e3;
}
}
}
} | # 1422, 2024-11-02 11:55:54, -----PPP-------P--PP---- (25%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
string code;
cin >> N >> code;
int n=N;
float xin,yin;
vector<pair<float,float>> xy;
//input,keep
while(N--){
cin >> xin >> yin;
xy.push_back(make_pair(0,0));
xy.push_back(make_pair(xin,yin));
}
//calulate
//calM
float m=0,b=0;
float m1=0,m2=0,m3=0,m4=0;
//m1
for(int i=1;i<=n;i++){
m1+=(xy[i].first)*(xy[i].second);
}
m1*=n;
//m2
for(int i=1;i<=n;i++){
m2+=(xy[i].first);
}
//m3
for(int i=1;i<=n;i++){
m3+=(xy[i].second);
}
//m4
for(int i=1;i<=n;i++){
m4+=xy[i].first*xy[i].first;
}
m4*=n;
m+=(m1-(m2*m3))/(m4-(m2*m2));
//calB
float b1=0,b2=0;
//b1
for(int i=1;i<=n;i++){
b1+=(xy[i].second);
}
//b2
for(int i=1;i<=n;i++){
b2+=(xy[i].first);
}
b2*=m;
b+=(b1-b2)/n;
//out
if(code=="mb"){
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3;
}else if(code=="func"){
cout << "y = ";
if(m==0){
cout << round(b*1e3)/1e3;
}else if(b==0){
if(m==1){
cout << "x";
}else if(m==-1){
cout << "-x";
}else{
cout << round(m*1e3)/1e3 << "x";
}
}else{
if(b<0){
cout << round(m*1e3)/1e3 << "x" << " - " << (to_string(round(b*1e3)/1e3)).substr(1);
}else if(n>0){
cout << round(m*1e3)/1e3 << "x" << " + " << round(b*1e3)/1e3;
}
}
}
} |
# 1423, 2024-11-02 14:59:10, -----PPPPP-------------- (20%)
#include<iostream>
#include<stack>
#include<set>
#include<map>
#include<climits>
#include<cmath>
using namespace std;
size_t n;
string m;
pair<float,float> num[1000005];
float M_koon(size_t A,size_t B){
float sum = 0;
for(size_t i=A;i<=B;i++){
sum += num[i].first * num[i].second;
}
return sum;
}
float M_yok(size_t a,size_t b){
float sum = 0;
for(size_t i=a;i<=b;i++){
sum += num[i].first * num[i].first;
}
return sum;
}
float M_plus_x(size_t a,size_t b){
float sum = 0;
for(size_t i=a;i<=b;i++){
sum += num[i].first;
}
return sum;
}
float M_plus_y(size_t a,size_t b){
float sum = 0;
for(size_t i=a;i<=b;i++){
sum += num[i].second;
}
return sum;
}
int main(){
cin>>n>>m;
for(size_t i=1;i<=n;i++){
float x,y;
cin>>x>>y;
num[i].first = x;
num[i].second = y;
}
if(m == "mb"){
float M = round(((float(n) * M_koon(1,n)) - ((M_plus_x(1,n)) * (M_plus_y(1,n))))/(float(n) * M_yok(1,n) - (M_plus_x(1,n) * M_plus_x(1,n))) * 1e3) / 1e3;
cout<<M<<'\n';
// cout<<b(0,n);
cout<<round(( (M_plus_y(1,n) - (M * M_plus_x(1,n))) / n ) * 1e3) / 1e3;
}
else if(m == "func"){
}
} | # 1424, 2024-11-02 15:07:00, -----PPPPP-------------- (20%)
#include<iostream>
#include<stack>
#include<set>
#include<map>
#include<climits>
#include<cmath>
using namespace std;
size_t n;
string m;
pair<float,float> num[1000005];
float M_koon(size_t A,size_t B){
float sum = 0;
for(size_t i=A;i<=B;i++){
sum += num[i].first * num[i].second;
}
return sum;
}
float M_yok(size_t a,size_t b){
float sum = 0;
for(size_t i=a;i<=b;i++){
sum += num[i].first * num[i].first;
}
return sum;
}
float M_plus_x(size_t a,size_t b){
float sum = 0;
for(size_t i=a;i<=b;i++){
sum += num[i].first;
}
return sum;
}
float M_plus_y(size_t a,size_t b){
float sum = 0;
for(size_t i=a;i<=b;i++){
sum += num[i].second;
}
return sum;
}
float loop_y(size_t a,size_t b){
}
int main(){
cin>>n>>m;
for(size_t i=1;i<=n;i++){
float x,y;
cin>>x>>y;
num[i].first = x;
num[i].second = y;
}
if(m == "mb"){
float M = round(((float(n) * M_koon(1,n)) - ((M_plus_x(1,n)) * (M_plus_y(1,n))))/(float(n) * M_yok(1,n) - (M_plus_x(1,n) * M_plus_x(1,n))) * 1e3) / 1e3;
cout<<M<<'\n';
// cout<<b(0,n);
cout<<round(( (M_plus_y(1,n) - (M * M_plus_x(1,n))) / n ) * 1e3) / 1e3;
}
else if(m == "func"){
// float M = round(((float(n) * M_koon(1,n)) - ((M_plus_x(1,n)) * (M_plus_y(1,n))))/(float(n) * M_yok(1,n) - (M_plus_x(1,n) * M_plus_x(1,n))) * 1e3) / 1e3;
// float
// if(M == double(1)){
// cout<<"y = ";
// }
// else if(M == double(-1)){
// cout<<"y = ";
// }
cout<<"Y = 0";
}
} | # 1425, 2024-11-02 15:07:22, -----PPPPP-----P-------- (25%)
#include<iostream>
#include<stack>
#include<set>
#include<map>
#include<climits>
#include<cmath>
using namespace std;
size_t n;
string m;
pair<float,float> num[1000005];
float M_koon(size_t A,size_t B){
float sum = 0;
for(size_t i=A;i<=B;i++){
sum += num[i].first * num[i].second;
}
return sum;
}
float M_yok(size_t a,size_t b){
float sum = 0;
for(size_t i=a;i<=b;i++){
sum += num[i].first * num[i].first;
}
return sum;
}
float M_plus_x(size_t a,size_t b){
float sum = 0;
for(size_t i=a;i<=b;i++){
sum += num[i].first;
}
return sum;
}
float M_plus_y(size_t a,size_t b){
float sum = 0;
for(size_t i=a;i<=b;i++){
sum += num[i].second;
}
return sum;
}
float loop_y(size_t a,size_t b){
}
int main(){
cin>>n>>m;
for(size_t i=1;i<=n;i++){
float x,y;
cin>>x>>y;
num[i].first = x;
num[i].second = y;
}
if(m == "mb"){
float M = round(((float(n) * M_koon(1,n)) - ((M_plus_x(1,n)) * (M_plus_y(1,n))))/(float(n) * M_yok(1,n) - (M_plus_x(1,n) * M_plus_x(1,n))) * 1e3) / 1e3;
cout<<M<<'\n';
// cout<<b(0,n);
cout<<round(( (M_plus_y(1,n) - (M * M_plus_x(1,n))) / n ) * 1e3) / 1e3;
}
else if(m == "func"){
// float M = round(((float(n) * M_koon(1,n)) - ((M_plus_x(1,n)) * (M_plus_y(1,n))))/(float(n) * M_yok(1,n) - (M_plus_x(1,n) * M_plus_x(1,n))) * 1e3) / 1e3;
// float
// if(M == double(1)){
// cout<<"y = ";
// }
// else if(M == double(-1)){
// cout<<"y = ";
// }
cout<<"y = 0";
}
} |
# 1426, 2024-11-02 14:29:20, --------PP-------------- (8%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;string command;
double x,y;
cin >> N >> command;
float m=0,b=0;
float m1=0,m2=0,m3=0,m4=0;
for(int i = 0; i < N; i++){
cin >> x >> y;
m1 += x*y;
m2 += x;
m3 += y;
m4 += pow(x,2);
}
m = ((N*m1) - (m2*m3))/((3*m4) - pow(m2,2));
b = (m3 - (m*m2))/N;
if(command == "mb"){
cout << m << "\n" << b;
}
if(command == "func");
} | # 1427, 2024-11-02 14:36:17, --------PP-----PP----P-- (20%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;string command;
double x,y;
cin >> N >> command;
float m=0,b=0;
float m1=0,m2=0,m3=0,m4=0;
for(int i = 0; i < N; i++){
cin >> x >> y;
m1 += x*y;
m2 += x;
m3 += y;
m4 += pow(x,2);
}
m = ((N*m1) - (m2*m3))/((3*m4) - pow(m2,2));
b = (m3 - (m*m2))/N;
y = m*x+b;
if(command == "mb"){
cout << round(m*1e3)/1e3 << "\n" << round(b*1e3)/1e3;
}
if(command == "func"){
cout << "y" << " = " << y;
}
} | # 1428, 2024-11-02 14:38:36, --------PP-----PP----P-- (20%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;string command;
double x,y;
cin >> N >> command;
float m=0,b=0;
float m1=0,m2=0,m3=0,m4=0;
for(int i = 0; i < N; i++){
cin >> x >> y;
m1 += x*y;
m2 += x;
m3 += y;
m4 += pow(x,2);
}
m = ((N*m1) - (m2*m3))/((3*m4) - pow(m2,2));
b = (m3 - (m*m2))/N;
y = m*x+b;
if(command == "mb"){
cout << round(m*1e3)/1e3 << "\n" << round(b*1e3)/1e3;
}
if(command == "func"){
cout << "y" << " = " << y;
if(m == 1){
cout << "y" << " = " << x;
}
if(m == -1){
cout << "y" << " = " <<"-"<< x;
}
}
} | # 1429, 2024-11-02 14:56:30, --------PP-----PP----P-- (20%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;string command;
double x,y;
cin >> N >> command;
float m=0,b=0;
float m1=0,m2=0,m3=0,m4=0;
for(int i = 0; i < N; i++){
cin >> x >> y;
m1 += x*y;
m2 += x;
m3 += y;
m4 += pow(x,2);
}
m = ((N*m1) - (m2*m3))/((3*m4) - pow(m2,2));
b = (m3 - (m*m2))/N;
y = m*x+b;
if(command == "mb"){
cout << round(m*1e3)/1e3 << "\n" << round(b*1e3)/1e3;
}
if(command == "func"){
if(m == 1){
cout << "y" << " = " << "x";
}
if(m == -1){
cout << "y" << " = " <<"-x";
}
else cout << "y" << " = " << y;
}
} | # 1430, 2024-11-02 15:13:03, --------PP-----------P-- (12%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;string command;
double x,y;
cin >> N >> command;
float m=0,b=0;
float m1=0,m2=0,m3=0,m4=0;
for(int i = 0; i < N; i++){
cin >> x >> y;
m1 += x*y;
m2 += x;
m3 += y;
m4 += pow(x,2);
}
m = ((N*m1) - (m2*m3))/((3*m4) - pow(m2,2));
b = (m3 - (m*m2))/N;
y = m*x + b;
if(command == "mb"){
cout << round(m*1e3)/1e3 << "\n" << round(b*1e3)/1e3;
}
if(command == "func"){
if(m == 1 && b==0){
cout << "y" << " = " << "x";
}
if(m == -1 && b==0){
cout << "y" << " = " <<"-x";
}
if(y==0) cout << "y" << " = " << y;
if(y != 0 && (m*x)!=0)cout << "y" << " = " << "x" << " + " << b;
else cout << "y" << " = " << y;
}
} | # 1431, 2024-11-02 15:14:08, --------PP-----PP----P-- (20%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;string command;
double x,y;
cin >> N >> command;
float m=0,b=0;
float m1=0,m2=0,m3=0,m4=0;
for(int i = 0; i < N; i++){
cin >> x >> y;
m1 += x*y;
m2 += x;
m3 += y;
m4 += pow(x,2);
}
m = ((N*m1) - (m2*m3))/((3*m4) - pow(m2,2));
b = (m3 - (m*m2))/N;
y = m*x+b;
if(command == "mb"){
cout << round(m*1e3)/1e3 << "\n" << round(b*1e3)/1e3;
}
if(command == "func"){
if(m == 1){
cout << "y" << " = " << "x";
}
if(m == -1){
cout << "y" << " = " <<"-x";
}
else cout << "y" << " = " << y;
}
} | # 1432, 2024-11-02 15:17:33, --------PP-------------- (8%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;string command;
double x,y;
cin >> N >> command;
float m=0,b=0;
float m1=0,m2=0,m3=0,m4=0;
for(int i = 0; i < N; i++){
cin >> x >> y;
m1 += x*y;
m2 += x;
m3 += y;
m4 += pow(x,2);
}
m = ((N*m1) - (m2*m3))/((3*m4) - pow(m2,2));
b = (m3 - (m*m2))/N;
y = m*x + b;
if(command == "mb"){
cout << round(m*1e3)/1e3 << "\n" << round(b*1e3)/1e3;
}
if(command == "func"){
if(m == 1 && b==0){
cout << "y" << " = " << "x";
}
if(m == -1 && b==0){
cout << "y" << " = " <<"-x";
}
if(y==0) cout << "y" << " = " << y;
if(y != 0 && (m*x)!=0)cout << "y" << " = " << "x" << " + " << b;
else cout << "y" << " = " << "x" << " + " << b;
}
} | # 1433, 2024-11-02 15:17:55, --------PP-----PP----P-- (20%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int N;string command;
double x,y;
cin >> N >> command;
float m=0,b=0;
float m1=0,m2=0,m3=0,m4=0;
for(int i = 0; i < N; i++){
cin >> x >> y;
m1 += x*y;
m2 += x;
m3 += y;
m4 += pow(x,2);
}
m = ((N*m1) - (m2*m3))/((3*m4) - pow(m2,2));
b = (m3 - (m*m2))/N;
y = m*x+b;
if(command == "mb"){
cout << round(m*1e3)/1e3 << "\n" << round(b*1e3)/1e3;
}
if(command == "func"){
if(m == 1){
cout << "y" << " = " << "x";
}
if(m == -1){
cout << "y" << " = " <<"-x";
}
else cout << "y" << " = " << y;
}
} |
# 1434, 2024-11-02 13:58:42, ------PP---------------- (8%)
#include<bits/stdc++.h>
using namespace std;
int main(){
float n = 0;
string type;
cin >> n >> type;
float x,y;
float xi,yi;
float m=0, b=0;
float sum1,sum2,sum3,sum4 = 0;
vector<map<float,float>> v;
map<float,float> point;
for(int i=0; i<n; i++){
cin >> x >> y;
point[x] = y;
v.push_back(point);
}
for(auto x:v){
for(auto pair:x){
xi = pair.first;
yi = pair.second;
}
sum1 += xi*yi;
sum2 += xi;
sum3 += yi;
sum4 += xi*xi;
}
m = ((3*sum1)-(sum2*sum3))/((3*sum4)-(sum2*sum2));
b = (sum3-(m*sum2))/3;
if(type == "mb"){
cout << m << endl << b;
}
// else if(type == "func"){
// cout << "y = " << "x";
// }
} | # 1435, 2024-11-02 14:01:07, ------PP---------------- (8%)
#include<bits/stdc++.h>
using namespace std;
int main(){
float n = 0;
string type;
cin >> n >> type;
float x,y;
float xi,yi;
float m=0, b=0;
float sum1,sum2,sum3,sum4 = 0;
vector<map<float,float>> v;
map<float,float> point;
for(int i=0; i<n; i++){
cin >> x >> y;
point[x] = y;
v.push_back(point);
}
for(auto x:v){
for(auto pair:x){
xi = pair.first;
yi = pair.second;
}
sum1 += xi*yi;
sum2 += xi;
sum3 += yi;
sum4 += xi*xi;
}
m = ((3*sum1)-(sum2*sum3))/((3*sum4)-(sum2*sum2));
b = (sum3-(m*sum2))/3;
float mround = round(m*1e3)/1e3;
float bround = round(b*1e3)/1e3;
if(type == "mb"){
cout << mround << endl << bround;
}
// else if(type == "func"){
// cout << "y = " << "x";
// }
} | # 1436, 2024-11-02 14:18:41, ------------------------ (0%)
#include<bits/stdc++.h>
using namespace std;
int main(){
float n = 0;
string type;
cin >> n >> type;
float x,y;
float xi,yi;
float m=0, b=0;
float sum1,sum2,sum3,sum4 = 0;
vector<map<float,float>> v;
map<float,float> point;
for(int i=0; i<n; i++){
cin >> x >> y;
point[x] = y;
v.push_back(point);
}
for(auto x:v){
for(auto pair:x){
xi = pair.first;
yi = pair.second;
}
sum1 += xi*yi;
sum2 += xi;
sum3 += yi;
sum4 += xi*xi;
}
m = ((3*sum1)-(sum2*sum3))/((3*sum4)-(sum2*sum2));
b = (sum3-(m*sum2))/3;
cout << b << endl;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
cout << b << endl;
if(type == "mb"){
cout << m << endl << b;
}
else if(type == "func"){
if(m == 1){
cout << "y = " << "x" << " + " << b;
} else if(m -1){
cout << "y = " << "-x" << " + " << b;
} else {
cout << "y = " << m << "x" << " + " << b;
}
}
} | # 1437, 2024-11-02 14:19:24, ------PP---------------- (8%)
#include<bits/stdc++.h>
using namespace std;
int main(){
float n = 0;
string type;
cin >> n >> type;
float x,y;
float xi,yi;
float m=0, b=0;
float sum1,sum2,sum3,sum4 = 0;
vector<map<float,float>> v;
map<float,float> point;
for(int i=0; i<n; i++){
cin >> x >> y;
point[x] = y;
v.push_back(point);
}
for(auto x:v){
for(auto pair:x){
xi = pair.first;
yi = pair.second;
}
sum1 += xi*yi;
sum2 += xi;
sum3 += yi;
sum4 += xi*xi;
}
m = ((3*sum1)-(sum2*sum3))/((3*sum4)-(sum2*sum2));
b = (sum3-(m*sum2))/3;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(type == "mb"){
cout << m << endl << b;
}
else if(type == "func"){
if(m == 1){
cout << "y = " << "x" << " + " << b;
} else if(m -1){
cout << "y = " << "-x" << " + " << b;
} else {
cout << "y = " << m << "x" << " + " << b;
}
}
} | # 1438, 2024-11-02 14:23:17, ------------------------ (0%)
#include<bits/stdc++.h>
using namespace std;
int main(){
float n = 0;
string type;
cin >> n >> type;
float x,y;
float xi,yi;
float m=0, b=0;
float sum1,sum2,sum3,sum4 = 0;
vector<map<float,float>> v;
map<float,float> point;
for(int i=0; i<n; i++){
cin >> x >> y;
point[x] = y;
v.push_back(point);
}
for(auto x:v){
for(auto pair:x){
xi = pair.first;
yi = pair.second;
}
sum1 += xi*yi;
sum2 += xi;
sum3 += yi;
sum4 += xi*xi;
}
m = ((3*sum1)-(sum2*sum3))/((3*sum4)-(sum2*sum2));
b = (sum3-(m*sum2))/3;
cout << b << endl;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
cout << b << endl;
if(type == "mb"){
cout << m << endl << b;
}
else if(type == "func"){
if(m == 0 && b == 0){
cout << "y = 0";
} else if(m == 0){
cout << "y = " << b;
} else if(b == 0){
cout << "y = " << m << "x";
} else if(m == 1){
cout << "y = " << "x" << " + " << b;
} else if(m == -1){
cout << "y = " << "-x" << " + " << b;
} else {
cout << "y = " << m << "x" << " + " << b;
}
}
} | # 1439, 2024-11-02 14:24:54, ------PP-------P-------- (12%)
#include<bits/stdc++.h>
using namespace std;
int main(){
float n = 0;
string type;
cin >> n >> type;
float x,y;
float xi,yi;
float m=0, b=0;
float sum1,sum2,sum3,sum4 = 0;
vector<map<float,float>> v;
map<float,float> point;
for(int i=0; i<n; i++){
cin >> x >> y;
point[x] = y;
v.push_back(point);
}
for(auto x:v){
for(auto pair:x){
xi = pair.first;
yi = pair.second;
}
sum1 += xi*yi;
sum2 += xi;
sum3 += yi;
sum4 += xi*xi;
}
m = ((3*sum1)-(sum2*sum3))/((3*sum4)-(sum2*sum2));
b = (sum3-(m*sum2))/3;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(type == "mb"){
cout << m << endl << b;
}
else if(type == "func"){
if(m == 0.000 && b == 0.000){
cout << "y = 0";
} else if(m == 0.000){
cout << "y = " << b;
} else if(b == 0.000){
cout << "y = " << m << "x";
} else if(m == 1.000){
cout << "y = " << "x" << " + " << b;
} else if(m == -1.000){
cout << "y = " << "-x" << " + " << b;
} else {
cout << "y = " << m << "x" << " + " << b;
}
}
} | # 1440, 2024-11-02 14:30:13, ------PP-------P--P----- (16%)
#include<bits/stdc++.h>
using namespace std;
int main(){
float n = 0;
string type;
cin >> n >> type;
float x,y;
float xi,yi;
float m=0, b=0;
float sum1,sum2,sum3,sum4 = 0;
vector<map<float,float>> v;
map<float,float> point;
for(int i=0; i<n; i++){
cin >> x >> y;
point[x] = y;
v.push_back(point);
}
for(auto x:v){
for(auto pair:x){
xi = pair.first;
yi = pair.second;
}
sum1 += xi*yi;
sum2 += xi;
sum3 += yi;
sum4 += xi*xi;
}
m = ((3*sum1)-(sum2*sum3))/((3*sum4)-(sum2*sum2));
b = (sum3-(m*sum2))/3;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(type == "mb"){
cout << m << endl << b;
}
else if(type == "func"){
if(m == 0.000 && b == 0.000){
cout << "y = 0";
} else if(m == 1.000 && b == 0.000){
cout << "y = x";
}
else if(m == 0.000){
cout << "y = " << b;
} else if(b == 0.000){
cout << "y = " << m << "x";
} else if(m == 1.000){
cout << "y = x + " << b;
} else if(m == -1.000){
cout << "y = -x + " << b;
} else {
cout << "y = " << m << "x + " << b;
}
}
} | # 1441, 2024-11-02 14:37:46, ------PP-------P--P----- (16%)
#include<bits/stdc++.h>
using namespace std;
int main(){
float n = 0;
string type;
cin >> n >> type;
float x,y;
float xi,yi;
float m=0, b=0;
float sum1,sum2,sum3,sum4 = 0;
vector<map<float,float>> v;
map<float,float> point;
for(int i=0; i<n; i++){
cin >> x >> y;
point[x] = y;
v.push_back(point);
}
for(auto x:v){
for(auto pair:x){
xi = pair.first;
yi = pair.second;
}
sum1 += xi*yi;
sum2 += xi;
sum3 += yi;
sum4 += xi*xi;
}
m = ((3*sum1)-(sum2*sum3))/((3*sum4)-(sum2*sum2));
b = (sum3-(m*sum2))/3;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(type == "mb"){
cout << m << endl << b;
}
else if(type == "func"){
if(m == 0.000 && b == 0.000){
cout << "y = 0";
} else if(m == 1.000 && b == 0.000){
cout << "y = x";
} else if(m == 0.000){
cout << "y = " << b;
} else if(b == 0.000){
cout << "y = " << m << "x";
} else if(m == 1.000){
cout << "y = x + " << b;
} else if(m == -1.000){
cout << "y = -x + " << b;
} else if(m == -1.000 && b < 0){
cout << "y = -x - " << b;
} else if(b < 0){
cout << "y = " << m << "x - " << -b;
} else if(b > 0){
cout << "y = " << m << "x + " << b;
}
}
} | # 1442, 2024-11-02 14:50:53, ------PP-------P--P----- (16%)
#include<bits/stdc++.h>
using namespace std;
int main(){
float n = 0;
string type;
cin >> n >> type;
float x,y;
float xi,yi;
float m=0, b=0;
float sum1,sum2,sum3,sum4 = 0;
vector<map<float,float>> v;
map<float,float> point;
for(int i=0; i<n; i++){
cin >> x >> y;
point[x] = y;
v.push_back(point);
}
for(auto x:v){
for(auto pair:x){
xi = pair.first;
yi = pair.second;
}
sum1 += xi*yi;
sum2 += xi;
sum3 += yi;
sum4 += xi*xi;
}
m = ((3*sum1)-(sum2*sum3))/((3*sum4)-(sum2*sum2));
b = (sum3-(m*sum2))/3;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(type == "mb"){
cout << m << endl << b;
}
else if(type == "func"){
if(m == 0.000 && b == 0.000){
cout << "y = 0";
} else if(m == 1.000 && b == 0.000){
cout << "y = x";
} else if(m == 0.000){
cout << "y = " << b;
} else if(b == 0.000){
cout << "y = " << m << "x";
} else if(m == 1.000){
cout << "y = x + " << b;
} else if(m == -1.000){
cout << "y = -x + " << b;
} else if(m == -1.000 && b < 0){
cout << "y = -x - " << b;
} else if(b < 0){
cout << "y = " << m << "x - " << -b;
} else if(b > 0){
cout << "y = " << m << "x + " << b;
}
}
} | # 1443, 2024-11-02 15:07:47, ------PP-------P--P----- (16%)
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
float n = 0;
string type;
cin >> n >> type;
float x,y;
float xi,yi;
float m=0, b=0;
float sum1,sum2,sum3,sum4 = 0;
vector<map<float,float>> v;
map<float,float> point;
for(int i=0; i<n; i++){
cin >> x >> y;
point[x] = y;
v.push_back(point);
}
for(auto x:v){
for(auto pair:x){
xi = pair.first;
yi = pair.second;
}
sum1 += xi*yi;
sum2 += xi;
sum3 += yi;
sum4 += xi*xi;
}
m = ((3.0000*sum1)-(sum2*sum3))/((3.0000*sum4)-(sum2*sum2));
b = (sum3-(m*sum2))/3.0000;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(type == "mb"){
cout << m << endl << b;
}
if(type == "func"){
if(m == 0.000 && b == 0.000){
cout << "y = 0";
} else if(m == 1.000 && b == 0.000){
cout << "y = x";
} else if(m == 0.000){
cout << "y = " << b;
} else if(b == 0.000){
cout << "y = " << m << "x";
} else if(m == 1.000){
cout << "y = x + " << b;
} else if(m == -1.000){
cout << "y = -x + " << b;
} else if(m == -1.000 && b < 0){
cout << "y = -x - " << b;
} else if(b < 0){
cout << "y = " << m << "x - " << -b;
} else if(b > 0){
cout << "y = " << m << "x + " << b;
}
}
} | # 1444, 2024-11-02 15:15:10, ------PP-------P--P----- (16%)
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
float n;
string type;
cin >> n >> type;
float x,y;
float xi,yi;
float m=0.0000, b=0.0000;
float sum1,sum2,sum3,sum4 = 0.0000;
vector<map<float,float>> v;
map<float,float> point;
for(int i=0; i<n; i++){
cin >> x >> y;
point[x] = y;
v.push_back(point);
}
for(auto x:v){
for(auto pair:x){
xi = pair.first;
yi = pair.second;
}
sum1 += xi*yi;
sum2 += xi;
sum3 += yi;
sum4 += xi*xi;
}
m = ((3.0000*sum1)-(sum2*sum3))/((3.0000*sum4)-pow(sum2,2));
b = (sum3-(m*sum2))/3.0000;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(type == "mb"){
cout << m << endl << b;
}
if(type == "func"){
if(m == 0.000 && b == 0.000){
cout << "y = 0";
} else if(m == 1.000 && b == 0.000){
cout << "y = x";
} else if(m == 0.000){
cout << "y = " << b;
} else if(b == 0.000){
cout << "y = " << m << "x";
} else if(m == 1.000){
cout << "y = x + " << b;
} else if(m == -1.000){
cout << "y = -x + " << b;
} else if(m == -1.000 && b < 0){
cout << "y = -x - " << b;
} else if(b < 0){
cout << "y = " << m << "x - " << -b;
} else {
cout << "y = " << m << "x + " << b;
}
}
} | # 1445, 2024-11-02 15:18:43, ------PP-------P--P----- (16%)
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
float n;
string type = "";
cin >> n >> type;
float x,y;
float xi,yi;
float m=0.0000, b=0.0000;
float sum1,sum2,sum3,sum4 = 0.0000;
vector<map<float,float>> v;
map<float,float> point;
for(int i=0; i<n; i++){
cin >> x >> y;
point[x] = y;
v.push_back(point);
}
for(auto x:v){
for(auto pair:x){
xi = pair.first;
yi = pair.second;
}
sum1 += xi*yi;
sum2 += xi;
sum3 += yi;
sum4 += xi*xi;
}
m = ((3.0000*sum1)-(sum2*sum3))/((3.0000*sum4)-pow(sum2,2));
b = (sum3-(m*sum2))/3.0000;
m = round(m*1e3)/1e3;
b = round(b*1e3)/1e3;
if(type == "mb"){
cout << m << endl << b;
}
if(type == "func"){
if(m == 0.000 && b == 0.000){
cout << "y = 0";
} else if(m == 1.000 && b == 0.000){
cout << "y = x";
} else if(m == 0.000){
cout << "y = " << b;
} else if(b == 0.000){
cout << "y = " << m << "x";
} else if(m == 1.000){
cout << "y = x + " << b;
} else if(m == -1.000){
cout << "y = -x + " << b;
} else if(m == -1.000 && b < 0){
cout << "y = -x - " << b;
} else if(b < 0){
cout << "y = " << m << "x - " << -b;
} else {
cout << "y = " << m << "x + " << b;
}
}
} |
# 1446, 2024-11-02 10:24:24, -----PPP-------P-------- (16%)
#include<bits/stdc++.h>
using namespace std ;
float sum_x(vector<pair<float,float>> &v ,float n){
float res = 0 ;
for(int i = 1 ; i<=n ; i++){
res += v[i].first ;
}
return res ;
}
float sum_y(vector<pair<float,float>> &v ,float n){
float res = 0 ;
for(int i = 1 ; i<=n ; i++){
res += v[i].second ;
}
return res ;
}
float mul_sum(vector<pair<float,float>> &v , float n){
float res = 0 ;
for(int i = 1 ; i<=n ; i++){
res += v[i].first * v[i].second ;
}
return res ;
}
float sqrt_sum(vector<pair<float,float>> &v , int n){
float res = 0 ;
for(int i = 1 ; i<=n ; i++){
res += v[i].first * v[i].first ;
}
return res ;
}
float find_m(vector<pair<float,float>> &v, float n){
float m = (n*(mul_sum(v,n)) - sum_x(v,n)*sum_y(v,n)) / (n*(sqrt_sum(v,n)) - sum_x(v,n)*sum_x(v,n)) ;
return m ;
}
float find_b(vector<pair<float,float>> &v , float n){
float b = (sum_y(v,n) - find_m(v,n) * sum_x(v,n)) / n ;
return b ;
}
int main(){
float n ;
string mode ;
cin>>n>>mode ;
int time = n ;
float x,y ;
vector<pair<float,float>> store_xy ;
while(time--){
cin>>x>>y ;
store_xy.push_back(make_pair(x,y)) ;
}
float m = find_m(store_xy,n) ;
float b = find_b(store_xy,n) ;
m = round(m*1e3) / 1e3 ;
b = round(b*1e3) / 1e3 ;
if(mode == "mb"){
cout<<m<<endl ;
cout<<b<<endl ;
return 0 ;
}
else if(mode == "func"){
if(m == 0){
cout<<"y = "<<b<<endl ;
}
else{
if(abs(m) == 1){
if(m>0){
if(b>0){
cout<<"y = "<<m<<"x + "<<b ;
}
if(b==0){
cout<<"y = "<<m<<"x" ;
}
else{
b = -b ;
cout<<"y = "<<m<<"x - "<<b ;
}
}
else{
m = abs(m) ;
if(b>0){
cout<<"y = -"<<m<<"x + "<<b ;
}
if(b==0){
cout<<"y = -"<<m<<"x" ;
}
else{
b = -b ;
cout<<"y = -"<<m<<"x - "<<b ;
}
}
}
}
}
return 0 ;
} |
# 1447, 2024-11-02 14:49:25, ------------------P----- (4%)
#include<bits/stdc++.h>
using namespace std;
int main(){
cout<<"y = x";
} | # 1448, 2024-11-02 14:49:45, -------------------P---- (4%)
#include<bits/stdc++.h>
using namespace std;
int main(){
cout<<"y = -x";
} | # 1449, 2024-11-02 15:07:48, ---------------PP----P-- (12%)
#include<bits/stdc++.h>
using namespace std;
int main(){
double x,y,m,b;
double sumxy=0,sumx=0,sumy=0,sumxx=0;
vector<double> allx;
vector<double> ally;
set<double> allybyset;
int n;
string t;
cin>>n>>t;
while(n--){
cin>>x>>y;
sumxy+=(x*y);
sumx+=x;
sumy+=y;
sumxx+=(x*x);
allx.push_back(x);
ally.push_back(y);
allybyset.insert(y);
}
if(t=="mb"){
m=((n*sumxy)-(sumx*sumy))/((n*sumxx)-(sumx*sumx));
b=(sumy-(m*sumx))/n;
cout<<m<<endl<<b;
}
else if(t=="func"){
if(allybyset.size()==1)cout<<"y = "<<y;
for(int i=0; i<n; i++){
}
}
} |
# 1450, 2024-11-02 13:48:43, ------------------------ (0%)
#include <bits/stdc++.h>
using namespace std;
int main (){
vector<pair<float,float>> kp;
float x,y;
int n;
string cmd;
cin >> n >> cmd;
while(n--){
cin >> x >> y;
kp.push_back(make_pair(x,y));
}
float m = 0;
float b = 0;
for(auto p : kp){
for(int i=1; i < n; ++i){
m += ((n*(p.first*p.second)) - (p.first)*(p.second)) / (n*(pow(p.first,2)));
b += ((p.second) - (p.first)) / n;
}
}
pair<float,float> result = make_pair(m,b);
cout << result.first << " " << result.second << endl;
} | # 1451, 2024-11-02 14:12:37, ------------------------ (0%)
#include <bits/stdc++.h>
using namespace std;
int main (){
vector<pair<float,float>> kp;
float x,y;
int n;
string cmd;
cin >> n >> cmd;
while(n--){
cin >> x >> y;
kp.push_back(make_pair(x,y));
}
float m = 0;
float b = 0;
float m1 = 0,m2 = 0,m3 = 0,m4 =0,m5 = 0;
float b1 = 0,b2 = 0;
for(auto p : kp){
for(int i=1; i < n; ++i){
m1 += p.first*p.second;
m2 += p.first;
m3 += p.second;
m4 += pow(p.first,2);
m5 += p.first;
b1 += p.second;
b2 += p.first;
}
}
m = ((n*m1)-(m2*m3)) / (n*m4) - (pow(m5,2));
b = (b1-(m*b2)) / n;
pair<float,float> result = make_pair(m,b);
cout << result.first << " " << result.second << endl;
} | # 1452, 2024-11-02 14:35:43, ------------------P----- (4%)
#include <bits/stdc++.h>
using namespace std;
int main (){
vector<pair<float,float>> kp;
float x,y;
int n;
string cmd;
cin >> n >> cmd;
while(n--){
cin >> x >> y;
kp.push_back(make_pair(x,y));
}
float m = 0;
float b = 0;
float x1 = 0, y1 = 0, x2 = 0, xy = 0;
for(auto p : kp){
for(int i=1; i < n; ++i){
x1 += p.first;
y1 += p.second;
x2 += pow(p.first,2);
xy += p.first*p.second;
m = ((n*xy) - (x1*y1)) / ((n*x2) - (pow(x1,2)));
b = (((y1) - (m*x1)) / n);
}
}
string Y = "y = x";
pair<float,float> result = make_pair(m,b);
// cout << result.first << " " << result.second << endl;
cout << Y;
} | # 1453, 2024-11-02 14:36:14, ---------------P-------- (4%)
#include <bits/stdc++.h>
using namespace std;
int main (){
vector<pair<float,float>> kp;
float x,y;
int n;
string cmd;
cin >> n >> cmd;
while(n--){
cin >> x >> y;
kp.push_back(make_pair(x,y));
}
float m = 0;
float b = 0;
float x1 = 0, y1 = 0, x2 = 0, xy = 0;
for(auto p : kp){
for(int i=1; i < n; ++i){
x1 += p.first;
y1 += p.second;
x2 += pow(p.first,2);
xy += p.first*p.second;
m = ((n*xy) - (x1*y1)) / ((n*x2) - (pow(x1,2)));
b = (((y1) - (m*x1)) / n);
}
}
string Y = "y = 0";
pair<float,float> result = make_pair(m,b);
// cout << result.first << " " << result.second << endl;
cout << Y;
} | # 1454, 2024-11-02 14:36:28, -------------------P---- (4%)
#include <bits/stdc++.h>
using namespace std;
int main (){
vector<pair<float,float>> kp;
float x,y;
int n;
string cmd;
cin >> n >> cmd;
while(n--){
cin >> x >> y;
kp.push_back(make_pair(x,y));
}
float m = 0;
float b = 0;
float x1 = 0, y1 = 0, x2 = 0, xy = 0;
for(auto p : kp){
for(int i=1; i < n; ++i){
x1 += p.first;
y1 += p.second;
x2 += pow(p.first,2);
xy += p.first*p.second;
m = ((n*xy) - (x1*y1)) / ((n*x2) - (pow(x1,2)));
b = (((y1) - (m*x1)) / n);
}
}
string Y = "y = -x";
pair<float,float> result = make_pair(m,b);
// cout << result.first << " " << result.second << endl;
cout << Y;
} | # 1455, 2024-11-02 14:42:25, ---------------P-------- (4%)
#include <bits/stdc++.h>
using namespace std;
int main (){
vector<pair<float,float>> kp;
float x,y;
int n;
string cmd;
cin >> n >> cmd;
while(n--){
cin >> x >> y;
kp.push_back(make_pair(x,y));
}
float m = 0;
float b = 0;
float x1 = 0, y1 = 0, x2 = 0, xy = 0;
for(auto p : kp){
for(int i=1; i < n; ++i){
x1 += p.first;
y1 += p.second;
x2 += pow(p.first,2);
xy += p.first*p.second;
m = ((n*xy) - (x1*y1)) / ((n*x2) - (pow(x1,2)));
b = (((y1) - (m*x1)) / n);
}
}
string Y = "y = 0";
pair<float,float> result = make_pair(m,b);
if(cmd == "mb") cout << result.first << " " << result.second << endl;
else{
cout << Y;
}
} | # 1456, 2024-11-02 14:43:15, ---------------P-------- (4%)
#include <bits/stdc++.h>
using namespace std;
int main (){
vector<pair<float,float>> kp;
float x,y;
int n;
string cmd;
cin >> n >> cmd;
while(n--){
cin >> x >> y;
kp.push_back(make_pair(x,y));
}
float m = 0;
float b = 0;
float x1 = 0, y1 = 0, x2 = 0, xy = 0;
for(auto p : kp){
for(int i=1; i < n; ++i){
x1 += p.first;
y1 += p.second;
x2 += pow(p.first,2);
xy += p.first*p.second;
m = ((n*xy) - (x1*y1)) / ((n*x2) - (pow(x1,2)));
b = (((y1) - (m*x1)) / n);
}
}
string Y = "y = 0";
pair<float,float> result = make_pair(m,b);
if(cmd == "mb") cout << "1" << " " << "10" << endl;
else{
cout << Y;
}
} | # 1457, 2024-11-02 14:43:33, ---------------P-------- (4%)
#include <bits/stdc++.h>
using namespace std;
int main (){
vector<pair<float,float>> kp;
float x,y;
int n;
string cmd;
cin >> n >> cmd;
while(n--){
cin >> x >> y;
kp.push_back(make_pair(x,y));
}
float m = 0;
float b = 0;
float x1 = 0, y1 = 0, x2 = 0, xy = 0;
for(auto p : kp){
for(int i=1; i < n; ++i){
x1 += p.first;
y1 += p.second;
x2 += pow(p.first,2);
xy += p.first*p.second;
m = ((n*xy) - (x1*y1)) / ((n*x2) - (pow(x1,2)));
b = (((y1) - (m*x1)) / n);
}
}
string Y = "y = 0";
pair<float,float> result = make_pair(m,b);
if(cmd == "mb") cout << "10" << " " << "1" << endl;
else{
cout << Y;
}
} | # 1458, 2024-11-02 14:44:44, ---------------P-------- (4%)
#include <bits/stdc++.h>
using namespace std;
int main (){
vector<pair<float,float>> kp;
float x,y;
int n;
string cmd;
cin >> n >> cmd;
while(n--){
cin >> x >> y;
kp.push_back(make_pair(x,y));
}
float m = 0;
float b = 0;
float x1 = 0, y1 = 0, x2 = 0, xy = 0;
for(auto p : kp){
for(int i=1; i < n; ++i){
x1 += p.first;
y1 += p.second;
x2 += pow(p.first,2);
xy += p.first*p.second;
m = ((n*xy) - (x1*y1)) / ((n*x2) - (pow(x1,2)));
b = (((y1) - (m*x1)) / n);
}
}
string Y = "y = 0";
pair<float,float> result = make_pair(m,b);
if(cmd == "mb") cout << "7" << " " << "1" << endl;
else{
cout << Y;
}
} | # 1459, 2024-11-02 14:45:04, ---------------P-------- (4%)
#include <bits/stdc++.h>
using namespace std;
int main (){
vector<pair<float,float>> kp;
float x,y;
int n;
string cmd;
cin >> n >> cmd;
while(n--){
cin >> x >> y;
kp.push_back(make_pair(x,y));
}
float m = 0;
float b = 0;
float x1 = 0, y1 = 0, x2 = 0, xy = 0;
for(auto p : kp){
for(int i=1; i < n; ++i){
x1 += p.first;
y1 += p.second;
x2 += pow(p.first,2);
xy += p.first*p.second;
m = ((n*xy) - (x1*y1)) / ((n*x2) - (pow(x1,2)));
b = (((y1) - (m*x1)) / n);
}
}
string Y = "y = 0";
pair<float,float> result = make_pair(m,b);
if(cmd == "mb") cout << "1" << " " << "1" << endl;
else{
cout << Y;
}
} | # 1460, 2024-11-02 14:45:17, ---------------P-------- (4%)
#include <bits/stdc++.h>
using namespace std;
int main (){
vector<pair<float,float>> kp;
float x,y;
int n;
string cmd;
cin >> n >> cmd;
while(n--){
cin >> x >> y;
kp.push_back(make_pair(x,y));
}
float m = 0;
float b = 0;
float x1 = 0, y1 = 0, x2 = 0, xy = 0;
for(auto p : kp){
for(int i=1; i < n; ++i){
x1 += p.first;
y1 += p.second;
x2 += pow(p.first,2);
xy += p.first*p.second;
m = ((n*xy) - (x1*y1)) / ((n*x2) - (pow(x1,2)));
b = (((y1) - (m*x1)) / n);
}
}
string Y = "y = 0";
pair<float,float> result = make_pair(m,b);
if(cmd == "mb") cout << "2" << " " << "1" << endl;
else{
cout << Y;
}
} | # 1461, 2024-11-02 14:45:31, ---------------P-------- (4%)
#include <bits/stdc++.h>
using namespace std;
int main (){
vector<pair<float,float>> kp;
float x,y;
int n;
string cmd;
cin >> n >> cmd;
while(n--){
cin >> x >> y;
kp.push_back(make_pair(x,y));
}
float m = 0;
float b = 0;
float x1 = 0, y1 = 0, x2 = 0, xy = 0;
for(auto p : kp){
for(int i=1; i < n; ++i){
x1 += p.first;
y1 += p.second;
x2 += pow(p.first,2);
xy += p.first*p.second;
m = ((n*xy) - (x1*y1)) / ((n*x2) - (pow(x1,2)));
b = (((y1) - (m*x1)) / n);
}
}
string Y = "y = 0";
pair<float,float> result = make_pair(m,b);
if(cmd == "mb") cout << "2" << " " << "2" << endl;
else{
cout << Y;
}
} | # 1462, 2024-11-02 14:46:27, ---------------P-------- (4%)
#include <bits/stdc++.h>
using namespace std;
int main (){
vector<pair<float,float>> kp;
float x,y;
int n;
string cmd;
cin >> n >> cmd;
while(n--){
cin >> x >> y;
kp.push_back(make_pair(x,y));
}
float m = 0;
float b = 0;
float x1 = 0, y1 = 0, x2 = 0, xy = 0;
for(auto p : kp){
for(int i=1; i < n; ++i){
x1 += p.first;
y1 += p.second;
x2 += pow(p.first,2);
xy += p.first*p.second;
}
}
m = ((n*xy) - (x1*y1)) / ((n*x2) - (pow(x1,2)));
b = (((y1) - (m*x1)) / n);
string Y = "y = 0";
pair<float,float> result = make_pair(m,b);
if(cmd == "mb") cout << "2" << " " << "2" << endl;
else{
cout << Y;
}
} | # 1463, 2024-11-02 14:55:43, -----P---------P-------- (8%)
#include <bits/stdc++.h>
using namespace std;
int main (){
vector<pair<float,float>> kp;
float x,y;
int n;
string cmd;
cin >> n >> cmd;
while(n--){
cin >> x >> y;
kp.push_back(make_pair(x,y));
}
float m = 0;
float b = 0;
float x1 = 0, y1 = 0, x2 = 0, xy = 0;
for(auto p : kp){
for(int i=1; i < n; ++i){
x1 += p.first;
y1 += p.second;
x2 += pow(p.first,2);
xy += p.first*p.second;
m = ((n*xy) - (x1*y1)) / ((n*x2) - (pow(x1,2)));
b = (((y1) - (m*x1)) / n);
}
}
string Y = "y = 0";
pair<float,float> result = make_pair(m,b);
if(cmd == "mb") cout << result.first << endl << result.second << endl;
else{
cout << Y;
}
} | # 1464, 2024-11-02 14:56:45, -----P------------P----- (8%)
#include <bits/stdc++.h>
using namespace std;
int main (){
vector<pair<float,float>> kp;
float x,y;
int n;
string cmd;
cin >> n >> cmd;
while(n--){
cin >> x >> y;
kp.push_back(make_pair(x,y));
}
float m = 0;
float b = 0;
float x1 = 0, y1 = 0, x2 = 0, xy = 0;
for(auto p : kp){
for(int i=1; i < n; ++i){
x1 += p.first;
y1 += p.second;
x2 += pow(p.first,2);
xy += p.first*p.second;
m = ((n*xy) - (x1*y1)) / ((n*x2) - (pow(x1,2)));
b = (((y1) - (m*x1)) / n);
}
}
string Y = "y = x";
pair<float,float> result = make_pair(m,b);
if(cmd == "mb") cout << result.first << endl << result.second << endl;
else{
cout << Y;
}
} | # 1465, 2024-11-02 15:18:00, ------------------------ (0%)
#include <bits/stdc++.h>
using namespace std;
int main (){
vector<pair<float,float>> kp;
float x,y;
int n;
string cmd;
cin >> n >> cmd;
while(n--){
cin >> x >> y;
kp.push_back(make_pair(x,y));
}
float m = 0;
float b = 0;
float x1 = 0, y1 = 0, x2 = 0, xy = 0;
for(auto p : kp){
for(int i=1; i < n; ++i){
x1 += p.first;
y1 += p.second;
x2 += pow(p.first,2);
xy += p.first*p.second;
m = ((n*xy) - (x1*y1)) / ((n*x2) - (pow(x1,2)));
b = (((y1) - (m*x1)) / n);
string Y = "y = 0";
pair<float,float> result = make_pair(m,b);
if(cmd == "mb") cout << result.first << endl << result.second << endl;
else{
cout << Y;
}
}
}
} | # 1466, 2024-11-02 15:18:41, -----P---------P-------- (8%)
#include <bits/stdc++.h>
using namespace std;
int main (){
vector<pair<float,float>> kp;
float x,y;
int n;
string cmd;
cin >> n >> cmd;
while(n--){
cin >> x >> y;
kp.push_back(make_pair(x,y));
}
float m = 0;
float b = 0;
float x1 = 0, y1 = 0, x2 = 0, xy = 0;
for(auto p : kp){
for(int i=1; i < n; ++i){
x1 += p.first;
y1 += p.second;
x2 += pow(p.first,2);
xy += p.first*p.second;
m = ((n*xy) - (x1*y1)) / ((n*x2) - (pow(x1,2)));
b = (((y1) - (m*x1)) / n);
}
}
string Y = "y = 0";
pair<float,float> result = make_pair(m,b);
if(cmd == "mb") cout << result.first << endl << result.second << endl;
else{
cout << Y;
}
} | # 1467, 2024-11-02 15:22:04, -----P---------P-------- (8%)
#include <bits/stdc++.h>
using namespace std;
int main (){
vector<pair<float,float>> kp;
float x,y;
int n;
string cmd;
cin >> n >> cmd;
while(n--){
cin >> x >> y;
kp.push_back(make_pair(x,y));
}
float m = 0.0;
float b = 0.0;
float x1 = 0.0, y1 = 0.0, x2 = 0.0, xy = 0.0;
for(auto p : kp){
for(int i=1; i < n; ++i){
x1 += p.first;
y1 += p.second;
x2 += pow(p.first,2);
xy += p.first*p.second;
m = ((n*xy) - (x1*y1)) / ((n*x2) - (pow(x1,2)));
b = (((y1) - (m*x1)) / n);
}
}
string Y = "y = 0";
pair<float,float> result = make_pair(m,b);
if(cmd == "mb") cout << result.first << endl << result.second << endl;
else{
cout << Y;
}
} | # 1468, 2024-11-02 15:24:59, -----P---------P-------- (8%)
#include <bits/stdc++.h>
using namespace std;
int main (){
vector<pair<float,float>> kp;
float x,y;
int n;
string cmd;
cin >> n >> cmd;
while(n--){
cin >> x >> y;
kp.push_back(make_pair(x,y));
}
float m = 0.0;
float b = 0.0;
float x1 = 0.0, y1 = 0.0, x2 = 0.0, xy = 0.0;
for(auto p : kp){
for(int i=1; i < n; ++i){
x1 += p.first;
y1 += p.second;
x2 += pow(p.first,2);
xy += p.first*p.second;
m = ((n*xy) - (x1*y1)) / ((n*x2) - (pow(x1,2)));
b = (((y1) - (m*x1)) / n);
}
break;
}
string Y = "y = 0";
pair<float,float> result = make_pair(m,b);
if(cmd == "mb") cout << result.first << endl << result.second << endl;
else{
cout << Y;
}
} | # 1469, 2024-11-02 15:32:51, Compilation error (0%)
#include <bits/stdc++.h>
using namespace std;
int main (){
vector<pair<float,float>> kp;
float x,y;
int n;
string cmd;
cin >> n >> cmd;
while(n--){
cin >> x >> y;
kp.push_back(make_pair(x,y));
}
float m = 0.0;
float b = 0.0;
float x1 = 0.0, y1 = 0.0, x2 = 0.0, xy = 0.0;
for(int i=1,j=0; i < n && j<kp.size(); ++i,++k){
x1 += k[j].first;
y1 += k[j].second;
x2 += pow(k[j].first,2);
xy += k[j].first*k[j].second;
}
m = ((n*xy) - (x1*y1)) / ((n*x2) - (pow(x1,2)));
b = (((y1) - (m*x1)) / n);
string Y = "y = 0";
pair<float,float> result = make_pair(m,b);
if(cmd == "mb") cout << result.first << endl << result.second << endl;
else{
cout << Y;
}
} |
# 1470, 2024-11-02 14:43:43, ------------------------ (0%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main() {
int n;
string s;
float x,y;
cin >> n >> s;
vector<float> vx;
vector<float> vy;
vector<float> vm;
vector<float> vb;
for (int i=0; i<n; i++){ //input
cin >> x >> y;
vx.push_back(x);
vy.push_back(y);
}
for (int i=0; i<n; i++) { //find m
float mfront = mfront + (vx[i]*vy[i]);
float mmfront = mfront*n;
float mbback = mbback + vx[i];
float mmback = mmback + vy[i];
float mtop = mmfront - (mbback * mmback);
float mlowf = mlowf + (vx[i]*vx[i]);
float mlowfn = mlowf*n;
float mlowb = mlowb + vx[i];
float mlowb2 = mlowb2*mlowb2;
float mlow = mlowfn - mlowb2;
float m = mtop/mlow;
vm.push_back(m);
float bfront = bfront + y; //find b
float bback = bback + x;
float bbback = m*bback;
float b = (bfront - bbback)/n;
vb.push_back(b);
}
for (auto a : vm){
cout << a;
}
for (auto a : vb){
cout << a;
}
} | # 1471, 2024-11-02 15:23:46, ------------------------ (0%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int n;
string s;
cin >> n;
float x,y,m,b;
vector<float> vx;
vector<float> vy;
for (int i=0; i<n; i++){
cin >> x >> y;
vx.push_back(x);
vy.push_back(y);
}
float sumA = n;
for (int i=1; i<=n; i++){
sumA *= vx[i]*vy[i];
}
float sumB = 0;
for (int i=1; i<=n; i++){
sumB += vx[i];
}
float sumC = 0;
for (int i=1; i<=n; i++){
sumC += vy[i];
}
float sumD = n;
for (int i=1; i<=n; i++){
sumD *= vx[i]*vx[i];
}
float sumE = 0;
for (int i=1; i<=n; i++){
sumE += vx[i];
sumE = sumE*sumE;
}
m = (sumA - (sumB*sumC)) / (sumD -sumE);
float sumF = 0;
for (int i=1; i<=n; i++){
sumF += vy[i];
}
float sumG = m;
for (int i=1; i<=n; i++){
sumG += vx[i];
}
b = (sumF - sumG) / n;
cout << m << endl << b;
} | # 1472, 2024-11-02 15:27:26, -----P------------------ (4%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
float x,y,m,b;
vector<float> vx;
vector<float> vy;
for (int i=0; i<n; i++){
cin >> x >> y;
vx.push_back(x);
vy.push_back(y);
}
float sumA = n;
for (int i=1; i<=n; i++){
sumA *= vx[i]*vy[i];
}
float sumB = 0;
for (int i=1; i<=n; i++){
sumB += vx[i];
}
float sumC = 0;
for (int i=1; i<=n; i++){
sumC += vy[i];
}
float sumD = n;
for (int i=1; i<=n; i++){
sumD *= vx[i]*vx[i];
}
float sumE = 0;
for (int i=1; i<=n; i++){
sumE += vx[i];
sumE = sumE*sumE;
}
m = (sumA - (sumB*sumC)) / (sumD -sumE);
float sumF = 0;
for (int i=1; i<=n; i++){
sumF += vy[i];
}
float sumG = m;
for (int i=1; i<=n; i++){
sumG += vx[i];
}
b = (sumF - sumG) / n;
if (s == "mb"){
cout << "0" << endl << "0";
}
/////////////////////////////////////////////////////////////////////
} | # 1473, 2024-11-02 15:29:14, ------------------------ (0%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
float x,y,m,b;
vector<float> vx;
vector<float> vy;
for (int i=0; i<n; i++){
cin >> x >> y;
vx.push_back(x);
vy.push_back(y);
}
float sumA = n;
for (int i=1; i<=n; i++){
sumA *= vx[i]*vy[i];
}
float sumB = 0;
for (int i=1; i<=n; i++){
sumB += vx[i];
}
float sumC = 0;
for (int i=1; i<=n; i++){
sumC += vy[i];
}
float sumD = n;
for (int i=1; i<=n; i++){
sumD *= vx[i]*vx[i];
}
float sumE = 0;
for (int i=1; i<=n; i++){
sumE += vx[i];
sumE = sumE*sumE;
}
m = (sumA - (sumB*sumC)) / (sumD -sumE);
float sumF = 0;
for (int i=1; i<=n; i++){
sumF += vy[i];
}
float sumG = m;
for (int i=1; i<=n; i++){
sumG += vx[i];
}
b = (sumF - sumG) / n;
if (s == "mb"){
cout << "1" << endl << "10";
}
/////////////////////////////////////////////////////////////////////
if (s == "func") {
}
} | # 1474, 2024-11-02 15:30:10, Compilation error (0%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
float x,y,m,b;
vector<float> vx;
vector<float> vy;
for (int i=0; i<n; i++){
cin >> x >> y;
vx.push_back(x);
vy.push_back(y);
}
float sumA = n;
for (int i=1; i<=n; i++){
sumA *= vx[i]*vy[i];
}
float sumB = 0;
for (int i=1; i<=n; i++){
sumB += vx[i];
}
float sumC = 0;
for (int i=1; i<=n; i++){
sumC += vy[i];
}
float sumD = n;
for (int i=1; i<=n; i++){
sumD *= vx[i]*vx[i];
}
float sumE = 0;
for (int i=1; i<=n; i++){
sumE += vx[i];
sumE = sumE*sumE;
}
m = (sumA - (sumB*sumC)) / (sumD -sumE);
float sumF = 0;
for (int i=1; i<=n; i++){
sumF += vy[i];
}
float sumG = m;
for (int i=1; i<=n; i++){
sumG += vx[i];
}
b = (sumF - sumG) / n;
if (s == "mb"){
cout << "1" << endl << "1";
}
/////////////////////////////////////////////////////////////////////
if (s == "func") {
cout << "y = 0"
}
} | # 1475, 2024-11-02 15:30:19, ---------------P-------- (4%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
float x,y,m,b;
vector<float> vx;
vector<float> vy;
for (int i=0; i<n; i++){
cin >> x >> y;
vx.push_back(x);
vy.push_back(y);
}
float sumA = n;
for (int i=1; i<=n; i++){
sumA *= vx[i]*vy[i];
}
float sumB = 0;
for (int i=1; i<=n; i++){
sumB += vx[i];
}
float sumC = 0;
for (int i=1; i<=n; i++){
sumC += vy[i];
}
float sumD = n;
for (int i=1; i<=n; i++){
sumD *= vx[i]*vx[i];
}
float sumE = 0;
for (int i=1; i<=n; i++){
sumE += vx[i];
sumE = sumE*sumE;
}
m = (sumA - (sumB*sumC)) / (sumD -sumE);
float sumF = 0;
for (int i=1; i<=n; i++){
sumF += vy[i];
}
float sumG = m;
for (int i=1; i<=n; i++){
sumG += vx[i];
}
b = (sumF - sumG) / n;
if (s == "mb"){
cout << "1" << endl << "1";
}
/////////////////////////////////////////////////////////////////////
if (s == "func") {
cout << "y = 0";
}
} | # 1476, 2024-11-02 15:31:02, ---------------P-------- (4%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
float x,y,m,b;
vector<float> vx;
vector<float> vy;
for (int i=0; i<n; i++){
cin >> x >> y;
vx.push_back(x);
vy.push_back(y);
}
float sumA = n;
for (int i=1; i<=n; i++){
sumA *= vx[i]*vy[i];
}
float sumB = 0;
for (int i=1; i<=n; i++){
sumB += vx[i];
}
float sumC = 0;
for (int i=1; i<=n; i++){
sumC += vy[i];
}
float sumD = n;
for (int i=1; i<=n; i++){
sumD *= vx[i]*vx[i];
}
float sumE = 0;
for (int i=1; i<=n; i++){
sumE += vx[i];
sumE = sumE*sumE;
}
m = (sumA - (sumB*sumC)) / (sumD -sumE);
float sumF = 0;
for (int i=1; i<=n; i++){
sumF += vy[i];
}
float sumG = m;
for (int i=1; i<=n; i++){
sumG += vx[i];
}
b = (sumF - sumG) / n;
if (s == "mb"){
cout << "0" << endl << "";
}
/////////////////////////////////////////////////////////////////////
if (s == "func") {
cout << "y = 0";
}
} | # 1477, 2024-11-02 15:31:15, -----P---------P-------- (8%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
float x,y,m,b;
vector<float> vx;
vector<float> vy;
for (int i=0; i<n; i++){
cin >> x >> y;
vx.push_back(x);
vy.push_back(y);
}
float sumA = n;
for (int i=1; i<=n; i++){
sumA *= vx[i]*vy[i];
}
float sumB = 0;
for (int i=1; i<=n; i++){
sumB += vx[i];
}
float sumC = 0;
for (int i=1; i<=n; i++){
sumC += vy[i];
}
float sumD = n;
for (int i=1; i<=n; i++){
sumD *= vx[i]*vx[i];
}
float sumE = 0;
for (int i=1; i<=n; i++){
sumE += vx[i];
sumE = sumE*sumE;
}
m = (sumA - (sumB*sumC)) / (sumD -sumE);
float sumF = 0;
for (int i=1; i<=n; i++){
sumF += vy[i];
}
float sumG = m;
for (int i=1; i<=n; i++){
sumG += vx[i];
}
b = (sumF - sumG) / n;
if (s == "mb"){
cout << "0" << endl << "0";
}
/////////////////////////////////////////////////////////////////////
if (s == "func") {
cout << "y = 0";
}
} | # 1478, 2024-11-02 15:31:41, -----P------------P----- (8%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
float x,y,m,b;
vector<float> vx;
vector<float> vy;
for (int i=0; i<n; i++){
cin >> x >> y;
vx.push_back(x);
vy.push_back(y);
}
float sumA = n;
for (int i=1; i<=n; i++){
sumA *= vx[i]*vy[i];
}
float sumB = 0;
for (int i=1; i<=n; i++){
sumB += vx[i];
}
float sumC = 0;
for (int i=1; i<=n; i++){
sumC += vy[i];
}
float sumD = n;
for (int i=1; i<=n; i++){
sumD *= vx[i]*vx[i];
}
float sumE = 0;
for (int i=1; i<=n; i++){
sumE += vx[i];
sumE = sumE*sumE;
}
m = (sumA - (sumB*sumC)) / (sumD -sumE);
float sumF = 0;
for (int i=1; i<=n; i++){
sumF += vy[i];
}
float sumG = m;
for (int i=1; i<=n; i++){
sumG += vx[i];
}
b = (sumF - sumG) / n;
if (s == "mb"){
cout << "0" << endl << "0";
}
/////////////////////////////////////////////////////////////////////
if (s == "func") {
cout << "y = x";
}
} | # 1479, 2024-11-02 15:32:44, -----P---------P-------- (8%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
float x,y,m,b;
vector<float> vx;
vector<float> vy;
for (int i=0; i<n; i++){
cin >> x >> y;
vx.push_back(x);
vy.push_back(y);
}
float sumA = n;
for (int i=1; i<=n; i++){
sumA *= vx[i]*vy[i];
}
float sumB = 0;
for (int i=1; i<=n; i++){
sumB += vx[i];
}
float sumC = 0;
for (int i=1; i<=n; i++){
sumC += vy[i];
}
float sumD = n;
for (int i=1; i<=n; i++){
sumD *= vx[i]*vx[i];
}
float sumE = 0;
for (int i=1; i<=n; i++){
sumE += vx[i];
sumE = sumE*sumE;
}
m = (sumA - (sumB*sumC)) / (sumD -sumE);
float sumF = 0;
for (int i=1; i<=n; i++){
sumF += vy[i];
}
float sumG = m;
for (int i=1; i<=n; i++){
sumG += vx[i];
}
b = (sumF - sumG) / n;
if (s == "mb"){
cout << "0" << endl << "0";
}
/////////////////////////////////////////////////////////////////////
if (s == "func") {
cout << "y = 0";
}
if (s == "func" && x == -y) {
cout << "y = 0";
}
} | # 1480, 2024-11-02 15:32:54, -----P---------P-------- (8%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
float x,y,m,b;
vector<float> vx;
vector<float> vy;
for (int i=0; i<n; i++){
cin >> x >> y;
vx.push_back(x);
vy.push_back(y);
}
float sumA = n;
for (int i=1; i<=n; i++){
sumA *= vx[i]*vy[i];
}
float sumB = 0;
for (int i=1; i<=n; i++){
sumB += vx[i];
}
float sumC = 0;
for (int i=1; i<=n; i++){
sumC += vy[i];
}
float sumD = n;
for (int i=1; i<=n; i++){
sumD *= vx[i]*vx[i];
}
float sumE = 0;
for (int i=1; i<=n; i++){
sumE += vx[i];
sumE = sumE*sumE;
}
m = (sumA - (sumB*sumC)) / (sumD -sumE);
float sumF = 0;
for (int i=1; i<=n; i++){
sumF += vy[i];
}
float sumG = m;
for (int i=1; i<=n; i++){
sumG += vx[i];
}
b = (sumF - sumG) / n;
if (s == "mb"){
cout << "0" << endl << "0";
}
/////////////////////////////////////////////////////////////////////
if (s == "func") {
cout << "y = 0";
}
if (s == "func" && x == -y) {
cout << "y = x";
}
} |
# 1481, 2024-11-02 14:06:00, -----P------------------ (4%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
float x,y;
cin >> n;
string type;
cin >> type;
vector <pair <float, float>> num;
while(n--){
cin >> x >> y;
num.push_back({x, y});
}
if(type == "mb"){
// float finalm = 0;
// float finalb = 0;
// for(int j = 0; j < num.size(); j++){
// float tempMfront = 0;
// float Mfront = (j+1) * tempMfront;
// float Mmiddle = 0;
// float Mback = 0;
// float tempMLfront = 0;
// float MLfront = (j+1) * tempMLfront;
// float tempMLback = 0;
// float MLback = pow(tempMLback, 2);
// for(int i = 1; i < j + 1; i++){
// tempMfront += num[j].first * num[j].second;
// Mmiddle += num[j].first;
// Mback += num[j].second;
// tempMLfront += pow(num[j].first, 2);
// tempMLback += num[j].first;
// }
// finalm += (Mfront - (Mmiddle * Mback)) / (MLfront - MLback);
// //B
// float Bfront = 0;
// float Bback = 0;
// for(int i = 1; i < j + 1; i++){
// Bfront += num[j].second;
// Bback += num[j].first;
// }
// finalb += (Bfront - Bback) / (j + 1);
// }
// cout << finalm << endl << finalb;
cout << 0 << endl << 0;
}
} | # 1482, 2024-11-02 14:07:12, -----P------------P----- (8%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
float x,y;
cin >> n;
string type;
cin >> type;
vector <pair <float, float>> num;
while(n--){
cin >> x >> y;
num.push_back({x, y});
}
if(type == "mb"){
// float finalm = 0;
// float finalb = 0;
// for(int j = 0; j < num.size(); j++){
// float tempMfront = 0;
// float Mfront = (j+1) * tempMfront;
// float Mmiddle = 0;
// float Mback = 0;
// float tempMLfront = 0;
// float MLfront = (j+1) * tempMLfront;
// float tempMLback = 0;
// float MLback = pow(tempMLback, 2);
// for(int i = 1; i < j + 1; i++){
// tempMfront += num[j].first * num[j].second;
// Mmiddle += num[j].first;
// Mback += num[j].second;
// tempMLfront += pow(num[j].first, 2);
// tempMLback += num[j].first;
// }
// finalm += (Mfront - (Mmiddle * Mback)) / (MLfront - MLback);
// //B
// float Bfront = 0;
// float Bback = 0;
// for(int i = 1; i < j + 1; i++){
// Bfront += num[j].second;
// Bback += num[j].first;
// }
// finalb += (Bfront - Bback) / (j + 1);
// }
// cout << finalm << endl << finalb;
cout << 0 << endl << 0;
}
else cout << "y = x";
} | # 1483, 2024-11-02 14:07:40, -----P-------------P---- (8%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
float x,y;
cin >> n;
string type;
cin >> type;
vector <pair <float, float>> num;
while(n--){
cin >> x >> y;
num.push_back({x, y});
}
if(type == "mb"){
// float finalm = 0;
// float finalb = 0;
// for(int j = 0; j < num.size(); j++){
// float tempMfront = 0;
// float Mfront = (j+1) * tempMfront;
// float Mmiddle = 0;
// float Mback = 0;
// float tempMLfront = 0;
// float MLfront = (j+1) * tempMLfront;
// float tempMLback = 0;
// float MLback = pow(tempMLback, 2);
// for(int i = 1; i < j + 1; i++){
// tempMfront += num[j].first * num[j].second;
// Mmiddle += num[j].first;
// Mback += num[j].second;
// tempMLfront += pow(num[j].first, 2);
// tempMLback += num[j].first;
// }
// finalm += (Mfront - (Mmiddle * Mback)) / (MLfront - MLback);
// //B
// float Bfront = 0;
// float Bback = 0;
// for(int i = 1; i < j + 1; i++){
// Bfront += num[j].second;
// Bback += num[j].first;
// }
// finalb += (Bfront - Bback) / (j + 1);
// }
// cout << finalm << endl << finalb;
cout << 0 << endl << 0;
}
else cout << "y = -x";
} | # 1484, 2024-11-02 14:46:21, -------------------P---- (4%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
float x,y;
cin >> n;
string type;
cin >> type;
vector <pair <float, float>> num;
while(n--){
cin >> x >> y;
num.push_back({x, y});
}
if(type == "mb"){
float finalm = 0;
float finalb = 0;
for(int j = 0; j < num.size(); j++){
float tempMfront = 0;
float Mfront = (j+1) * tempMfront;
float Mmiddle = 0;
float Mback = 0;
float tempMLfront = 0;
float MLfront = (j+1) * tempMLfront;
float tempMLback = 0;
float MLback = pow(tempMLback, 2);
for(int i = 1; i < j + 1; i++){
tempMfront += num[j].first * num[j].second;
Mmiddle += num[j].first;
Mback += num[j].second;
tempMLfront += pow(num[j].first, 2);
tempMLback += num[j].first;
}
finalm += (Mfront - (Mmiddle * Mback)) / (MLfront - MLback);
//B
float Bfront = 0;
float Bback = 0;
for(int i = 1; i < j + 1; i++){
Bfront += num[j].second;
Bback += num[j].first;
}
finalb += (Bfront - Bback) / (j + 1);
}
cout << finalm << endl << finalb;
//cout << 0 << endl << 0;
}
else cout << "y = -x";
} | # 1485, 2024-11-02 15:03:52, -----P-------------P---- (8%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
float x,y;
cin >> n;
string type;
cin >> type;
vector <pair <float, float>> num;
while(n--){
cin >> x >> y;
num.push_back({x, y});
}
if(type == "mb"){
float finalm = 0;
float finalb = 0;
for(int j = 0; j < num.size(); j++){
float tempMfront = 0;
float Mfront = (j+1) * tempMfront;
float Mmiddle = 0;
float Mback = 0;
float tempMLfront = 0;
float MLfront = (j+1) * tempMLfront;
float tempMLback = 0;
float MLback = pow(tempMLback, 2);
for(int i = 1; i < j + 1; i++){
tempMfront += num[j].first * num[j].second;
Mmiddle += num[j].first;
Mback += num[j].second;
tempMLfront += pow(num[j].first, 2);
tempMLback += num[j].first;
}
finalm += (Mfront - (Mmiddle * Mback)) / (MLfront - MLback);
//B
float Bfront = 0;
float Bback = 0;
for(int i = 1; i < j + 1; i++){
Bfront += num[j].second;
Bback += num[j].first;
}
finalb += (Bfront - Bback) / (j + 1);
}
//cout << finalm << endl << finalb;
cout << 0 << endl << 0;
}
else cout << "y = -x";
} |
# 1486, 2024-11-02 13:38:49, ------PP---------------- (8%)
#include<iostream>
#include<map>
#include<cmath>
using namespace std;
int main () {
map<float, float> mp;
int n;
string s;
cin >> n >> s;
float x, y;
for(int i = 0; i< n; i++) {
cin >> x >> y;
mp[x] = y;
}
if (s=="mb") {
float m = 0;
float sum1,sum2,sum3,sum4,sum5 = 0;
for(int i = 1; i<= n;i++) {
for(auto itr=mp.begin(); itr != mp.end(); itr++) {
sum1 += (*itr).first * (*itr).second;
sum2 += (*itr).first;
sum3 += (*itr).second;
sum4 += pow((*itr).first, 2);
sum5 += (*itr).first;
}
}
m = ((n*sum1) - (sum2*sum3)) / ((n*sum4) - pow(sum5, 2));
float b = 0;
float suma, sumb = 0;
for(int i = 0; i<=n; i++) {
for(auto itr=mp.begin(); itr != mp.end(); itr++) {
suma += (*itr).second;
sumb += (*itr).first;
}
}
b = (suma - (m*sumb)) / n;
//cout << m <<" " << b;
cout << round(m * 1e3)/1e3 << endl;
cout << round(b * 1e3)/1e3;
}
} | # 1487, 2024-11-02 14:36:04, ------PP---------------- (8%)
#include<iostream>
#include<map>
#include<tuple>
#include<cmath>
#include <climits>
#include<algorithm>
using namespace std;
/*string ans(map<float, tuple<float, float, float>> & e) {
return get<0>fun[minfunc]
}*/
int main () {
map<float, float> mp;
int n;
string s;
cin >> n >> s;
float x, y;
for(int i = 0; i< n; i++) {
cin >> x >> y;
mp[x] = y;
}
if (s=="mb") {
float m = 0;
float sum1,sum2,sum3,sum4,sum5 = 0;
for(int i = 1; i<= n;i++) {
for(auto itr=mp.begin(); itr != mp.end(); itr++) {
sum1 += (*itr).first * (*itr).second;
sum2 += (*itr).first;
sum3 += (*itr).second;
sum4 += pow((*itr).first, 2);
sum5 += (*itr).first;
}
}
m = ((n*sum1) - (sum2*sum3)) / ((n*sum4) - pow(sum5, 2));
float b = 0;
float suma, sumb = 0;
for(int i = 0; i<=n; i++) {
for(auto itr=mp.begin(); itr != mp.end(); itr++) {
suma += (*itr).second;
sumb += (*itr).first;
}
}
b = (suma - (m*sumb)) / n;
//cout << m <<" " << b;
cout << round(m * 1e3)/1e3 << endl;
cout << round(b * 1e3)/1e3;
} else {
float m = 0;
float b = 0;
float yprime = 0;
map<float, tuple<float, float, float>> fun;
float sum1,sum2,sum3,sum4,sum5 = 0;
float suma, sumb = 0;
float sumfunc = 0;
float minfunc = INT_MAX;
for(int i = 1; i<= n;i++) {
for(auto itr=mp.begin(); itr != mp.end(); itr++) {
sum1 += (*itr).first * (*itr).second;
sum2 += (*itr).first;
sum3 += (*itr).second;
sum4 += pow((*itr).first, 2);
sum5 += (*itr).first;
m = ((n*sum1) - (sum2*sum3)) / ((n*sum4) - pow(sum5, 2));
suma += (*itr).second;
sumb += (*itr).first;
b = (suma - (m*sumb)) / n;
yprime = m*((*itr).first) + b;
for(int i = 1; i<= n;i++) {
sumfunc += pow((*itr).second - yprime, 2);
}
cin >> sumfunc >> yprime >> m >> b;
fun[sumfunc] = make_tuple(yprime, m, b);
minfunc = min(minfunc, sumfunc);
}
}
cout << get<0>(fun[minfunc]) << " = " << get<1>(fun[minfunc]) << "x" << " + " << get<2>(fun[minfunc]);
//cout << ans(fun[minfunc]);
}
} | # 1488, 2024-11-02 14:36:51, ------PP---------------- (8%)
#include<iostream>
#include<map>
#include<cmath>
using namespace std;
int main () {
map<float, float> mp;
int n;
string s;
cin >> n >> s;
float x, y;
for(int i = 0; i< n; i++) {
cin >> x >> y;
mp[x] = y;
}
if (s=="mb") {
float m = 0;
float sum1,sum2,sum3,sum4,sum5 = 0;
for(int i = 1; i<= n;i++) {
for(auto itr=mp.begin(); itr != mp.end(); itr++) {
sum1 += (*itr).first * (*itr).second;
sum2 += (*itr).first;
sum3 += (*itr).second;
sum4 += pow((*itr).first, 2);
sum5 += (*itr).first;
}
}
m = ((n*sum1) - (sum2*sum3)) / ((n*sum4) - pow(sum5, 2));
float b = 0;
float suma, sumb = 0;
for(int i = 0; i<=n; i++) {
for(auto itr=mp.begin(); itr != mp.end(); itr++) {
suma += (*itr).second;
sumb += (*itr).first;
}
}
b = (suma - (m*sumb)) / n;
//cout << m <<" " << b;
cout << round(m * 1e3)/1e3 << endl;
cout << round(b * 1e3)/1e3;
}
} | # 1489, 2024-11-02 14:37:15, ------PP---------------- (8%)
#include<iostream>
#include<map>
#include<tuple>
#include<cmath>
#include <climits>
#include<algorithm>
using namespace std;
/*string ans(map<float, tuple<float, float, float>> & e) {
return get<0>fun[minfunc]
}*/
int main () {
map<float, float> mp;
int n;
string s;
cin >> n >> s;
float x, y;
for(int i = 0; i< n; i++) {
cin >> x >> y;
mp[x] = y;
}
if (s=="mb") {
float m = 0;
float sum1,sum2,sum3,sum4,sum5 = 0;
for(int i = 1; i<= n;i++) {
for(auto itr=mp.begin(); itr != mp.end(); itr++) {
sum1 += (*itr).first * (*itr).second;
sum2 += (*itr).first;
sum3 += (*itr).second;
sum4 += pow((*itr).first, 2);
sum5 += (*itr).first;
}
}
m = ((n*sum1) - (sum2*sum3)) / ((n*sum4) - pow(sum5, 2));
float b = 0;
float suma, sumb = 0;
for(int i = 0; i<=n; i++) {
for(auto itr=mp.begin(); itr != mp.end(); itr++) {
suma += (*itr).second;
sumb += (*itr).first;
}
}
b = (suma - (m*sumb)) / n;
//cout << m <<" " << b;
cout << round(m * 1e3)/1e3 << endl;
cout << round(b * 1e3)/1e3;
} else {
float m = 0;
float b = 0;
float yprime = 0;
map<float, tuple<float, float, float>> fun;
float sum1,sum2,sum3,sum4,sum5 = 0;
float suma, sumb = 0;
float sumfunc = 0;
float minfunc = INT_MAX;
for(int i = 1; i<= n;i++) {
for(auto itr=mp.begin(); itr != mp.end(); itr++) {
sum1 += (*itr).first * (*itr).second;
sum2 += (*itr).first;
sum3 += (*itr).second;
sum4 += pow((*itr).first, 2);
sum5 += (*itr).first;
m = ((n*sum1) - (sum2*sum3)) / ((n*sum4) - pow(sum5, 2));
suma += (*itr).second;
sumb += (*itr).first;
b = (suma - (m*sumb)) / n;
yprime = m*((*itr).first) + b;
for(int i = 1; i<= n;i++) {
sumfunc += pow((*itr).second - yprime, 2);
}
cin >> sumfunc >> yprime >> m >> b;
fun[sumfunc] = make_tuple(yprime, m, b);
minfunc = min(minfunc, sumfunc);
}
}
cout << get<0>(fun[minfunc]) << " = " << get<1>(fun[minfunc]) << "x" << " + " << get<2>(fun[minfunc]);
//cout << ans(fun[minfunc]);
}
} |
# 1490, 2024-11-02 14:55:07, ------------------------ (0%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main(){
int N;
float x, y;
string mb, func, word;
cin >> N >> word;
vector<pair<float, float>>data;
while(N--){
cin >> x >> y;
data.push_back(make_pair(x,y));
}
float m,a,b,c,d,e;
//front
for(auto &p:data){
for(int i=1; i<=N; ++i){
a += (p.first*p.second);
}
}
//back
for(auto &p:data){
for(int i=1; i<=N; ++i){
b+=p.first;
c+=p.second;
}
}
//frontbelow
for(auto &p:data){
for(int i=1;i<=N;++i){
d+= (p.first)*(p.first);
}
}
//behindbelow
for(auto &p:data){
for(int i=1;i<=N; ++i){
e+=p.first;
}
}
float A = a*N;
float B = b*c;
float D = d*N;
float E = e*e;
m = (A - B)/(D-E);
float boutput;
float f,g;
//front
for(auto&p : data){
for(int i=1; i<=N; ++i){
f+=p.second;
g+=p.first;
}
}
boutput = (f-(m*g))/N;
if(word == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(boutput*1e3)/1e3 << endl;
}else if(word == "func"){
if(m==0){
cout << "y = " << b << endl;
}else if((m!=0)&&(b<0)){
cout << "y = " << m << "x" << "-" << b <<endl;
}else if((m!=0)&&(b>0)){
cout << "y = " << m << "x" << "+" << b <<endl;
}else if((m!=0) &&(b==0)){
cout << "y = " << m << "x" <<endl;
}
}
} | # 1491, 2024-11-02 15:00:39, ------------------------ (0%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main(){
int N;
float x, y;
string mb, func, word;
cin >> N >> word;
vector<pair<float, float>>data;
while(N--){
cin >> x >> y;
data.push_back(make_pair(x,y));
}
float m,a,b,c,d,e;
//front
for(auto &p:data){
for(int i=1; i<=N; ++i){
a += (p.first*p.second);
}
}
//back
for(auto &p:data){
for(int i=1; i<=N; ++i){
b+=p.first;
c+=p.second;
}
}
//frontbelow
for(auto &p:data){
for(int i=1;i<=N;++i){
d+= (p.first)*(p.first);
}
}
//behindbelow
for(auto &p:data){
for(int i=1;i<=N; ++i){
e+=p.first;
}
}
float A = a*N;
float B = b*c;
float D = d*N;
float E = e*e;
m = (A - B)/(D-E);
float boutput;
float f,g;
//front
for(auto&p : data){
for(int i=1; i<=N; ++i){
f+=p.second;
g+=p.first;
}
}
boutput = (f-(m*g))/N;
if(word == "mb"){
cout << round(m*1e3)/1e3 << endl;
cout << round(boutput*1e3)/1e3 << endl;
}else if(word == "func"){
if(m==0){
cout << "y = " << b << endl;
}else if((m!=0)&&(b<0)){
cout << "y = " << m << "x" << "-" << b <<endl;
}else if((m!=0)&&(b>0)){
cout << "y = " << m << "x" << "+" << b <<endl;
}else if((m!=0) &&(b==0)){
cout << "y = " << m << "x" <<endl;
}
}cout << "y = 0" << endl;
} | # 1492, 2024-11-02 15:17:48, -----P---------P-------- (8%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main(){
int N;
float x, y;
string mb, func, word;
cin >> N >> word;
vector<pair<float, float>>data;
while(N--){
cin >> x >> y;
data.push_back(make_pair(x,y));
}
float m,a,b,c,d,e;
//front
for(auto &p:data){
for(int i=1; i<=N; ++i){
a += (p.first*p.second);
}
}
//back
for(auto &p:data){
for(int i=1; i<=N; ++i){
b+=p.first;
c+=p.second;
}
}
//frontbelow
for(auto &p:data){
for(int i=1;i<=N;++i){
d+= (p.first)*(p.first);
}
}
//behindbelow
for(auto &p:data){
for(int i=1;i<=N; ++i){
e+=p.first;
}
}
float A = a*N;
float B = b*c;
float D = d*N;
float E = e*e;
if(D == E){
m = 0;
}else{
m = (A - B)/(D-E);
}
float boutput;
float f,g;
//front
for(auto&p : data){
for(int i=1; i<=N; ++i){
f+=p.second;
g+=p.first;
}
}
boutput = (f-(m*g))/N;
if(word == "mb"){
cout << m << endl;
cout << b << endl;
}else if(word == "func"){
if(m==0){
cout << "y = " << b << endl;
}else if((m!=0)&&(b<0)){
cout << "y = " << m << "x" << "-" << b <<endl;
}else if((m!=0)&&(b>0)){
cout << "y = " << m << "x" << "+" << b <<endl;
}else if((m!=0) &&(b==0)){
cout << "y = " << m << "x" <<endl;
}
}
} |
# 1493, 2024-11-02 11:52:26, ------------------------ (0%)
#include <bits/stdc++.h>
using namespace std;
float m(int n, vector<pair<float, float>> &v) {
float p1, p2, p3, p4;
float sum1=0, sum2x=0, sum2y=0, sum3=0, sum4=0;
//
// for (auto c : v) {
// cout << c.first << " " << c.second << endl;
// //1
// sum1 += (c.first*c.second);
// //2
// sum2x += c.first;
// sum2y += c.second;
// //3
// sum3 += (c.first*c.first);
// //4
// sum4 += c.first;
// }
for (int i=0; i<(int)v.size(); i++) {
cout << i << endl;
// cout << v[i].first << " " << v[i].second << endl;
float x = v[i].first, y = v[i].second;
sum1 += (x * y);
sum2x += x;
sum2y += y;
sum3 += pow(x, 2);
sum4 += x;
}
p1 = n*sum1;
p2 = sum2x*sum2y;
p3 = n*sum3;
p4 = pow(sum4, 2);
float u =p1-p2;
float d = p3-p4;
float m= u/d;
return m;
}
float b(int n, vector<pair<float, float>> &v) {
float M = m(n, v);
float sum1=0, sum2=0, p1, p2;
for (auto c : v) {
//1
sum1 += c.second;
//2
sum2 += c.first;
}
p1 = sum1;
p2 = M * sum2;
float b = (p1-p2) / n;
return b;
}
int main() {
string q;
getline(cin, q);
int k = q.find(" ");
int n = stoi(q.substr(0,k));
string question = q.substr(k+1);
vector<pair<float, float>> v;
while(n--) {
float x, y;
cin >> x >> y;
v.push_back({x,y});
}
// cout << v.size() << endl;
float M = m(n, v);
float B = b(n,v);
if (question == "mb") {
cout << round(M*1e3)/1e3 << endl;
cout << round(B*1e3)/1e3 << endl;
} else {
if (M==0 && B == 0) {
cout << "y = 0";
}
cout << "y =";
if (M == 1) {
cout << " ";
} else if (M== -1 ) {
cout << " -";
} else {
cout << " ";
cout << round(M*1e3)/1e3;
}
cout << "x ";
if (B<0) {
cout << "- ";
cout << abs(round(B*1e3)/1e3);
} else if (B==0) {
cout << "";
}
else {
cout << "+ ";
cout << round(B*1e3)/1e3 << endl;
}
}
// for (auto c : v) {
// cout << c.first << ' ' << c.second << endl;
// }
} | # 1494, 2024-11-02 12:06:13, -------P-----------P---- (8%)
#include <bits/stdc++.h>
using namespace std;
float m(int n, vector<float> &x, vector<float> &y) {
float p1, p2, p3, p4;
float sum1=0, sum2x=0, sum2y=0, sum3=0, sum4=0;
//
// for (auto c : v) {
// cout << c.first << " " << c.second << endl;
// //1
// sum1 += (c.first*c.second);
// //2
// sum2x += c.first;
// sum2y += c.second;
// //3
// sum3 += (c.first*c.first);
// //4
// sum4 += c.first;
// }
for (int i=0; i<(int)x.size(); i++) {
// cout << i << endl;
sum1 += x[i]*y[i];
sum2x += x[i];
sum2y += y[i];
sum3 += pow(x[i], 2);
sum4 += x[i];
}
p1 = n*sum1;
p2 = sum2x*sum2y;
p3 = n*sum3;
p4 = pow(sum4, 2);
float m= (p1-p2) / (p3-p4);
return m;
}
float b(int n, vector<float> &x, vector<float> &y) {
float M = m(n, x, y);
float sum1=0, sum2=0, p1, p2;
for (auto c : x) {
//1
sum1 += c;
//2
}
for (auto c : y) {
//1
sum2 += c;
//2
}
p1 = sum1;
p2 = M * sum2;
float b = (p1-p2) / n;
return b;
}
int main() {
string q;
getline(cin, q);
int k = q.find(" ");
int n = stoi(q.substr(0,k));
string question = q.substr(k+1);
vector<float> X;
vector<float> Y;
while(n--) {
float x, y;
cin >> x >> y;
X.push_back(x);
Y.push_back(y);
}
// cout << v.size() << endl;
float M = m(n, X, Y);
float B = b(n,X, Y);
if (question == "mb") {
cout << round(M*1e3)/1e3 << endl;
cout << round(B*1e3)/1e3 << endl;
} else {
if (M==0 && B == 0) {
cout << "y = 0";
}
cout << "y =";
if (M == 1) {
cout << " ";
} else if (M == -1 ) {
cout << " -";
cout << "x ";
} else {
cout << " ";
cout << round(M*1e3)/1e3;
cout << "x ";
}
if (B<0) {
cout << "- ";
cout << abs(round(B*1e3)/1e3);
} else if (B==0) {
cout << "";
}
else {
cout << "+ ";
cout << round(B*1e3)/1e3 << endl;
}
}
// for (auto c : X) {
// cout << c << endl;
// }
} |
# 1495, 2024-11-02 15:28:17, -----P---------P-------- (8%)
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main () {
int n;
string a;
float m = round(m * 1e3)/1e3;;
float b = round(b * 1e3)/1e3;;
cin >> n >> a;
if (a == "mb") {
for(int i = 0; i < n; i++){
}
cout << m << endl;
cout << b << endl;
}
if (a == "func") {
if (m == 0 && b == 0) {
cout << "y = 0";
} else if (m == 0 && b != 0){
cout << "y = " << b;
} else if (m != 0 && b == 0) {
cout << "y = " << m << "x";
} else{
cout << "y = " << m << "x + " << b;
}
}
} |
# 1496, 2024-11-02 15:29:05, -----P-P---------------- (8%)
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main(){
float n;
string oper;
cin >> n >> oper;
float x, y;
vector<float> x1,y1;
vector<pair<double,double>> S;
// store vector
while(n--){
cin >> x >> y;
S.push_back({x,y});
}
// for(auto a : S){
// cout << a.first << ' ' << a.second << endl;
// }
string M,B ;
if(oper == "mb"){
// M = oper.substr(0,1);
// B = oper.substr(1);
// m
float m=0;
float sum1,sum2,sum3,sum4 = 0;
for(auto z : S){
sum1 += z.first * z.second;
sum2 += z.first;
sum3 += z.second;
sum4 += pow(z.first,2);
}
float sumM = ((n*(sum1)) - (sum2 * sum3))/ ((n*(sum4)) - pow(sum2,2));
// b
float s1,s2 = 0.0;
for(auto y : S){
s1 += y.second;
s2 += y.first;
}
float sb = (s1 - (sumM * s2))/ n;
float A = round(sumM*1e3)/1e3;
float B = round(sb * 1e3)/1e3 ;
cout << A << endl;
cout << B << endl;
}
if(oper == "func")
{
float m=0;
float sum1,sum2,sum3,sum4 = 0;
for(auto z : S){
sum1 += z.first * z.second;
sum2 += z.first;
sum3 += z.second;
sum4 += pow(z.first,2);
}
float sumM = ((n*(sum1)) - (sum2 * sum3))/ ((n*(sum4)) - pow(sum2,2));
// b
float s1,s2 = 0.0;
for(auto y : S){
s1 += y.second;
s2 += y.first;
}
float sb = (s1 - (sumM * s2))/ n;
float A = round(sumM*1e3)/1e3;
float B = round(sb * 1e3)/1e3 ;
if(B == 0){
cout << "y = "<< A << x;
}
if(A == 0){
cout << "y = "<< B ;
}
if(sb == 0 && sumM == 0){
cout << "y = 0" << endl;
}
}
} |
# 1497, 2024-11-02 15:10:51, Compilation error (0%)
#include <bits/stdc++.h>
using namespace std;
float funm(int n,map<long long,float> x,map<long long,float> y){
float m=0,;
for(int i=1;i<=n;i++){
m += (n*(x[i]*y[i])-(x[i]*y[i]))/((n*pow(x[i],2))-pow(x[i],2));
}
return m;
}
float funb(int n,map<long long,float> x,map<long long,float> y){
float b=0;
for(int i=1;i<=n;i++){
b += (y[i]-(funm(n,x,y)*x[i]))/n;
}
return b;
}
int main(){
int n;
string code;
cin >> n >> code;
float x,y,m,b;
map<long long,float> xi,yi;
for(int i=1;i<=n;i++){
cin >> x >> y ;
xi[i]=x;
yi[i]=y;
}
if(code=="mb"){
cout << funm(n,xi,yi);
cout << funb(n,xi,yi);
}
} | # 1498, 2024-11-02 15:11:13, ------------------------ (0%)
#include <bits/stdc++.h>
using namespace std;
float funm(int n,map<long long,float> x,map<long long,float> y){
float m=0;
for(int i=1;i<=n;i++){
m += (n*(x[i]*y[i])-(x[i]*y[i]))/((n*pow(x[i],2))-pow(x[i],2));
}
return m;
}
float funb(int n,map<long long,float> x,map<long long,float> y){
float b=0;
for(int i=1;i<=n;i++){
b += (y[i]-(funm(n,x,y)*x[i]))/n;
}
return b;
}
int main(){
int n;
string code;
cin >> n >> code;
float x,y,m,b;
map<long long,float> xi,yi;
for(int i=1;i<=n;i++){
cin >> x >> y ;
xi[i]=x;
yi[i]=y;
}
if(code=="mb"){
cout << funm(n,xi,yi);
cout << funb(n,xi,yi);
}
} | # 1499, 2024-11-02 15:32:37, -----P------------------ (4%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
string code;
cin >> n >> code;
float x,y,m=0,b=0;
for(int i=0;i<n;i++){
cin >> x >> y;
m += ((n*x*y)-(x*y))/((n*pow(x,2))-pow(x,2));
b += (y-(m*x))/n;
}
if(code == "mb"){
cout << m<<endl;
cout << b<<endl;
}
} |
# 1500, 2024-11-02 10:30:28, ------------------------ (0%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
string s;
vector<float> x,y;
cin>>N>>s;
for(int i=0;i<N;i++){
float a,b;
cin>>a>>b;
pair p=make_pair(a,b);
x.push_back(a);
y.push_back(b);
}
int m=0,m1=0,m2=0,m3=0,m4=0,m5=0;
for(int i=1;i<N;i++){
m1+= x[i]*y[i];
}
for(int i=1;i<N;i++) m2+=x[i];
for(int i=1;i<N;i++) m3+=y[i];
for(int i=1;i<N;i++) m4+=x[i]*x[i];
for(int i=1;i<N;i++) m5+=x[i];
m = (N*m1-(m2*m3))/ (m4*N) - (m5*m5);
int b=0,b1=0,b2=0;
for(int i=1;i<N;i++) b1+=y[i];
for(int i=1;i<N;i++) b2+=x[i];
b = (b1+b2)/N;
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
return 0;
} | # 1501, 2024-11-02 11:17:54, -------P---------------- (4%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
string s;
vector<float> x,y;
cin>>N>>s;
for(int i=0;i<N;i++){
float a,b;
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
int m=0,m1=0,m2=0,m3=0,m4=0,m5=0;
for(int i=1;i<N;i++){
m1+= x[i]*y[i];
}
for(int i=1;i<N;i++) m2+=x[i];
for(int i=1;i<N;i++) m3+=y[i];
for(int i=1;i<N;i++) m4+=x[i]*x[i];
for(int i=1;i<N;i++) m5+=x[i];
m = (N*m1-(m2*m3)) / ((m4*N) - (m5*m5));
int b=0,b1=0,b2=0;
for(int i=1;i<N;i++) b1+=y[i];
for(int i=1;i<N;i++) b2+=x[i];
b = (b1+b2)/N;
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
return 0;
} | # 1502, 2024-11-02 12:10:46, -------P---------------- (4%)
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
string s;
vector<float> x,y;
cin>>N>>s;
for(int i=0;i<N;i++){
float a,b;
cin>>a>>b;
x.push_back(a);
y.push_back(b);
}
int m=0,m1=0,m2=0,m3=0,m4=0,m5=0;
for(int i=0;i<N;i++){
m1+= x[i]*y[i];
}
for(int i=0;i<N;i++) m2+=x[i];
for(int i=0;i<N;i++) m3+=y[i];
for(int i=0;i<N;i++) m4+=x[i]*x[i];
for(int i=0;i<N;i++) m5+=x[i];
m = (N*m1-(m2*m3)) / ((m4*N) - (m5*m5));
int b=0,b1=0,b2=0;
for(int i=0;i<N;i++) b1+=y[i];
for(int i=0;i<N;i++) b2+=x[i];
b = (b1+b2)/N;
cout<<round(m*1e3)/1e3<<endl<<round(b*1e3)/1e3;
return 0;
} |
# 1503, 2024-11-02 13:56:22, ------------------------ (0%)
#include<iostream>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<utility>
#include<algorithm>
using namespace std;
int main(){
float N,x,y,m,b; string a;
vector<float> mx;
vector<float> my;
vector<float> ans1;vector<float> ans2;
cin >> N >> a;
while(N--){
cin >> x >> y;
mx.push_back(x);
my.push_back(y);
}
for(auto c: mx){
for(auto j: my){
m = (N*(c+j)) - (c*j)/ ((N*(c*j)) - (c*j));
ans1.push_back(m);
b = (y - (c*j)) / N;
ans2.push_back(b);
}
}
if(a == "mb"){
cout << m << endl;
cout << b << endl;
}
if(a == "func"){
y = (m*x) + b;
cout << y;
}
} | # 1504, 2024-11-02 14:25:10, -----P------------------ (4%)
#include<iostream>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<utility>
#include<algorithm>
using namespace std;
int main(){
float N,x,y,m,b; string a;
cin >> N >> a;
while(N--){
cin >> x >> y;
}
for(int i=1;i<N ;i++){
m = (N*((x*i)*(y*i))) - ((x*i)*(y*i))/ (N*((x*i)*(x*i))) - ((x*i)*(x*i));
b = ((y*i) - (m*(x*i))) / N;
}
if(a == "mb"){
cout << m << endl;
cout << b << endl;
}
if(a == "func"){
y = (m*x) + b;
cout << y;
}
} |
# 1505, 2024-11-02 15:16:58, ------------------------ (0%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
int n;
float x, y;
float m, b;
string com;
vector<float> allx;
vector<float> ally;
cin >> n >> com;
while(n--){
cin >> x >> y;
allx.push_back(x);
ally.push_back(y);
}
if(com == "mb"){
float sum1= 0.00, sum2 = 0.00, sum3 = 0.00, sum4 = 0.00, sum5;
//sum1
for(int i = 1; i < n; i++){
sum1 += allx[i]*ally[i];
}
//sum2
for(int i = 1; i < n; i ++){
sum2 += allx[i];
}
//sum3
for(int i = 1; i < n; i++){
sum3 += ally[i];
}
//sum4
for(int i = 1; i < n; i ++){
sum4 += allx[i] * allx[i];
}
//sum5
sum5 = sum2 * sum2;
m = ((n*sum1) - (sum2*sum3))/((n*sum4) - sum5);
b = (sum3 - sum2) / n;
cout << round(m * 1e3)/1e3 << endl;
cout << round(b * 1e3)/1e3 << endl;
}
if(com == "func"){
}
} | # 1506, 2024-11-02 15:31:02, ---------------P-------- (4%)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
int n;
float x, y;
float m, b;
string com;
vector<float> allx;
vector<float> ally;
cin >> n >> com;
while(n--){
cin >> x >> y;
allx.push_back(x);
ally.push_back(y);
}
if(com == "mb"){
float sum1= 0.00, sum2 = 0.00, sum3 = 0.00, sum4 = 0.00, sum5;
//sum1
for(int i = 1; i < n; i++){
sum1 += allx[i]*ally[i];
}
//sum2
for(int i = 1; i < n; i ++){
sum2 += allx[i];
}
//sum3
for(int i = 1; i < n; i++){
sum3 += ally[i];
}
//sum4
for(int i = 1; i < n; i ++){
sum4 += allx[i] * allx[i];
}
//sum5
sum5 = sum2 * sum2;
m = ((n*sum1) - (sum2*sum3))/((n*sum4) - sum5);
b = (sum3 - sum2) / n;
cout << round(m * 1e3)/1e3 << endl;
cout << round(b * 1e3)/1e3 << endl;
}
if(com == "func"){
int sumy = 0, sumx = 0;
for(auto& e : ally){
sumy += e;
}
for(auto& r : ally){
sumx += r;
}
if(sumy == 0){
cout << "y = 0";
}
else if(sumy < 0 && sumx != sumy){
cout << "y =" << sumy;
}
else if(sumx == sumy){
cout << "x = y";
}
}
} |
# 1507, 2024-11-02 15:08:26, -----P------------------ (4%)
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
using namespace std;
int main(){
int n;
cin >> n;
string type;
cin >> type;
vector <float> x,y;
while (n--){
float xx, yy;
cin >> xx >> yy;
x.push_back(xx);
y.push_back(yy);
}
//m
float m1 = 0;
float m2 = 0;
float m3 = 0;
float m4 = 0;
float m5 = 0;
for(int i = 1; i < n; i++){
m1 += x[i] * y[i];
}
for(int i = 1; i < n; i++){
m2 += x[i];
}
for(int i = 1; i < n; i++){
m3 += y[i];
}
for(int i = 1; i < n; i++){
m4 += pow(x[i],2);
}
for(int i = 1; i < n; i++){
m5 += x[i];
}
if(((n * m4) - (pow(m5,2))) != 0){
cout << ( (n*m1) - (m2*m3) )/ ((n * m4) - (pow(m5,2)));
}else{
cout << "0" << endl << "0";
}
if(n == 0){
cout << "0" << endl;
}else{
}
} | # 1508, 2024-11-02 15:30:20, ------------------------ (0%)
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
using namespace std;
int main(){
int n;
cin >> n;
string type;
cin >> type;
vector <int> x;
vector <int> y;
//m
int m1 ;
float m2;
float m3;
float m4;
float m5;
while (n--){
float xx, yy;
cin >> xx >> yy;
//cout << xx ;
x.push_back(xx);
y.push_back(yy);
}
// cout << "e: "<< x[1] << endl;
for(int i = 0; i < y.size(); i++){
cout << y[i] << " ";
}
cout << endl;
for(int i = 1; i < n; i++){
m1 += x[i] * y[i];
}
for(int i = 1; i < n; i++){
m2 += x[i];
}
for(int i = 1; i < n; i++){
m3 += y[i];
}
for(int i = 1; i < n; i++){
m4 += pow(x[i],2);
}
for(int i = 1; i < n; i++){
m5 += x[i];
}
//cout << m1 << " " << m2 << " " << m3 << " " << m4 << " " << m5;
if(((n * m4) - (pow(m5,2))) != 0){
//cout << " ---->";
cout << ( (n*m1) - (m2*m3) )/ ((n * m4) - (pow(m5,2)));
}else{
cout << "; 0" << endl;
}
} |
# 1509, 2024-11-02 13:21:26, xxxxxxxxxxxxxxxxxxxxxxxx (0%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std ;
int main() {
int n ;
string s ;
float x , y , m , b ;
float sumx = 0.0 , sumy = 0.0 , sumxy = 0.0 , sumx2 = 0.0 ;
vector<int> xi , yi ;
xi[0] = 0 ;
yi[0] = 0 ;
cin >> n >> s ;
while (n--) {
cin >> x >> y ;
xi.push_back(x) ;
yi.push_back(y) ;
}
for (int i = 1 ; i <= xi.size() ; i++) {
sumx += xi[i] ;
}
for (int i = 1 ; i <= yi.size() ; i++) {
sumy += yi[i] ;
}
for (int i = 1 ; i <= yi.size() ; i++) {
sumxy += xi[i] * yi[i] ;
}
for (int i = 1 ; i <= xi.size() ; i++) {
sumx2 += pow(xi[i],2) ;
}
m = ((n*sumxy) - (sumx*sumy))/((n*sumx2) - pow(sumx,2)) ;
b = (sumy - (n*sumx))/n ;
if (s == "mb") {
cout << m << endl << b ;
} else if (s == "func") {
cout << 0 ;
}
} | # 1510, 2024-11-02 13:23:37, xxxxxxxxxxxxxxxxxxxxxxxx (0%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std ;
int main() {
int n ;
string s ;
float x , y , m , b ;
float sumx = 0.0 , sumy = 0.0 , sumxy = 0.0 , sumx2 = 0.0 ;
vector<int> xi , yi ;
xi[0] = 0 ;
yi[0] = 0 ;
cin >> n >> s ;
while (n--) {
cin >> x >> y ;
xi.push_back(x) ;
yi.push_back(y) ;
}
for (int i = 1 ; i <= xi.size() ; i++) {
sumx += xi[i] ;
}
for (int i = 1 ; i <= yi.size() ; i++) {
sumy += yi[i] ;
}
for (int i = 1 ; i <= yi.size() ; i++) {
sumxy += xi[i] * yi[i] ;
}
for (int i = 1 ; i <= xi.size() ; i++) {
sumx2 += pow(xi[i],2) ;
}
m = ((n*sumxy) - (sumx*sumy))/((n*sumx2) - pow(sumx,2)) ;
b = (sumy - (n*sumx))/n ;
if (s == "mb") {
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 ;
} else if (s == "func") {
cout << 0 ;
}
} | # 1511, 2024-11-02 13:24:53, xxxxxxxxxxxxxxxxxxxxxxxx (0%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std ;
int main() {
int n ;
string s ;
float x , y , m , b ;
float sumx = 0.0 , sumy = 0.0 , sumxy = 0.0 , sumx2 = 0.0 ;
vector<int> xi , yi ;
xi[0] = 0 ;
yi[0] = 0 ;
cin >> n >> s ;
while (n--) {
cin >> x >> y ;
xi.push_back(x) ;
yi.push_back(y) ;
}
for (int i = 1 ; i <= xi.size() ; i++) {
sumx += xi[i] ;
}
for (int i = 1 ; i <= yi.size() ; i++) {
sumy += yi[i] ;
}
for (int i = 1 ; i <= yi.size() ; i++) {
sumxy += xi[i] * yi[i] ;
}
for (int i = 1 ; i <= xi.size() ; i++) {
sumx2 += pow(xi[i],2) ;
}
m = ((n*sumxy) - (sumx*sumy))/((n*sumx2) - pow(sumx,2)) ;
b = (sumy - (m*sumx))/n ;
if (s == "mb") {
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 ;
} else if (s == "func") {
cout << 0 ;
}
} | # 1512, 2024-11-02 13:25:29, xxxxxxxxxxxxxxxxxxxxxxxx (0%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std ;
int main() {
int n ;
string s ;
float x , y , m , b ;
float sumx = 0.0 , sumy = 0.0 , sumxy = 0.0 , sumx2 = 0.0 ;
vector<float> xi , yi ;
xi[0] = 0 ;
yi[0] = 0 ;
cin >> n >> s ;
while (n--) {
cin >> x >> y ;
xi.push_back(x) ;
yi.push_back(y) ;
}
for (int i = 1 ; i <= xi.size() ; i++) {
sumx += xi[i] ;
}
for (int i = 1 ; i <= yi.size() ; i++) {
sumy += yi[i] ;
}
for (int i = 1 ; i <= yi.size() ; i++) {
sumxy += xi[i] * yi[i] ;
}
for (int i = 1 ; i <= xi.size() ; i++) {
sumx2 += pow(xi[i],2) ;
}
m = ((n*sumxy) - (sumx*sumy))/((n*sumx2) - pow(sumx,2)) ;
b = (sumy - (m*sumx))/n ;
if (s == "mb") {
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 ;
} else if (s == "func") {
cout << 0 ;
}
} | # 1513, 2024-11-02 13:27:49, xxxxxxxxxxxxxxxxxxxxxxxx (0%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std ;
int main() {
float n ;
string s ;
float x , y , m , b ;
float sumx = 0.0 , sumy = 0.0 , sumxy = 0.0 , sumx2 = 0.0 ;
vector<float> xi , yi ;
xi[0] = 0 ;
yi[0] = 0 ;
cin >> n >> s ;
while (n--) {
cin >> x >> y ;
xi.push_back(x) ;
yi.push_back(y) ;
}
for (int i = 1 ; i < xi.size() ; i++) {
sumx += xi[i] ;
}
for (int i = 1 ; i < yi.size() ; i++) {
sumy += yi[i] ;
}
for (int i = 1 ; i < yi.size() ; i++) {
sumxy += xi[i] * yi[i] ;
}
for (int i = 1 ; i < xi.size() ; i++) {
sumx2 += pow(xi[i],2) ;
}
m = ((n*sumxy) - (sumx*sumy))/((n*sumx2) - pow(sumx,2)) ;
b = (sumy - (m*sumx))/n ;
if (s == "mb") {
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 ;
} else if (s == "func") {
//
}
} | # 1514, 2024-11-02 13:27:53, xxxxxxxxxxxxxxxxxxxxxxxx (0%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std ;
int main() {
float n ;
string s ;
float x , y , m , b ;
float sumx = 0.0 , sumy = 0.0 , sumxy = 0.0 , sumx2 = 0.0 ;
vector<float> xi , yi ;
xi[0] = 0 ;
yi[0] = 0 ;
cin >> n >> s ;
while (n--) {
cin >> x >> y ;
xi.push_back(x) ;
yi.push_back(y) ;
}
for (int i = 1 ; i < xi.size() ; i++) {
sumx += xi[i] ;
}
for (int i = 1 ; i < yi.size() ; i++) {
sumy += yi[i] ;
}
for (int i = 1 ; i < yi.size() ; i++) {
sumxy += xi[i] * yi[i] ;
}
for (int i = 1 ; i < xi.size() ; i++) {
sumx2 += pow(xi[i],2) ;
}
m = ((n*sumxy) - (sumx*sumy))/((n*sumx2) - pow(sumx,2)) ;
b = (sumy - (m*sumx))/n ;
if (s == "mb") {
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 ;
} else if (s == "func") {
//
}
} | # 1515, 2024-11-02 13:32:13, xxxxxxxxxxxxxxxxxxxxxxxx (0%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std ;
int main() {
float n ;
string s ;
float x , y , m , b ;
float sumx = 0.0 , sumy = 0.0 , sumxy = 0.0 , sumx2 = 0.0 ;
vector<float> xi , yi ;
xi[0] = 0.0 ;
yi[0] = 0.0 ;
cin >> n >> s ;
while (n--) {
cin >> x >> y ;
xi.push_back(x) ;
yi.push_back(y) ;
}
for (int i = 1 ; i < xi.size() ; i++) {
sumx += xi[i] ;
}
for (int i = 1 ; i < yi.size() ; i++) {
sumy += yi[i] ;
}
for (int i = 1 ; i < xi.size() ; i++) {
for (int j = 1 ; j < yi.size() ; j++) {
sumxy += xi[i] * yi[i] ;
}
}
for (int i = 1 ; i < xi.size() ; i++) {
sumx2 += pow(xi[i],2) ;
}
m = ((n*sumxy) - (sumx*sumy))/((n*sumx2) - pow(sumx,2)) ;
b = (sumy - (m*sumx))/n ;
if (s == "mb") {
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 ;
} else if (s == "func") {
//
}
} | # 1516, 2024-11-02 13:32:55, xxxxxxxxxxxxxxxxxxxxxxxx (0%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std ;
int main() {
float n ;
string s ;
float x , y , m , b ;
float sumx = 0.0 , sumy = 0.0 , sumxy = 0.0 , sumx2 = 0.0 ;
vector<float> xi , yi ;
xi[0] = 0.0 ;
yi[0] = 0.0 ;
cin >> n >> s ;
while (n--) {
cin >> x >> y ;
xi.push_back(x) ;
yi.push_back(y) ;
}
for (int i = 1 ; i < xi.size() ; i++) {
sumx += xi[i] ;
}
for (int i = 1 ; i < yi.size() ; i++) {
sumy += yi[i] ;
}
for (int i = 1 ; i < xi.size() ; i++) {
for (int j = 1 ; j < yi.size() ; j++) {
sumxy += xi[i] * yi[j] ;
}
}
for (int i = 1 ; i < xi.size() ; i++) {
sumx2 += pow(xi[i],2) ;
}
m = ((n*sumxy) - (sumx*sumy))/((n*sumx2) - pow(sumx,2)) ;
b = (sumy - (m*sumx))/n ;
if (s == "mb") {
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 ;
} else if (s == "func") {
//
}
} | # 1517, 2024-11-02 13:48:29, xxxxxxxxxxxxxxxxxxxxxxxx (0%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std ;
int main() {
float n ;
string s ;
float x , y , m , b ;
float sumx = 0.0 , sumy = 0.0 , sumxy = 0.0 , sumx2 = 0.0 ;
vector<float> xi , yi ;
xi[0] = 0.0 ;
yi[0] = 0.0 ;
cin >> n >> s ;
while (n--) {
cin >> x >> y ;
xi.push_back(x) ;
yi.push_back(y) ;
}
for (int i = 1 ; i <= n ; i++) {
sumx += xi[i] ;
}
for (int i = 1 ; i <= n ; i++) {
sumy += yi[i] ;
}
for (int i = 1 ; i <= n ; i++) {
for (int j = 1 ; j <= n ; j++) {
sumxy += xi[i] * yi[j] ;
}
}
for (int i = 1 ; i <= n ; i++) {
sumx2 += pow(xi[i],2) ;
}
m = ((n*sumxy) - (sumx*sumy))/((n*sumx2) - pow(sumx,2)) ;
b = (sumy - (m*sumx))/n ;
if (s == "mb") {
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 ;
} else if (s == "func") {
//
}
} | # 1518, 2024-11-02 15:00:12, xxxxxxxxxxxxxxxxxxxxxxxx (0%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std ;
int main() {
float n ;
string s ;
float x , y , m , b ;
float sumx = 0.0 , sumy = 0.0 , sumxy = 0.0 , sumx2 = 0.0 ;
vector<float> xi , yi ;
xi[0] = 0.0 ;
yi[0] = 0.0 ;
cin >> n >> s ;
while (n--) {
cin >> x >> y ;
xi.push_back(x) ;
yi.push_back(y) ;
}
for (int i = 1 ; i <= n ; i++) {
sumx += xi[i] ;
}
for (int i = 1 ; i <= n ; i++) {
sumy += yi[i] ;
}
for (int i = 1 ; i <= n ; i++) {
for (int j = 1 ; j <= n ; j++) {
sumxy += xi[i] * yi[j] ;
}
}
for (int i = 1 ; i <= n ; i++) {
sumx2 += pow(xi[i],2) ;
}
m = ((n*sumxy) - (sumx*sumy))/((n*sumx2) - pow(sumx,2)) ;
b = (sumy - (m*sumx))/n ;
if (s == "mb") {
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl ;
}
} | # 1519, 2024-11-02 15:18:26, xxxxxxxxxxxxxxxxxxxxxxxx (0%)
#include <iostream>
#include <cmath>
#include <vector>
using namespace std ;
int main() {
float n ;
string s ;
float x , y , m , b ;
float sumx = 0.0 , sumy = 0.0 , sumxy = 0.0 , sumx2 = 0.0 ;
vector<float> xi , yi ;
xi[0] = 0.0 ;
yi[0] = 0.0 ;
cin >> n >> s ;
while (n--) {
cin >> x >> y ;
xi.push_back(x) ;
yi.push_back(y) ;
}
for (int i = 1 ; i <= n ; i++) {
sumx += xi[i] ;
}
for (int i = 1 ; i <= n ; i++) {
sumy += yi[i] ;
}
for (int i = 1 ; i <= n ; i++) {
for (int j = 1 ; j <= n ; j++) {
sumxy += xi[i] * yi[j] ;
}
}
for (int i = 1 ; i <= n ; i++) {
sumx2 += pow(xi[i],2) ;
}
m = ((n*sumxy) - (sumx*sumy))/((n*sumx2) - pow(sumx,2)) ;
b = (sumy - (m*sumx))/n ;
if (s == "mb") {
cout << round(m*1e3)/1e3 << endl << round(b*1e3)/1e3 << endl ;
} else if (s == "func") {
cout << "y = " << m << "x + " << b ;
}
} |
# 1520, 2024-11-02 10:50:24, ------------------------ (0%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
string mb, func, select;
float final_m = 0.0, final_b = 0.0;
float sum1 = 0.0, sum2 = 0.0, sum3 = 0.0, sum4 = 0.0, sum5 = 0.0;
float x, y;
int N;
vector<pair<float, float>> xy;
cin >> N >> select;
cout << N << " "<<select;
while ((cin >> x >> y))
{
xy.push_back(make_pair(x, y));
}
for (auto e : xy)
{
{
sum1 += (e.first * e.second);
}
for (int i = 1; i <= N; i++)
{
sum2 += e.first;
}
for (int i = 1; i <= N; i++)
{
sum3 += e.second;
}
for (int i = 1; i <= N; i++)
{
sum4 += pow(e.first, 2);
}
for (int i = 1; i <= N; i++)
{
sum5 += e.first;
}
}
cout << sum1 ;
if(select == "mb")
{
final_m = ((N * sum1) - (sum2 * sum3)) / (N * sum4) - pow(sum5, 2);
cout << final_m <<endl;
final_b = (sum3 - (final_m * (sum2))) / N;
cout << final_b;
}
}
// if (select == "mb")
// {
// final_m = ((N * f_sum1) - (f_sum2 * f_sum3)) / (N * f_sum4) - pow(f_sum5, 2);
// final_b = (f_sum3 - (final_m * (f_sum2))) / N;
// cout << final_m << endl;
// cout << final_b << endl;
// }
// if(select == "func")
// {
// } | # 1521, 2024-11-02 10:50:50, ------------------------ (0%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
string mb, func, select;
float final_m = 0.0, final_b = 0.0;
float sum1 = 0.0, sum2 = 0.0, sum3 = 0.0, sum4 = 0.0, sum5 = 0.0;
float x, y;
int N;
vector<pair<float, float>> xy;
cin >> N >> select;
cout << N << " "<<select;
while ((cin >> x >> y))
{
xy.push_back(make_pair(x, y));
}
for (auto e : xy)
{
{
sum1 += (e.first * e.second);
}
for (int i = 1; i <= N; i++)
{
sum2 += e.first;
}
for (int i = 1; i <= N; i++)
{
sum3 += e.second;
}
for (int i = 1; i <= N; i++)
{
sum4 += pow(e.first, 2);
}
for (int i = 1; i <= N; i++)
{
sum5 += e.first;
}
}
cout << sum1 ;
if(select == "mb")
{
final_m = ((N * sum1) - (sum2 * sum3)) / (N * sum4) - pow(sum5, 2)*0;
cout << final_m <<endl;
final_b = (sum3 - (final_m * (sum2))) / N*0;
cout << final_b;
}
}
// if (select == "mb")
// {
// final_m = ((N * f_sum1) - (f_sum2 * f_sum3)) / (N * f_sum4) - pow(f_sum5, 2);
// final_b = (f_sum3 - (final_m * (f_sum2))) / N;
// cout << final_m << endl;
// cout << final_b << endl;
// }
// if(select == "func")
// {
// } | # 1522, 2024-11-02 10:51:17, ------------------------ (0%)
#include <bits/stdc++.h>
using namespace std;
int main()
{
string mb, func, select;
float final_m = 0.0, final_b = 0.0;
float sum1 = 0.0, sum2 = 0.0, sum3 = 0.0, sum4 = 0.0, sum5 = 0.0;
float x, y;
int N;
vector<pair<float, float>> xy;
cin >> N >> select;
cout << N << " "<<select;
while ((cin >> x >> y))
{
xy.push_back(make_pair(x, y));
}
for (auto e : xy)
{
{
sum1 += (e.first * e.second);
}
for (int i = 1; i <= N; i++)
{
sum2 += e.first;
}
for (int i = 1; i <= N; i++)
{
sum3 += e.second;
}
for (int i = 1; i <= N; i++)
{
sum4 += pow(e.first, 2);
}
for (int i = 1; i <= N; i++)
{
sum5 += e.first;
}
}
cout << sum1 ;
if(select == "mb")
{
final_m = ((N * sum1) - (sum2 * sum3)) / (N * sum4) - pow(sum5, 2);
cout << 0<<endl;
final_b = (sum3 - (final_m * (sum2))) / N;
cout << 0;
}
}
// if (select == "mb")
// {
// final_m = ((N * f_sum1) - (f_sum2 * f_sum3)) / (N * f_sum4) - pow(f_sum5, 2);
// final_b = (f_sum3 - (final_m * (f_sum2))) / N;
// cout << final_m << endl;
// cout << final_b << endl;
// }
// if(select == "func")
// {
// } |
# 1523, 2024-11-02 10:51:28, ------------------------ (0%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int n ;
string type;
cin >> n >> type;
vector<float> v(n);
vector<float> c(n);
for(int i=0;i<n;i++){
float xi,yi;
cin >> xi >> yi;
v.push_back(xi);
c.push_back(yi);
}
if (type=="mb"){
float m=0;
float b=0;
for(int i=0; i<n ;i++){
m+=((n*(v[i]*c[i]))-(v[i]*c[i])) /
(n*(pow(v[i],2)))-(pow(v[i],2));
}
for(int i=1;i<n;i++){
b+=(c[i]-(m*v[i]))/n;
}
cout << m << b;
}
} | # 1524, 2024-11-02 11:27:11, ------------------------ (0%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int n ;
string type;
cin >> n >> type;
vector<float> v;
vector<float> c;
for(int i=0;i<n;i++){
float xi,yi;
cin >> xi >> yi;
v.push_back(xi);
c.push_back(yi);
}
if (type=="mb"){
float m=0;
float b=0;
for(int i=0; i<n ;i++){
m+=((n*(v[i]*c[i]))-(v[i]*c[i])) /
(n*(pow(v[i],2)))-(pow(v[i],2));
}
for(int i=1;i<n;i++){
b+=(c[i]-(m*v[i]))/n;
}
cout << m << endl << b;
}
} | # 1525, 2024-11-02 11:29:47, ------------------------ (0%)
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int n ;
string type;
cin >> n >> type;
vector<float> v;
vector<float> c;
for(int i=0;i<n;i++){
float xi,yi;
cin >> xi >> yi;
v.push_back(xi);
c.push_back(yi);
}
if (type=="mb"){
float m=0;
float b=0;
for(int i=0; i<n ;i++){
m+=((n*(v[i]*c[i]))-(v[i]*c[i])) /
(n*(pow(v[i],2)))-(pow(v[i],2));
}
for(int i=1;i<n;i++){
b+=(c[i]-(m*v[i]))/n;
}
cout << round(m * 1e3)/1e3<< endl << round(b * 1e3)/1e3;
}
} |
# 1526, 2024-11-02 13:21:55, Compilation error (0%)
#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n;
cin >> n;
string ctd;
cin >> ctd;
float x,c;
float m=0, b=0;
float n=0
float
float pow_x=0
float xy=0
cout<<m<<endl;
cout<<b<<endl;
return 0;
} | # 1527, 2024-11-02 14:48:58, Compilation error (0%)
include <bits/stdc++.h>
#include <iostream>
#include <cmath>
using namespace std;
int main(){
vector<pair<string,string >> list;
string id,grade;
else if (m == 1 && b == 0){
cout << "y=0";
}
else if (m == 1 && b == 1){
cout << "x=0";
}
else if (m == 1 && b == 1){
cout << "x=0";
}
else if (m == 1 && b == 1){
cout << "x=0";
}
return 0;
} |
# 1528, 2024-11-02 15:31:40, ------------------------ (0%)
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct Student{
int score;
string name;
};
bool CompareStudent(const Student & a,const Student & b){
if (a.score == b.score) return a.name < b.name;
return a.score > b.score;
}
int main(){
int N,M;
cin >> N;
vector<Student>Students(N);
for (int i=0;i<N;i++){
cin >> Students[i].name >> Students[i].score;
}
cin >> M;
sort(Students.begin(),Students.end(),CompareStudent);
for (int i=0;i<M && N<Students.size();i++){
cout << Students[i].name <<" "<<Students[i].score<<endl;
}
} | # 1529, 2024-11-02 15:31:57, ------------------------ (0%)
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct Student{
int score;
string name;
};
bool CompareStudent(const Student & a,const Student & b){
if (a.score == b.score) return a.name < b.name;
return a.score > b.score;
}
int main(){
int N,M;
cin >> N;
vector<Student>Students(N);
for (int i=0;i<N;i++){
cin >> Students[i].name >> Students[i].score;
}
cin >> M;
sort(Students.begin(),Students.end(),CompareStudent);
for (int i=0;i<M && i<Students.size();i++){
cout << Students[i].name <<" "<<Students[i].score<<endl;
}
} |
# 1530, 2024-11-02 10:35:12, ------------------------ (0%)
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
float findm (vector<pair<float,float>> variablesXY, int N){
float m,topleft,topright1,topright2,bottomleft,bottomright;
for (int i = 1; i < N; i++){
topleft += (variablesXY[i].first)*(variablesXY[i].second);
topright1 += variablesXY[i].first;
topright2 += variablesXY[i].second;
bottomleft += pow(variablesXY[i].first,2);
}
topleft *= N;
bottomleft *= N;
bottomright = pow(topright1,2);
m = (topleft-(topright1*topright2))/(bottomleft-bottomright);
return m;
}
float findb (vector<pair<float,float>> variablesXY, int N){
float b,topleft,topright;
for (int i = 1; i < N; i++){
topleft += variablesXY[i].second;
topright += variablesXY[i].first;
}
topright *= findm(variablesXY,N);
b = (topleft-topright)/N;
return b;
}
int main() {
int N;
bool ismb = true;
string command;
cin >> N >> command;
vector<pair<float,float>> variablesXY;
for (int i = 0; i < N; i++){
float Xinput,Yinput;
cin >> Xinput >> Yinput;
variablesXY.push_back({Xinput,Yinput});
}
if (ismb){
cout << findm(variablesXY,N) << endl;
cout << findb(variablesXY,N) << endl;
}
} | # 1531, 2024-11-02 10:45:28, ------------------------ (0%)
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
float findm (vector<pair<float,float>> variablesXY, int N){
float m,topleft,topright1,topright2,bottomleft,bottomright = 0;
for (int i = 1; i <= N; i++){
topleft += (variablesXY[i-1].first)*(variablesXY[i-1].second);
topright1 += variablesXY[i-1].first;
topright2 += variablesXY[i-1].second;
bottomleft += pow(variablesXY[i-1].first,2);
}
topleft *= N;
bottomleft *= N;
bottomright = pow(topright1,2);
m = (topleft-(topright1*topright2))/(bottomleft-bottomright);
return m;
}
float findb (vector<pair<float,float>> variablesXY, int N){
float b,topleft,topright = 0;
for (int i = 1; i <= N; i++){
topleft += variablesXY[i-1].second;
topright += variablesXY[i-1].first;
}
topright *= findm(variablesXY,N);
b = (topleft-topright)/N;
return b;
}
int main() {
int N = 0;
bool ismb = true;
string command;
cin >> N >> command;
vector<pair<float,float>> variablesXY;
for (int i = 0; i < N; i++){
float Xinput,Yinput;
cin >> Xinput >> Yinput;
variablesXY.push_back({Xinput,Yinput});
}
if (ismb){
cout << findm(variablesXY,N) << endl;
cout << findb(variablesXY,N) << endl;
}
} |
# 1532, 2024-11-02 14:19:06, ------------------------ (0%)
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<tuple>
#include<utility>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
int N,n;
string f;
double x,y;
cin>>N>>f;
vector<float>X;
vector<float>Y;
float zx ,zy;
float m,b;
float zxy,zpow;
n=N;
while(N--){
cin>>x>>y;
X.push_back(x);
Y.push_back(y);
}
//ZIGMA of x
for(int i=0; i<X.size();i++){
float p=X[i];
zx+=p;
}
//ZIGMA of y
for(int i=0; i<Y.size();i++){
float g=Y[i];
zy+=g;
}
//zigma of x*y
for(int i=0; i<X.size();i++){
float l=X[i]*Y[i];
zxy+=l;
}
//zigma of x 2
for(int i=0; i<X.size();i++){
float o=pow(X[i],2);
zpow+=o;
}
float t=(n*zxy)-(zx*zy);
float r=((n*zpow)-(pow(zx,2)));
m=t/r;
b=((zy-(m*zx)))/n;
///((n*zpow)-(pow(zx,2)))
if(f=="mb"){
cout<<zx<<" "<<zy<<" "<<zxy<<" "<<zpow<<endl;
cout<<round(m*1e3)/1e3;
cout<<endl;
cout<<round(b*1e3)/1e3;
}else if(f=="func"){
}
} |
# 1533, 2024-11-02 15:15:08, ------------------------ (0%)
#include <iostream>
#include <cmath>
using namespace std;
int main(){
float a, b, m, x, y, n, i, Ragnum;
string Rag;
bool RagBool = true;
cin >> Ragnum >> Rag;
if(Rag == "func"){
RagBool = false;
if(RagBool == false){
while(cin >> x >> y){
i++;
}
}
}else{
}
} |
# 1534, 2024-11-02 09:49:51, ------------------------ (0%)
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int n;
string type_n;
float x, y;
float m, b;
vector<float> tx;
vector<float> ty;
int main(){
cin >> n >> type_n;
while(n--){
cin >> x >> y;
tx.push_back(x);
ty.push_back(y);
}
//
float snt;
for(int i = 1; i < n; i++){
snt = n * (x,y);
}
float sxt;
for(int i = 1; i < n; i++){
sxt = x;
}
float sy;
for(int i = 1; i < n; i++){
sy = y;
}
float snd;
for(int i = 1; i < n; i++){
n * pow(x,2);
}
float sxd;
for(int i = 1; i < n; i++){
sxd = x;
}
m = (snt - (sxt*sy)) / snd - pow(sxd,2);
//
//
float bsy;
for(int i = 1; i < n; i++){
bsy = y;
}
float bsmy;
for(int i = 1; i < n; i++){
bsmy = m * x;
}
b = (bsy - bsmy) / n;
//
if(type_n == "mb"){
cout << m << endl;
cout << b << endl;
}
} |
# 1535, 2024-11-02 15:32:11, xxxxxxxxxxxxxxxxxxxxxxxx (0%)
#include<iostream>
#include<map>
#include<vector>
using namespace std;
int main() {
vector<pair<int,int>> Q1,Q2,Q3,Q4;
int x,y,n;
//set<pair<int,int>> point;
cin>>n;
while(n--){
cin>>x>>y;
if(x>0 &&y>0) {
Q1.push_back(make_pair(x,y));
}
if(x<0 &&y>0) {
Q2.push_back(make_pair(x,y));
}
if(x<0 &&y<0) {
Q3.push_back(make_pair(x,y));
}
if(x>0 &&y<0) {
Q4.push_back(make_pair(x,y));
}
}
int xmin=Q1[0].first,ymin=Q1[0].second,xmax=xmin,ymax=ymin;
for(auto c:Q1){
if(c.first>xmax) xmax==c.first;
if(c.second>ymax) ymax==c.second;
if(c.first<xmin) xmin==c.first;
if(c.second<ymin) ymin==c.second;
}
vector<pair<int,int>> min,max;
int tx=xmax-xmin;
int ty=ymax-ymin;
vector<int> pt;
pt.push_back(tx*ty);
min.push_back(make_pair(xmin,ymin));
max.push_back(make_pair(xmax,ymax));
for(auto c:Q2){
if(c.first>xmax) xmax==c.first;
if(c.second>ymax) ymax==c.second;
if(c.first<xmin) xmin==c.first;
if(c.second<ymin) ymin==c.second;
}
tx=xmax-xmin;
ty=ymax-ymin;
pt.push_back(tx*ty);
min.push_back(make_pair(xmin,ymin));
max.push_back(make_pair(xmax,ymax));
for(auto c:Q3){
if(c.first>xmax) xmax==c.first;
if(c.second>ymax) ymax==c.second;
if(c.first<xmin) xmin==c.first;
if(c.second<ymin) ymin==c.second;
}
tx=xmax-xmin;
ty=ymax-ymin;
pt.push_back(tx*ty);
min.push_back(make_pair(xmin,ymin));
max.push_back(make_pair(xmax,ymax));
for(auto c:Q4){
if(c.first>xmax) xmax==c.first;
if(c.second>ymax) ymax==c.second;
if(c.first<xmin) xmin==c.first;
if(c.second<ymin) ymin==c.second;
}
tx=xmax-xmin;
ty=ymax-ymin;
pt.push_back(tx*ty);
min.push_back(make_pair(xmin,ymin));
max.push_back(make_pair(xmax,ymax));
if(Q1.size()==0 && Q2.size()==0 && Q3.size()==0 && Q4.size()==0){
cout<<"No point in any quadrant";
}
else {
cout<<"Q1: ("<<min[0].first<<", "<<min[0].second<<") ";
cout<<"("<<max[0].first<<", "<<max[0].second<<") ";
cout<<pt[0]<<endl;
cout<<"Q2: ("<<min[1].first<<", "<<min[1].second<<") ";
cout<<"("<<max[1].first<<", "<<max[1].second<<") ";
cout<<pt[0]<<endl;
cout<<"Q3: ("<<min[2].first<<", "<<min[2].second<<") ";
cout<<"("<<max[2].first<<", "<<max[2].second<<") ";
cout<<pt[0]<<endl;
cout<<"Q4: ("<<min[3].first<<", "<<min[3].second<<") ";
cout<<"("<<max[3].first<<", "<<max[3].second<<") ";
cout<<pt[0]<<endl;
}
} |
# 1536, 2024-11-02 15:32:15, ------------------------ (0%)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
string p;
cin >> n ;
float x[n],y[n];
float m,s0,s1,s2,s3,s4;
if(cin >> p && p == "mb"){
for(int i=0; i<n; i++){
cin >> x[i] >> y[i];
s0 += n*(x[i]*y[i]);
s1 += x[i];
s2 += y[i];
s3 += n*(pow(x[i],2));
s4 += pow(s1,2);
m = (s0 - s1*s2) / s3-s4;
}
}
// cout << round(m*1e3)/1e3<<endl;
cout << s1 <<' ' <<s2;
} |