NCPC2016 (贪心算法,简单模拟)

Jumbled Compass

#include
#include
#include
using namespace std;
int main()
{
    int n1,n2;
    int m1,m2;
    while(~scanf("%d %d",&n1,&n2))
    {
        m1=n2-n1;
        if(m1<0)
            m1+=360;
        else
            m1%=360;
            m2=360-m1;
        if(m1

精简代码:

#include 
main()
{
   int n,m;
   while(~scanf("%d%d",&n,&m))
   {
       if(m

Daydreaming Stockbroker

#include
#include
#include
using namespace std;
int main()
{
    int n;
   long long x,s1,s2,y;
    while(~scanf("%d",&n))
    {
    s1=y=100;
    s2=0;
    while(n--)
    {
        scanf("%lld",&x);
        if(x<=y)
        {
            s2=s1/x;
           // printf("s2=%d\n",s2);
            y=x;
        }
        if(s2>100000)
            s2=100000;
        if(x>y)
        {
            s1+=x*s2-y*s2;
           // printf("s1=%d\n",s1);
            y=x;
        }
        /*if(s2>100000)
            s2=100000;*/
    }
    printf("%lld\n",s1);
    }
    return 0;
}

Game Rank

#include
#include
#include
#include
#include
using namespace std;
char s[10010];
int main(){

	int rank[30] = {5,5,5,5,5,5,5,5,5,5,5,4,4,4,4,4,3,3,3,3,3,2,2,2,2,2,0,0,0,0};
  while(~scanf("%s",s))
  {
      int len=strlen(s);
      int i,j;
      int sum=0;
      int level=25;
      for(i=0;i1&&s[i-1]=='W'&&s[i-2]=='W'&&level>=6)
              {
                  sum++;
              }
              if(sum>rank[level])
              {
                  sum-=rank[level];
                   level--;
              }
          }
          else if(s[i]=='L')
          {
              if(level>20||level==20&&sum==0)
              {
                  continue;
              }
              sum--;
              if(sum<0)
              {
                  level++;
                  sum=rank[level]-1;
              }
          }
          if(level==0)
            break;
      }
      if(level)
        printf("%d\n",level);
      else
        printf("Legend\n");
  }
  return 0;
}

 

你可能感兴趣的:(NCPC2016 (贪心算法,简单模拟))