11月28日学习总结

完成事项:

  1. 快速排序

  2. 《啊哈算法》栈,队列

  3. jsuacm.cn的菜鸟杯做了4题

  4. 复习快速幂

学习效果展示

快速排序

#include<stdio.h>
main()
{
    void quicksort(int a[100],int low,int high);
    int a[100];
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    quicksort(a,0,n-1);
    for(int i=0;i<n;i++)
        printf("%d ",a[i]);
}
void quicksort(int a[100],int low,int high)
{
    int i,j,k;
    if(low<high)
    {  i=low;
       j=high;
        k=a[low];
    while(i<j)
    {
        while(i<j&&a[j]>=k)//考虑a[j]==k;
        {
            j--;
        }
        if(i<j)
            a[i++]=a[j];
        while(i<j&&a[i]<=k)
            i++;
        if(i<j)
            a[j--]=a[i];
    }
    a[i]=k;
    quicksort(a,low,i);//分俩个区域以I为界
    quicksort(a,i+1,high);
}
}

#include<stdio.h>
#include<string.h>
main()
{
    char a[101],s[101];
    int i,len,mid,next,top;
    gets(a);
    len=strlen(a);
    mid=len/2-1;//求中间位子
    top=0;
    for(i=0;i<=mid;i++)
        s[++top]=a[i];//到了一半
    if(len%2==0)//判断字符长度奇偶决定哪边开始算
        next=mid+1;
    else
        next=mid+2;
    for(i=next;i<=len-1;i++)

        {if(a[i]!=s[top])
            break;
        top--;}

    if(top==0)//如果全部做完top就是0,其他情况都是因为不是回文强制退出
      printf("YES\n");
      else
        printf("NO\n");
        getchar();
        getchar();
        return 0;

}

队列

#include<stdio.h>
main()
{
    int p[102]={0,6,3,1,7,5,8,9,2,4},head=1,tail=10;
    while(head<tail)
    {
        printf("%d ",p[head]);
        head++;//出列
        p[tail++]=p[head];//放到尾巴
        head++;//出列
    }
    getchar();
    getchar();
    return 0;
}
#include<stdio.h>
struct queue
{
    int data[100];//队列的主体
    int head;//队首
    int tail;//对尾
};
main()
{
   struct queue q;
   int i;//初始化队列
   q.head=1;//头
   q.tail=1;//尾
   for(int i=1;i<=9;i++)
   {
       scanf("%d",&q.data[q.tail]);//输入9个数
       q.tail++;//为什么走q.tail是因为可以走到最后面,统计数量
   }
while(q.head<q.tail)//当队列不为空循环
{
    printf("%d ",q.data[q.head]);//打印队首,移出去
    q.head+=1;//到了第二个
    q.data[q.tail]=q.data[q.head];//将新的队首移到队尾
    q.tail++;
    q.head++;//再次移出去
}
getchar();
getchar();
return ;

}

 吉首大学

http://jsuacm.cn/problem.php?cid=1659&pid=0

#include<stdio.h>
#include<string.h>
char s[100010];
main()
{
    int n;
    scanf("%d",&n);
    getchar();
    gets(s);
    int c=0;
    for(int i=0;i<n-10;i++)//n-10是因为有效字段
        if(s[i]=='2')
        c++;
    if(c>(n-11)/2)
        printf("yyds\n");
        else
        printf("orz");
}

首页

#include<stdio.h>
#include<string.h>
char a[10010];
main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        getchar();
        scanf("%s",&a);
        int m=strlen(a);
        int x;
        if(a[0]==a[m-1])
            x=0;
        else
        {
            a[m-1]=a[0];
            x=1;
        }
        printf("%d\n",x);
        puts(a);

    }

}










首页

#include<stdio.h>
long long int n;
int a[200100];
main()
{
    long long int f(long long int n,long long int m);
    scanf("%lld",&n);
    while(n--)
 {
     long long int m;
     scanf("%lld",&m);
        long long int x0=0,x1=0;
    for(long long int i=0;i<m;i++)
    {
        scanf("%lld",a+i);
        if(a[i]==1)
            x1++;
        if(a[i]==0)
            x0++;
    }
    long long int sum;
    sum=f(2,x0);
   printf("%lld\n",(sum*x1)%1000000007);

 }
}
long long int f(long long int n,long long int m)//为什么不用pow,是因为pow会爆数据
 {

     long long int ans=1;
     while(m)
     {
         if(m&1)
         {
             ans=(ans*n)%1000000007;//这里要1000000007
         }
         m=m>>1;
         n=(n*n)%1000000007;//也要1000000007。我这里错了好久
     }
     return ans%1000000007;//还要1000000007
 }

首页

#include<stdio.h>
main()
{
    long long int f(long long int n);
    long long int n;
    scanf("%lld",&n);
    long long x,y,k;
    while(n--)
    {
        long long int c=0;
        scanf("%lld %lld",&x,&y);
        if(y>=100)
          {
                c=c+y-100+1;//大于等于100一定是
                k=99;
          }
          else
            k=y;

        for( ;x<=k;x++)
        {
            if(x>=100)
                c++;
            else
            {
                if(x>=10)
                  {
                        if(f(x))
                        c++;
                        else if(f(x%10))
                            c++;
                        else if(f(x/10))
                            c++;
                  }
                  else
                  {
                      if(f(x))
                        c++;
                  }
                }
            }
             printf("%lld\n",c);
        }


}
long long int f(long long int n)
{
    if(n%3==0)
        return 1;
    else
        return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值