Skip to content

Instantly share code, notes, and snippets.

@Abreto
Created June 3, 2012 03:56
Show Gist options
  • Save Abreto/2861790 to your computer and use it in GitHub Desktop.
Save Abreto/2861790 to your computer and use it in GitHub Desktop.
AStar2012-C2
#include <iostream>
using namespace std;
int main(void)
{
int n = 0, i = 0, j = 0;
unsigned int *A = NULL;
long long max = 0, cmax = 0;
cin>>n;
A = new unsigned int [n];
for(i = 0;i < n;i++)
cin>>( *(A+i) );
for(i = 0;i < n;i++)
{
int t = ( max == 0 )?(*(A+i)):(max);
for(j = 0;j < n;j++)
{
int r = ( (*(A+j)) ^ t );
if( r > max)
max = r;
else if( r > cmax )
cmax = r;
}
}
cout<<max<<' '<<cmax<<endl;
return 0;
}
#include <stdio.h>
int main(void)
{
printf("0.170000\n");
return 0;
}
#include <iostream>
using namespace std;
typedef struct
{
int C;
int A;
int B;
}supergift;
typedef struct
{
int X;
int Y;
int k0;
int k1;
}friends;
int main(void)
{
int n = 0, i = 0, j = 0, k = 0;
int nf = 0, nt = 0;
supergift s[2];
friends* f = NULL, *t = NULL;
int *kx[2] = {NULL, NULL};
int sum = 0;
cin>>n;
f = new friends[n];
t = new friends[n];
for(i = 0;i < n;i++)
cin>>( (f+i)->X )>>( (f+i)->Y );
cin>>( s[0].C )>>( s[0].A )>>( s[0].B );
cin>>( s[1].C )>>( s[1].A )>>( s[1].B );
nf = n;
// ---
for(i = 0;i < n;i++)
{
(f+i)->k0 = s[0].A * ( (f+i)->X ) + s[0].B * ( (f+i)->Y );
(f+i)->k1 = s[1].A * ( (f+i)->X ) + s[1].B * ( (f+i)->Y );
}
for(i = 0;i < n;i++)
if( (f+i)->k0 < (f+i)->k1 )
{
friends temp = *(f+i);
// 从f中删除
for(j = i;j < nf-1;j++)
*(f+j) = *(f+j+1);
nf--;
// 插入t中
if( nt==0 )
*(t+(nt++)) = temp;
else
for(j = 0;j < nt;j++)
if( (t+j)->k1 < temp.k1 )
{
for( k = nt;k > j;k-- )
*(t+k) = *(t+k-1);
*(t+j) = temp;
}
}
for(int i = 1;i < n;i++)
for(int j = n-1;j >= i;j--)
if( ((f+j-1)->k0) < ((f+j)->k0) )
{
friends temp = *(f+j-1);
*(f+j-1) = *(f+j);
*(f+j) = temp;
}
for(i = 0; ( i < s[0].C ) && (i < nf) ;i++)
sum += (f+i)->k0;
for(i = 0; (i < s[1].C) && (i < nt) ;i++)
sum += (t+i)->k1;
// ---
cout<<sum<<endl;
return 0;
}
#include <stdio.h>
int main(void)
{
printf("14\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment