345 - It's Ir-Resist-Able!

All about problems in Volume 3. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
klopyrev
New poster
Posts: 8
Joined: Tue Dec 26, 2006 10:37 am

345 - It's Ir-Resist-Able!

Post by klopyrev » Fri May 11, 2007 4:43 am

General question... How would you solve this without using any knowledge outside of what is given in the problem statement. I mean without using all the advanced electricity laws. I've thought about it for quite a while and can't quite figure out how to do it. Please help me.

KL

metaphysis
Experienced poster
Posts: 128
Joined: Wed May 18, 2011 3:04 pm

Re: 345 - It's Ir-Resist-Able!

Post by metaphysis » Sun Feb 11, 2018 4:03 am

Test data generator.

Code: Select all

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <vector>

using namespace std;

int main(int argc, char *argv[])
{
    srand(time(NULL));
    
    for (int i = 1; i <= 100; i++)
    {
        int N = rand() % 30 + 2;
        
        vector<string> items;
        
        int S = 1, E = 2;
        for (int j = 1; j <= N; j++)
        {
            if (j == 1 || rand() % 2 == 1)
            {
                int T = max(S, E);
                S = rand() % T + 1;
                E = rand() % T + 1;
                while (E == S)
                    E = rand() % T + 1;
            }
            else
            {
                if (rand() % 2 == 1)
                {
                    E = max(S, E) + 1;
                }
                else
                {
                    S = max(S, E);
                    E = S + 1;
                }
            }
            
            items.push_back(to_string(S) + ' ' + to_string(E) + ' ' + to_string((rand() % 10000 + 1)));
        }
        
        int T = max(S, E);
        S = rand() % T + 1;
        E = rand() % T + 1;
        while (E == S)
            E = rand() % T + 1;

        items.insert(items.begin(), to_string(N) + ' ' + to_string(S) + ' ' + to_string(E));
        
        for (auto item : items)
            cout << item << '\n';
    }
    
    cout << "0 0 0\n";
    
    return 0;
}

Post Reply

Return to “Volume 3 (300-399)”