Codeforces Round #364 (Div. 2)

本文探讨了两张卡片游戏的分配方式,确保每位玩家手中的卡片数值相等,并解决了棋盘上放置战车后不受攻击格子数量的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A:

A. Cards
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There are n cards (n is even) in the deck. Each card has a positive integer written on it. n / 2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player.

Find the way to distribute cards such that the sum of values written of the cards will be equal for each player. It is guaranteed that it is always possible.

Input

The first line of the input contains integer n (2 ≤ n ≤ 100) — the number of cards in the deck. It is guaranteed that n is even.

The second line contains the sequence of n positive integers a1, a2, ..., an (1 ≤ ai ≤ 100), where ai is equal to the number written on the i-th card.

Output

Print n / 2 pairs of integers, the i-th pair denote the cards that should be given to the i-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input.

It is guaranteed that solution exists. If there are several correct answers, you are allowed to print any of them.

Examples
Input
6
1 5 7 4 4 3
Output
1 3
6 2
4 5
Input
4
10 10 10 10
Output
1 2
3 4
Note

In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8.

In the second sample, all values ai are equal. Thus, any distribution is acceptable.

题意:

n个数,任意两个数和相同,输出数的位置。

题解:

先求出这个”和“,遍历,找到后输出并标记。

#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
#define mem(a) memset(a, 0, sizeof(a))
#define eps 1e-5
#define M 200005
#define inf 1000000007
using namespace std;
int a[102];
int b[102];
int main()
{
    int t;
    while(cin>>t)
    {
        mem(a);
        mem(b);
        int ans=0;
        for(int i=1;i<=t;i++)
        {
            cin>>a[i];
            ans+=a[i];
        }
        int sum=ans/(t/2);//和
        for(int i=1;i<=t;i++)
        {
            for(int j=i+1;j<=t;j++)
            {
                if(a[i]+a[j]==sum&&b[i]==0&&b[j]==0)
                {
                    cout<<i<<" "<<j<<endl;
                    b[i]=b[j]=1;
                    break;
                }
            }
        }
    }
}

B:

B. Cells Not Under Attack
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya has the square chessboard of size n × n and m rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another.

The cell of the field is under rook's attack, if there is at least one rook located in the same row or in the same column with this cell. If there is a rook located in the cell, this cell is also under attack.

You are given the positions of the board where Vasya will put rooks. For each rook you have to determine the number of cells which are not under attack after Vasya puts it on the board.

Input

The first line of the input contains two integers n and m (1 ≤ n ≤ 100 000, 1 ≤ m ≤ min(100 000, n2)) — the size of the board and the number of rooks.

Each of the next m lines contains integers xi and yi (1 ≤ xi, yi ≤ n) — the number of the row and the number of the column where Vasya will put the i-th rook. Vasya puts rooks on the board in the order they appear in the input. It is guaranteed that any cell will contain no more than one rook.

Output

Print m integer, the i-th of them should be equal to the number of cells that are not under attack after first i rooks are put.

Examples
Input
3 3
1 1
3 1
2 2
Output
4 2 0 
Input
5 2
1 5
5 1
Output
16 9 
Input
100000 1
300 400
Output
9999800001 
Note

On the picture below show the state of the board after put each of the three rooks. The cells which painted with grey color is not under the attack.

题意:

n*n的矩阵,m个车。每一个车,会把它所在行,所在列的棋子吃掉,问每放一个车,剩余的棋子数?

题解:

设矩阵(A,B)如果放的车的所在行所在列没有之前的车,则a--,b--,如果有,则不用减。

代码:

#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
#define mem(a) memset(a, 0, sizeof(a))
#define eps 1e-5
#define M 100005
#define inf 1000000007
using namespace std;
int l[M];
int r[M];
long long sum[M];
int main()
{
    int n,m,x,y;
    long long ans;
    while(cin>>n>>m)
    {
        mem(l);
        mem(r);
        mem(sum);
        long long  a,b;
        a=b=n;
        for(int i=1; i<=m; i++)
        {
            a--;
            b--;
            scanf("%d%d",&x,&y);
            l[x]++;
            r[y]++;
            if(l[x]!=1)
                a++;
            if(r[y]!=1)
                b++;
            ans=a*b;
            sum[i]=ans;
        }
      cout<<sum[1];
        for(int i=2; i<=m; i++)
        {
            cout<<" "<<sum[i];
        }

        printf("\n");
    }
}





                                                                                                                                                                                                                                                                                         

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值