ICPC Pacific Northwest Regional Contest 2017 (计蒜客马拉松赛)

19 篇文章 0 订阅

A. Odd Palindrome

在这里插入图片描述

We say that a string is oddodd if and only if all palindromic substrings of the string have odd length.
Given a string ss, determine if it is oddodd or not.
A substring of a string ss is a nonempty sequence of consecutive characters from ss. A palindromic substring is a substring that reads the same forwards and backwards.
1 Input
The input consists of a single line containing the string ss (1 ≤ |s| ≤ 100)(1≤∣s∣≤100).
It is guaranteed that ss consists of lowercase ASCIIASCII letters (‘a’–‘z’)(‘a’–‘z’) only.
2 Output
If ss is oddodd, then print “Odd.Odd.” on a single line (without quotation marks). Otherwise, print “Or\ not.Or not.” on a single line (without quotation marks).
样例输入复制
amanaplanacanalpanama
madamimadam
annamyfriend
nopalindromes
样例输出复制
Odd.
Odd.
Or not.
Odd.

题目大意
输入一个长度为只包含小写字母的字符串,如果的所有回文子串都长度为奇数则输出,
否则输出
题目解析
如果存在一个长度为偶数的回文串,那么必定存在长度为的回文串,枚举判断是否存在相邻两个相同的字
符即可。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
int main() {
    string s; int flag;
    while(cin >> s) {
        flag = 0;
        for(int i=1; i<s.size(); i++)
            if(s[i] == s[i - 1]) { flag = 1,cout << "Or not." << endl; break;}
        if(!flag) cout << "Odd." << endl;
    }
    return 0;
}

C. Fear Factoring

在这里插入图片描述
The Slivians are afraid of factoring; it’s just, well, difficult.
Really, they don’t even care about the factors themselves, just how much they sum to.
We can define F(n)F(n) as the sum of all of the factors of nn; so F(6) = 12F(6)=12 and F(12) = 28F(12)=28. Your task is, given two integers aa and bb with a ≤ ba≤b, to calculate S = \sum_{a≤n≤b} F(n)S=∑
a≤n≤b
F(n).
1 Input
The input consists of a single line containing space-separated integers aa and bb (1 ≤ a ≤ b ≤ 10^{12}; b-a ≤ 10^{6} )(1≤a≤b≤10
12
;b−a≤10
6
).

2 Output

Print SS on a single line.

样例输入复制
101 101
28 28
1 10
987654456799 987654456799
963761198400 963761198400
5260013877 5260489265
样例输出复制
102
56
87
987654456800
5531765944320
4113430571304040
在这里插入图片描述
除法分块,那我顺便复习一下

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#define Maxn 1000005
#define LL unsigned long long
using namespace std;

 LL calc(LL n) {
     LL Ans = 0;
     for(LL l=1; l<=n; l++) {
         LL t = n / l;
         LL r = n / t;
         Ans += (l + r) * (r - l + 1) / 2 * t;
         l = r;
     }
     return Ans;
}

int main() {

    LL a,b,Ans = 0;
    while(cin >> a >> b) {
		cout << calc(b) - calc(a - 1) << endl;
    }
    
    return 0;
}

E. Straight Shot

![You have a toy robot that walks straight at a constant speed vv, and you wish for it to travel on the two-dimensional plane from (0, 0)(0,0) to (X, 0)(X,0). If the plane were empty, you could start the robot facing straight east from the origin, and it would walk there in X/vX/v time. Unfortunately, between the start and the destination are nn moving sidewalks, each moving directly north or south, which affect the robot’s position while it is walking.

The direction that robot is facing is not changed by the sidewalks; the robot will face in the same orientation for the entire duration of its walk. These sidewalks are aligned with the y-axisy−axis and are infinitely long. You still must get the robot to go from start to finish, but you’ll need to adjust the orientation of the robot at the start. Given that you choose this direction correctly, so that the robot arrives exactly at the destination, how long will it take the robot to get there?]

在这里插入图片描述

One final caveat: You don’t want the toy robot to walk for too long. If the robot cannot reach the destination in at most twice the time it would take in the absence of all moving sidewalks (i.ei.e., 2X/v2X/v), indicate this.
在这里插入图片描述
denotes the speed of the sidewalk. A positive speed means the sidewalk moves north, while a negative speed means the sidewalk moves south.
2 Output
If the robot cannot reach the destination in at most twice the time it would take in the absence of all moving sidewalks, output “Too\ hardToo hard” on a single line (without quotation marks).
Otherwise, output, on a single line, the travel time of the robot from the start to the destination, rounded and displayed to exactly three decimal places.
样例输入1复制
1 806873 66
91411 631975 -57.5
样例输出1复制
15055.988
样例输入2复制
2 422193 100
38180 307590 86.4
366035 403677 -4.7
样例输出2复制
5043.896
样例输入3复制
1 670764 22.4
113447 642610 -64.8
样例输出3复制
Too hard

题目大意:
一个机器人有速度 v v v,目前在 ( 0 , 0 ) (0,0) (0,0),希望走到 ( x , 0 ) (x,0) (x,0),选择一个角度一直走。路上有一些河流,第 i i i条河流从 l i l_i li r i r_i ri,水的流速是 w i w_i wi,求最短到达目的地时间,如果时间超过 2 x v \frac{2x}{v} v2x则输出 − 1 -1 1
题目分析:
目的是使得机器人在 y y y轴上走的距离是 0 0 0,相当于 v v v y y y轴上分量的和是 0 0 0。发现在 y y y轴上走过的距离是与速度分量成正比,考虑一个 y y y轴速度分量和 y y y轴上走过距离的函数,与那么问题转化成了求该函数的零点。二分 y y y轴方向的速度,由于距离函数是单调的,二分求出零点即可。
这是官方题解给出的solution,但是我们知道初始速度,Vx^2 + Vy2==V2 这是一个等式 ,然后根据垂直方向位移是0,再列一个等式,帮第二个等式搞一下直接计算初始时候的Vy,然后判断一下就好了,注意这样算出来初始的Vy有可能大于V,这就是Too hard的情况之一,不判断这个就是WA
在这里插入图片描述
其中Wi表示每个河流的宽度,solution的二分做法是不是瞬间黯然失色😆😆😆😆😆😆

// 直接能够推导一个公式    然后让我们一起hhhhh solution的二分答案做法
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#define Maxn 105
using namespace std;
int L[Maxn],R[Maxn];
double vi[Maxn];
int main(int argc,char* argv[]) {
    int n,X; double V;
    scanf("%d %d %lf",&n,&X,&V);
    double sum = 0;
    for(int i=1; i<=n; i++) {
        scanf("%d %d %lf",&L[i],&R[i],&vi[i]);
        sum += (R[i] - L[i]) * vi[i];
    }
    sum = -sum;
    double Vy = sum / X;
    if(Vy > V) { printf("Too hard"); return 0; }
    double Vx = sqrt(V * V - Vy * Vy);
    double Time = X / Vx;
    if(Time > 2.0 * X / V) printf("Too hard");
    else printf("%.3lf",Time);
    return 0;
}

P. Purple Rain

在这里插入图片描述
Purple rain falls in the magic kingdom of Linearland which is a straight, thin peninsula.
On close observation however, Professor Nelson Rogers finds that the purple rain is actually a mix of red and blue raindrops.
In his zeal, he records the location and color of the raindrops in different locations along the peninsula. Looking at the data, Professor Rogers wants to know which part of Linearland had the “least” purple rain.
After some thought, he decides to model this problem as follows. Divide the peninsula into nn sections and number them west to east from 11 to nn. Then, describe the raindrops as a sequence of RR and BB, depending on whether the rainfall in each section is primarily red or blue. Finally, find a subsequence of contiguous sections where the difference between the number of RR and the number of BB is maximized.
1 Input
The input consists of a single line containing a string of nn characters (1 ≤ n ≤ 10^{5} )(1≤n≤10
5 ), describing the color of the raindrops in sections 11 to nn.
It is guaranteed that the string consists of uppercase ASCIIASCII letters ‘RR’ and ‘BB’ only.
2 Output
Print, on a single line, two space-separated integers that describe the starting and ending positions of the part of Linearland that had the least purple rain. These two numbers should describe an inclusive range; both numbers you print describe sections included in the range.

If there are multiple possible answers, print the one that has the westernmost starting section. If there are multiple answers with the same westernmost starting section, print the one with the westernmost ending section.

样例输入1 复制
BBRRBRRBRB
样例输出1 复制
3 7
样例输入2 复制
BBRBBRRB
样例输出2 复制
1 5

题目大意:
给出一段只有字母R和字母B字符串 然后找出一个子串 使得其中的R和B的数量之差尽可能大
题目分析:
容易想到最长字段和的例题,将R看成1 B看成-1 求一下最长子段和 维护的时候跟新一下左右端点 注意一个事情就是这个求出来的一定是R多余B并且RB之差最大的情况 再反过来求一边 搞定B比R多的情况 最后判断一下

// 原来写的代码在家里的电脑里,本来今天是想来网吧打比赛的  但是到了网吧发现比赛取消了  那就补题吧,补昨天的题  把没写的代码再写一遍

#include<iostream>
#include<cstring>
#include<cstdio>
#define Maxn 100005
using namespace std;
char s[Maxn];
int a[Maxn],n;

inline void DP(int &begin,int &end,int &sum) {
	sum = a[1]; begin = end = 1;
	int temp = a[1],pos = 1;
	for(int i=2; i<=n; i++) {
		if(temp >= 0) temp += a[i];
		else {
			temp = a[i];
			pos = i;
		}
		if(temp > sum) {
			sum = temp;
			begin = pos;
			end = i;
		}
	}
}

int main(int argc,char* argv[]) {
	scanf("%s",s + 1);
	n = strlen(s + 1);
	for(int i=1; i<=n; i++) 
		if(s[i] == 'R') a[i] = 1;
		else a[i] = -1;	
		
	int beg,end,len = 0;
	DP(beg,end,len);
	
	for(int i=1; i<=n; i++)
		if(s[i] == 'B') a[i] = 1;
		else a[i] = -1;
	int beg1,end1,lenth = 0;
	DP(beg1,end1,lenth);
	
	if(len > lenth) printf("%d %d\n",beg,end);
	else if(lenth > len) printf("%d %d\n",beg1,end1);
	else { // lenth == len
		if(beg1 == beg) printf("%d %d\n",beg1,min(end,end1));
		else if(beg1 < beg) printf("%d %d\n",beg1,end1);
		else if(beg1 > beg) printf("%d %d\n",beg,end);
	}
	
	
	return 0;
}

N. Latin Squares

A Latin Square is an nn-by-nn array filled with nn different digits, each digit occurring exactly once in each row and once in each column. (The name “Latin Square” was inspired by the work of Leonhard Euler, who used Latin characters in his papers on the topic.)

A Latin Square is said to be in reducedreduced form if both its top row and leftmost column are in their natural order. The natural order of a set of digits is by increasing value.

Your team is to write a program that will read an nn-by-nn array, and determine whether it is a Latin Square, and if so, whether it is in reducedreduced form.

1 Input

The first line of input contains a single integer nn (2 ≤ n ≤ 36)(2≤n≤36).

Each of the next nn lines contains nn digits in base nn, with the normal digits ‘00’ through ‘99’ for digit values below 1010 and uppercase letters ‘AA’ through ‘ZZ’ representing digit values 1010 through 3535. All digits will be legal for base nn; for instance, if nn is 33, the only legal characters in the nn input lines describing the square will be ‘00’, ‘11’, and ‘22’.

2 Output

If the given array is not a Latin Square, print “NoNo” on a single line (without quotation marks). If it is a Latin Square, but not in reducedreduced form, print “Not\ ReducedNot Reduced” on a single line (without quotation marks). If it is a Latin Square in reducedreduced form, print “ReducedReduced” on a single line (without quotation marks).

样例输入1 复制
3
012
120
201
样例输出1 复制
Reduced
样例输入2 复制
4
3210
0123
2301
1032
样例输出2 复制
Not Reduced
样例输入3 复制
11
0123458372A
A9287346283
0285475A834
84738299A02
1947584037A
65848430002
038955873A8
947530200A8
93484721084
95539A92828
04553883568
样例输出3 复制
No

题目大意:
L a t i n Latin Latin S q u a r e Square Square是一个 n × n n×n n×n的数组,其中填充了 n n n个不同的数字,每个数字在每一行和每一列中恰好出现一次。 (“ L a t i n Latin Latin S q u a r e Square Square”的名称受 L e o n h a r d Leonhard Leonhard E u l e r Euler Euler的作品启发,他在有关该主题的论文中使用了拉丁字符。)
如果 L a t i n Latin Latin S q u a r e Square Square的顶行和最左列均按自然顺序排列,则称其为简化形式。一组数字的自然顺序是通过增加值来实现的。
题目分析:
一共三十六个字符 直接就暴力判断就行了
但是我必须要你吐槽一下,这个题 真的就是 当我的队友AC的时候我还在读题,等他AC的时候我才读明白题目,hhhhhhhhhhhhh

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define Maxn 55
using namespace std;
char s[Maxn][Maxn];
int vis[Maxn],a[Maxn][Maxn];
int main(int argc,char* argv[]) {
	int n; scanf("%d",&n);
	for(int i=1; i<=n; i++)
		scanf("%s",s[i] + 1);
	for(int i=1; i<=n; i++)
		for(int j=1; j<=n; j++) {
			if(s[i][j] >= '0' && s[i][j] <= '9') a[i][j] = s[i][j] - '0';
			else a[i][j] = s[i][j] - 'A' + 10;
		}
	int flag;
	for(int i=1; i<=n; i++) {
		memset(vis,0,sizeof(vis));
		flag = 0;
		for(int j=1; j<=n; j++) {
			vis[a[i][j]]++;
			if(vis[a[i][j]] == 2) { flag = 1; break; } // m某个字符出现两次 
		}
		if(flag == 1) break;
	}
	if(flag == 1) { printf("No"); return 0; }
	
	flag = 0;
	for(int i=1; i<=n; i++)
		if(a[1][i] != i-1) {
			flag = 1; break;
		}
	for(int i=1; i<=n; i++)
		if(a[i][1] != i-1) {
			flag = 1; break;
		}
	if(flag) printf("Not Reduced\n");
	else printf("Reduced\n");
	return 0;
}

O. Halfway

在这里插入图片描述
A friend of yours has written a program that compares every pair of a list of items. With nn items, it works as follows. First, it prints a 11, and it compares item 11 to items 22, 33, 44, . . … , nn. It then prints a 22, and compares item 22 to items 3, 4, 5, . . . , n3,4,5,…,n. It continues like that until every pair of items has been compared exactly once. If it compares item xx to item yy, it will not later compare item yy to item xx. Also, it does not compare any item to itself.
Your friend wants to know when his program is halfway\ donehalfway done. For a program that makes an odd number of total comparisons, this is when it is doing the middle comparison. For a program that makes an even number of total comparisons, this is when it is doing the first of the two middle comparisons.
What will the last number printed be when the program is halfway\ donehalfway done?
Note that since the earlier items have more comparisons than the later items, the answer is not simply n/2n/2.
1 Input
The input consists of a single line containing the integer nn (2 ≤ n ≤ 10^{9} )(2≤n≤10 ^9).
2 Output
Print, on a single line, the last number your friend’s program prints when it is halfway\ donehalfway done.

样例输入 复制
4
7
10
1919
290976843
样例输出 复制
1
2
3
562
85225144

题目大意:
懒得码字了,看个图片凑活一下吧
在这里插入图片描述
题目分析:
假设当前比较的数是x,也就是拿着x与x+1,x+2,,,,n进行比较,那么根据公式能够直接计算出已经完成的比较次数(n - 1 + n - (k - 1)) * (k - 1) / 2,然后已经很明显了,直接就二分答案就行了

#include<iostream>
#include<cstdio>
#include<cstring>
#define LL long long
using namespace std;
LL Sum,n;
inline bool check(int k) {
	LL num = (n - 1 + n - (k - 1)) * (k - 1) / 2;
	
	if(num <= Sum) return true;
	else return false;
}

int main(int argc,char* argv[]) {
	scanf("%lld",&n);
	Sum = n * (n - 1) >> 1;
	if(Sum & 1) Sum >>= 1;
	else Sum = (Sum >> 1) - 1;
	

	int l = 1,r = n,Mid,Ans;
	while(l <= r) {
		Mid = l + r >> 1;
		if(check(Mid)) {
			Ans = Mid;
			l = Mid + 1;
		}else r = Mid - 1;
	}
	printf("%d\n",Ans);
	return 0;
}

Q. Unloaded Die

在这里插入图片描述
Consider a six-sided die, with sides labeled 11 through 66. We say the die is fairfair if each of its sides is equally likely to be face up after a roll. We say the die is loadedloaded if it isn’t fairfair. For example, if the side marked 66 is twice as likely to come up as than any other side, we are dealing with a loadedloaded die. For any die, define the expected\ resultexpected result of rolling the die to be equal to the average of the values of the sides, weighted by the probability of those sides coming up. For example, all six sides of a fairfair die are equally likely to come up, and thus the expected\ resultexpected result of rolling it is (1+2+3+4+5+6)/6 = 3.5(1+2+3+4+5+6)/6=3.5.
You are given a loadedloaded die, and you would like to unloadunload it to make it more closely resemble a fairfair die. To do so, you can erase the number on one of the sides, and replace it with a new number which does not need to be an integer or even positive. You want to do so in such a way that
• The expected\ resultexpected result of rolling the die is 3.53.5, just like a fairfair die.
• The difference between the old label and the new label on the side you change is as small as possible.
1 Input
The input consists of a single line containing six space-separated nonnegative real numbers v_{1} . . . v_{6}v 1 …v 6 , where v_{i}v i
represents the probability that side ii (currently labeled by the number ii) is rolled.
It is guaranteed that the given numbers will sum to 11.
2 Output
Print, on a single line, the absolute value of the difference between the new label and old label, rounded and displayed to exactly three decimal places.

样例输入1复制
0.16666 0.16667 0.16667 0.16666 0.16667 0.16667
样例输出1复制
0.000
样例输入2复制
0.2 0.2 0.1 0.2 0.2 0.1
样例输出2复制
1.000

昨天在网吧的时候居然好久 没搞明白题意

/*
题目大意:  一个六边形  给定每个边出现的概率
然后修改一个边权 使得六个边的期望值是3.5    修改的绝对值之差尽量小 
*/

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>

using namespace std;
double s[7];
int main(int argc,char* argv[])  {
	double aver = 0;
	for(int i=1; i<=6; i++) {
		cin >> s[i];
		aver += s[i] * i;
	}
	double Ans = 1e9;
	for(int i=1; i<=6; i++) {
		aver -= s[i] * i ;
		Ans = min(Ans,fabs((3.5 - aver) / s[i] - i));
		aver += s[i] * i;
	}
	printf("%.3lf\n",Ans);
	return 0;
}

R. Star Arrangements

这个R题也是个傻逼题,真的就是傻逼题, 就是读题,

The recent vote in Puerto Rico favoring United States statehood has made flag makers very excited. An updated flag with 5151 stars rather than the current one with 5050 would cause a huge jump in U.S. flag sales. The current pattern for 5050 stars is five rows of 66 stars, interlaced with four offset rows of 55 stars. The rows alternate until all stars are represented.
在这里插入图片描述
This pattern has the property that adjacent rows differ by no more than one star. We represent this star arrangement compactly by the number of stars in the first two rows: 6,56,5.

A 5151-star flag that has the same property can have three rows of 99 stars, interlaced with threerows of 88 stars (with a compact representation of 9,89,8). Conversely, if a state were to leave the union, one appealing representation would be seven rows of seven stars (7,7)(7,7).

A flag pattern is visually\ appealingvisually appealing if it satisfies the following conditions:

• Every other row has the same number of stars.

• Adjacent rows differ by no more than one star.

• The first row cannot have fewer stars than the second row.

Your team sees beyond the short-term change to 5151 for the U.S. flag. You want to corner the market on flags for any union of three or more states. Given the number SS of stars to draw on a flag, find all possible visually\ appealingvisually appealing flag patterns.

1 Input

The input consists of a single line containing the integer SS (3 ≤ S ≤ 32,767)(3≤S≤32,767).

2 Output

On the first line, print SS, followed by a colon. Then, for each visually\ appealingvisually appealing flag of SS stars, print its compact representation, one per line.

This list of compact representations should be printed in increasing order of the number of stars in the first row; if there are ties, print them in order of the number of stars in the second row. The cases 11-by-SS and SS-by-11 are trivial, so do not print those arrangements.

The compact representations must be printed in the form “x,yx,y”, with exactly one comma between xx and yy and no other characters.

样例输入1复制
3
样例输出1复制
3:
2,1
样例输入2复制
50
样例输出2复制
50:
2,1
2,2
3,2
5,4
5,5
6,5
10,10
13,12
17,16
25,25
样例输入3复制
51
样例输出3复制
51:
2,1
3,3
9,8
17,17
26,25

题目大意:
波多黎各最近投票赞成美国建国,这使标志制造商非常兴奋。更新后的星标为 51 51 51星,而不是当前的星标为 50 50 50星,这将导致美国星标的销售大幅增长。当前 50 50 50个星的模式是 5 5 5 6 6 6个星,与 5 5 5个星的 4 4 4个偏移行交错。这些行交替进行,直到代表所有星星为止。

这种模式的性质是相邻行的差异不超过一个星。我们通过前两行中的恒星数量来紧凑地表示这种恒星排列: 6 , 5 6,5 65

具有相同属性的 51 51 51星级标志可以具有三行 9 9 9星,与三行 8 8 8星交错(紧凑表示为 9 , 8 9,8 9,8)。相反,如果一个州要退出联盟,一个吸引人的代表就是七排七颗星 ( 7 , 7 ) (7,7) 7,7

满足以下条件的标志图案在视觉上很有吸引力:
•每隔一行具有相同数量的星星。

•相邻的行相差不超过一星。

•第一行的星数不能少于第二行。
您的团队认为,对于美国国旗来说,短期内不会更改为 51 51 51。您想将标志垄断三个或更多州的市场。给定要画星号的星数 S S S,找到所有可能在视觉上吸引人的星型。

#include<iostream>
#include<cstdio> 
#include<cstring>

using namespace std;

int main(int argc,char* argv[])  {
	int n;
	cin >> n;
	cout << n << ":" << endl;
	for(int i=2; i<=n/2+1; i++) {
		if(n % (i + i - 1) == 0 || n % (i + i - 1) == i ) 
			cout << i << ',' << i - 1 << endl;
		if(n % i == 0) cout << i << ',' << i << endl;
	}
	
	
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

七情六欲·

学生党不容易~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值