![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
UVa
穷源溯流
路很长,尽管走便是。
展开
-
洛谷 UVA10298 Power Strings(KMP)
const int N=1e6+5; int n,m; int i,j,k; char s[N]; int f[N];void getfail(char *s){ f[0]=f[1]=0; int len=strlen(s); for(int i=1;i<len;i++){ int j=f[i]; while(j && s[i]!=s[j]) j=f[j]; ...原创 2021-04-19 10:36:33 · 187 阅读 · 0 评论 -
UVa10887 Concatenation of Languages(Trie)
Sample Input23 2catdogmouseratbat1 1abccabSample OutputCase 1: 6Case 2: 1有 n 个 A 串,m 个 B 串,问可以组成多少种 AB 串将所有的组合放入字典树中即可,话说为什么会有空串啊喂const int N=2e6+5; int n,m; int i,j,k; int t[N][26],tot=0; int vis[N]; cha...原创 2021-02-24 18:01:04 · 140 阅读 · 0 评论 -
UVa 11475 Extend to Palindrome(KMP+思维)
Sample InputaaaaabbaamanaplanacanalxyzSample Outputaaaaabbaamanaplanacanalpanamaxyzyx给出一个字符串,将其变为最短的回文串通过观察样例发现每一个字符串都为 \\\\\\A 的形式,其中 A 为回文字符串,计算非回文串的长度并不是很好计算,但是如果知道 A 的长度同样可以解决问题我们将字符串反转 A///////,求 A 的长度,那么将字符串变为 A////////\\\\\\\\...原创 2021-02-13 09:30:41 · 362 阅读 · 0 评论 -
UVA 11168 Airport(凸包)
Sample Input440 00 11 01 1215035 3957234582 3953530 00 11 050 00 22 02 21 1Sample OutputCase #1: 0.500Case #2: 0.000Case #3: 0.236Case #4: 1.000原创 2020-11-25 08:47:42 · 174 阅读 · 0 评论 -
UVA10652 Board Wrapping(凸包)
Sample Input144 7.5 6 3 08 11.5 6 3 09.5 6 6 3 904.5 3 4.4721 2.2361 26.565Sample Output64.3 %原创 2020-11-24 16:51:08 · 177 阅读 · 0 评论 -
UVALive 3263 && POJ 2284 That Nice Euler Circuit (欧拉定理+计算几何)
给出 n 个点,将其连成一个回路,问这些线段将平面分成几部分根据欧拉定理,平面数 ans=边数-顶点数+2所以只需要利用计算机和基础计算顶点数和边数即可因为所连的线是由给定的顺序产生的,所以可以从前面按照顺序枚举,两两相邻的点作为一条边,判断是否产生交点由于可能产生多线共点的情况,再进行去重。最后判断每一个点再几条边上,这样线段内的一个点将一条线段分为两条线段const int N=300+5; int i,j,k; int n,m,t; ...原创 2020-11-22 11:54:06 · 156 阅读 · 0 评论 -
UVA12300 Smallest Regular Polygon(计算几何基础)
Sample Input0 0 1 1 41 2 3 4 52 3 4 5 60 0 0 0 0Sample Output1.0000005.2573115.196152给出两个点的坐标以及整数 n,求穿过这两个点的面积最小的正n边形要求面积最小,根据贪心这条边一定是最长的一条对角线将这个正 n 边形放到圆内,360 被分成了 n 分,每份记为 x°,我们只要知道这个圆的半径之后就可以求得这个 n 边形的面积n 为偶数的时候,就是这两点之间的距离的一半...原创 2020-11-18 08:09:04 · 198 阅读 · 0 评论 -
UVA11817 Tunnelling the Earth(计算几何基础)
Sample Input143.466667 -80.516667 30.058056 31.228889Sample Output802333输入两个点的经纬度,已知地球半径为 6 371 009 ,求这两点之间的弧长与直线距离的差不难想到要将所给点的经纬度转化成球上的坐标,剩下的按照常规求解,将这两个点看做成一个向量向量的长度为直线距离 = 向量自身的点积 再开平方 弧长=两点与坐标原点所形成向量的夹角*地球半径 struct Point ...原创 2020-11-16 19:05:59 · 243 阅读 · 0 评论 -
UVA11800 Determine the Shape(计算几何基础)
Sample Input60 02 02 20 20 03 03 20 20 08 45 03 40 02 03 21 20 05 04 31 30 05 04 31 4Sample OutputCase 1: SquareCase 2: RectangleCase 3: RhombusCase 4: ParallelogramCase 5: TrapeziumCase 6: Ordinary Quadrilateral给...原创 2020-11-16 18:24:27 · 213 阅读 · 0 评论 -
UVA11646 Athletics Track(计算几何基础)
Sample Input3 : 25 : 4Sample OutputCase 1: 117.1858168913 78.1238779275Case 2: 107.2909560477 85.8327648381有一个长为 400 米的跑道,给出跑道矩形的长和宽的比值,已知两边的圆弧(silced circle)是以矩形中点为圆心的圆弧,求长与宽的值如上图所示,我们可以由比例求得 r 的大小和的大小,由于 r 并不是真正的 r 的值,跑道的一半长度为 200,...原创 2020-11-15 17:53:12 · 334 阅读 · 0 评论 -
UVA11524 InCircle(计算几何基础)
Sample Input2140.950053649715.3010457320 550.3704847907464.9681681852 65.973737823055.0132446384 10.7791711946208.2835101182145.7725891419 8.82641764527.6610997600 436.1911036207483.6031801012 140.2797089713Sample Output400156.40759088...原创 2020-11-15 12:55:02 · 166 阅读 · 0 评论 -
UVA11437 Triangle Fun(计算几何基础)
23994.707 9251.677 4152.916 7157.810 5156.835 2551.9726903.233 3540.932 5171.382 3708.015 213.959 2519.85298099206144在三角形 ABC 中,D E F 分别是三边的三等分点,P Q R 三点构成了一个三角形,求这个三角形的面积 int i,j,k; int n,m,t; struct Point { dou...原创 2020-11-14 22:22:12 · 175 阅读 · 0 评论 -
UVA11186 Circum Triangle(计算几何基础)
现在有一个圆心坐标在 (0,0) 的圆,给出 n 个点的极角,再给出圆的半径 r可以证明任意在圆上的三个点是不共线的,所以求出任意三个点所围成的三角形的面积之和题目告诉了圆心的坐标和圆的半径,以及点的极角,所以很容易求得所有点的坐标,然后暴力枚举,利用向量的叉乘计算各个三角形的面积由于点的个数只有 500 ,所以 O(n^3) 的时间复杂度完全可以const double pi=acos(-1.0);const int N=500+5; int i,j,...原创 2020-11-14 16:44:50 · 212 阅读 · 0 评论 -
UVA10566 Crossed Ladders(计算几何+二分)
有两把梯子搭在墙上,给出这两把梯子的长度 x,y,以及他们的交点,交点的高度为 h,求这两个房屋之间的距离 double x,y,h;bool C(double aim){ double ans=1.0/sqrt(x*x-aim*aim)+1.0/sqrt(y*y-aim*aim); if(ans<1/h) return true; else return false;}int main(){ //IOS; while(~s...原创 2020-11-14 15:47:13 · 241 阅读 · 0 评论 -
UVa 11178 Morley‘s Theorem(计算几何基础)
//#pragma GCC optimize(2)//#include <bits/stdc++.h>#include <iostream>#include <cmath>#include <cstdio>#include <algorithm>#include <cstring>#include <queue>#include <vector>#include <utility>.原创 2020-11-12 15:01:37 · 164 阅读 · 0 评论 -
POJ 2800 && UVa 1363 Joseph‘s Problem(分块求余)
给出 n,k 求 (k mod i)原创 2020-07-25 15:01:45 · 146 阅读 · 0 评论 -
UVa 10006 Carmichael Numbers (快速幂)
给出一个合数 n ,如果对于任意数 a 都有 (2<=a<=n-1) a^n mod n =a ,则称 n 是一个卡迈克尔数.给出一整数n,判断其是否是卡迈克尔数如果数 n 本身为质数,即使通过费马测试也不是卡迈尔数 int n,m,t; int i,j,k;ll pow_mod(ll a,ll x,ll mod){ ll ans=1; while(x){ if(x&1) ans=ans*a%mod;...原创 2020-07-21 22:35:19 · 200 阅读 · 0 评论 -
Duathlon
const int N=1e6+5; int n; double m,t; int i,j,k; pair<double,double> p[N]; double C(double x){ //计算第 n 位与其余选手的耗时之差 double ans=inf; double t1=x/p[n-1].first+(m-x)/p[n-1].second; for(i=0;i<n-1;i++){ doub...原创 2020-06-26 11:10:11 · 249 阅读 · 0 评论 -
Symmetry UVA - 1595( set+pair )
YESNOYES我们假设对称轴坐标为 x ,那么这 n 个点中每两个对称的点的横坐标 <X1, Xn> <X2,Xn-1> 满足X1+Xn=2*x或者是位于对称轴上的数 <Xm> (Xm*2 = x*2)所有数的横坐标相加则为 n*x,假设我们要判断 Xn 是否有对称点,只需要证明 2*x-Xn=X1即可,我们在等式两边 同 ×n,即可避免除法运算计算对称轴 Pair p[N]; set<Pair> all;...原创 2020-06-24 14:49:53 · 168 阅读 · 0 评论 -
Compound Words
#include<iostream>#include<cstring>#include<algorithm>#include<map>#include<set>using namespace std;const int maxn = 120010;int main(){ set<string> s; string str; while(cin>>str) { s.insert(str); ...原创 2020-06-23 23:52:14 · 381 阅读 · 0 评论 -
Foreign Exchange(map)
Sample Input101 22 13 44 3100 200200 10057 22 571 22 1101 23 45 67 89 1011 1213 1415 1617 1819 200Sample OutputYESNO int n,m,t; int i,j,k; map<Pair,int> mp;int main(){ //IOS; while(~sd(n)...原创 2020-06-23 21:40:28 · 187 阅读 · 0 评论 -
Ducci Sequence (水题)
题目链接1000此操作之内,若可以全变为 0 则输出 zero ,否则 loop,(大写) int n,m,t; int i,j,k; int a[N];int main(){ IOS; rush(){ cin>>n; int num=1001; bool f=0; for(i=0;i<n;i++) cin>>a[i]; while(n..原创 2020-06-23 20:48:03 · 188 阅读 · 0 评论 -
Broken Keyboard (a.k.a. Beiju Text)
你有一个键盘,键盘上所有的键都能正常使用,只是Home键和End键有时会自动按下。你并不知道这一情况,而是专心地打稿子,甚至连显示器都没开电源。当你打开显示器之后,展现在你面前的是一段悲剧文本。你的任务是根据给出的键盘上实际输入的内容,计算并输出这段悲剧文本(即显示器上展现的文本)Input:一行文本不超过1000000个字符,只包括字母、下划线、字符‘[‘(表示Home键)和字符‘]‘(表示End键盘)。Output:一个字符串,即符合题目描述的悲剧文本。Example:In.原创 2020-06-12 23:12:12 · 213 阅读 · 0 评论 -
Oil Deposits (连通块 模板题)
传送门求连通块的个数#pragma GCC optimize(2)#include <bits/stdc++.h>#define rush() int T;cin>>T;while(T--)#define go(a) while(cin>>a)#define ms(a,b) memset(a,b,sizeof a)#define E 1e-8#define debug(a) cout<<"*"<<a<<"*"<原创 2020-06-12 19:54:06 · 220 阅读 · 0 评论 -
Matrix Chain Multiplication
Suppose you have to evaluate an expression like ABCDE where A,B,C,D and E are matrices.Since matrix multiplication is associative, the order in which multiplications are performed is arbitrary.However, the number of elementary multiplications needed stro原创 2020-06-11 21:14:28 · 336 阅读 · 0 评论 -
Rails
波普什市有一个著名的火车站。那里的乡村有着令人难以置信的丘陵。这个车站建于上个世纪。不幸的是,当时的资金极为有限。只能建立一条地面轨道。此外,事实证明,空间站可能只是一个死胡同(见图),由于缺乏可用的空间,它只能有一个轨道。在这里插入图片描述当地的传统是,从A方向到达的每一列火车都会继续向B方向行驶,教练也会以某种方式重新组织起来。假设从A方向到达的列车编号为N<=1000辆客车,编号为1,2,…,N。列车重组主管必须知道是否有可能将客车继续沿B方向行驶,以便其顺序为A1、a2、.a。帮助他并编写原创 2020-06-11 20:51:30 · 670 阅读 · 0 评论 -
Team Queue
题意有t个团队的人正在排一个长队。每次新来一个人时,如果他有队友在排队,那么这个新人会插队到最后一个队友身后。如果没有任何一个队友排队,则他会排到长队的队尾。输入每个团队中所有队员的编号,要求支持如下3种指令(前两种指令可以穿插进行)。ENQUEUE:编号为X的人进入长队。DEQUEUE:长队队首出队。STOP:停止模拟。对于每个DEQUEUE指令,输出出队的人的编号。输入输入文件中有一组或多组测试数据。每组测试数据开始有t个团队。下面t行,每行的第一个数字代表这个团队人数,...原创 2020-06-04 14:37:40 · 469 阅读 · 0 评论 -
Ugly Numbers
题意丑数是指不能被2,3,5以外的其他素数整除的数。把丑数从小到大排列起来,结果如下:1,2,3,4,5,6,8,9,10,12,15……求第1500个丑数输入没有输入输出The 1500'th ugly number is <number>.#pragma GCC optimize(2)#include <bits/stdc++.h>#define rush() int T;cin>>T;while(T--)#define...原创 2020-06-03 22:55:08 · 303 阅读 · 0 评论 -
Ananagrams(map)
Most crossword puzzle fans are used to anagrams--groups of words with the same letters in different orders--for example OPTS, SPOT, STOP, POTS and POST. Some words however do not have this attribute, no matter how you rearrange their letters, you cannot fo原创 2020-06-01 21:36:36 · 260 阅读 · 0 评论 -
Andys First Dictionary
DescriptionAndy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy task for him, as the number of words that he knows is, well, not quite enough. Instead of thinking up all the words himself, he has a briliant idea. From .原创 2020-06-01 20:40:13 · 230 阅读 · 0 评论