POJ1183 除输入方式外与这道题完全一样 题目大意是给定一个a 求最小的满足arctan(1/A)=arctan(1/B)+arctan(1/C) 的B+C的最小值 根据上述递推规律,我们只要从2*a开始往前递增寻找找到第一个满足b,c均为正整数的情况就是最小的 #include <cstdio> #define ll long long int main() { int T,n; scanf("%d",&T); while(T--){ scanf("…
详细的题解见这里. 图片转自上面的博客 假设我们已经推导出来x在处取得最小值,并且注意到这个点是位于两个整点之间的,所以从这两个整数往左右两边枚举b就能找到b+c的最小值. 其实只用往一边枚举就够了,由于对称性,我们不妨假设b ≤ c,那么只要让b从2a开始递减枚举即可. #include <iostream> using namespace std; long long a, i; ;)%(i-a))i--;cout<<(i*i+)/(i-a)<<endl;};} 代…
题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ..., an and a number of d-queries. A d-query is a pair (i, j) (1 ≤ i ≤ j ≤ n). For each d-query (i, j), you have to return the number of distinct elem…
SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50000) integers between -10000 and 10000. On this sequence you have to apply M (M <= 50000) operations: modify the i-th element in the sequence or for giv…
http://www.spoj.com/problems/SUBLEX/ 好难啊. 建出后缀自动机,然后在后缀自动机的每个状态上记录通过这个状态能走到的不同子串的数量.该状态能走到的所有状态的f值的和+1就是当前状态的f值. 最后对于询问的k,从root开始走顺便加加减减就可以了. #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int in() { int k =…
Time Limit: 1000MS Memory Limit: 1572864KB 64bit IO Format: %lld & %llu Description Being a completist and a simplist, kid Yang Zhe cannot solve but get Wrong Answer from most of the OI problems. And he refuse to write two program of same kind at…
题目 Source http://www.spoj.com/problems/TSUM/ Description You're given a sequence s of N distinct integers.Consider all the possible sums of three integers from the sequence at three different indicies.For each obtainable sum output the number of diff…
COT - Count on a tree #tree You are given a tree with N nodes.The tree nodes are numbered from 1 to N.Each node has an integer weight. We will ask you to perform the following operation: u v k : ask for the kth minimum weight on the path from node u …
Query on a tree Time Limit: 5000ms Memory Limit: 262144KB This problem will be judged on SPOJ. Original ID: QTREE64-bit integer IO format: %lld Java class name: Main Prev Submit Status Statistics Discuss Next Font Size: + - Type: None Graph…
http://www.spoj.com/problems/DISUBSTR/ 题意:求字符串不同子串的数目. #include <bits/stdc++.h> using namespace std; const int N=1005; void sort(int *x, int *y, int *sa, int n, int m) { static int c[N], i; for(i=0; i<m; ++i) c[i]=0; for(i=0; i<n; ++i) ++c[x[y…
DQUERY - D-query #sorting #tree English Vietnamese Given a sequence of n numbers a1, a2, ..., an and a number of d-queries. A d-query is a pair (i, j) (1 ≤ i ≤ j ≤ n). For each d-query (i, j), you have to return the number of distinct elements in the…
题目链接:http://www.spoj.com/problems/COT3/ Alice and Bob are playing a game on a tree of n nodes.Each node is either black or white initially. They take turns to do the following operation:Choose a white node v from the current tree;Color all white node…
题目链接:http://www.spoj.com/problems/COT2/ You are given a tree with N nodes.The tree nodes are numbered from 1 to N.Each node has an integer weight. We will ask you to perfrom the following operation: u v : ask for how many different integers that repr…
SPOJ Problem Set (classical) 7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N lattice. One corner is at (0,0,0) and the opposite one is at (N,N,N). How many lattice points are visible from corner at (0,0,0) ? A point X is visible…
Coding a Dijkstra is not hard. %70 of my time spent on tackling TLE, as my last post. Dijkstra works in BFS manner, but at each step, it picks the shortest child greedily and then relax all other neighbors. Data Structure: since there could be up to…