The first day punch Codeforces Round # 569 (Div. 2)

In order to be able early on purple name, I hereby open a record title record brush every day.
In addition to the daily themes, a day set cf, driving a virtual competition to do.
A
water problem

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<bitset>
#include<map>
//#include<regex>
#include<cstdio>
#define up(i,a,b)  for(int i=a;i<b;i++)
#define dw(i,a,b)  for(int i=a;i>b;i--)
#define upd(i,a,b) for(int i=a;i<=b;i++)
#define dwd(i,a,b) for(int i=a;i>=b;i--)
//#define local
typedef long long ll;
typedef unsigned long long ull;
const double esp = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int inf = 1e9;
using namespace std;
ll read()
{
    char ch = getchar(); ll x = 0, f = 1;
    while (ch<'0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
    return x * f;
}
typedef pair<int, int> pir;
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lrt root<<1
#define rrt root<<1|1
int n;
int main()
{
    n = read();
    int sum = 0; int len = 2 * n - 1;
    upd(i, 1, n - 2)sum += i;
    cout << (len*len-((n-1)*(n-1) - sum)*4) << endl;
    return 0;
}

B
This question wa seven times. . I started with a feeling, a little later to derive a bit.
It should not be ah.

The meaning of problems: given a sequence of operations required can be performed in a sequence of a certain value of I = -a I -1, Q maximum product.
Solution:
As can be seen, just look at the absolute value, then we can see that there will be only positive becomes negative a positive return. That we do not care, first of all sequence becomes negative to say.
If the sequence length is an even number, then the product is positive, it is still on.
If the sequence length is odd, the product is negative, is not still on.
Then we need to change a negative to a positive number.
It assumed that the number is a. (A <0)
assumes the presence of a number b, | a | <| b |
so the cost becomes. 1-a is a SUM
becomes price for b. 1-b
SUM 2 .
Removing portions of the same, becomes (. 1-A) B, (. 1-B) A change in the absolute value so we large numbers.

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<bitset>
#include<map>
//#include<regex>
#include<cstdio>
#define up(i,a,b)  for(int i=a;i<b;i++)
#define dw(i,a,b)  for(int i=a;i>b;i--)
#define upd(i,a,b) for(int i=a;i<=b;i++)
#define dwd(i,a,b) for(int i=a;i>=b;i--)
//#define local
typedef long long ll;
typedef unsigned long long ull;
const double esp = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int inf = 1e9;
using namespace std;
ll read()
{
    char ch = getchar(); ll x = 0, f = 1;
    while (ch<'0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
    return x * f;
}
typedef pair<int, int> pir;
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lrt root<<1
#define rrt root<<1|1
const int N = 1e5 + 10;
struct node {
    int val, pos;
    bool operator < (const node &a)const {
        return val < a.val;
    }
}b[N];
int a[N];
int n;
int ans[N];
int main()
{
    n = read();
    upd(i, 1, n)a[i] = read(),b[i].val=a[i],b[i].pos=i;
    upd(i, 1, n)
        if (b[i].val >= 0)b[i].val = -b[i].val - 1;
    sort(b+1, b + n+1);
    if (n %2)
    {
        b[1].val = -b[1].val - 1;
    }
    upd(i, 1, n)ans[b[i].pos] = b[i].val;
    upd(i, 1, n)cout << ans[i] << " ";
}

c: to give a deque, takes out the first two, a, b, on the first large numbers, on a small tail.
Q a and b in the m-th operation.
Read the title on the second out. . I feel much simpler than b. . .
Obviously this topic old routine, first find the law, because a large m.
Sure enough, look at the subject to sample found when the team moved to max first, followed by n-1 digital will infinite loop.
Therefore, we determine what m, is the team moved to the max or after separate discussions prior to first.

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<bitset>
#include<map>
//#include<regex>
#include<cstdio>
#define up(i,a,b)  for(int i=a;i<b;i++)
#define dw(i,a,b)  for(int i=a;i>b;i--)
#define upd(i,a,b) for(int i=a;i<=b;i++)
#define dwd(i,a,b) for(int i=a;i>=b;i--)
//#define local
typedef long long ll;
typedef unsigned long long ull;
const double esp = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int inf = 1e9;
using namespace std;
ll read()
{
    char ch = getchar(); ll x = 0, f = 1;
    while (ch<'0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
    return x * f;
}
typedef pair<int, int> pir;
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lrt root<<1
#define rrt root<<1|1
int n, q;
const int N = 1e5 + 10;
int a[N];
deque<int>dq;
int a2[N];
pair<int, int>p[N];
int main()
{
    n = read(), q = read();
    int maxn = -1, pos = -1;
    up(i, 0, n)
    {
        a[i] = read();
        if (maxn < a[i])maxn = a[i], pos = i;
        dq.push_back(a[i]);
    }
    int num = 1;
    int cnt = 0;
    while (1)
    {
        int a = dq.front();
        if (a == maxn)break;
        dq.pop_front();
        int b = dq.front();
        dq.pop_front();
        p[cnt++] = make_pair(a, b);
        if (a < b)swap(a, b);
        dq.push_front(a);
        dq.push_back(b);
        num++;
        if (a == maxn)break;
    }
   ll m = 0;
    up(i, 0, n)
        a2[i] = dq.front(), dq.pop_front();
    //cout << num << endl;
    while (q--)
    {
        m = read();
        if (m < num)
        {
            printf("%d %d", p[m-1].first,p[m-1].second);
        }
        else {
            ll temp = m - num;
            int mod = temp % (n - 1);
            printf("%d %d", a2[0], a2[mod + 1]);
        }
        cout << endl;
    }
    return 0;
    
}

d: find the law
gives a lattice, each can freely walk, but to ensure that the route between two points, i.e., line, is not completely the same (including the direction) can be.
Beginning to see the title I thought it was meant to find a symmetrical relationship, one going up, go down the corresponding half found not do this.
Carefully think about the discovery, first find up and down, in a symmetric go on the trip.
I.e., transverse to jump repeatedly from 1,1 - n, m - 1,2 - n, m-1 --......-- 1, m - n, 1--2,1 --.....

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<bitset>
#include<map>
//#include<regex>
#include<cstdio>
#define up(i,a,b)  for(int i=a;i<b;i++)
#define dw(i,a,b)  for(int i=a;i>b;i--)
#define upd(i,a,b) for(int i=a;i<=b;i++)
#define dwd(i,a,b) for(int i=a;i>=b;i--)
//#define local
typedef long long ll;
typedef unsigned long long ull;
const double esp = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int inf = 1e9;
using namespace std;
ll read()
{
    char ch = getchar(); ll x = 0, f = 1;
    while (ch<'0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
    return x * f;
}
typedef pair<int, int> pir;
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lrt root<<1
#define rrt root<<1|1
int n, m;
vector<int>vec;
int main()
{
    n = read(), m = read();
    if (n & 1)
    {
        upd(i, 1, n / 2)
        {
            upd(j, 1, m)
            {
                printf("%d %d\n%d %d\n", i, j, n - i+1, m - j+1);
            }
        }
        if(m%2)
        {
            upd(j, 1, m / 2)
            {
                printf("%d %d\n%d %d\n", n / 2 + 1, j, n / 2 + 1, m - j + 1);
            }
            printf("%d %d\n", n / 2 + 1, m / 2 + 1);
        }
        else {
            upd(j, 1, m / 2)
            {
                printf("%d %d\n%d %d\n", n / 2 + 1, j, n / 2 + 1, m - j + 1);
            }
        }
    }
    else {
        upd(i, 1, n / 2)
        {
            upd(j, 1, m)
            {
                printf("%d %d\n%d %d\n", i, j, n - i + 1, m - j + 1);
            }
        }
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/LORDXX/p/11979735.html