Codeforces Round #364 (Div. 2)(A ~ D)
来源:互联网 发布:如何使用网络 编辑:程序博客网 时间:2024/04/27 18:18
There are n cards (n iseven) 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.
The first line of the input contains integer n (2 ≤ n ≤ 100) — the number of cards in the deck. It is guaranteed thatn is even.
The second line contains the sequence of n positive integersa1, a2, ..., an (1 ≤ ai ≤ 100), where ai is equal to the number written on thei-th card.
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.
61 5 7 4 4 3
1 36 24 5
410 10 10 10
1 23 4
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。
题目大意:给你n个数,然后n / 2 个人各取两个数字,使得每个人取得的两个数字和相同,输出每个人取的数字的下标
思路:求出每个人的和,然后直接暴力枚举
#include <bits/stdc++.h>using namespace std;int num[200];int vis[200];int res[200][2];int main(){ int n; while (~scanf("%d",&n)) { int sum = 0; for (int i = 0 ; i < n ; i++ ) { scanf("%d",&num[i]); sum += num[i]; } sum /= n / 2; memset(vis,0,sizeof(vis)); int cou = 0; for (int i = 0 ; i < n ; i++ ) { if(vis[i] == 1) { continue; } for (int j = i + 1 ; j < n ; j++ ) { if (vis[j] == 1) continue; if (num[i] + num[j] == sum) { res[cou][0] = i + 1; res[cou++][1] = j + 1; vis[i] = 1; vis[j] = 1; break; } } } for (int i = 0 ; i < cou ; i++ ) { printf("%d %d\n",res[i][0],res[i][1]); } }}
Vasya has the square chessboard of size n × n andm 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 arenot under attack after Vasya puts it on the board.
The first line of the input contains two integers n andm (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 integersxi andyi (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.
Print m integer, the i-th of them should be equal to the number of cells that are not under attack after firsti rooks are put.
3 31 13 12 2
4 2 0
5 21 55 1
16 9
100000 1300 400
9999800001
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个棋子,每放一个棋子,这个棋子所在的行和列都会变成白色的。问每次放棋子的时候还剩下多少格子是黑的
思路:设置两个数组r[],l[]存放该行和列有是否有棋子了,然后再定义R,L存放有多少行多少列已经变白了,因为新的行列会有交叉。然后就简单了。
#include <bits/stdc++.h>using namespace std;__int64 r[111111],l[111111];int main(){ __int64 n,m; while (~scanf("%I64d%I64d",&n,&m)) { memset(r,0,sizeof(r)); memset(l,0,sizeof(l)); __int64 res = n * n; __int64 R = 0,L = 0; for (int i = 0 ; i < m ; i++ ) { int x,y; scanf("%d%d",&x,&y); if ( r[x] == 1 && l[y] != 1) { res -= n - R; L ++; } if (l[y] == 1 && r[x] != 1) { res -= n - L; R++; } if (r[x] != 1 && l[y] != 1) { res -= n + n - 1 - L - R; R++; L++; } r[x] = 1; l[y] = 1; printf("%I64d\n",res); } } return 0;}
Sergei B., the young coach of Pokemons, has found the big house which consists ofn flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number2 and the flat number n is only connected with the flat numbern - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
The first line contains the integer n (1 ≤ n ≤ 100 000) — the number of flats in the house.
The second line contains the row s with the lengthn, it consists of uppercase and lowercase letters of English alphabet, thei-th letter equals the type of Pokemon, which is in the flat numberi.
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
3AaA
2
7bcAAcbc
3
6aaBCCe
5题目大意:给你一串长度为n的字符串,由大小写字母组成。问至少长度为多少的子串能包括这字符串出现过的所有字符。
#include <bits/stdc++.h>using namespace std;char st[111111];map<char,int>ma;int main(){ int n; while (~scanf("%d",&n)) { getchar(); ma.clear(); int cou = 0; for (int i = 0 ; i < n ; i++ ) { scanf("%c",&st[i]); if(ma[st[i]] == 0) { cou ++; ma[st[i]] = 1; } } int res = 111111; ma.clear(); int x = 0; int temp = 0; for (int i = 0 ; i < n ; i++ ) { if (cou != 0) { if (ma[st[i]] == 0) { cou--; } ma[st[i]] ++; temp++; if (cou == 0) { while(ma[st[x]] > 1) { ma[st[x]] --; x++; temp--; } res = min(temp,res); } } else if (cou == 0) { ma[st[i]]++; temp++; while(ma[st[x]] > 1) { ma[st[x]] --; x++; temp--; } res = min(temp,res); } //printf("%d\n",temp); } if (cou == 0) { while(ma[st[x]] > 1) { ma[st[x]] --; x++; temp--; } res = min(temp,res); } printf("%d\n",res); }}
On vacations n pupils decided to go on excursion and gather all together. They need to overcome the path with the lengthl meters. Each of the pupils will go with the speed equal tov1. To get to the excursion quickly, it was decided to rent a bus, which has seats fork people (it means that it can't fit more thank people at the same time) and the speed equal tov2. In order to avoid seasick, each of the pupils want to get into the busno more than once.
Determine the minimum time required for all n pupils to reach the place of excursion. Consider that the embarkation and disembarkation of passengers, as well as the reversal of the bus, take place immediately and this time can be neglected.
The first line of the input contains five positive integers n, l, v1, v2 andk (1 ≤ n ≤ 10 000,1 ≤ l ≤ 109,1 ≤ v1 < v2 ≤ 109,1 ≤ k ≤ n) — the number of pupils, the distance from meeting to the place of excursion, the speed of each pupil, the speed of bus and the number of seats in the bus.
Print the real number — the minimum time in which all pupils can reach the place of excursion. Your answer will be considered correct if its absolute or relative error won't exceed10 - 6.
5 10 1 2 5
5.0000000000
3 6 1 2 1
4.7142857143
题目大意:n个人要走l长度的路,然后行走速度为v1,但是有一辆公交车,速度为v2,每辆公交车可以坐k个人
思路:最贪心,自然是每个人都坐一次车,然后最后大家一起到达终点。然后就是推公式,推出来就ok了,不过也有其他方法,自行百度
#include <bits/stdc++.h>using namespace std;int main(){ double l,v1,v2; int n,k; while (~scanf("%d%lf%lf%lf%d",&n,&l,&v1,&v2,&k)) { int cou = n / k + ( n % k ? 1 : 0 ); double l1 = (v1 + v2) * l / ( (2 * ( cou - 1) + 1) * v1 + v2); double ans = ( l - l1) / v1 + l1/v2; printf("%.7lf\n",ans); } return 0; }
- Codeforces Round #364 (Div. 2)(A ~ D)
- Codeforces Round #209 (Div. 2) <A-D>
- Codeforces Round #231 (Div. 2)A-D
- Codeforces Round #235 (Div. 2) A~D
- Codeforces Round #237 (Div. 2) A~D
- Codeforces Round #240 (Div. 2) A~D
- Codeforces Round #239 (Div. 2) A~D
- Codeforces Round #242 (Div. 2) <A-D>
- Codeforces Round #250 (Div. 2) A-D
- Codeforces Round #256 (Div. 2)A-D
- Codeforces Round #263 (Div. 2) A-D
- Codeforces Round #269 (Div. 2) A~D
- Codeforces Round #358 (Div. 2)A~D
- Codeforces Round #359 (Div. 2) A ~D
- Codeforces Round #368 (Div. 2) A~D
- Codeforces Round #369 (Div. 2) A~D
- Codeforces Round #369 (Div. 2) A~D
- Codeforces Round #374 (Div. 2) A~D
- 概率数据结构
- C++11新特性:移动语义和右值引用
- scala入门教程:scala的数据类型
- day07_configParser模块学习之一
- 关于snmpwalk -t TIMEOUT 参数说明
- Codeforces Round #364 (Div. 2)(A ~ D)
- Android之PULL解析XMl文件-新浪微博效果
- Python大数据处理代码性能优化
- CodeForces 46D Parking Lot (线段树区间合并)
- SPOJ AMR11J
- iOS中键盘与文本框的处理(一)
- stl容器区别: vector list deque set map-底层实现
- FFmpeg中的滤镜(六):视频滤镜 -- atadenoise
- Spring学习笔记