xdoj ranting记

43 篇文章 0 订阅
30 篇文章 0 订阅

莫名想刷一波xdoj的排名,很玄学


1053: 正数负数

思路:先来一道纯水题,判断正负

#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        if(n>0)
            printf("yes\n");
        else if(n<0)
            printf("no\n");
        else
            printf("light\n");
    }
    return 0;
}


1003: 亮亮做加法 (a.k.a another A+B Problem)

思路:按位模拟一下进制加法计算进位过程,虽然提示用java,但我还是用c++跑完了,没错,就是这么任性

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

char x[100],y[100];
int sum[100];

int c2i(char a)
{
    if(a>='0'&&a<='9')
        return (int)(a-'0');
    else if(a>='A'&&a<='F')
        return (int)(10+a-'A');
    else
        return -1;
}

char i2c(int a)
{
    if(a>=0&&a<=9)
        return (char)('0'+a);
    else if(a>=10&&a<=15)
        return (char)('A'+a-10);
    else
        return 'N';
}

int main()
{
    int b,xlen,ylen;
    while(scanf("%d%s%s",&b,x,y)!=EOF)
    {
        bool jw=false;
        memset(sum,0,100*sizeof(int));
        xlen=strlen(x);
        ylen=strlen(y);
        int t=0;
        for(int i=xlen-1,j=ylen-1;i>=0||j>=0||jw;i--,j--)
        {
            if(i<0)
            {
                i=0;
                x[i]='0';
            }
            if(j<0)
            {
                j=0;
                y[j]='0';
            }
            int temp;
            temp=c2i(x[i])+c2i(y[j])+sum[t];
       //     cout<<temp<<endl;
            if(temp>=b)
            {
                sum[t]=temp%b;
      //          cout<<sum[t]<<endl;
                t++;
                sum[t]+=temp/b;
                jw=true;
            }
            else
            {
                sum[t]=temp;
     //           cout<<sum[t]<<endl;
                t++;
                jw=false;
            }
        }
        for(int i=t-1;i>=0;i--)
        {
            char temp;
            temp=i2c(sum[i]);
            printf("%c",temp);
        }
        printf("\n");
    }
    return 0;
}

1008: Josephus环

思路:这是个很经典的问题了,由于数据范围很友好,直接模拟一遍就好了

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

bool a[1010];

int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int leftcount=n;
    int index=0;
    int countnum=0;
    memset(a,true,n*sizeof(bool));
    while(leftcount>1)
    {
        if(a[index])
        {
            countnum++;
            if(countnum==k)
            {
                countnum=0;
                a[index]=false;
                printf("%d ",index+1);
                leftcount--;
            }
        }
        index++;
        if(index==n)
            index=0;
    }
    for(int i=0;i<n;i++)
    {
        if(a[i])
            printf("%d\n",i+1);
    }
    return 0;
}


1041: Franky的游戏O

思路:这又是一道超级水题,主要就是读懂题意,转换一下,就成了奇偶判断的题了

#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,m;
        scanf("%d%d",&n,&m);
        if(n%2==0&&m%2==0)
            printf("%d\n",2);
        else
            printf("%d\n",1);
    }
    return 0;
}


1054: 攻击BOSS

思路:又是一道模拟题,直接逐位判断就好了

#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int sum=0;
        while(n>0)
        {
            int m=n%10;
            n=n/10;
            if(m==8)
                sum+=2;
            else if(m==6||m==9||m==0)
                sum++;
        }
        printf("%d\n",sum);
    }
    return 0;
}

1055: 如此遍历

思路:蛇形dfs搜索,注意一下边界转换条件

#include <iostream>
#include <cstdio>

using namespace std;

const int maxn = 60;

int a[maxn][maxn];

int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        int i,j;
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                scanf("%d",&a[i][j]);
            }
        }
        i=0;
        j=0;
        bool up = false;
        bool unchange = true;
        if(n==1)
        {
            for(int k=0;k<m-1;k++)
            {
                printf("%d ",a[n-1][k]);
            }
            printf("%d\n",a[n-1][m-1]);
        }
        else if(m==1)
        {
            for(int k=0;k<n-1;k++)
            {
                printf("%d ",a[k][m-1]);
            }
            printf("%d\n",a[n-1][m-1]);
        }
        else
        {
            while(i<n-1||j<m-1)
            {
                printf("%d ",a[i][j]/*,i,j*/);
                if(i==n-1&&unchange)
                {
                    if(up)
                        up = false;
                    else
                        up = true;
                    j++;
                    unchange = false;
              //      cout << "1" << " ";
                }
                else if(j==0&&unchange)
                {
                    if(up)
                        up = false;
                    else
                        up = true;
                    i++;
                 //   cout << "2" << " ";
                    unchange = false;
                }
                else if(j==m-1&&unchange)
                {
                    if(up)
                        up = false;
                    else
                        up = true;
                    i++;
                    unchange = false;
                //    cout << "2" << " ";
                }
                else if(i==0&&unchange)
                {
                    if(up)
                        up = false;
                    else
                        up = true;
                    j++;
                    unchange = false;
                 //   cout << "1" << " ";
                }
                else if(up)
                {
                    i--;
                    j++;
                    unchange = true;
                 //   cout << "3" << " ";
                }
                else
                {
                    i++;
                    j--;
                    unchange = true;
                 //   cout << "4" << " ";
                }
            }
            printf("%d\n",a[n-1][m-1]);
        }
    }
    return 0;
}

1056: 寻找BOSS

思路:这就是个简单dp了,按位置dp所有可能情况就好了

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#include <stack>

using namespace std;

const int maxn = 1e3+10;
const int mode = 1e4+7;

int dp[maxn][maxn];

int main()
{
    int n;
    memset(dp,0,sizeof(dp));
    for(int i=0;i<=1000;i++)
    {
        dp[i][0] = 1;
    }
    for(int i=1;i<=1000;i++)
    {
        for(int j=i;j<=1000;j++)
        {
            dp[j][i] = (dp[j-1][i] + dp[j][i-1]) % mode;
        }
    }
    while(scanf("%d",&n)!=EOF)
    {
        printf("%d\n",dp[n][n]);
    }
    return 0;
}

1001: 又是苹果

思路:vector嵌vector存图,坐标处理

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

vector <vector <char> > a;

const int maxn = 1e6+10;

int xmax[maxn];
int ymax[maxn];

//int **a;

int main()
{
    int n,m,t=0;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        t++;
        printf("Case #%d:\n",t);
        getchar();
        a.clear();
   //     a=new int *[n];
        for(int i=0;i<n;i++)
        {
            xmax[i]=i;
        }
        for(int j=0;j<m;j++)
        {
            ymax[j]=j;
        }
        for(int i=0;i<n;i++)
        {
     //       a[i]=new int[n];
            vector <char> b;
            b.clear();
            for(int j=0;j<m;j++)
            {
                char temp;
                scanf("%c",&temp);
     //           a[i][j]=temp;
                b.push_back(temp);
            }
            getchar();
            a.push_back(b);
        }
        int q,c,x,y;
        scanf("%d",&q);
        while(q--)
        {
            scanf("%d%d%d",&c,&x,&y);
            x--;
            y--;
            switch(c)
            {
                case 1:
                    if(a[xmax[x]][ymax[y]]=='T')
                        printf("Tree\n");
                    else if(a[xmax[x]][ymax[y]]=='i')
                        printf("Phone\n");
                    else
                        printf("Empty\n");
                    break;
                case 2:
                    int temp;
                    temp=xmax[x];
                    xmax[x]=xmax[y];
                    xmax[y]=temp;
                  /*  for(int j=0;j<m;j++)
                    {
         //               swap(a[x],a[y]);

                        char temp;
                        temp=a[x][j];
                        a[x][j]=a[y][j];
                        a[y][j]=temp;

                    }*/
                    break;
                case 3:
//                    int temp;
                    temp=ymax[x];
                    ymax[x]=ymax[y];
                    ymax[y]=temp;
                  /*  for(int i=0;i<n;i++)
                    {
                        char temp;
                        temp=a[i][x];
                        a[i][x]=a[i][y];
                        a[i][y]=temp;
                    }*/
                    break;
            }
        }
    //    free(a);
    }
    return 0;
}

1061: A+B of lw

思路:分数计算,辗转相除最大公约数板子

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

const int maxn = 1e5+10;

int gcd(int a,int b)
{
	return b == 0 ? a : gcd(b, a % b);
}

int main()
{
    int a1,a2,b1,b2,c1,c2,re1,re2;
    while(scanf("%d/%d %d/%d",&a1,&a2,&b1,&b2)!=EOF)
    {
        //cout << a1 << a2 << endl;
        c2 = a2*b2;
        c1 = a1*b2+a2*b1;
        re1 = c1/gcd(c1,c2);
        re2 = c2/gcd(c1,c2);
        printf("%d/%d\n",re1,re2);
    }
    return 0;
}

1060: 坑爹的杜神

思路:手动模拟四舍五入,注意补0和进位

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#include <stack>

using namespace std;

const int maxn = 1e5+10;

int main()
{
    long long num;
    while(scanf("%lld",&num)!=EOF)
    {
        bool pl = false;
        if(num % 10LL >= 5LL)
        {
            pl = true;
        }
        long long lef1 = num/10LL%10LL;
        long long lef2 = num/100LL%10LL;
        num /= 1000LL;
        if(pl)
        {
            lef1++;
            if(lef1==10)
            {
                lef1=0;
                lef2++;
                if(lef2==10)
                {
                    lef2=0;
                    num++;
                }
            }
        }
        printf("%lld.%lld%lld\n",num,lef2,lef1);
    }
    return 0;
}

瞬间做了10到水题,ranting上升到了12,下一个目标估计就是破百了,以后找时间再加油吧。


文章地址:http://blog.csdn.net/owen_q/article/details/78444381

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值