Skip to content

Instantly share code, notes, and snippets.

@cbdavide
Created January 20, 2019 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbdavide/a9cde6acd073a4cd389893ab74aa539b to your computer and use it in GitHub Desktop.
Save cbdavide/a9cde6acd073a4cd389893ab74aa539b to your computer and use it in GitHub Desktop.
UVa 10719 - Quotient Polynomial
#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