codeforces #341(A,B)

//一开始脑残了,用高精度来写的,后来发现int64就可以
#include <stdio.h>
  int main()
  {
      __int64 sum;
      int i,m,n,min;
     scanf("%d",&n);
      sum=0;
      min=999999999;
      for (i=0;i<n;i++)
      {
          scanf("%d",&m);
          sum+=m;
          if ((m%2==1)&&(m<min))
           min=m;
      }
      if (sum%2==0)
        printf("%I64d\n",sum);
      else
        printf("%I64d\n",sum-min);
      return 0;

  }



类似n皇后的判定方法,再用到类似桶排序的开那么大个空间存储,有个技巧是当求差会为负数就先加上20000
#include <stdio.h>
#include <string.h>
 int s1[400005];
 int s2[400005];
 int main()
{
     int i,j,n,m,a,b;
     __int64 sum;
     memset(s1,0,sizeof(s1));
     memset(s2,0,sizeof(s2));
     scanf("%d",&n);
     for (i=0;i<n;i++)
     {
         scanf("%d%d",&a,&b);
         s1[a+b]++;
         s2[a-b+200000]++;
      }
      sum=0;
      for (i=0;i<=400000;i++)
      {
         sum=sum+s1[i]/2.0*(s1[i]-1);
         sum=sum+s2[i]/2.0*(s2[i]-1);
      }
      printf("%I64d\n",sum);
      return 0;

 }


你可能感兴趣的:(codeforces #341(A,B))