Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // C code attempting to solve the Cannons vs Tarsiers challenge
- // Liam Fisher 2019
- #include <stdio.h>
- int PRISMATA(int fh, int fl, int gh, int g, int t, int TCH, int sF, int TURN){
- if (TURN != 0) {
- if (t >= (fh + TCH)) // Mariusz Wins
- return TURN;
- // MARIUSZ ACTIONS
- fh -= sF; // Fabricator health -= "Shoot Fabricator"
- TCH -= (t-sF);
- // Update cannon count
- if (TCH <= 0){
- g = 0;
- TCH = 0;
- }
- else
- g = (TCH + gh - 1) / gh; // hacky way in c to calculate ceil(TCH/gh) using positive integers
- // PAWEL ACTIONS
- t -= g;
- if (t <= 0) // Pawel Wins
- return -1;
- // Fabricator builds a cannon
- if(fh > 0 && fl > 0){
- fl--;
- if (fl == 0)
- fh = 0;
- g++;
- TCH += gh;
- }
- // OPTIMIZATION //
- // Hard code some cases to reduce number of function calls
- if (t >= (fh + TCH)) // We know Mariusz will win on the next turn
- return TURN+1;
- //////////////////
- }
- TURN++;
- int MaxFD, MinFD; // Maximum and minimum amount of damage that can be assigned to the fabricator
- if (fh == 0){
- MaxFD = 0;
- MinFD = 0;
- }
- else {
- if (fh >= t)
- MaxFD = t;
- else
- MaxFD = fh;
- if (TCH >= t)
- MinFD = 0;
- else
- MinFD = t-TCH;
- }
- int result;
- int j = 0;
- int BestResult = -1;
- for (int i = MinFD; i <= MaxFD; i++){
- result = PRISMATA(fh, fl, gh, g, t, TCH, i, TURN);
- if ((result > -1 && result < BestResult) || BestResult == -1)
- BestResult = result;
- j++;
- }
- return BestResult;
- }
- int main(void)
- {
- int T; //
- scanf("%d", &T);
- int fh, fl, gh, g, t;
- int fh_A[T], fl_A[T], gh_A[T], g_A[T], t_A[T];
- int TCH; // Total cannon health
- int Result;
- for (int n = 0; n < T; n++){
- scanf("%d", &fh_A[n]);
- scanf("%d", &fl_A[n]);
- scanf("%d", &gh_A[n]);
- scanf("%d", &g_A[n]);
- scanf("%d", &t_A[n]);
- }
- for (int n = 0; n < T; n++){
- fh = fh_A[n];
- fl = fl_A[n];
- gh = gh_A[n];
- g = g_A[n];
- t = t_A[n];
- TCH = gh * g;
- Result = PRISMATA(fh, fl, gh, g, t, TCH, 0, 0);
- if (Result > -1)
- printf("MARIUSZ %d\n", Result);
- else
- printf("PAWEL\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement