浪在ACM集训队清明训练部分题集

浪在ACM集训队清明训练部分题集

    • DAY.1
      • Dangerous Dive
        • 题面
        • 题解
      • Triangles
        • 题面
        • 题解
    • DAY.2
      • Jamie and Alarm Snooze
        • 题面
          • Input
          • Output
          • Examples
          • Note
        • 题解
      • Alice's Print Service
        • 题面
          • Input
          • Output
        • 题解
    • DAY.3
      • Robot Motion
        • 题面
          • Input
          • Output
        • 解析
      • Beautiful Paintings
        • 题面
          • Input
          • Output
          • Examples
          • Note
        • 解析
      • Good String
        • 题面
          • Input
          • Output
          • Example
          • Note
        • 解析
      • Coffee Break
        • 题面
          • Input
          • Output
          • Examples
          • Note
        • 解析
    • DAY.4
      • HDU Today
        • 题面
          • Input
          • Output
          • Hint:
        • 解析
      • Emag eht htiw Em Pleh
        • 题面
          • Input
        • Output
        • Sample Input
        • Sample Output
        • 解析
      • Quicksum
        • 题面
          • Input
          • Output
        • 解析

  涉及后面省赛名额,大家都拿出真本事了,除了某些copy小子被我们逮出来的.
  我好菜哦~~~( ﹁ ﹁ ) ~~~

DAY.1

Download

Dangerous Dive

Gym 101473E

题面

   你再看这里也莫得哦

题解

  缺啥补啥,都回来了就万事大吉输出*

#include
#include
#include
#include
#include
#include
#include
#include
#include
#ifndef NULL
#define NULL 0
#endif
using namespace std;

typedef long long ll;
ll read()
{
   ll f = 1, x = 0; char s = getchar();
   while (s<'0' || s>'9') { if (s == '-')f = -1; s = getchar(); }
   while (s >= '0'&&s <= '9') { x = x * 10 + s - '0'; s = getchar(); }
   x *= f;
   return x;
}
int a[100010];
int main()
{
   int n=read(), m=read();
   for (int i = 0; i < m; i++) {
   	int x = read();
   	a[x] = 1;
   }
   if (n == m)
   	cout << "*" << endl;
   else {
   	for (int i = 1; i <= n; i++)
   		if (!a[i])
   			cout << i << ' ';
   	cout << endl;
   }
   return 0;
}

Triangles

Gym 101473F

题面

   你再看这里也莫得哦

题解

   给你个圆,问你这个圆中能取出多少个三角.数据量很小,之前做过比这个数据量大太多的题目中的L题线段树存点,求点点之间的距离,然后二分查找答案,好像就我代码最长=^=.

#include
#include
#include
#include
#include
#include
#include
#include
#include
#ifndef NULL
#define NULL 0
#endif
using namespace std;

typedef long long ll;
typedef struct vec* Node;
struct vec {
	ll d;
	int left, right;
	Node lson, rson;
}*root;
int n;
ll s;
ll read()
{
	ll f = 1, x = 0; char s = getchar();
	while (s<'0' || s>'9') { if (s == '-')f = -1; s = getchar(); }
	while (s >= '0'&&s <= '9') { x = x * 10 + s - '0'; s = getchar(); }
	x *= f;
	return x;
}
Node built(int left, int right)
{
	Node p = new(vec);
	p->left = left, p->right = right;
	if (left == right) {
		p->d = read();
		p->lson = p->rson = NULL;
	}
	else {
		int mid = (left + right) / 2;
		p->lson = built(left, mid);
		p->rson = built(mid + 1, right);
		p->d = p->lson->d + p->rson->d;
	}
	return p;
}
ll find(Node p, int x, int y)
{
	if (p->left == x && p->right == y)
		return p->d;
	int mid = (p->left + p->right) / 2;
	if (y <= mid)
		return find(p->lson, x, y);
	if (x > mid)
		return find(p->rson, x, y);
	return find(p->lson, x, mid) + find(p->rson, mid + 1, y);
}
void close(Node p)
{
	if (p != NULL) {
		close(p->lson);
		close(p->rson);
		free(p);
	}
	return;
}
int Binary_Search(int i, int left, int right)
{
	while (left < right) {
		int mid = (left + right) / 2;
		ll t = find(root, i, mid);
		if (t > s)
			right = mid;
		else if (t < s)
			left = mid + 1;
		else
			return mid;
	}
	return -1;
}
int main()
{
	int ans = 0;
	n = read();
	root = built(1, n);
	s = root->d / 3;
	for (int i = 1; i <= n; i++) {
		int j = Binary_Search(i, i, n) + 1;
		if (j == 0)
			continue;
		else if (Binary_Search(j, j, n) != -1)
			ans++;
	}
	cout << ans << endl;
	return 0;
}

DAY.2

Jamie and Alarm Snooze

CodeForces 916A

题面

  Jamie loves sleeping. One day, he decides that he needs to wake up at exactly hh: mm. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every x minutes until hh: mm is reached, and only then he will wake up. He wants to know what is the smallest number of times he needs to press the snooze button.
A time is considered lucky if it contains a digit ‘7’. For example, 13: 07 and 17: 27 are lucky, while 00: 48 and 21: 34 are not lucky.
  Note that it is not necessary that the time set for the alarm and the wake-up time are on the same day. It is guaranteed that there is a lucky time Jamie can set so that he can wake at hh: mm.
Formally, find the smallest possible non-negative integer y such that the time representation of the time x·y minutes before hh: mm contains the digit ‘7’.
  Jamie uses 24-hours clock, so after 23: 59 comes 00: 00.

Input

  The first line contains a single integer x (1 ≤ x ≤ 60).
  The second line contains two two-digit integers, hh and mm (00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59).

Output

  Print the minimum number of times he needs to press the button.

Examples

Input
3
11 23
Output
2
Input
5
01 07
Output
0

Note

  In the first sample, Jamie needs to wake up at 11:23. So, he can set his alarm at 11:17. He would press the snooze button when the alarm rings at 11:17 and at 11:20.
  In the second sample, Jamie can set his alarm at exactly at 01:07 which is lucky.

题解

  "超级大"模拟,模拟时钟.跟你起床的时间,问什么时候定闹钟,使赖床时间最短且闹钟时间符合xx条件.
  只能向前找,我还考虑向后找来着=-=

#include
#include
#include
#include
#include
#include
#include
#include
#include
#ifndef NULL
#define NULL 0
#endif
using namespace std;

typedef long long ll;
const int T = 24 * 60;
bool f[60] = { 0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0 };
ll read()
{
	ll f = 1, x = 0; char s = getchar();
	while (s<'0' || s>'9') { if (s == '-')f = -1; s = getchar(); }
	while (s >= '0'&&s <= '9') { x = x * 10 + s - '0'; s = getchar(); }
	x *= f;
	return x;
}
int main()
{
	string s1, s2;
	int t = read(), h = 0, m = 0, minn = T / t;
	cin >> s1 >> s2;
	for (int i = 0; i < s1.length(); i++)
		h = h * 10 + s1[i] - '0';
	for (int i = 0; i < s2.length(); i++)
		m = m * 10 + s2[i] - '0';
	if (f[h] || f[m])
		minn = 0;
	int x = h,y = m;
	for (int i = 1; i <= T / t; i++) {
		y -= t;
		if (y < 0) {
			x--;
			y += 60;
		}
		if (x < 0)
			x += 24;
		if (f[x] || f[y]) {
			minn = min(i, minn);
			break;
		}
	}
	cout << minn << endl;
	return 0;
}

Alice’s Print Service

HDU 4791

题面

  Alice is providing print service, while the pricing doesn’t seem to be reasonable, so people using her print service found some tricks to save money.
  For example, the price when printing less than 100 pages is 20 cents per page, but when printing not less than 100 pages, you just need to pay only 10 cents per page. It’s easy to figure out that if you want to print 99 pages, the best choice is to print an extra blank page so that the money you need to pay is 100 × 10 cents instead of 99 × 20 cents.
  Now given the description of pricing strategy and some queries, your task is to figure out the best ways to complete those queries in order to save money.

Input

  The first line contains an integer T (≈ 10) which is the number of test cases. Then T cases follow.
  Each case contains 3 lines. The first line contains two integers n, m (0 < n, m ≤ 10 5 ). The second line contains 2n integers s 1, p 1 , s 2, p 2 , …, s n, p n (0=s 1 < s 2 < … < s n ≤ 10 9 , 10 9 ≥ p 1 ≥ p 2 ≥ … ≥ p n ≥ 0)… The price when printing no less than s i but less than s i+1 pages is p i cents per page (for i=1…n-1). The price when printing no less than s n pages is p n cents per page. The third line containing m integers q 1 … q m (0 ≤ q i ≤ 10 9 ) are the queries.

Output

  For each query q i, you should output the minimum amount of money (in cents) to pay if you want to print q i pages, one output in one line.
Sample Input
1
2 3
0 20 100 10
0 99 100
Sample Output
0
1000
1000

题解

  打印一些东西,超过一定阈值就输出一个固定的值.
  从后往前找,让每个分割点都存最小值,最小值为分割点×价钱
  正巧在自学c++的面向对象方面的知识,试着写了写class.
  不会用c++自带的stl二分找结构体,只好自己手搓==

#include
#include
#include
#include
#include
#include
#include
#include
#include
#ifndef NULL
#define NULL 0
#endif
using namespace std;

typedef long long ll;
const int T = 24 * 60;
class vec {
public:
	ll s, p,cost;
	vec() {
		cost =(ll) 1e18;
	}
};
ll read()
{
	ll f = 1, x = 0; char s = getchar();
	while (s<'0' || s>'9') { if (s == '-')f = -1; s = getchar(); }
	while (s >= '0'&&s <= '9') { x = x * 10 + s - '0'; s = getchar(); }
	x *= f;
	return x;
}
ll upper_bound(vec *array, ll size, ll key)
{
	ll len = size,first=1;
	ll half, middle;
	while (len > 0) {
		half = len >> 1;
		middle = first + half;
		if (array[middle].s > key)
			len = half;
		else {
			first = middle + 1;
			len = len - half - 1;
		}
	}
	return first;
}
int main()
{
	ll t = read();
	while (t--) {
		vec a[100010];
		ll n=read(), m=read();
		for (int i = 1; i <= n; i++)
			a[i].s = read(), a[i].p = read();
		ll minn = a[n].p*a[n].s;
		for (ll i = n - 1; i >= 1; i--) {
			a[i].cost = minn;
			minn = min(minn,a[i].p*a[i].s);
		}
		for (int i = 1; i <= m; i++) {
			ll q = read(),t= upper_bound(a,n,q)-1;
			cout << min(q*a[t].p, a[t].cost) << endl;
		}
	}
	return 0;
}

DAY.3

Robot Motion

POJ 1573

题面


  A robot has been programmed to follow the instructions in its path. Instructions for the next direction the robot is to move are laid down in a grid. The possible instructions are

N north (up the page)
S south (down the page)
E east (to the right on the page)
W west (to the left on the page)

  For example, suppose the robot starts on the north (top) side of Grid 1 and starts south (down). The path the robot follows is shown. The robot goes through 10 instructions in the grid before leaving the grid.
Compare what happens in Grid 2: the robot goes through 3 instructions only once, and then starts a loop through 8 instructions, and never exits.
You are to write a program that determines how long it takes a robot to get out of the grid or how the robot loops around.

Input

  There will be one or more grids for robots to navigate. The data for each is in the following form. On the first line are three integers separated by blanks: the number of rows in the grid, the number of columns in the grid, and the number of the column in which the robot enters from the north. The possible entry columns are numbered starting with one at the left. Then come the rows of the direction instructions. Each grid will have at least one and at most 10 rows and columns of instructions. The lines of instructions contain only the characters N, S, E, or W with no blanks. The end of input is indicated by a row containing 0 0 0.

Output

  For each grid in the input there is one line of output. Either the robot follows a certain number of instructions and exits the grid on any one the four sides or else the robot follows the instructions on a certain number of locations once, and then the instructions on some number of locations repeatedly. The sample input below corresponds to the two grids above and illustrates the two forms of output. The word “step” is always immediately followed by “(s)” whether or not the number before it is 1.
Sample Input
3 6 5
NEESWE
WWWESS
SNWWWW
4 5 1
SESWE
EESNW
NWEEN
EWSEN
0 0 0
Sample Output
10 step(s) to exit
3 step(s) before a loop of 8 step(s)

解析

假的dfs

#include
#include
#include
#include
using namespace std;

char map[20][20];
int n,m;
int visit[20][20];
void dfs(int x,int y,int deep)
{
	if(x<0||x==n||y<0||y==m){
		cout<<deep-1<<" step(s) to exit"<<'\n';
		return ;
	}
	if(visit[x][y]==0){
		visit[x][y]=deep;
		switch(map[x][y]){
			case 'N':
				x-=1;
				dfs(x,y,deep+1);
				break;
			case 'E':
				y+=1;
				dfs(x,y,deep+1);
				break;
			case 'S':
				x+=1;
				dfs(x,y,deep+1);
				break;
			case 'W':
				y-=1;
				dfs(x,y,deep+1);
				break;
		}
	}
	else
		cout<<visit[x][y]-1<<" step(s) before a loop of "<<deep-visit[x][y]<<" step(s)"<<'\n';
}
int main()
{
	int y;
	while(cin>>n>>m>>y,n&&m&&y){
		memset(map,0,sizeof(map));
		memset(visit,0,sizeof(visit));
		for(int i=0;i<n;i++)
			cin>>map[i];
		dfs(0,y-1,1);
	}
	return 0;
}

Beautiful Paintings

CodeForces 651B

题面

  There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
  We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of a in any order. What is the maximum possible number of indices i (1 ≤ i ≤ n - 1), such that ai + 1 > ai.

Input

  The first line of the input contains integer n (1 ≤ n ≤ 1000) — the number of painting.
  The second line contains the sequence a1, a2, …, an (1 ≤ ai ≤ 1000), where ai means the beauty of the i-th painting.

Output

  Print one integer — the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement.

Examples

Input
5
20 30 10 50 40
Output
4
Input
4
200 100 100 200
Output
2

Note

  In the first sample, the optimal order is: 10, 20, 30, 40, 50.
  In the second sample, the optimal order is: 100, 200, 100, 200.

解析

善用桶,反正数据小,直接暴力

#include
#include
#include
using namespace std;

int a[1010];
int main()
{
	int n,maxx=0,maxm=0;
	cin>>n;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		a[x]++;
		maxx=max(a[x],maxx);
		maxm=max(x,maxm);
	}
	int tot=0;
	while(maxx--){
		for(int i=maxm;i>=0;i--)
			if(a[i]){
				tot++;
				a[i]--;
			}
			tot--;
	}
	cout<<tot<<endl;
	return 0;
}

Good String

CodeForces 1140B

题面

  You have a string s of length n consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the last one, nothing happens). If you choose a character <, the character that comes right before it is deleted (if the character you chose was the first one, nothing happens).
  For example, if we choose character > in string > > < >, the string will become to > > >. And if we choose character < in string > <, the string will become to <.
  The string is good if there is a sequence of operations such that after performing it only one character will remain in the string. For example, the strings >, > > are good.
  Before applying the operations, you may remove any number of characters from the given string (possibly none, possibly up to n−1, but not the whole string). You need to calculate the minimum number of characters to be deleted from string s so that it becomes good.

Input

  The first line contains one integer t (1≤t≤100) – the number of test cases. Each test case is represented by two lines.
  The first line of i-th test case contains one integer n (1≤n≤100) – the length of string s.
  The second line of i-th test case contains string s, consisting of only characters > and <.

Output

  For each test case print one line.
  For i-th test case print the minimum number of characters to be deleted from string s so that it becomes good.

Example

Input
3
2

<>

3

><<

1

>

Output
1
0
0

Note

  In the first test case we can delete any character in string <>.
  In the second test case we don’t need to delete any characters. The string > < < is good, because we can perform the following sequence of operations: > < < → < < → <.

解析

从两头找,找到结束

#include
#include
using namespace std;

string s;
int main()
{
	int t,len;
	cin>>t;
	while(t--){
		cin>>len>>s;
		for(int i=0;i<len;i++)
			if(s[i]=='>'||s[len-i-1]=='<'){
				cout<<i<<endl;
				break;
			}
	}
	return 0;
}

Coffee Break

CodeForces 1041C

题面

  Recently Monocarp got a job. His working day lasts exactly m minutes. During work, Monocarp wants to drink coffee at certain moments: there are n minutes a1,a2,…,an, when he is able and willing to take a coffee break (for the sake of simplicity let’s consider that each coffee break lasts exactly one minute).
  However, Monocarp’s boss doesn’t like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute ai, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least d minutes pass between any two coffee breaks. Monocarp also wants to take these n coffee breaks in a minimum possible number of working days (he doesn’t count days when he is not at work, and he doesn’t take coffee breaks on such days). Take into account that more than d minutes pass between the end of any working day and the start of the following working day.
  For each of the n given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.

Input

  The first line contains three integers n, m, d (1≤n≤2⋅105,n≤m≤109,1≤d≤m) — the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks.
  The second line contains n distinct integers a1,a2,…,an (1≤ai≤m), where ai is some minute when Monocarp wants to have a coffee break.

Output

  In the first line, write the minimum number of days required to make a coffee break in each of the n given minutes.
  In the second line, print n space separated integers. The i-th of integers should be the index of the day during which Monocarp should have a coffee break at minute ai. Days are numbered from 1. If there are multiple optimal solutions, you may print any of them.

Examples

Input
4 5 3
3 5 1 2
Output
3
3 1 1 2
Input
10 10 1
10 5 7 4 6 3 2 1 9 8
Output
2
2 1 1 2 2 1 2 1 1 2

Note

  In the first example, Monocarp can take two coffee breaks during the first day (during minutes 1 and 5, 3 minutes will pass between these breaks). One break during the second day (at minute 2), and one break during the third day (at minute 3).
  In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.

解析

  喝咖啡,每次喝咖啡用时1分钟,两次间隔d分钟,i咖啡只能在任意一天的a_i时间喝,不能早也不能晚.问怎么样安排才能在最短时间内喝完.
  当时组队赛的时候做过,队友做出来了,我就没补,结果就考到了…难受.比完赛赶紧补上.
在cf上找了ac代码研究了半天才搞懂

#include
#include
#include
#include
using namespace std;

typedef long long ll;
pair<int ,int >p[200100];
int day[200100];
int main()
{
	int k=0,n,m,d;
	cin>>n>>m>>d;
	for(int i=0;i<n;i++)
		cin>>p[i].first,p[i].second=i;
	sort(p,p+n);
	for(int i=0,j=0;i<n;i++){
		while(j<n&&p[j].first-p[i].first<=d)	//两种咖啡之间符合条件的最小值中的最大值就是要消耗的天数
			j++;
		k=max(k,j-i);
	}
	cout<<k<<endl;
	for(int i=0;i<n;i++)
		day[p[i].second]=i%k+1;	//一个萝卜一个坑,按天分,不符合d时间的,就只能放在下一天喝
	for(int i=0;i<n;i++)
		cout<<day[i]<<' ';
	cout<<'\n';
}

DAY.4

HDU Today

HDU 2112

题面

  经过锦囊相助,海东集团终于度过了危机,从此,HDU的发展就一直顺风顺水,到了2050年,集团已经相当规模了,据说进入了钱江肉丝经济开发区500强。这时候,XHD夫妇也退居了二线,并在风景秀美的诸暨市浬浦镇陶姚村买了个房子,开始安度晚年了。
  这样住了一段时间,徐总对当地的交通还是不太了解。有时很郁闷,想去一个地方又不知道应该乘什么公交车,在什么地方转车,在什么地方下车(其实徐总自己有车,却一定要与民同乐,这就是徐总的性格)。
  徐总经常会问蹩脚的英文问路:“Can you help me?”。看着他那迷茫而又无助的眼神,热心的你能帮帮他吗?
  请帮助他用最短的时间到达目的地(假设每一路公交车都只在起点站和终点站停,而且随时都会开)。

Input

  输入数据有多组,每组的第一行是公交车的总数N(0<=N<=10000);
  第二行有徐总的所在地start,他的目的地end;
  接着有n行,每行有站名s,站名e,以及从s到e的时间整数t(0   note:一组数据中地名数不会超过150个。
  如果N==-1,表示输入结束。

Output

  如果徐总能到达目的地,输出最短的时间;否则,输出“-1”。
Sample Input
6
xiasha westlake
xiasha station 60
xiasha ShoppingCenterofHangZhou 30
station westlake 20
ShoppingCenterofHangZhou supermarket 10
xiasha supermarket 50
supermarket westlake 10
-1
Sample Output
50

Hint:

  The best route is:
  xiasha->ShoppingCenterofHangZhou->supermarket->westlake
  虽然偶尔会迷路,但是因为有了你的帮助
  **和**从此还是过上了幸福的生活。
  ――全剧终――

解析

  做这个题脑子容易抽,经典的dj单源最短路板子题目.
  把地点对应成数字,我拒绝hash.
  为什么还要问我,当起点和终点是一个的时候怎么坐车
  我绝对不用板子!真香

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;

typedef long long ll;
const int INF = 0x3f3f3f3f;
const int MAXN = 10010;
struct qnode {
	int v, c;
	qnode(int _v = 0, int _c = 0) :v(_v), c(_c) {}
	bool operator<(const qnode &r)const {
		return c > r.c;
	}
};
struct Edge {
	int v, cost;
	Edge(int _v = 0, int _cost = 0) :v(_v), cost(_cost) {}
};
vector<Edge>E[MAXN];
bool vis[MAXN];
int dist[MAXN];
void read(int &x)
{
	int f = 1; x = 0; char s = getchar();
	while (s<'0' || s>'9') { if (s == '-')f = -1; s = getchar(); }
	while (s >= '0'&&s <= '9') { x = x * 10 + s - '0'; s = getchar(); }
	x *= f;
}
void dij(int n, int start)
{
	memset(vis, false, sizeof(vis));
	for (int i = 1; i <= n; i++) dist[i] = INF;
	priority_queue<qnode>que;
	while (!que.empty())que.pop();
	dist[start] = 0;
	que.push(qnode(start, 0));
	qnode tmp;
	while (!que.empty()) {
		tmp = que.top();
		que.pop();
		int u = tmp.v;
		if (vis[u]) continue;
		vis[u] = true;
		for (int i = 0; i < E[u].size(); i++) {
			int v = E[tmp.v][i].v;
			int cost = E[u][i].cost;
			if (!vis[v] && dist[v] > dist[u] + cost) {
				dist[v] = dist[u] + cost;
				que.push(qnode(v, dist[v]));
			}
		}
	}
}
void addedge(int u, int v, int w)
{
	E[u].push_back(Edge(v, w));
}
int main()
{
	int n;
	string is, ie;
	while (read(n), n != -1) {
		for (int i = 1; i <= n; i++)
			E[i].clear();
		map<string, int >p;
		int tot = 1;
		cin >> is >> ie;
		if (!p[is]) {
			p[is] = tot;
			tot++;
		}
		if (!p[ie]) {
			p[ie] = tot;
			tot++;
		}
		for (int i = 0; i < n; i++) {
			string s, e;
			int w;
			cin >> s >> e;
			read(w);
			if (!p[s]) {
				p[s] = tot;
				tot++;
			}
			if (!p[e]) {
				p[e] = tot;
				tot++;
			}
			addedge(p[s], p[e], w);
			addedge(p[e], p[s], w);
		}
		dij(tot - 1, 1);
		if (dist[p[ie]] >= INF)
			cout << -1 << endl;
		else
			cout << dist[p[ie]] << endl;
	}
	return 0;
}

Emag eht htiw Em Pleh

POJ 2993

题面

  This problem is a reverse case of the problem 2996. You are given the output of the problem H and your task is to find the corresponding input.

Input

  according to output of problem 2996.

Output

  according to input of problem 2996.

Sample Input

White: Ke1,Qd1,Ra1,Rh1,Bc1,Bf1,Nb1,a2,c2,d2,f2,g2,h2,a3,e4
Black: Ke8,Qd8,Ra8,Rh8,Bc8,Ng8,Nc6,a7,b7,c7,d7,e7,f7,h7,h6

Sample Output

+---+---+---+---+---+---+---+---+
|.r.|:::|.b.|:q:|.k.|:::|.n.|:r:|
+---+---+---+---+---+---+---+---+
|:p:|.p.|:p:|.p.|:p:|.p.|:::|.p.|
+---+---+---+---+---+---+---+---+
|...|:::|.n.|:::|...|:::|...|:p:|
+---+---+---+---+---+---+---+---+
|:::|...|:::|...|:::|...|:::|...|
+---+---+---+---+---+---+---+---+
|...|:::|...|:::|.P.|:::|...|:::|
+---+---+---+---+---+---+---+---+
|:P:|...|:::|...|:::|...|:::|...|
+---+---+---+---+---+---+---+---+
|.P.|:::|.P.|:P:|...|:P:|.P.|:P:|
+---+---+---+---+---+---+---+---+
|:R:|.N.|:B:|.Q.|:K:|.B.|:::|.R.|
+---+---+---+---+---+---+---+---+

解析

  这谜一样题目,秀儿,又是你!
  暴力完事.

#include
#include
#include
#include
#include
#include
#include
using namespace std;

typedef long long ll;
string s[] = { "+---+---+---+---+---+---+---+---+",
"|...|:::|...|:::|...|:::|...|:::|",
"+---+---+---+---+---+---+---+---+",
"|:::|...|:::|...|:::|...|:::|...|",
"+---+---+---+---+---+---+---+---+",
"|...|:::|...|:::|...|:::|...|:::|",
"+---+---+---+---+---+---+---+---+",
"|:::|...|:::|...|:::|...|:::|...|",
"+---+---+---+---+---+---+---+---+",
"|...|:::|...|:::|...|:::|...|:::|",
"+---+---+---+---+---+---+---+---+",
"|:::|...|:::|...|:::|...|:::|...|",
"+---+---+---+---+---+---+---+---+",
"|...|:::|...|:::|...|:::|...|:::|",
"+---+---+---+---+---+---+---+---+",
"|:::|...|:::|...|:::|...|:::|...|",
"+---+---+---+---+---+---+---+---+" };
char s1[1700],s2[1700];
int main()
{
	scanf("White: %s\nBlack: %s",s1,s2);
	int len1 = strlen(s1), len2 = strlen(s2);
	for (int i = 0; i < len1; )
		if (s1[i] >= 'A'&&s1[i] <= 'Z') {
			s[17-2*(s1[i+2]-'0')][(s1[i + 1] - 'a')*4 + 2] = s1[i];
			i+=3;
		}
		else if(s1[i]>='a'&&s1[i]<='z'&&i>0&&s1[i-1]==','){
			s[17-2*(s1[i+1]-'0')][(s1[i] - 'a')*4 + 2] = 'P';
			i+=2;
		}
		else
			i++; 
	for (int i = 0; i < len2; )
		if (s2[i] >= 'A'&&s2[i] <= 'Z') {
			s[17-2*(s2[i+2]-'0')][(s2[i + 1] - 'a')*4 + 2] = s2[i]-'A'+'a';
			i+=3;
		}
		else if(s2[i]>='a'&&s2[i]<='z'&&i>0&&s2[i-1]==','){
			s[17-2*(s2[i+1]-'0')][(s2[i] - 'a')*4 + 2] = 'p';
			i+=2;
		}
		else
			i++; 
	for (int i = 0; i < 17; i++)
		cout << s[i] << '\n';
	return 0;
}

Quicksum

POJ 3094

题面

  A checksum is an algorithm that scans a packet of data and returns a single number. The idea is that if the packet is changed, the checksum will also change, so checksums are often used for detecting transmission errors, validating document contents, and in many other situations where it is necessary to detect undesirable changes in data.
  For this problem, you will implement a checksum algorithm called Quicksum. A Quicksum packet allows only uppercase letters and spaces. It always begins and ends with an uppercase letter. Otherwise, spaces and letters can occur in any combination, including consecutive spaces.
  A Quicksum is the sum of the products of each character’s position in the packet times the character’s value. A space has a value of zero, while letters have a value equal to their position in the alphabet. So, A=1, B=2, etc., through Z=26. Here are example Quicksum calculations for the packets “ACM” and “MID CENTRAL”:

ACM: 1*1  + 2*3 + 3*13 = 46
MID CENTRAL: 1*13 + 2*9 + 3*4 + 4*0 + 5*3 + 6*5 + 7*14 + 8*20 + 9*18 + 10*1 + 11*12 = 650
Input

  The input consists of one or more packets followed by a line containing only # that signals the end of the input. Each packet is on a line by itself, does not begin or end with a space, and contains from 1 to 255 characters.

Output

  For each packet, output its Quicksum on a separate line in the output.

Sample Input
ACM
MID CENTRAL
REGIONAL PROGRAMMING CONTEST
ACN
A C M
ABC
BBC

Sample Output
46
650
4690
49
75
14
15

解析

  水题,读懂就行了.

#include
#include
#include
#include
#include
#include
#include
using namespace std;

typedef long long ll;
char s[1700];
int main()
{
	int len;
	while(gets(s)){
		if(s[0]=='#')
			break;
		len=strlen(s);
		int ans=0;
		for(int i=0;i<len;i++)
			if(s[i]!=' ')
				ans+=(i+1)*(s[i]-'A'+1);
		cout<<ans<<endl;
	}
	return 0;
}

你可能感兴趣的:(QLU_ACM比赛)