题意: 给一个无向图,再给一系列操作(以下3种),输出最后的平均查询结果. (1)D X 删除第x条边. (2)Q X k 查询与点X相连的连通分量中第k大的点的权值. (3)C X v 将点X的权值改为v. 思路: 第一点,由于需要删除边,不是很方便,所以可以先将所有操作存起来,反序来操作,这样删边就变成加边,方便了不少.每次加边时若两点不属于同个连通分量,就将点少的整个连通分量中的点逐个插入到另一个连通分量中. 第二点,查第k大,这个比较简单,只需要维护Treap上每个点的的左右孩子数量…
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2041 A number of students are members of a club that travels annually to exotic locations. Their destinations in the past have included Indian…
Pie My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N of them, of various tastes and of various sizes. F of my friends are coming to my party and each of them gets a piece of pie. This should be one p…
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4109 题意: 输入正整数n和k(1≤n,k≤1e9),计算sum(k mod i)(1≤i≤n). 分析: 被除数固定,除数逐次加1,直观上余数也应该有规律.假设k/i的整数部分等于d,则k mod i = k-i*d.因为k/(i+1)和k/i差别不大,如果k/(i+1)的整数部…
This is a two player game. Initially there are n integer numbers in an array and players A and B get chance to take them alternatively. Each player can take one or more numbers from the left or right end of the array but cannot take from both ends at…
题意:根据这个式子来递推求得每个随机数x,step和mod给定,seed(0)=0.如果推出来的序列是mod个不重复的数字(0~mod-1)则打印good,否则bad(因为不能产生所有的数). 思路: 用一个数组记录所产生过的数,当出现数字已记录过时,判断是否个数为mod个.若是就返回good. #include <bits/stdc++.h> #define LL long long using namespace std; ; bool ans[N]; int main() { //fre…
题意:给定Z, I, M, L,根据随机数产生式k=(Z*L+I)%M.但是L表示的是上一个产生的数,比如根据产生式产生了序列{2,5,4,3}那么5是由L=2算来的,4由L=5算来的..第1个所产生的数所需的L由系统给定.那么肯定会产生一个环,到某个位置就会开始产生重复的序列,比如12345345345....求循环中有多少个数(循环节)?(如例是3,分别是345) 思路:因为z i m 都是不变的,当L一定,那么产生的数肯定是一定的,所以只要L有重复出现,那就会从那里开始循环.标记一下所产…
[题意] 南极有n个科研站, 要把这些站用卫星或者无线电连接起来,使得任意两个都能直接或者间接相连.任意两个都有安装卫星设备的,都可以直接通过卫星通信,不管它们距离有多远. 而安装有无线电设备的两个站,距离不能超过D. D越长费用越多. 现在有s个卫星设备可以安装,还有足够多的无线电设备,求一个方案,使得费用D最少(D取决与所有用无线电通信的花费最大的那条路径). InputThe first line of input contains N, the number of test cases.…
Ugly Numbers Descriptions: Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, ... shows the first 11 ugly numbers. By convention, 1 is included. Write a program to find and print the 1500…