Topic link

A  The Third Three Number Problem

The question

To give you one n, Let you be satisfied Of a,b,c.

If not, output -1.

Ideas

Obviously arbitrary a,b,c It is impossible to get odd numbers .

Considering only even numbers, we can get a special structure n/2 , 0 , 0 .

Code

#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;
const ll N = 1e6;
void solve()
{
int n;
cin >> n;
if (n % 2 == 1)
cout << "-1\n";
else
cout << n / 2 << " 0 0\n";
} int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--)
solve();
return 0;
}

B - Almost Ternary Matrix

The question

structure 01 matrix , It is required that at most two numbers of each number are the same .

Ideas

With this pattern    Extend the basic construction unit , Then cut out the required pattern according to the scope given by the meaning of the topic .

Code

#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;
const ll N = 1e6;
int s[10][65];
void solve()
{
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
cout << s[i % 4][j] << " ";
cout << endl;
}
} int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
s[1][1] = 1, s[1][2] = 0, s[1][3] = 0, s[1][4] = 1;
s[1][0] = 1;
s[2][1] = 0, s[2][2] = 1, s[2][3] = 1, s[2][4] = 0;
s[2][0] = 0;
for (int i = 1; i <= 60; i++)
{
s[0][i] = s[1][i % 4];
s[1][i] = s[1][i % 4];
s[2][i] = s[2][i % 4];
s[3][i] = s[2][i % 4];
}
int t;
cin >> t;
while (t--)
solve();
return 0;
}

C - The Third Problem

The question

Give a long for n Array of a, The content is 0 To n-1. Define an operation MEX For collection c1,c2,.....,ck   The minimum non negative number that does not appear in .

for example

Let you find an array b, The content is also 0 To n-1. To any   There are

Ideas

Set yes s[x] by x stay a Position in

First consider 0 The location of , because MEX[0]=1, therefore 0 The position of can only be s[0], Can be determined 1 The location of the for s[1].

Let's make sure 2~n-1 The same way , With 0 and 1 The index of determines the interval  [L, R], If the next Count x The rope is in the entry section [L, R], Update ans by (( Interval length )-(x-1))*ans, If k If the index of is outside the interval, it will be updated L or R Increase the interval length .

Code

#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;
const ll N = 1e5, mod = 1e9 + 7;
void solve()
{
int n;
cin >> n;
int sf[n];
vector<int> s(n);
for (int i = 0; i < n; i++)
{
cin >> sf[i];
s[sf[i]] = i;
}
int l = s[0], r = s[0];
ll ans = 1;
for (int i = 1; i < n; i++)
{
if (s[i] > r)
r = s[i];
else if (s[i] < l)
l = s[i];
else
ans = ans * (r - l + 1 - i) % mod;
}
cout << ans << endl;
} int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--)
solve();
return 0;
}

Codeforces Round #804 (Div. 2) More articles about

  1. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it Water problem #I hate that I love that I hate ...

  2. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  3. Codeforces Round #368 (Div. 2)

    Through –>Codeforces Round #368 (Div. 2) A Brain’s Photos To give you one NxM Matrix , A letter represents a color , If there is ”C”,”M”,”Y” Any one of the three will lose ...

  4. cf The way ,1,Codeforces Round #345 (Div. 2)

     cf The way ,1,Codeforces Round #345 (Div. 2) ps: For the first time yesterday cf match , Before the game, in order to get familiar with cf The difficulty of the title . So I did round#345 Try the depth of the water .....   ...

  5. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) I'm turning green ! Problems     # Name     A Team Olympiad standard input/outpu ...

  6. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

  7. Codeforces Round #262 (Div. 2) 1004

    Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...

  8. Codeforces Round #371 (Div. 1)

    A: The main idea of the topic : In a multiset I'm asking for support 3 Kind of operation : 1. Add a number 2. Delete a number 3. Give a 01 Sequence , ask multiset How many of these numbers are there in , Change the odd number in its decimal representation to 1, Even number changed to 0 After and to ...

  9. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 Back in school , Less time , I don't want to write the water problem , No, the problem of water is not so detailed ...

  10. greedy + simulation Codeforces Round #288 (Div. 2) C. Anya and Ghosts

    Subject portal /* greedy + simulation : First , If the burning time of a candle is less than the minimum number of candles that need to be lit, it must be -1( The candle is 1 One per second ), num[g[i]] Record the number of candles lit per ghost visit , If not enough ,tmp For the number of candles needed , ...

Random recommendation

  1. 【USB Multiple power supply 】--- Requirement analysis plan making

    Requirements describe : USB Interface input 5V, Output, respectively, ±5V,100mA; 3.3V,100mA: 1.2V,500mA: Four power supplies . At the same time, it can charge the lithium battery , Removing USB When input, lithium battery can supply power . analysis : First consider the need for a charging device ...

  2. springMVC The code problem - turn

    Thorough solution Spring MVC Chinese garbled problem     1: Form submission controller Get Chinese parameters after garbled solution Be careful :  jsp Page encoding is set to UTF-8 form The form submission method must be post,get ...

  3. Rotate Array

    Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array  ...

  4. understand C# event

    The previous article introduced the concepts related to delegation , Delegate an instance to save this operation or group of operations , The program will use these operations through the delegate instance at a specific time . If you have done GUI Application development , You may be familiar with the above description . stay GUI In the program , Click on a butto ...

  5. C++ And STL And string

    /*C Character arrays in languages generally use char str[] To hold the , But it will be more troublesome ,C++ stay stl Added string type , Encapsulate the common functions of strings , It's easy to operate */#include<cst ...

  6. Shell Python Date and time stamp conversion

    One . The original : A lot of times , Time is stored in timestamp format , If you need to display, you need to convert it into standard format date . You may need to date and timestamp Interturn . Two . Method : 1.Shell Next pair date and timestamp Of each other , Yetong ...

  7. 3 month 3 Japan (2) Search Insert Position

    This question ... It's a little simple , Why only 34% Pass rate of ? The meaning of the title is simply to find index, Or unknown inserted in ascending order ,WA once , Sin , Next time, pay special attention to the changes of variables in the program , Check with samples before submitting . Simply, I'm a little embarrassed to post code ...

  8. Oracle Modify table operation

    As the title :    -- Add column operation : alert table Table name add Name The type of the column eg:alter table EMP1 add pwd varchar2(10); -- Delete column operation : alert ...

  9. torch.utils.data.DataLoader Usage method

    Data loader , A combination of data sets and samplers , And it can provide multiple threads to process data sets . Use this function when training the model , Used to divide training data into groups , This function throws one set of data at a time . Until all the data is thrown . Is to do a data initialization . Generate iteration ...

  10. Four :( Of the seven _ How to interact with running containers )Dockerfile Grammar and practice

    1. Specify the network connection :--net=””   (bridge/host/none/container:  Four types ) notes :192.168.33.18 this IP Is in vagrantfile The virtual machine specified in IP:c ...