HDU 5500+HDU 1097 (找规律)

队内选拔赛两道水题……然而一直卡在第一题的规律唉……

HDU 5500:

题意:你可以从数列中任一个位置取一个数字放到数列首部,问到达顺序为1~n所需要的最小操作数

其实就是将两个连续数字间的其他数字移走,不用去在意移走后数字的先后顺序,因为在相同的操作数内总有办法使之达到我们所需要的数列;因为最大的数总是在最后,因此我们从后往前找连续的数位,剩下的就是需要移动的数字;
如:2 1 4 3 5 从后往前,连续数位为5 4,需要移动3 1 2;

#include <iostream>
#include <cstdio>
using namespace std;
const int N=50;
int n;
int a[N];
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
        }
        int cnt=0,j=n;
        for(int i=n;i>=1;i--){
            if(a[i]==j) j--;
            else cnt++;
        }
        printf("%d\n",cnt);
    }
}
HDU 1097:

第一眼看到我以为要快速幂呢,后来其实还是就是找规律;
题意:给a,b,求a^b的个位;
a的个位1~10分别考虑一下即可,枚举;

#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
int main(){
    ll a,b;
    while(~scanf("%lld %lld",&a,&b)){
        ll ans=0;
        ll a1=a%10;
        ll b1=0;
        if(a1==1||a1==5||a1==6){
            ans=a1;
        }
        else if(a1==2){
            b1=b%4;
            if(b1==0){
                ans=6;
            }
            else if(b1==1){
                ans=2;
            }
            else if (b1==2){
                ans=4;
            }
            else if(b1==3){
                ans=8;
            }
        }
        else if(a1==3){
            b1=b%4;
            if(b1==0){
                ans=1;
            }
            else if(b1==1){
                ans=3;
            }
            else if (b1==2){
                ans=9;
            }
            else if(b1==3){
                ans=7;
            }
        }
        else if(a1==4){
            b1=b%2;
            if(b1==0){
                ans=6;
            }
            else if(b1==1){
                ans=4;
            }
        }
        else if(a1==7){
            b1=b%4;
            if(b1==0){
                ans=1;
            }
            else if(b1==1){
                ans=7;
            }
            else if (b1==2){
                ans=9;
            }
            else if(b1==3){
                ans=3;
            }
        }
        else if(a1==8){
            b1=b%4;
            if(b1==0){
                ans=6;
            }
            else if(b1==1){
                ans=8;
            }
            else if (b1==2){
                ans=4;
            }
            else if(b1==3){
                ans=2;
            }
        }
        else if(a1==9){
            b1=b%42;
            if(b1==0){
                ans=1;
            }
            else if(b1==1){
                ans=9;
            }
        }
        printf("%lld\n",ans);   
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值