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;
}
}
持续更新中~~