当前位置:网站首页>Contest 2050 and Codeforces Round #718 (Div. 1 + Div. 2)
Contest 2050 and Codeforces Round #718 (Div. 1 + Div. 2)
2022-06-27 22:03:00 【My story was traded for wine】
2021.4.23
A
The question : Give a number n, Judge n Can be 2050*10^k Add the numbers taken from to get .
Answer key : Every number added is 2050 Multiple , So direct judgment n Can be 2050 Get by dividing , If you can, add the number of digits of the quotient and .
#include <cstdio>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
int main()
{
ll t,n;
scanf("%lld",&t);
while(t--)
{
scanf("%lld",&n);
if(n%2050)
printf("-1\n");
else
{
ll ans=n/2050;
ll sum=0;
while(ans)
{
sum+=ans%10;
ans/=10;;
}
printf("%lld\n",sum);
}
}
return 0;
}B
The question : to n+1 A little bit ,0 To n, Each adjacent point has m side , So there is n Group m side , value =0 To n The length of the smallest side of , Each edge can only be used once , For this m The minimum sum of the group scheme values , Find a specific solution .
Answer key : Just take out the front of all sides m Small , And then put this front m The small edges are placed on different schemes , The sum of the value thus obtained is the smallest .
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdlib.h>
#include <cstring>
#define ll long long
using namespace std;
struct node
{
int x,y,v;
}s[100005];
bool cmp(const node &t1,const node &t2)
{
return t1.v<t2.v;
}
int main()
{
ll t,n,m,a[105][105],b[105][105];
scanf("%lld",&t);
while(t--)
{
scanf("%lld%lld",&n,&m);
int l=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
scanf("%lld",&a[i][j]);
s[l].x=i;
s[l].y=j;
s[l++].v=a[i][j];
}
}
sort(s,s+l,cmp);
int p=0;
memset(b,0,sizeof(b));
for(int i=1;i<=m;i++)
{
b[s[p].x][i]=s[p].v;
p++;
}
for(int i=p;i<l;i++)
{
for(int j=1;j<=m;j++)
{
if(!b[s[i].x][j])
{
b[s[i].x][j]=s[i].v;
break;
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++)
printf("%lld ",b[i][j]);
printf("\n");
}
}
return 0;
}C
The question : Give a sequence , The sequence is required to be placed on the diagonal of the matrix ( From top left to bottom right ), Then give the matrix design scheme , The number of areas in the same block is the same , And the number of numbers in the region = The number of , All numbers are in the lower left corner of the matrix , If there is no such matrix, output -1.
Answer key : First place the sequence on the diagonal of the matrix , Then determine the area from top to bottom , Each area is defined to the left , If the left position has been placed , Just look on the left of the next line , Loop this operation , Know to determine the complete half matrix , If the existing number is not put out and there is no place to put it, it will be output -1( Practice has proved that there is no such thing -1).
#include <cstdio>
#include <queue>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <map>
#include <stack>
#include <stdlib.h>
#include <set>
#include <cstring>
#include <string>
using namespace std;
int n,vis[505],x,b[505][505];
void init()
{
for(int i=1;i<=n;i++)
vis[i]=i;
}
int main(void)
{
scanf("%d",&n);
init();
for(int i=1;i<=n;i++)
{
scanf("%d",&x);
b[i][i]=x;
vis[x]--;
}
for(int i=1;i<=n;i++)
{
int k=b[i][i],l=i,r=i;
while(r<=n)
{
if(!vis[k])
break;
if(!b[r][l-1]&&l!=1)
{
b[r][l-1]=k;
vis[k]--;
l--;
continue;
}
r++;
b[r][l]=k;
vis[k]--;
}
if(vis[k])
{
printf("-1\n");
return 0;
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
printf("%d ",b[i][j]);
printf("\n");
}
return 0;
}D
The question : Give me a n×m Matrix , Tell you the length of each adjacent grid edge , Ask each point to go k The shortest length to return to the origin after step , You can walk to the same grid many times , But you can't stand still at every step .
Answer key : When k It is impossible to go to the origin when it is an odd number , Direct output -1.k For even when , It can be understood as walking k/2 The shortest length of a step . Can record each grid walk k/2 The minimum length spent after a step , direct dp,x,y The smallest part of this grid i The step path is the smallest path of the four sided lattice i-2 Walk on foot 2 Step to the target grid ( You can read the code directly if you don't understand it )
linear equation :dp[k][i][j]=min(dp[k-2][i-1][y],dp[k-2][i+1][y],dp[k-2][i][j-1],dp[k-2][i][j+1]).
#include <cstdio>
#include <queue>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <map>
#include <stack>
#include <stdlib.h>
#include <set>
#include <cstring>
#include <string>
#include <vector>
#include <iomanip>
#define ll long long
#define pi acos(-1)
#define mod 1000000007
#define INF 111111
#define exp 1e-8
using namespace std;
int n,m,k;
ll dp[25][505][505],b[505][505],c[505][505];
int main(void)
{
int x,y;
scanf("%d%d%d",&n,&m,&k);
memset(b,INF,sizeof(b));
memset(c,INF,sizeof(c));
for(int i=1;i<=n;i++)
for(int j=1;j<m;j++)
scanf("%lld",&b[i][j]);
for(int i=1;i<n;i++)
for(int j=1;j<=m;j++)
scanf("%lld",&c[i][j]);
if(k%2)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
printf("-1 ");
printf("\n");
}
}
else
{
memset(dp,INF,sizeof(dp));
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
dp[0][i][j]=0;
for(int i=2;i<=k;i+=2)
{
for(int j=1;j<=n;j++)
{
for(int o=1;o<=m;o++)
{
// Here, because the cross-border grid has been counted as the largest , Therefore, it does not affect the minimum value
// Don't drive ll It will explode here , If you add the condition to judge whether the lattice is out of bounds, you can not open it ll
dp[i][j][o]=min(dp[i][j][o],dp[i-2][j-1][o]+2*c[j-1][o]);
dp[i][j][o]=min(dp[i][j][o],dp[i-2][j+1][o]+2*c[j][o]);
dp[i][j][o]=min(dp[i][j][o],dp[i-2][j][o-1]+2*b[j][o-1]);
dp[i][j][o]=min(dp[i][j][o],dp[i-2][j][o+1]+2*b[j][o]);
}
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
printf("%lld ",dp[k][i][j]);
printf("\n");
}
}
return 0;
}
边栏推荐
- Go from introduction to practice -- shared memory concurrency mechanism (notes)
- Open source technology exchange - Introduction to Chengying, a one-stop fully automated operation and maintenance manager
- GBase 8a V8版本节点替换期间通过并发数控制资源使用减少对系统影响的方法
- \w和[A-Za-z0-9_],\d和[0-9]等价吗?
- Go from introduction to actual combat -- channel closing and broadcasting (notes)
- GBase 8a OLAP分析函数cume_dist的使用样例
- [Sword Offer II]剑指 Offer II 029. 排序的循环链表
- xpath
- Test automatique de Test logiciel - test d'interface de l'introduction à la maîtrise, apprendre un peu chaque jour
- [LeetCode]186. Flip word II in string
猜你喜欢

登录凭证(cookie+session和Token令牌)

不外泄的测试用例设计秘籍--模块测试

开源技术交流丨一站式全自动化运维管家ChengYing入门介绍
![[LeetCode]动态规划解拆分整数I[Silver Fox]](/img/18/8dc8159037ec1262444db8899cde0c.png)
[LeetCode]动态规划解拆分整数I[Silver Fox]

Go from introduction to practice -- definition and implementation of behavior (notes)

Simulink导出FMU模型文件方法

STM32F107+LAN8720A使用STM32cubeMX配置网络连接+tcp主从机+UDP app

Go from introduction to actual combat -- channel closing and broadcasting (notes)

洛谷P5706 再分肥宅水

Experience sharing of meituan 20K Software Test Engineers
随机推荐
qt 大文件生成md5校验码
Interview question 3 of software test commonly used by large factories (with answers)
Summary of gbase 8A database user password security related parameters
分享|智慧环保-生态文明信息化解决方案(附PDF)
北京邮电大学|用于成本和延迟敏感的虚拟网络功能放置和路由的多智能体深度强化学习
Process control task
Little known MySQL import data
How to do function test well? Are you sure you don't want to know?
GBase 8a的create database 会被查询耗时很长怀疑卡住的现象分析
GBase 8a V8版本节点替换期间通过并发数控制资源使用减少对系统影响的方法
Oracle migration MySQL unique index case insensitive don't be afraid
[LeetCode]508. 出現次數最多的子樹元素和
vmware虚拟机PE启动
.NET学习笔记(五)----Lambda、Linq、匿名类(var)、扩展方法
YOLOv6:又快又准的目标检测框架开源啦
[LeetCode]508. 出现次数最多的子树元素和
Burp suite遇到的常见问题
win11桌面出現“了解此圖片”如何删除
Hash table - sum of arrays
Stm32cubeide1.9.0\stm32cubemx 6.5 f429igt6 plus lan8720a, configure eth+lwip