UESTC 2018 Summer Training #5 Div.2

本文解析了一场算法挑战赛中的三道题目:A题为单词算术问题,需要计算不同解的数量;B题涉及图论中的最短路径计算;C题则是高尔夫机器人击球策略问题。

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

A题

GREAT+SWERC=PORTO
We want to have a great SWERC at Porto this year and we approached this challenge in several ways. We even framed it as a word addition problem, similar to the classic SEND+MORE=MONEY, where each letter stands for a single digit (0, 1, 2, ..., 8, 9) that makes the arithmetic operation correct. In word additions different letters cannot be assigned the same digit and the leftmost letter in a word cannot be zero (0). In particular, a single letter term cannot be zero.
To solve this word addition problem we had to find positive digits for G, S and P, and digits for R, E, A, T, W, C, O, so that each letter has a different digit and the sum is correct. It turns out that, unlike the classical SEND+MORE=MONEY which has a single solution, GREAT+SWERC=PORTO has six solutions. T=7, E=3, W=9, G=1, A=0, P=4, S=2, C=8, R=6, O=5 T=7, E=3, W=9, G=2, A=0, P=4, S=1, C=8, R=6, O=5 T=8, E=5, W=1, G=3, A=7, P=9, S=6, C=4, R=0, O=2 T=8, E=5, W=1, G=6, A=7, P=9, S=3, C=4, R=0, O=2 T=9, E=5, W=2, G=1, A=8, P=7, S=6, C=4, R=0, O=3 T=9, E=5, W=2, G=6, A=8, P=7, S=1, C=4, R=0, O=3 HavingmorethanonesolutiondoesnotmakeGREAT+SWERC=PORTOagoodproblem tosolvebyhand, butitisstillapieceofcakeforaprogramer. Moreover, itgivesusanother reason to organize SWERC again next year and, who knows, in years to come!
Task Given a word addition problem, compute the number of solutions (possibly zero).
Input A line with an integer n, followed by n lines containing a word each with maximum length of 10 letters. The first n−1 words are the terms to be added and the last line is the result. Universidade do Porto Computer Science Department 3
Problem A Problem A
Wordscontainonlycapitalletters. Ifwordshavedifferentlengths, theymustbeinterpreted as aligning to the right. For instance, in the SEND+MORE=MONEY problem, the D of the first word and E of the second word align with the Y of the final word. You can also assume that the size of the last word is greater than or equal to the maximum size of the preceding words, and moreover, at most ten distinct letters are involved in a word problem.
Constraints 3 ≤ n ≤ 10 Each word has at most 10 symbols (capital letters). A word problem has at most 10 distinct letters.
Output A single line with an integer: the number of solutions of the word addition problem given as input.
Sample Input 1 3 GREAT SWERC PORTO
Sample Output 1 6
Sample Input 2 3 SEND MORE MONEY
Sample Output 2 1
Sample Input 3
5 TOO GOOD TO BE TRUE
Sample Output 3
93
A题算是一道小水题:就是对字母对应字数的枚举,写了一个cal计算字符串的值,和dp()枚举:枚举所有情况所以需要回溯。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>

#define MOD 10000000
using namespace std; 
typedef long long LL;
typedef unsigned long long ULL;
ULL base=233;
long long quickpow(long long n, long long base) {
    long long res = 1;
    while(n) {
        if(n & 1) {
            res = res * base % MOD;
        }
        n >>= 1;
        base = base * base % MOD;
    }
    return res;
}//快速幂 
ULL HASH(char s[])
{
	int l=strlen(s);
	ULL ans=0;
	for(int i=0;i<l;i++)
	{
		ans=ans*base+(ULL)s[i];
	}
	return ans;
}
set<ULL>hash0;//手动哈希 
set<ULL>::iterator it;//STL迭代器 
set<int >set0;
char A[200];
int  B[200];
char C[150][200];
int data0[100];
int data1[300];
int data2[300];
LL ans=0;
map<int ,int>map0;
LL cal(char s[])
{
	int len=strlen(s+1);
	LL t=1;
	LL sum=0;
	for(int i=len;i>=1;i--)
	{
		sum+=t*data0[s[i]-'A'+1];
		t*=10;
	}
	return sum;
}
void dp(int index,int x,int n)
{
	if(index==x+1)
	{
		LL SUM=0;
		for(int i=1;i<=n-1;i++)
		{
			SUM+=cal(C[i]);
		}
		 
		if(SUM==cal(C[n]))
		{ans++;
	}
		return;
	}
	if(data2[A[index]-'A'+1]==1)
	{for(int i=1;i<=9;i++)
	{
		if(!data1[i])
		{
		  data1[i]=1;
		  data0[A[index]-'A'+1]=i;
		  dp(index+1,x,n);
		  data1[i]=0;
		}
	}}
	else
	{
		for(int i=0;i<=9;i++)
	{
		if(!data1[i])
		{
		  data1[i]=1;
		  data0[A[index]-'A'+1]=i;
		  dp(index+1,x,n);
		  data1[i]=0;
		}
	}
	}
	return ;
}
int main()
{
     
     int n,k=0;
     cin>>n;
     int x=0;
     for(int i=1;i<=n;i++)
     {
     	cin>>C[i]+1;
     }
     memset(data2,0,sizeof(data2));
     for(int i=1;i<=n;i++)
     {
     	int len=strlen(C[i]+1);
     	for(int j=1;j<=len;j++)
     	{
     		if(j==1)data2[C[i][1]-'A'+1]=1;
     		if(!map0[C[i][j]-'A'+1])
	     	{
			  map0[C[i][j]-'A'+1]=1;
	     	  A[++k]=C[i][j];
            }
        }
     }
     x=map0.size();
     dp(1,x,n);
     cout<<ans<<endl;
}

单独还要判断那些处于首字母的数字不能为0。(我忘了有很多的首字母一开始)

B题

Flowery Trails
!"
#$%&'$()"
*+,-).%" /)'0"
122"
1!2"
342"
522"
!22"
652"
!42"
72" 72"
5!2"
!12" 622"
162"18!"
!12"
6"
7"
4"
9"
3"
5"
8"
1"
2"
In order to attract more visitors, the manager of a national park had the idea of planting flowers along both sides of the popular trails, which are the trails used by common people. Common people only go from the park entrance to its highest peak, where views are breathtaking, by a shortest path. So, he wants to know how many metres of flowers are needed to materialize his idea. For instance, in the park whose map is depicted in the figure, common people make only one of the three following paths (which are the shortest paths from the entrance to the highest peak). • At the entrance, some start in the rightmost trail to reach the point of interest 3 (after 100 metres), follow directly to point 7 (200 metres) and then pick the direct trail to the highest peak (620 metres). • The others go to the left at the entrance and reach point 1 (after 580 metres). Then, they take one of the two trails that lead to point 4 (both have 90 metres). At point 4, they follow the direct trail to the highest peak (250 metres).
Notice that popular trails (i.e., the trails followed by common people) are highlighted in yellow. Since the sum of their lengths is 1930 metres, the extent of flowers needed to cover both sides of the popular trails is 3860 metres (3860 = 2×1930).
Task Given a description of the park, with its points of interest and (two-way) trails, the goal is to find out the extent of flowers needed to cover both sides of the popular trails. It is guaranteed that, for the given inputs, there is some path from the park entrance to the highest peak.
Input The first line of the input has two integers: P and T. P is the number of points of interest and T is the number of trails. Points are identified by integers, ranging from 0 to P −1. The entrance point is 0 and the highest peak is point P −1. Universidade do Porto Computer Science Department 5
Problem B Problem B
Each of the following T lines characterises a different trail. It contains three integers, p1, p2, and l, which indicate that the (two-way) trail links directly points p1 and p2 (not necessarily distinct) and has length l (in metres). Integers in the same line are separated by a single space.
Constraints 2 ≤ P ≤ 10000 Number of points. 1 ≤ T ≤ 250000 Number of trails. 1 ≤ l ≤ 1000 Length of a trail. Output The output has a single line with the extent of flowers (in metres) needed to cover both sides of the popular trails.
Sample Input 1 10 15 0 1 580 1 4 90 1 4 90 4 9 250 4 2 510 2 7 600 7 3 200 3 3 380 3 0 150 0 3 100 7 8 500 7 9 620 9 6 510 6 5 145 5 9 160
Sample Output 1 3860
Sample Input 2 4 7 0 1 1 0 2 2 0 3 10 0 3 3 1 3 2 2 3 1 1 1 1
Sample Output 2 18
重边+多条最短路+筛选的题目。

EMMM感觉很难。单独会讲:

C题

Golf Bot
Do you like golf? I hate it. I hate golf so much that I decided to build the ultimate golf robot, a robot that will never miss a shot. I simply place it over the ball, choose the right direction and distance and, flawlessly, it will strike the ball across the air and into the hole. Golf will never be played again. Unfortunately, it doesn’t work as planned. So, here I am, standing in the green and preparing my first strike when I realize that the distance-selector knob built-in doesn’t have all the distance options! Not everything is lost, as I have 2 shots.
Task Given my current robot, how many holes will I be able to complete in 2 strokes or less?
Input The first line has one integer: N, the number of different distances the Golf Bot can shoot. Each of the following N lines has one integer, ki, the distance marked in position i of the knob. Next line has one integer: M, the number of holes in this course. Each of the following M lines has one integer, dj, the distance from Golf Bot to hole j.
Constraints 1 ≤ N,M ≤ 200000 1 ≤ ki,dj ≤ 200000
Output You should output a single integer, the number of holes Golf Bot will be able to complete. Golf Bot cannot shoot over a hole on purpose and then shoot backwards.
Universidade do Porto Computer Science Department 7
Problem C Problem C
Sample Input
3 1 3 5 6 2 4 5 7 8 9
Sample Output
4
Sample Output Explanation Golf Bot can shoot 3 different distances (1, 3 and 5) and there are 6 holes in this course at distances 2, 4, 5, 7, 8 and 9. Golf Bot will be able to put the ball in 4 of these: • The 1st hole, at distance 2, can be reached by striking two times a distance of 1. • The 2nd hole, at distance 4, can be reached by striking with strength 3 and then strength 1 (or vice-versa). • The 3rd hole can be reached with just one stroke of strength 5. • The 5th hole can be reached with two strikes of strengths 3 and 5. Holes 4 and 6 can never be reached.
题意很简单:写起来简单:TLE也很简单。

要用到FFT来简化:单独会讲:

PS:想到做题的小朋友可以直接在Vjudge上搜哦:如果有密码就是zxynb nbzxy.(因为我题目可能看不大清楚)

### XeLaTeX 中因 `Undefined control sequence` 导致的编译错误分析 当在使用 XeLaTeX 编译 UESTC 毕业论文模板时,如果遇到 `Undefined control sequence` 错误提示,并且该错误涉及 `\RequireXeLaTeX` 命令,则可能是由于以下原因之一引起的: #### 1. 宏包版本不兼容 `\RequireXeLaTeX` 是一个特定于某些 LaTeX 类文件或宏包中的命令,用于检测当前使用的引擎是否为 XeLaTeX。如果所依赖的类文件或宏包版本较旧,而本地安装的 TeX 发行版更新过快,可能会导致此类问题[^1]。 #### 2. 缺少必要的宏包 有时,模板所需的宏包可能未被正确加载或者缺失。例如,`thesis-uestc.cls` 文件可能依赖一些特殊的宏包来实现其功能。如果没有正确引入这些宏包,就会触发类似的错误。 --- ### 解决方案 以下是针对上述问题的具体解决方法: #### 方法一:确认并升级 TeX 发行版 确保已安装最新版本的 TeX Live 或 MiKTeX。可以通过以下方式检查和更新: - 对于 TeX Live 用户,在终端中执行以下命令以更新发行版及其所有宏包: ```bash tlmgr update --all ``` - 如果使用的是 MiKTeX,可以打开 MiKTeX Console 并通过图形界面完成更新操作。 #### 方法二:替换或修改类文件中的命令 如果无法更改 TeX 环境,也可以尝试手动调整 `thesis-uestc.cls` 文件的内容。具体做法如下: - 找到定义 `\RequireXeLaTeX` 的部分; - 将此命令替换为更通用的形式,比如直接调用 `\documentclass[xetex]{article}` 来强制指定文档引擎。 #### 方法三:重新配置编译流程 对于复杂项目(如包含 BibTeX 和多个 `.aux` 文件的情况),建议严格按照给定顺序多次运行工具链: 1. 首次运行 `xelatex main.tex`; 2. 接着运行 `bibtex main.aux`, 若存在额外辅助文件则还需处理它们 (如 `accomplish.aux`); 3. 再依次重复两次以上过程直到无新警告为止。 --- ### 示例代码片段 下面是一个简单的测试框架,可用于验证环境设置是否正常工作: ```latex \documentclass{thesis-uestc} % 使用 UESTC 论文模板 \begin{document} 这是正文内容。 \bibliographystyle{plain} \bibliography{references} \end{document} ``` 注意:实际应用前需保证路径下有对应的参考文献数据库 (`references.bib`) 存在。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值