新生51场
问题 D: 方格取数
题目描述
设有n×m的方格图,每个方格中都有一个整数。现有一只小熊,想从图的左上角走到右下角,每一步只能向上、向下或向右走一格,并且不能重复经过已经走过的方格,也不能走出边界。小熊会取走所有经过的方格中的整数,求它能取到的整数之和的最大值。输入
第1行两个正整数n,m。接下来n行每行m个整数,依次代表每个方格中的整数。
输出
一个整数,表示小熊能取到的整数之和的最大值。样例输入 (41条消息) UPC2022/3/18 晚训练赛补题_一条小小yu的博客-CSDN博客
问题 G: Secret Message
Jack and Jill developed a special encryption method, so they can enjoy conversations without worrrying about eavesdroppers. Here is how: let L be the length of the original message, and M be the smallest square number greater than or equal to L. Add (M ? L) asterisks to the message, giving a padded message with length M. Use the padded message to ?ll a table of size K × K, where K2= M. Fill the table in row-major order (top to bottom row, left to right column in each row). Rotate the table 90 degrees clockwise. The encrypted message comes from reading the message in row-major order from the rotated table, omitting any asterisks.
For example, given the original message ‘iloveyouJack’, the message length is L = 12. Thus the padded message is ‘iloveyouJack****’, with length M = 16. Below are the two tables before and after rotation.
Then we read the secret message as ‘Jeiaylcookuv’.
输入
The ?rst line of input is the number of original messages, 1 ≤ N ≤ 100. The following N lines each have a message to encrypt. Each message contains only characters a–z (lower and upper case), and has length 1 ≤ L ≤ 10 000.
输出
For each original message, output the secret message.
样例输入 Copy
2
iloveyoutooJill
TheContestisOver
样例输出 Copy
iteiloylloooJuv
OsoTvtnheiterseC
就是模拟,没啥好说的
#include
#include
using namespace std;
const int N=5000;
char c[N][N];
int f;
int pfs(int n)
{
for(int i=1;;i++)
{
if(i==n/i)
{
f=i;
return 1;
}
if(i*i>n)
break;
}
return 0;
}
int main(){
int n;
cin>>n;
while(n--)
{
int len,b;
char ch[20000],str[20000];
cin>>ch;
len=strlen(ch);
for(int i=len;;i++)
{
if(pfs(i))
{
b=f;
break;
}
}
//cout<
int k=0;
for(int i=1;i<=b;i++)
{
for(int j=1;j<=b;j++)
{
c[i][j]=ch[k];
k++;
if(k>len)
c[i][j]='*';
}
}
k=0;
for(int j=1;j<=b;j++)
{
for(int i=b;i>=1;i--)
{
str[k]=c[i][j];
k++;
}
}
for(int i=0;i)
{
if(str[i]=='*')
continue;
else
cout<<str[i];
}
cout<<endl;
}
return 0;
}
问题 E: 优美的数
题目描述
在BLUESKY007眼中,如果一个数包含7或这个数是7的倍数,这个数就是优美的。
BLUESKY007在纸上写下了所有大于0的优美的数,她想考考你,第k个数是多少?
输入
第一行一个整数t,表示数据组数。
接下来的t行,每行一个整数k。
输出
一共t行,第i行输出第i组数据的答案。
样例输入 Copy
11
1
2
3
4
5
6
7
8
9
10
2021
样例输出 Copy
7
14
17
21
27
28
35
37
42
47
5477
提示
对于40%的数据,1≤t,k≤10。
对于75%的数据,1≤t,k≤100。
对于100%的数据,1≤t,k≤2021
数据范围也不大,直接算出每个数,然后输出就可以了
#include
using namespace std;
const int N=3000;
int a[N];
int chaifen(int n)
{
while(n)
{
if(n%10==7)
return 1;
n/=10;
}
return 0;
}
int main(){
int n;
cin>>n;
int k=1;
for(int i=7;;i++)
{
if(i%7==0||chaifen(i))
{
a[k]=i;
k++;
}
if(k>2021)
break;
}
while(n--)
{
int x;
cin>>x;
cout<endl;
}
return 0;
}
问题 A: 优秀的拆分
题目描述
一般来说,一个正整数可以拆分成若干个正整数的和。例如,1=1,10=1+2+3+4等。
对于正整数n的一种特定拆分,我们称它为“优秀的”,当且仅当在这种拆分下,n被分解为了若干个不同的2的正整数次幂。注意,一个数x能被表示成2的正整数次幂,当且仅当x能通过正整数个2相乘在一起得到。
例如,10=8+2=23+21是一个优秀的拆分。但是,7=4+2+1=22+21+20就不是一个优秀的拆分,因为1不是2的正整数次幂。
现在,给定正整数n,你需要判断这个数的所有拆分中,是否存在优秀的拆分。若存在,请你给出具体的拆分方案。
输入
输入只有一行,一个正整数n,代表需要判断的数。
输出
如果这个数的所有拆分中,存在优秀的拆分。那么,你需要从大到小输出这个拆分中的每一个数,相邻两个数之间用一个空格隔开。可以证明,在规定了拆分数字的顺序后,该拆分方案是唯一的。
若不存在优秀的拆分,输出“-1”(不包含双引号)。
样例输入 Copy
【样例1】
6
【样例2】
7
样例输出 Copy
【样例1】
4 2
【样例2】
-1
提示
样例1解释
6=4+2=22+21是一个优秀的拆分。注意,6=2+2+2不是一个优秀的拆分,因为拆分成的3个数不满足每个数互不相同。
对于20%的数据,n≤10。
对于另外20%的数据,保证n为奇数。
对于另外20%的数据,保证n为2的正整数次幂。
对于80%的数据,n≤1024。
对于100%的数据,1≤n≤1×107。
这个循环细节卡了好久...不知道为什么
怪怪的
#include
#include
using namespace std;
int main(){
int n;
cin>>n;
if(n%2!=0)
{
cout<<"-1"<<endl;
return 0;
}
while(1)
{
if(n<=0)
break;
int k=1;
while(1)
{
if(pow(2,k+1)>n)
break;
k++;
}
int x=pow(2,k);
n-=x;
printf("%d ",(int)x);
}
return 0;
}
就是模拟,没啥好说的