By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
 428,601 Members | 989 Online + Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,601 IT Pros & Developers. It's quick & easy.

# Finalize the program

 P: 3 input with this test is true 10 # the number of digits in the bottom 4 2 2 2 2 2 # first digit number of degrees in this row -1 1 2 2 1 3 2 1 2 3 3 2 2 2 2 2 2 2 2 1 3 3 3 3 3 3 3 2 4 3 3 2 2 3 4 output 2 4 3 6 7 5 9 10 1 8 Here the task is to raise to a power and then compare their numbers to derive the index in the order of increasing numbers exponentiation is from the end 2 2 3 4 is raised as 3 ^ 4 = 81 Now 2 ^ 81 = 2417851639229258349412352 if you submit such numbers, it works incorrectly input 3 4 5 2 49 4 5 4 3 2 7 2 11 4 2 2 49 32 2 output 3 2 1 should be my conclusion 3 1 2 Expand|Select|Wrap|Line Numbers #include  #include    #include  #include  using namespace std;   class tower_t { public:     int num;      int height;      double val; // содержимое     double cache; // кэш для ускорения расчета       // Конструктор     tower_t() {         for (int i = 0; i < 11; i++) {             val[i] = 1;             cache[i] = 0;         }         height = 0;     }       // Тройной логарифм верхних 3-х уровней      double head(int level) {         if(cache[level] == 0) cache[level] = (log2(log2(val[level])) + log2(val[level + 1]) * val[level + 2]);         return cache[level];     }       // Вычисление верхушки до тех пока влазит в double     void normalize() {         while(height > 1 && (log2(val[height - 2]) * val[height - 1]) < 50) {             val[height - 2] = pow(val[height - 2], val[height - 1]);             val[height - 1] = 1;             height--;         }     }       // Вывод для отладки     void print() { #ifdef _DEBUG         printf("%2d: {", num);         for (int i = 0; i < height; i++) {             if (i > 0) printf(", ");             if(val[i] < 1000000000) {                 printf("%0.0f", val[i]);             } else {                 printf("%0.3e", val[i]);             }         }         printf("}\n"); #endif     } };   // сравнение двух  bool compare(tower_t& t1, tower_t& t2) {     // этаж с которого сравнивать три последних уровня     int level = ((t1.height > t2.height) ? t1.height : t2.height) - 3;     if (level < 0) level = 0;     if(t1.height == t2.height) { // если  одной высоты, сравниваем поэтажно         for (int i = t1.height - 1; i >= 0; i--) {             if (abs(t1.val[i] - t2.val[i]) > (t1.val[i] * 1e-14)) {                 if (i < level) { // верхи  совпали ниже level                     return t1.val[i] < t2.val[i];                 }                 break;             }         }     }     return t1.head(level) < t2.head(level); }   int main() {     // Считывание задания     ifstream in ("input.txt");     int cnt;     in >> cnt;     tower_t* towers = new tower_t[cnt];     for (int i = 0; i < cnt; i++) {         int len;         in >> len;         towers[i].num = i + 1;         bool write = true;         for (int j = 0; j <= len; j++) {             int val;             in >> val;             if (val <= 1) write = false; // если уровень <= 1 то выше не читать             if(write) {                 towers[i].val[j] = val;                 towers[i].height = j + 1;             }         }         towers[i].print();         towers[i].normalize();     }     // Сортировка     sort(towers, towers + cnt, compare);     // Вывод результата     ofstream out("output.txt");     for (int i = 0; i < cnt; i++) {         out << towers[i].num << " ";         towers[i].print();     }     out << endl;     out.close();     delete[] towers;     return 0; } Jun 3 '18 #1
Share this Question
1 Reply

 Expert Mod 5K+ P: 9,197 What is your question, exactly? Jun 3 '18 #2

### Post your reply

Sign in to post your reply or Sign up for a free account. 