Created
January 20, 2019 17:15
-
-
Save cbdavide/a9cde6acd073a4cd389893ab74aa539b to your computer and use it in GitHub Desktop.
UVa 10719 - Quotient Polynomial
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
#define F first | |
#define S second | |
#define endl '\n' | |
#define PB push_back | |
typedef long long ll; | |
typedef vector<ll> vll; | |
typedef pair<int, int> ii; | |
typedef vector<ii> vii; | |
typedef vector<int> vi; | |
const int oo = ~(1<<31); | |
bool cmp(ii a, ii b) { | |
if(a.F == b.F) return a.S > b.S; | |
return a.F < b.F; | |
} | |
int main() { | |
#ifndef CBDAVIDES | |
ios_base::sync_with_stdio(false); | |
cin.tie(NULL); | |
#endif | |
int k, a; | |
string line; | |
while(cin >> k) { | |
getline(cin, line); | |
getline(cin, line); | |
vi C, D; | |
stringstream ss(line); | |
while(ss >> a) C.PB(a); | |
k *= -1; | |
for(int i=0; i<(int)C.size()-1; i++) { | |
D.PB(C[i]); | |
C[i + 1] += -(C[i] * k); | |
C[i] = 0; | |
} | |
cout << "q(x):"; | |
for(int i : D) cout << " " << i; cout << endl; | |
cout << "r = " << C.back() << endl << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment