试题 A: 九进制转十进制
送分
试题 B: 顺子日期
Python写个循环遍历判断
试题 C: 刷题统计
除法
试题 D: 修剪灌木
每个点两边最大距离
试题 E: X 进制减法
应该是贪心,随便写的,做错了
#include
#include
#include
using namespace std;
#define int long long
#define p 1000000007
int n;
int lena,lenb;
int a[100010], b[100010];
signed main()
{
cin>>n;
cin>>lena;
for(int i=1;i<=lena;i++) cin>>a[i];
cin>>lenb;
for(int i=lena-lenb+1;i<=lena;i++) cin>>b[i];
int sum=0, last=1;
for(int i=lena;i>0;i--){
int x=0;
if(a[i]==0&&b[i]==0) x=2;
else x=max(a[i],b[i])+1;
sum += (a[i]-b[i])*last%p;
last*=x;
}
cout<<sum;
return 0;
}
试题 F: 统计子矩阵
前缀和转化为一维问题,求子序列和,三重循环
试题 G: 积木画
DP一下
试题 H: 扫雷
直接建图 + 暴力拿低保分
试题 I: 李白打酒加强版
DP
# include
# include
# include
using namespace std;
#define int long long
#define p 1000000007
int n, m;
int dp[105][105][105];
signed main()
{
cin >> n >> m;
memset(dp, 0, sizeof dp);
dp[0][0][2] = 1;
for (int i=0;i <= n;i++)
for (int j=0;j <= m;j++) {
if (i == 0 & & j == 0)
continue;
for (int k = 0; k <= m; k++) {
if (j > 0) dp[i][j][k] += dp[i][j - 1][k + 1];
if (i > 0 & & k % 2 == 0) dp[i][j][k] += dp[i - 1][j][k / 2];
}
}
cout << dp[n][m - 1][1];
return 0;
}
试题 J: 砍竹子
贪心+模拟
# include
# include
# include
# include
using namespace std;
# define int long long
# define N 200010
int n,ans;
vector<int>vec;
int get(int h){
return floor(sqrt(h / 2 + 1));
}
signed main()
{
// 从高到低进行修剪,连续的合并
cin >> n;
for (int i=1;i <= n;i++) {
int x;cin>>x;
vec.push_back(x);
}
while(++ans){
auto maxx = max_element(vec.begin(), vec.end());
*maxx = get(*maxx);
while(maxx+1!=vec.end()&&*maxx==*(maxx+1)) maxx++;
while(maxx!=vec.begin()&&*maxx == *(maxx-1)) vec.erase(maxx),maxx--;
if(vec.size()==1&&vec[0]==1) break;
}
cout<<ans;
return 0;
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)