当前位置:网站首页>Codeforces Round #719 (Div. 3)
Codeforces Round #719 (Div. 3)
2022-06-27 22:03:00 【My story was traded for wine】
2021.5.6
B
The question : Enter a number n, Judge 1-n There are several numbers that can be broken down per digit ( bits , ten ) All equal .
The question : The decimal system has 1-9, Add the same bit value every time (1->11->111->1111), It is required to be less than or equal to n Can .
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
int main()
{
std::ios::sync_with_stdio(false);
ll t,n;
cin>>t;
while(t--)
{
cin>>n;
ll m=0;
for(ll i=1;i<=9;i++)
{
ll j=i,k=i;
while(j<=n)
{
m++;
j=j*10+k;
}
}
cout<<m<<endl;
}
return 0;
}
D
The question : Give a length of n Sequence , Judge how many numbers are satisfied (i<j)and.
Answer key : If you are more careful, you will find that the above formula can be reduced to , Knowing this simplification, you can easily see the answer , Record the value of each element - Index value , And then judge the value of the previous element each time you input - The number of index values equal to this element .
#include <iostream>
#include <algorithm>
#include <map>
#define ll long long
using namespace std;
int main()
{
std::ios::sync_with_stdio(false);
ll t,n;
cin>>t;
while(t--)
{
cin>>n;
ll sum=0,x;
map<ll,ll>m;
for(int i=1;i<=n;i++)
{
cin>>x;
sum+=m[x-i];
m[x-i]++;
}
cout<<sum<<endl;
}
return 0;
}
E
The question : Give a string , It contains characters * And character ., It is required that all characters * Hyphenated characters * How many steps need to be taken .
Answer key : Traversal string , Record the characters in each position * How much to move to the left for the center , How much to move to the right , The answer is to minimize the sum of the left and right sides .
#include <iostream>
#include <algorithm>
#include <cstdio>
#define ll long long
using namespace std;
ll l[1000005],r[1000005];
char s[1000005];
int main()
{
ll t,n;
scanf("%lld",&t);
while(t--)
{
scanf("%lld%s",&n,s);
for(int i=0;i<n;i++)
{
l[i]=0;
r[i]=0;
}
ll k1=0,k2=0,m1=0,m2=0,sum1=0,sum2=0;
for(int i=0;i<n;i++)
{
if(s[i]=='*')
{
l[i]=k1*m1+sum1;
sum1=l[i];
k1++;
m1=0;
}
else if(s[i]=='.')
{
m1++;
}
}
ll minx=10000000000000000;
for(int i=n-1;i>=0;i--)
{
if(s[i]=='*')
{
r[i]=k2*m2+sum2;
minx=min(minx,l[i]+r[i]);
sum2=r[i];
k2++;
m2=0;
}
else if(s[i]=='.')
{
m2++;
}
}
if(minx==10000000000000000)
printf("0\n");
else
printf("%lld\n",minx);
}
return 0;
}
F1
The question : Yes n One by one (1,0) The number of components , Every time you can (l-r) Elements and , Judgment No. k individual 0 In that position .
Answer key : Two points , Find it directly r The location of , front r The sum of the numbers is r-k;
#include <iostream>
#include <algorithm>
using namespace std;
int ask(int l,int r)
{
int x;
cout<<"? "<<l<<' '<<r<<endl;
cin>>x;
return x;
}
int main()
{
int t,n,k;
cin>>n>>t>>k;
int l=0,r=n,mid;
while(r-1>l)
{
mid=(l+r)/2;
if(mid-ask(1,mid)>=k)
r=mid;
else
l=mid;
}
cout<<"! "<<r<<endl;
return 0;
}
F2
The question : stay F1 Under the premise of t A case , Every time you find the first k individual 0 The location of , Put the position of 0 Replace with 1, Continue with the new case and enter a new k.
Answer key : Use one map Before saving r Number 0 The number of , Then use the same two points to find the first k individual 0 The location of , After the completion of each case, it is necessary to transfer the k Positions and back map Save location 0 The location of -1, This will ensure that each case will 0 Replace with 1.
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
map<int,int>mp;// Before saving r Number 0 The number of
int ask(int r)
{
if(mp.find(r)!=mp.end())
return mp[r];
int x;
cout<<"? 1"<<' '<<r<<endl;
cin>>x;
return mp[r]=r-x;
}
int main()
{
int t,n,k;
cin>>n>>t;
while(t--){
cin>>k;
int l=0,r=n,mid;
while(r-1>l)
{
mid=(l+r)/2;
if(ask(mid)>=k)
r=mid;
else
l=mid;
}
cout<<"! "<<r<<endl;
map<int,int>::iterator it=mp.lower_bound(r);
while(it!=mp.end())
{
it->second--;
it++;
}
}
return 0;
}
G
The question : Find from (1,1) To (n,m) The shortest distance ,a[i][j] by 0 It takes... To take one step w, by -1 You can't go ,>=1 For the portal , It can be transmitted to any other portal , need a[i][j]+ The value of the other portal , The portal can also be empty without using the transport function .
Answer key : from (1,1) and (n,m) Run twice bfs Find the shortest distance of each point , If you use a portal , Need to compute (1,1) Shortest portal to use +(n,m) Shortest portal to use + The cost of using , The shortest gate is the shortest sum of the three , Finally, compare from (1,1) To (n,m) The shortest distance between using and not using the portal .
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <stack>
#include <cstring>
#include <vector>
#define ll long long
using namespace std;
int n,m,w;
int dy[4][2]={1,0,0,1,-1,0,0,-1};
void bfs(int sx,int sy,vector<vector<ll> > &d,vector<vector<ll> > &a)
{
int x,y;
pair<int,int>pi;
queue<pair<int,int> >q;
q.push(make_pair(sx,sy));
d[sx][sy]=0;
while(!q.empty())
{
pi=q.front();
q.pop();
x=pi.first;
y=pi.second;
for(int i=0;i<4;i++)
{
int fx=x+dy[i][0];
int fy=y+dy[i][1];
if(fx>=1&&fy>=1&&fx<=n&&fy<=m&&d[fx][fy]==-1&&a[fx][fy]!=-1)
{
d[fx][fy]=d[x][y]+1;
q.push(make_pair(fx,fy));
}
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin>>n>>m>>w;
vector<vector<ll> > a(n+2,vector<ll>(m+2));
vector<vector<ll> > d1(n+2,vector<ll>(m+2));
vector<vector<ll> > d2(n+2,vector<ll>(m+2));
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>a[i][j];
d1[i][j]=-1;
d2[i][j]=-1;
}
}
bfs(1,1,d1,a);
bfs(n,m,d2,a);
ll best=1e18;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(a[i][j]>=1&&d1[i][j]!=-1)
{
best=min(best,a[i][j]+w*d1[i][j]);
}
}
}
ll ans=1e18;
if(d1[n][m]!=-1)
ans=w*d1[n][m];
if(best!=1e18){
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(a[i][j]>=1&&d2[i][j]!=-1)
ans=min(ans,a[i][j]+w*d2[i][j]+best);
}
}
}
if(ans==1e18)
cout<<-1<<endl;
else
cout<<ans<<endl;
return 0;
}
边栏推荐
- xpath
- [LeetCode]动态规划解分割数组II[Arctic Fox]
- 【Redis】零基础十分钟学会Redis
- [LeetCode]515. 在每个树行中找最大值
- Interview question 3 of software test commonly used by large factories (with answers)
- 年薪50W+的测试大鸟都在用这个:Jmeter 脚本开发之——扩展函数
- 使用Jmeter进行性能测试的这套步骤,涨薪2次,升职一次
- Hash table - sum of arrays
- Gbase 8A OLAP analysis function cume_ Example of dist
- matlab查找某一行或者某一列在矩阵中的位置
猜你喜欢
Go from introduction to practice -- definition and implementation of behavior (notes)
不外泄的测试用例设计秘籍--模块测试
清华大学教授:软件测试已经走入一个误区——“非代码不可”
开源技术交流丨一站式全自动化运维管家ChengYing入门介绍
Summary of Web testing and app testing by bat testing experts
Go from introduction to actual combat -- channel closing and broadcasting (notes)
The create database of gbase 8A takes a long time to query and is suspected to be stuck
It smells good. Since I used Charles, Fiddler has been completely uninstalled by me
[MySQL] database function clearance Tutorial Part 2 (window function topic)
Simulink method for exporting FMU model files
随机推荐
This set of steps for performance testing using JMeter includes two salary increases and one promotion
GBase 8a OLAP分析函数 cume_dist的使用样例
. Net learning notes (V) -- lambda, LINQ, anonymous class (VaR), extension method
matlab查找某一行或者某一列在矩阵中的位置
语言弱点列表--CWE,一个值得学习的网站
Analysis of stone merging
[LeetCode]动态规划解分割数组I[Red Fox]
[Sword Offer II]剑指 Offer II 029. 排序的循环链表
[LeetCode]161. 相隔为 1 的编辑距离
"Apprendre cette image" apparaît sur le Bureau win11 comment supprimer
[LeetCode]515. Find the maximum value in each tree row
Software test automation test -- interface test from entry to proficiency, learn a little every day
Secret script of test case design without leakage -- module test
Stm32f107+lan8720a use stm32subemx to configure network connection +tcp master-slave +udp app
How to do function test well? Are you sure you don't want to know?
GBase 8a V8版本节点替换期间通过并发数控制资源使用减少对系统影响的方法
Go from introduction to actual combat - only any task is required to complete (notes)
不外泄的测试用例设计秘籍--模块测试
【MySQL】数据库函数通关教程下篇(窗口函数专题)
Special tutorial - Captain selection game