17级2019春季个人训练赛-8

A - Hailstone HOTPO

Sample Input
4
1 1
2 3
3 9999
4 100000
Sample Output
1 1
2 16
3 101248
4 100000

题意:• If n is even, divide it by 2 to get n ′    • if n is odd, multiply it by 3 and add l to get n 直到n变为1停止,求这个过程中n的最大值为多少。

#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
const int MAX=1e6+7;
deque <ll> dq;
int main()
{
    ll T,i,j,maxx=1,ans,e,n,p;
    cin>>T;
    while(T--)
    {
        cin>>e>>n;
        maxx=n;
        while(1)
        {
            if(n==1)
                break;
            p=n;
            if(n%2==0)
                n=n/2;
            else
                n=n*3+1;
            if(n>=maxx)
                maxx=n;
          //  cout<<maxx<<" "<<n<<endl;
        }
        cout<<e<<" "<<maxx<<endl;
    }
    return 0;
}

B - B-Casting

Sample Input
5
1 10 7829
2 7 123456
3 6 432504023545112
4 8 37777777777777773
5 2 10110100010101010101101110001010001010101010101010111
Sample Output
1 8
2 3
3 1
4 6
5 0

题意:给两个数,一个p,一个n,     p代表n是几进制的   要求n对(p-1)求余

#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
const int MAX=1e7+7;
deque <ll> dq;
string s;
int main()
{
    ll T,i,j,maxx=1,ans,e,n,p;
    cin>>T;
    while(T--)
    {
        s.clear();
        cin>>e>>p>>s;
        ll len=s.size();
        ll f=1,sum=0;
        ll m=1;
        if(p==2)
        {
            cout<<e<<" 0"<<endl;
            continue;
        }
        for(i=len-1;i>=0;i--)
        {
            sum+=(s[i]-'0')%(p-1)*f;//都要求一下余
            //sum=sum%(p-1);
            f*=p;
            f%=(p-1);
        }
        cout<<e<<" "<<sum%(p-1)<<endl;
    }
    return 0;
}

J Mystery

Sample Input
7
1
MAC
3
1 1 1
2
IW2C0NP3OS 1RLDFA
22
0 3 3 -3 7 -8 2 7 -4 3 8 7 4 1 1 -4 5 2 5 -6 -3 -4
3
G.IETSNPRBU
17
2 4 5 -6 -1 -3 -2 -4 -4 1 -1 5 -3 4 1 -2 4
4
PIBN MRDSYEO
16
-4 4 -1 4 5 3 -5 4 -3 -3 -2 -5 -5 -3 1 3
5
D^obV@k"W*B&#]4!NcF$’lj%(d6XG5fi<Hxz7)2Lt~=8aQuvh}r_m+C9eI‘-.>EwYyngZRsJKpqO{[\U|MPS,;T?031/A
93
-1 11 44 39 -31 -44 10 5 24 14 1 -33 42 28 -34 7 -37 24 14 3 -7 18 4 19 37 4 20 2 41 -42 18 15 -3 10
7 12 -11 -41 14 8 31 -26 37 -19 -17 -9 -16 15 31 14 29 -22 1 -24 20 -30 6 1 16 -29 31 -30 6 17 -43 -
10 7 7 4 -22 10 -2 15 13 14 2 6 -17 34 -27 28 29 -28 2 33 -13 -15 6 -31 24 41 29 26
6
I
1
0
7
I
13
0 0 0 0 0 0 0 0 0 0 0 0 0


Sample Output
1 ACM
2 ICPC 2013 WORLD FINALS
3 INST. PETERSBURG
4 SPONSORED BY IBM
5 ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz~’!@#$%^&*()_+-={}[]\|’";/.,<>?
6 I
7 IIIIIIIIIIIII

题意:第一行是总样例数T,然后是第几组数e,第一组样例开始输入一个字符串,输入n,接下来输入n个数,求该位置在s串中的字符是什么,位置是累加的。

话说题目样例不对啊。

#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
const int MAX=1e6+7;
deque <ll> dq;
typedef long long ll;
int main()
{
    ll T,i,j,e,n,p,m;
    char s[101010];
    cin>>T;
    while(T--)
    {
        cin>>e;

        memset(s,0,sizeof(s));
        getchar();
        gets(s);
        cin>>n;
        p=0;m=0;
        ll len=strlen(s);
        cout<<e<<" ";
        for(i=1;i<=n;i++)
        {
            cin>>p;
            m+=p;
            while(1)
            {
                if(m>=0&&m<len)
                    break;
                if(m>=len)
                    m=m%len;
                else
                if(m<0)
                   m+=len;
            }
            cout<<s[m];
        }
        cout<<endl;
    }
}

持续更新中~~

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值