Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int,int>
- #define vec vector
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvl(vector <ll> &v){
- for (auto x: v) cout<<x<<'\n';
- cout<<"\n";
- }
- void cvv(vector <vector <int> > &v){
- for (auto x: v) cv(x);
- cout<<"\n";
- }
- void cvb(vector <bool> v){
- for (bool x: v) cout<<x<<' ';
- cout<<"\n";
- }
- vector <vector <bool> > num(10, vector <bool> (7, 1));// 1 - i-я палоча есть, 0 - нет
- vector <vector <int> > opr(10, vector <int> (10, 0)); //сколько операция нужно, чтобы перейти из числа a в число b
- ll mv(int x, int y){//move from num a to num b
- string a, b;
- a = to_string(x);
- b = to_string(y);
- ll res = 0;
- reverse(a.begin(), a.end());
- reverse(b.begin(), b.end());
- if (a.size() < b.size()) res += 2;
- for (int i = 0; i < a.size(); ++i){
- if (a[i] != b[i]){
- res += opr[a[i] - 48][b[i] - 48];
- }
- }
- return res;
- }
- vector <ll> pref(1e9+5, 0);
- int main()
- {
- /*ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);*/
- //представить все цифры в виде палочек
- vector <int> del;
- vector <vector<int> > del_al;
- del = {1};
- del_al.push_back(del);
- del = {0, 1, 2, 3, 4};
- del_al.push_back(del);
- del = {3, 6};
- del_al.push_back(del);
- del = {3, 4};
- del_al.push_back(del);
- del = {0, 2, 4};
- del_al.push_back(del);
- del = {4,5};
- del_al.push_back(del);
- del = {5,};
- del_al.push_back(del);
- del = {1, 2, 3, 4};
- del_al.push_back(del);
- del = {};
- del_al.push_back(del);
- del = {4};
- del_al.push_back(del);
- for (auto v: del_al){
- // cv(v);
- }
- for (int i = 0; i < 10;++i){
- for (int idx: del_al[i]){
- num[i][idx] = 0;
- }
- }
- //cout<<"HELLO\n";
- //for (auto v: num) cvb(v);
- //посчитали, сколько палочек менять для перехода между числами
- for (int i = 0; i < 10; ++i){
- //cout <<"i= "<<i<<"\n";
- for (int j=0;j<10;++j){
- //cout<<"j= "<<j<<"\n";
- //cout<<"a b = "<<i<<' '<<j<<"\n";
- for (int idx = 0; idx < 7; ++idx){
- //cout<<"idx = "<<idx<<"\n";
- //cout<<"a(idx) b(idx) == "<<num[i][idx]<<' '<<num[j][idx]<<"\n";
- if (num[i][idx] != num[j][idx]){
- opr[i][j]++;
- //cout<<idx<<' ';
- }
- }
- //cout<<"\n need to change = "<<opr[i][j]<<"\n";
- //cout<<"\n\n";
- }
- }
- //cvv(opr);
- /*int t; cin>>t;
- for (int i=0;i<t;++i){
- int a,b; cin>>a>>b;
- cout<<opr[a][b]<<"\n\n";
- }*/
- //1e9+2
- //cout<<"GO\n";
- cout<<"conting prefix\n";
- for (int i = 1; i <= 1e9+2;++i){
- //if (i >= 1e6) cout<<i<<" ";
- pref[i] = pref[i-1] + mv(i-1, i);
- }cout<<"\n cin numbers \n";
- int t; cin>>t;
- vector <ll> ans;
- for (int i=0;i<t;++i){
- int k ; cin>>k;
- //cout<<pref[k]<<"\n";
- ans.push_back(pref[k]);
- }
- cout<<"ANSWER\n";
- cvl(ans);
- cout<<"DONE! \n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement