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 to8.

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

这题没什么好说的,求出平均值然后两层循环遍历就可以了

#include<bits/stdc++.h>
using namespace std;
const int N=100+10;
int a[N],v[N];
int main()
{
int n,i;
while(~scanf("%d",&n))
{
memset(v,0,sizeof(v));
int sum=0;
for(i=1; i<=n; i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
sum/=(n/2);
for(i=1; i<n; i++)
if(!v[i])
{
for(int j=i+1; j<=n; j++)
if(!v[j])
{
if(a[i]+a[j]==sum)
{
v[i]=v[j]=1;
printf("%d %d\n",i,j);
break;
}
} }
}
return 0;
}
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的象棋盘,每个象棋可以攻击与其同行或同列的旗子,问当放置第i个旗子后棋盘中不受攻击的象棋格子有多少;

思路:我们分几种情况就可以发现规律了,设有k1行已经被用过,k2列已经被用过,如果每次放置的旗子都与前面已经放好的旗子不同行且不同列,则剩下的不受攻击的格子有sum=sum-n-n+lie+hang+1;如果当前放置的旗子与前面某一放置好的旗子同行或同列,则sum=sum-n+(hang或lie);加上被用过的是因为前面已经减过了,再减就重复减了,所以要加回来;

#include<bits/stdc++.h>
using namespace std;
const int N=100000+10;
long long a[N],v1[N],v2[N];//注意数据范围;
int main()
{
long long n,m;
int i;
while(~scanf("%I64d%I64d",&n,&m))
{
memset(v1,0,sizeof(v1));
memset(v2,0,sizeof(v2));
long long x,y,hang=0,lie=0;
long long sum=n*n;
for(i=1; i<=m; i++)
{
scanf("%I64d%I64d",&x,&y);
if(v1[x]&&!v2[y])//这个判断条件一定要写全,下面同;不然跪;
{
sum=sum-n+hang;
v2[y]=1;
lie++;
}
else if(v2[y]&&!v1[x])//当前列被用过,也就是在前面的旗子的攻击范围内;
{
sum=sum-n+lie;
v1[x]=1;
hang++;
}
else if(!v1[x]&&!x2[y])
{
sum=sum-n-n+hang+lie+1;
v1[x]=v2[y]=1;
hang++;
lie++;
}
if(sum<=0) sum=0;
a[i]=sum;
}
for( i=1; i<=m; i++)
{
printf("%I64d",a[i]);
if(i!=m)
printf(" ");
else
printf("\n");
}
}
return 0;
}

Codeforces Round #364 (Div. 2),只有A与B的更多相关文章

  1. Codeforces Round #364 (Div. 2)

    这场是午夜场,发现学长们都睡了,改主意不打了,第二天起来打的virtual contest. A题 http://codeforces.com/problemset/problem/701/A 巨水无 ...

  2. Codeforces Round #364 (Div.2) D:As Fast As Possible(模拟+推公式)

    题目链接:http://codeforces.com/contest/701/problem/D 题意: 给出n个学生和能载k个学生的车,速度分别为v1,v2,需要走一段旅程长为l,每个学生只能搭一次 ...

  3. Codeforces Round #364 (Div.2) C:They Are Everywhere(双指针/尺取法)

    题目链接: http://codeforces.com/contest/701/problem/C 题意: 给出一个长度为n的字符串,要我们找出最小的子字符串包含所有的不同字符. 分析: 1.尺取法, ...

  4. 树形dp Codeforces Round #364 (Div. 1)B

    http://codeforces.com/problemset/problem/700/B 题目大意:给你一棵树,给你k个树上的点对.找到k/2个点对,使它在树上的距离最远.问,最大距离是多少? 思 ...

  5. Codeforces Round #364 (Div. 2) B. Cells Not Under Attack

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

  6. Codeforces Round #364 (Div. 2) Cells Not Under Attack

    Cells Not Under Attack 题意: 给出n*n的地图,有给你m个坐标,是棋子,一个棋子可以把一行一列都攻击到,在根据下面的图,就可以看出让你求阴影(即没有被攻击)的方块个数 题解: ...

  7. Codeforces Round #364 (Div. 2) Cards

    Cards 题意: 给你n个牌,n是偶数,要你把这些牌分给n/2个人,并且让每个人的牌加起来相等. 题解: 这题我做的时候,最先想到的是模拟,之后码了一会,发现有些麻烦,就想别的方法.之后发现只要把它 ...

  8. Codeforces Round #364 (Div. 2)->A. Cards

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

  9. Codeforces Round #364 (Div. 2) E. Connecting Universities

    E. Connecting Universities time limit per test 3 seconds memory limit per test 256 megabytes input s ...

  10. Codeforces Round #364 (Div. 2) C.They Are Everywhere

    C. They Are Everywhere time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

随机推荐

  1. K - KazaQ’s Socks

    Bryce1010模板 #include <bits/stdc++.h> using namespace std; #define LL long long int main() { LL ...

  2. 题解报告:hdu 1263 水果

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1263 Problem Description 夏天来了~~好开心啊,呵呵,好多好多水果~~ Joe经营 ...

  3. HTTP/0.9、HTTP/1.0、HTTP/1.1、HTTP/2 历史演变和设计思路(详)*

    HTTP 协议是互联网的基础协议,也是网页开发的必备知识,最新版本 HTTP/2 更是让它成为技术热点. 本文介绍 HTTP 协议的历史演变和设计思路. 一.HTTP/0.9 HTTP 是基于 TCP ...

  4. 转-关于UIView的autoresizingMask属性的研究

    在 UIView 中有一个autoresizingMask的属性,它对应的是一个枚举的值(如下),属性的意思就是自动调整子控件与父控件中间的位置,宽高. 1 2 3 4 5 6 7 8 9 enum  ...

  5. 数据流和ByteArray

    问题:如何把一个long类型的数写进一个文件里 所以现在有DataInputStream和DataOutputStream 这两个是节点流 例子代码: import java.io.*; public ...

  6. ambari-server启动WARN qtp-ambari-client-87] ServletHandler: 563 /api/v1/stacks/HDP/versions/2.4/recommendations java.lang.NullPointerException报错解决办法(图文详解)

      问题详情 来源是,我在Ambari集群里,安装Hue. 给Ambari集群里安装可视化分析利器工具Hue步骤(图文详解 所遇到的这个问题. 然后,去ambari-server的log日志,查看,如 ...

  7. Aspose.Word 的常见使用(2018-12-26 更新版)

    Aspose.Word 的常见使用 起因 因项目需要,而且使用html转Word的时候,样式不兼容问题,于是只能使用Aspose.Word通过代码生成.下面是通过DocumentBuilder来设计W ...

  8. WPF学习10:基于MVVM Light 制作图形编辑工具(1)

    图形编辑器的功能如下图所示: 除了MVVM Light 框架是一个新东西之外,本文所涉及内容之前的WPF学习0-9基本都有相关介绍. 本节中,将搭建编辑器的界面,搭建MVVM Light 框架的使用环 ...

  9. es6核心特性-数组扩展

    1. Array.from() : 将伪数组对象或可遍历对象转换为真数组 如果一个对象的所有键名都是正整数或零,并且有length属性,那么这个对象就很像数组,称为伪数组.典型的伪数组有函数的argu ...

  10. npm run dev报错--Error: Cannot find module 'yargs-parser'

    Error: Cannot find module 'yargs-parser'  ---报错不知何解??? 百度了很久没找到方法,是缺少“ yargs-parser ”模块,需要安装一下即可:cnp ...