NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>

/**
* Score points by scanning valuable fish faster than your opponent.
**/

// sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));

int distance(int x1, int y1, int x2, int y2)
{
return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}

int dist(int nbr1, int nbr2)
{
int dist = nbr1 - nbr2;
if (dist < 0)
dist *= -1;
return (dist);
}

int main()
{
int drone1_x = 0;
int drone1_y = 0;
int drone2_x = 0;
int drone2_y = 0;
int enm[6];
int enm1_x = 0;
int enm1_y = 0;
int enm2_x = 0;
int enm2_y = 0;
int base1_x = 2000;
int base1_y = 9000;
int target1_x = 2000;
int target1_y = 9000;
int base2_x = 8000;
int base2_y = 9000;
int target2_x = 8000;
int target2_y = 9000;
int distance = 0;
int a = 0;
bool allert1 = false;
bool allert2 = false;
int dir1 = 0;
int dir2 = 0;
bool flag1 = false;
bool flag2 = false;

int creature_count;
scanf("%d", &creature_count);
for (int i = 0; i < creature_count; i++) {
int creature_id;
int color;
int type;
scanf("%d%d%d", &creature_id, &color, &type);
if (type == -1)
{
enm[a] = creature_id;
a++;
}
}

// game loop
while (1) {
int my_score;
scanf("%d", &my_score);
int foe_score;
scanf("%d", &foe_score);
int my_scan_count;
scanf("%d", &my_scan_count);
for (int i = 0; i < my_scan_count; i++) {
int creature_id;
scanf("%d", &creature_id);
}
int foe_scan_count;
scanf("%d", &foe_scan_count);
for (int i = 0; i < foe_scan_count; i++) {
int creature_id;
scanf("%d", &creature_id);
}
int my_drone_count;
scanf("%d", &my_drone_count);
for (int i = 0; i < my_drone_count; i++) {
int drone_id;
int drone_x;
int drone_y;
int emergency;
int battery;
scanf("%d%d%d%d%d", &drone_id, &drone_x, &drone_y, &emergency, &battery);
if (i == 0)
{
drone1_x = drone_x;
drone1_y = drone_y;
}
else
{
drone2_x = drone_x;
drone2_y = drone_y;
}
}
int foe_drone_count;
scanf("%d", &foe_drone_count);
for (int i = 0; i < foe_drone_count; i++) {
int drone_id;
int drone_x;
int drone_y;
int emergency;
int battery;
scanf("%d%d%d%d%d", &drone_id, &drone_x, &drone_y, &emergency, &battery);
}
int drone_scan_count;
scanf("%d", &drone_scan_count);
for (int i = 0; i < drone_scan_count; i++) {
int drone_id;
int creature_id;
scanf("%d%d", &drone_id, &creature_id);
}
int visible_creature_count;
scanf("%d", &visible_creature_count);
for (int i = 0; i < visible_creature_count; i++) {
int creature_id;
int creature_x;
int creature_y;
int creature_vx;
int creature_vy;
scanf("%d%d%d%d%d", &creature_id, &creature_x, &creature_y, &creature_vx, &creature_vy);
fprintf(stderr, "%dn", creature_id);
for (int j = 0; j < 5; j++)
{
if (creature_id == enm[j])
{
if (dist(creature_x, drone1_x) < dist(creature_x, drone2_x))
{

enm1_x = creature_x;
enm1_y = creature_y;
allert1 = true;
flag1 = true;

}
else
{
if (creature_y > drone2_y && dir2 == 0)
{
enm2_x = creature_x;
enm2_y = creature_y;
allert2 = true;
flag2 = true;
}
if (creature_y < drone2_y && dir2 == 1)
{
enm2_x = creature_x;
enm2_y = creature_y;
allert2 = true;
flag2 = true;
}
}
}
}
}
int radar_blip_count;
scanf("%d", &radar_blip_count);
for (int i = 0; i < radar_blip_count; i++) {
int drone_id;
int creature_id;
char radar[3];
scanf("%d%d%s", &drone_id, &creature_id, radar);
}
for (int i = 0; i < my_drone_count; i++) {
if (i == 0) // drone 1
{
if (flag1 == false)
allert1 = false;
if (drone1_y >= 7000 && dir1 == 0)
{
base1_x = 2000;
base1_y = 0;
target1_x = base1_x;
target1_y = base1_y;
dir1 = 1;
}
if (allert1)
{
if (dir1 == 0 || dir1 == 2)
{
if (drone1_y < enm1_y && drone1_x > enm1_x)
{
target1_x = drone1_x + 3000;
target1_y = drone1_y + 3000;
}
else if (drone1_y > enm1_y && drone1_x > enm1_x)
{
target1_x = drone1_x + 2000;
target1_y = drone1_y + 5000;
}
else if (drone1_y < enm1_y && drone1_x < enm1_x)
{
if (drone1_y < 6500)
{
target1_x = drone1_x - 2000;
target1_y = drone1_y + 5000;
}
else
{
base1_x = 2000;
base1_y = 0;
target1_x = base1_x;
target1_y = base1_y;
dir1 = 1;
}
}
}
else if (dir1 == 1 || dir1 == 3)
{
if (drone1_y > enm1_y && drone1_x < enm1_x)
{
target1_x = drone1_x - 5000;
target1_y = drone1_y - 2000;
}
if (drone1_y > enm1_y && drone1_x > enm1_x)
{
target1_x = drone1_x + 1000;
target1_y = drone1_y - 2000;
}
if (drone1_y < enm1_y && drone1_x < enm1_x)
{
target1_x = drone1_x - 1000;
target1_y = drone1_y - 3000;
}
}
}
else
{
target1_x = base1_x;
target1_y = base1_y;
}

// if (drone1_y % 1000 < 500)
// printf("MOVE %d %d 1n", target1_x, target1_y);
// else
// printf("MOVE %d %d 0n", target1_x, target1_y);
printf("MOVE %d %d 1n", target1_x, target1_y);

if (drone1_x == base1_x && drone1_y == base1_y)
{
base1_x = 2000;
base1_y = 0;
target1_x = base1_x;
target1_y = base1_y;
dir1 = 1;
}
if (drone1_x == 2000 && drone1_y == 0)
{
base1_x = 2000;
base1_y = 8500;
target1_x = 2000;
target1_y = 8500;
dir1 = 2;
}
flag1 = false;
// Write an action using printf(). DON'T FORGET THE TRAILING n
// To debug: fprintf(stderr, "Debug messages...n");
}
else // drone 2
{
if (flag2 == false)
allert2 = false;
if (drone2_y >= 7000 && dir2 == 0)
{
base2_x = 8000;
base2_y = 0;
target2_x = base2_x;
target2_y = base2_y;
dir2 = 1;
}
if (allert2)
{
if (dir2 == 0 || dir2 == 2)
{
if (drone2_y < enm2_y && drone2_x > enm2_x)
{
target2_x = drone2_x + 3000;
target2_y = drone2_y + 3000;
}
else if (drone2_y > enm2_y && drone2_x > enm2_x)
{
target2_x = drone2_x + 2000;
target2_y = drone2_y + 5000;
}
else if (drone2_y < enm2_y && drone2_x < enm2_x)
{
if (drone2_y < 6500)
{
target2_x = drone2_x - 2000;
target2_y = drone2_y + 5000;
}
else
{
base2_x = 2000;
base2_y = 0;
target2_x = base2_x;
target2_y = base2_y;
dir2 = 1;
}
}
}
else if (dir2 == 1 || dir2 == 3)
{
if (drone2_y > enm2_y && drone2_x < enm2_x)
{
target2_x = drone2_x - 5000;
target2_y = drone2_y - 2000;
}
if (drone2_y > enm2_y && drone2_x > enm2_x)
{
target2_x = drone2_x + 2000;
target2_y = drone2_y - 2000;
}
if (drone2_y < enm2_y && drone2_x < enm2_x)
{
target2_x = drone2_x - 2000;
target2_y = drone2_y - 3000;
}
}
}
else
{
target2_x = base2_x;
target2_y = base2_y;
}

// if (drone1_y % 1000 < 500)
// printf("MOVE %d %d 1n", target1_x, target1_y);
// else
// printf("MOVE %d %d 0n", target1_x, target1_y);
printf("MOVE %d %d 1n", target2_x, target2_y);

if (drone2_x == base2_x && drone2_y == base2_y)
{
base2_x = 8000;
base2_y = 0;
target2_x = base2_x;
target2_y = base2_y;
dir2 = 1;
}
if (drone2_x == 8000 && drone2_y == 0)
{
base2_x = 8000;
base2_y = 8500;
target2_x = 8000;
target2_y = 8500;
dir2 = 2;
}
flag2 = false;
// Write an action using printf(). DON'T FORGET THE TRAILING n
// To debug: fprintf(stderr, "Debug messages...n");
}
}
}

return 0;
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.