LogoLogo
  • CP Gymnasium
  • Week 3 Math / Number Theory
    • Week 3 Math / Number Theory
      • Problem 1: Tetration
      • Problem 2: Peragrams
      • Problem 3: Veci
      • Problem 4: Architecture
      • Problem 5: Joint Attack
      • Problem 6: How Many Digits?
      • Problem 7: Abstract Painting
  • Week 4 Array / Greedy
    • Week 4 Array / Greedy
      • Problem 1: Vaccine Efficacy
      • Problem 2: Frosh Week
      • Problem 3: Inquiry
      • Problem 4: Bank Queue
      • Problem 5: Log Land
  • Week 6 Sorting / Binary Search
    • Week 6 Sorting / Binary Search
      • Problem 1: Falling Apart
      • Problem 2: Synchronizing Lists
      • Problem 3: Distributing Ballot Boxes
      • Problem 4: Financial Planning
      • Problem 5: Big Boxes
  • Week 7 Dynamic Programming
    • Week 7 Dynamic Programming
      • Problem 1: Ocean's Anti-11
      • Problem 2: Batmanacci
      • Problem 3: Radio Commercials
      • Problem 4: Welcome to Code Jam (Hard)
      • Problem 5: Honeycomb Walk
  • Week 8 Graph Traversals
    • Week 8 Graph Traversals
      • Problem 1: Reachable Roads
      • Problem 2: Money Matters
      • Problem 3: Squawk Virus
      • Problem 4: Beehives
      • Problem 5: Running MoM
      • Problem 6: Amanda Lounges
Powered by GitBook
On this page
  1. Week 3 Math / Number Theory
  2. Week 3 Math / Number Theory

Problem 3: Veci

https://open.kattis.com/problems/veci

PreviousProblem 2: PeragramsNextProblem 4: Architecture

Last updated 4 years ago

A couple approaches:

  1. Brute Force: because the input is at most 6 digits, you only need to check numbers between the input XXX and 999999999999999999. You can check all numbers iii s.t. X<i≤999999 X < i \leq 999999X<i≤999999. If any have the same digits as XXX (can be checked by counting the # of each digit), output the smallest such iii. Otherwise, output 000.

  2. C++ has a next_permutation() function which finds the smallest permutation larger than a given input. This function returns true if successful, and false if there are no more valid permutations. Example usage:

string s = "27711";
next_permutation(s.begin(), s.end()); // s is now 71127