AtCoder Beginner Contest 278
A - Shift
Title description:
Give you n numbers, perform k rounds of left shift operation, the leftmost element will be deleted, and a 0 will be added to the far right
output the final result
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define inf 0x3f3f3f3f
#define m_p(a, b) make_pair(a, b)
#define mod9 998244353
#define mod7 1000000007
#define io ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef pair<int, int>pii;
#define MAX 300050
int n, m, k, x;
int tr[MAX];
void work()
{
cin >>n >>k;
for(int i= 1; i <= n; ++i)cin >>tr[i];
for(int i = k +1; i <= n; ++i)cout <<tr[i] << ' ';
for(int i = 1; i <= min(k, n); ++i)cout << 0 << ' ';
cout << endl;
}
int main()
{
io;
work();
return 0;
}
B - Misjudge the Time
Title description:
Give you a 24-hour time, expressed as
AB:CD
, if a timeAC:BD
is also a legal time, then this time is a good timeNow give you a point in time, ask when is the next good time from this point (including this point)
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define inf 0x3f3f3f3f
#define m_p(a, b) make_pair(a, b)
#define mod9 998244353
#define mod7 1000000007
#define io ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef pair<int, int>pii;
#define MAX 300050
int n, m, k, x;
int tr[MAX];
bool judge(int x, int y)
{
if(x >= 0 && x < 24 && y >= 0 &&y<60)return true;
else return false ;
}
void work()
{
cin >>n >>k;
int x, y = k;
for(int i = n; i <= 23; ++i)
{
int a = i / 10, b = i % 10;
for(int j = y; y <= 59; ++y)
{
int c = j / 10,d = j % 10;
if(judge(a*10+c, b*10+d))
{
cout << i <<' ' <<j << endl;
return;
}
}
y = 0;
}
cout << 0 << ' ' << 0 << endl;
}
int main()
{
io;
work();
return 0;
}
C - FF
Title description:
three operations
1 a b
, if a does not have an edge pointing to b, connect a and b with a directed edge2 a b
, if there is an edge pointing to b in a, remove this directed edge3 a b
, ask whether there is a directed edge from a to b, output if there is oneYes
, and output if notNo
Ideas:
map<pair<int,int>, bool>
Just use violence
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define inf 0x3f3f3f3f
#define m_p(a, b) make_pair(a, b)
#define mod9 998244353
#define mod7 1000000007
#define io ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef pair<int, int>pii;
#define MAX 300050
int n, m, k, x;
int tr[MAX];
int op, a, b;
void work()
{
cin >>n >>m;
map<pii, bool>mp;
for(int i = 1; i <= m; ++i)
{
cin >> op >> a >>b;
if(op == 1)mp[m_p(a, b)] = 1;
else if(op == 2)
{
if(mp.count(m_p(a, b)) == 1)mp[m_p(a, b)] = 0;
}
else
{
if(mp[m_p(a, b)] == 1 && mp[m_p(b, a)] == 1)cout <<"Yes\n";
else cout <<"No\n";
}
}
}
int main()
{
io;
work();
return 0;
}
D - All Assign Point Add
Title description:
array of length n, perform q operations
1 x
, turning all elements of the array intox
2 i x
,Givea[i]+=x
3 i
, outputa[i]
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define inf 0x3f3f3f3f
#define m_p(a, b) make_pair(a, b)
#define mod9 998244353
#define mod7 1000000007
#define io ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef pair<int, int>pii;
#define MAX 300050
int n, m, k, x;
int op, a, b;
int tr[MAX];
bool vis[MAX];
void work()
{
vector<int>v;
cin >>n;
for(int i = 1; i <= n; ++i)
{
cin >>tr[i];
vis[i] = 1;
v.push_back(i);
}
cin >> m;
x = 0;
for(int i= 1; i <= m; ++i)
{
cin >>op;
if(op == 1)
{
cin >> a;
for(auto u :v)vis[u] = 0;
v.clear();
x = a;
}
else if(op == 2)
{
cin >> a >> b;
if(vis[a])tr[a] += b;
else
{
vis[a] = 1;
v.push_back(a);
tr[a] = x + b;
}
}
else
{
cin >> a;
if(vis[a])cout << tr[a] << endl;
else cout << x << endl;
}
}
}
signed main()
{
io;
work();
return 0;
}
E - Grid Filling
Title description:
Given
H∗W
a matrix, the value of each element in the matrix is1∼N
between . Givenh,w
, for all(k,l)
,0≤k≤H−h,0≤l≤W−w
, to output:If you cover the rectangle
(k,l)
with the upper left corner, the length ish
, and the widthw
is , how many kinds of numbers can there be left on the matrix.1 ≤ H , W , N ≤ 300 , 1 ≤ h ≤ H , 1 ≤ w ≤ W 1≤H,W,N≤300,1≤h≤H,1≤w≤W 1≤H,W,N≤300,1≤h≤H,1≤w≤W
Ideas:
Violence is fine
For each layer, first violently deduct the influence of the entire matrix, and then start to move to the right. Every time you move, you only need to add back the left column and deduct the influence of the right column.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define inf 0x3f3f3f3f
#define m_p(a, b) make_pair(a, b)
#define mod9 998244353
#define mod7 1000000007
#define io ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef pair<int, int>pii;
#define MAX 300050
int n, m, k, p, q, x, y;
int op, a, b;
int tr[305][305];
void work()
{
cin >>n >> m >> k >> p >>q;
map<int, int>mp;
for(int i = 1; i <= n; ++i)
{
for(int j = 1; j <= m; ++j)
{
cin >>tr[i][j];
++mp[tr[i][j]];
}
}
for(int i = 1; i + p - 1 <= n; ++i)
{
map<int, int>mpp;mpp = mp;
for(int x = i; x <= i + p - 1; ++ x)
{
for(int y = 1; y <= q; ++y)
{
--mpp[tr[x][y]];
if(mpp[tr[x][y]] == 0)mpp.erase(tr[x][y]);
}
}
cout << mpp.size();
for(int j = 2; j + q - 1 <= m; ++j)
{
for(int x = i; x <= i +p - 1; ++x)
{
++mpp[tr[x][j-1]];
--mpp[tr[x][j+q-1]];
if(mpp[tr[x][j+q-1]] == 0)mpp.erase(tr[x][j+q-1]);
}
cout << ' ' << mpp.size();
}
cout << endl;
}
}
signed main()
{
io;
work();
return 0;
}
F - Shiritori
Title description:
Given n strings, play a game
Except for the first time you can take the string at will, other times you can only take the string starting with the last character of the string you took last time
Ask whoever fails first loses
Ideas:
I was very happy when I successfully got the F question in the first competition
This question looks like a classic problem of adversarial games, we can directly go to dfs violently
first build a graph
We define
dfs(x)
that when the previous person choosess[x]
the string, the current state of the first hand, if the first hand must win, it will returntrue
, and if the first hand must lose, it will returnfalse
Obviously, the current state can be pushed from the following state. If
x
there is a state that the first hand must lose in the subsequent node, then the current point can make the second hand lose by going to that point, and then it will reach the state of the first hand must win, so return true ; Conversely, if the successor node is in the state of the first mover must win, then this point will face the second mover must win no matter what, then it is the first mover must lose, and return flaseSince the first string can be selected at will, we can start from each string to search
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define inf 0x3f3f3f3f
#define m_p(a, b) make_pair(a, b)
#define mod9 998244353
#define mod7 1000000007
#define io ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef pair<int, int>pii;
#define MAX 300050
int n, m, k, p, q, x, y;
int op, a, b;
vector<int>G[30];
string s[20];
bool vis[MAX];
bool dfs(int u)
{
for(auto v : G[s[u].back() - 'a'+1])
{
if(vis[v])continue;
vis[v] = 1;
if(dfs(v) == 0){
vis[v] = 0;
return 1;
}
vis[v] = 0;
}
return 0;
}
void work()
{
cin >> n;
for(int i = 1; i <= n; ++i)
{
cin >>s[i];
G[s[i][0]-'a'+1].push_back(i);
}
for(int i = 1; i <= n; ++i)
{
vis[i] = 1;
if(dfs(i) == 0)
{
cout <<"First\n";
return;
}
vis[i] = 0;
}
cout <<"Second\n";
}
int main()
{
io;
work();
return 0;
}