Codeforces710

本文探讨了棋盘上国王的可能移动路径计算,通过编程解决数据点位置优化问题,以及矩阵数值填充技巧。同时,涉及字符串操作、排序算法、动态规划等编程技术,展示了算法设计与实现的细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

【未完待续】

A

The only king stands on the standard chess board. You are given his position in format "cd", where c is the column from 'a' to 'h' and dis the row from '1' to '8'. Find the number of moves permitted for the king.

 

King moves from the position e4
Input

The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'.

Output

Print the only integer x — the number of moves permitted for the king.

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 #include<string>
 4 #include<string.h>
 5 #include<iostream>
 6 #include<algorithm>
 7 #include<queue>
 8 #include<math.h>
 9 #include<vector>
10 #include<map>
11 #include<set>
12 #define il inline
13 #define re register
14 using namespace std;
15 string a;
16 int main(){
17     cin>>a;
18     if(a[0]=='a'||a[0]=='h'){
19         if(a[1]=='1'||a[1]=='8')
20             cout<<"3";
21         else cout<<"5";
22     }
23     else{
24         if(a[1]=='1'||a[1]=='8')
25             cout<<"5";
26         else cout<<"8";
27     }
28     return 0;
29 }

B

You are given n points on a line with their coordinates xi. Find the point x so the sum of distances to the given points is minimal.

Input

The first line contains integer n (1 ≤ n ≤ 3·10^5) — the number of points on the line.

The second line contains n integers xi ( - 10^9 ≤ xi ≤ 10^9) — the coordinates of the given n points.

Output

Print the only integer x — the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 #include<string>
 4 #include<string.h>
 5 #include<iostream>
 6 #include<algorithm>
 7 #include<queue>
 8 #include<math.h>
 9 #include<vector>
10 #include<map>
11 #include<set>
12 #define il inline
13 #define re register
14 using namespace std;
15 int n,a[1000001];
16 int main(){
17     scanf("%d",&n);
18     for(int i=1;i<=n;i++)
19         scanf("%d",&a[i]);
20     sort(a+1,a+n+1);
21     if(n&1){
22         cout<<a[n/2+1];
23     }
24     else{
25         cout<<a[n/2];
26     }
27     return 0;
28 }

C

Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both main diagonals are odd.

Input

The only line contains odd integer n (1 ≤ n ≤ 49).

Output

Print n lines with n integers. All the integers should be different and from 1 to n2. The sum in each row, column and both main diagonals should be odd.

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 #include<string>
 4 #include<string.h>
 5 #include<iostream>
 6 #include<algorithm>
 7 #include<queue>
 8 #include<math.h>
 9 #include<vector>
10 #include<map>
11 #include<set>
12 #define il inline
13 #define re register
14 using namespace std;
15 int x=1,y,cnt=1,n,a[101][101];
16 int main(){
17     cin>>n;y=n/2+1;
18     while(cnt<=n*n){
19         a[x][y]=(cnt++);
20         if(x==1){
21             if(y==n){
22                 x=2;y=n;
23             }
24             else{
25                 x=n;y++;
26             }
27         }
28         else if(y==n){
29             x--;y=1;
30         }
31         else{
32             if(a[x-1][y+1]>0){
33                 x++;
34             }
35             else{
36                 x--;y++;
37             }
38         }
39     }
40     for(int i=1;i<=n;i++){
41         for(int j=1;j<=n;j++)
42             cout<<a[i][j]<<" ";
43         cout<<endl;
44     }
45     return 0;
46 }

E

zscoder wants to generate an input file for some programming competition problem.

His input is a string consisting of n letters 'a'. He is too lazy to write a generator so he will manually generate the input in a text editor.

Initially, the text editor is empty. It takes him x seconds to insert or delete a letter 'a' from the text file and y seconds to copy the contents of the entire text file, and duplicate it.

zscoder wants to find the minimum amount of time needed for him to create the input file of exactly n letters 'a'. Help him to determine the amount of time needed to generate the input.

Input

The only line contains three integers nx and y (1 ≤ n ≤ 10^7, 1 ≤ x, y ≤ 10^9) — the number of letters 'a' in the input file and the parameters from the problem statement.

Output

Print the only integer t — the minimum amount of time needed to generate the input file.

可以花费x的代价使得一个数加一或者减一,或者y的代价使得他乘2,问达到n需要多少的代价

这道题嘛,非常巧妙,看dp方程就ok了,主要是利用了减一之前必须乘2的性质【废话】

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 #include<string>
 4 #include<string.h>
 5 #include<iostream>
 6 #include<algorithm>
 7 #include<queue>
 8 #include<math.h>
 9 #include<vector>
10 #include<map>
11 #include<set>
12 #define il inline
13 #define re register
14 using namespace std;
15 typedef long long ll;
16 ll f[10000001];
17 int n,x,y;
18 int main(){
19     scanf("%d%d%d",&n,&x,&y);
20     for(int i=1;i<=n;i++){
21         f[i]=min(f[i-1]+x,f[(i+1)>>1]+y+x*(i&1));
22     }
23     printf("%I64d",f[n]);
24     return 0;
25 }

 

转载于:https://www.cnblogs.com/ExiledPoet/p/5803303.html

资源下载链接为: https://pan.quark.cn/s/f989b9092fc5 在 Android 应用开发中,开发一款仿 OPPO 手机计算器的应用是极具实践价值的任务,它融合了 UI 设计、事件处理以及数学逻辑等多方面的技术要点。当前的“最新版仿 OPPO 手机计算器--android.rar”压缩包中,提供了该计算器应用的源代码,这为开发者深入学习 Android 编程提供了宝贵的资源。 UI 设计是构建此类计算器应用的基石。OPPO 手机的计算器界面以清晰的布局和良好的用户交互体验著称,其中包括数字键、运算符键以及用于显示结果的区域等关键元素。开发者需借助 Android Studio 中的 XML 布局文件来定义这些界面元素,可选用 LinearLayout、GridLayout 或 ConstraintLayout 等布局管理器,并搭配 Button 控件来实现各个按键功能。同时,还需考虑不同分辨率屏幕和设备尺寸的适配问题,这通常涉及 Density Independent Pixel(dp)单位的应用以及 Android 尺寸资源的合理配置。 事件处理构成了计算器的核心功能。开发者要在每个按钮的点击事件中编写相应的处理代码,通常通过实现 OnClickListener 接口来完成。例如,当用户点击数字键时,相应的值会被添加到显示区域;点击运算符键时,则会保存当前操作数并设定运算类型。而对于等号(=)按钮,需要执行计算操作,这往往需要借助栈数据结构来存储操作数和运算符,并运用算法解析表达式以完成计算。 数学逻辑的实现则是计算器功能的关键体现。在 Android 应用中,开发者可以利用 Java 内置的 Math 类,或者自行设计算法来完成计算任务。基本的加减乘除运算可通过简单的算术操作实现,而像求幂、开方等复杂运算则需调用 Math 类的相关方法。此外
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值