题目链接:  http://codeforces.com/problemset/problem/14/D 思路:直接枚举每一天路径的两端,然后求以每一端为树根的树上最长路径,然后相乘就可以了. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #define REP(i, a, b) for (int…
//求出4×4矩阵中最大和最小元素值及其所在行下标和列下标,求出两条主对角线元素之和 #include <stdio.h> int main() { int sum=0; int max,min; int max1,max2;//记录最大值的坐标 int min1,min2;//记录最小值的坐标 int i,j; int a[4][4]; //为数组赋值 for(i=0;i<4;i++) { for(j=0;j<4;j++) { scanf("%d",&…
A - Fashion in Berland 水 // #pragma comment(linker, "/STACK:102c000000,102c000000") #include <iostream> #include <cstdio> #include <cstring> #include <sstream> #include <string> #include <algorithm> #include &…
F. Four Divisors 题目连接: http://www.codeforces.com/contest/665/problem/F Description If an integer a is divisible by another integer b, then b is called the divisor of a. For example: 12 has positive 6 divisors. They are 1, 2, 3, 4, 6 and 12. Let's def…
题目链接:http://codeforces.com/problemset/problem/691/F 题目大意:给定n个数,再给m个询问,每个询问给一个p,求n个数中有多少对数的乘积≥p 数据范围:2≤n≤10^6, 1≤ai≤3*10^6,1≤m≤10^6, 1≤p≤3*10^6 解题思路:比赛的时候比较naive的思路是把n中的数字排序去了重之后,对于每个p,最多枚举√p步,就能得到答案.而这个naive的思路是O(p√p)的,结果T了. 后来百思不得其解,去看了官方的解答.感觉是一种很有…
题目链接 分析:一些边把各个节点连接成了一颗颗树.因为每棵树上的边可以走任意次,所以不难想出要字典序最大,就是每棵树中数字大的放在树中节点编号比较小的位置. 我用了极为暴力的方法,先dfs每棵树,再用了优先队列.我估计最大复杂度约在,理论上应该跑不过.因为再cf上做题,看见5s时限,强行上了.很侥幸,在4秒的时候过了= =. /*****************************************************/ //#pragma comment(linker, "/ST…
题目链接:http://codeforces.com/problemset/problem/691/D 给你n个数,各不相同,范围是1到n.然后是m行数a和b,表示下标为a的数和下标为b的数可以交换无数次.问你最后字典序最大的数列是什么. 将下面的a和b用并查集联系起来存到祖节点对应的数组中,然后从大到小排序数组,最后依次按照父节点的数组中的顺序输出. 也可以用dfs的方法解(略麻烦),形成一个环路的就在一个数组中... //并查集 #include <bits/stdc++.h> using…
题目链接:http://codeforces.com/contest/691/problem/D 题意: 题目给出一段序列,和m条关系,你可以无限次互相交换这m条关系 ,问这条序列字典序最大可以为多少 思路: 并查集维护这m条关系,用个vector存一下当前点所能到达的点,拍下序大的优先,输出的时候输出当前点所能找到的最大的数,已输出的标记下就好了. 实现代码: #include<bits/stdc++.h> using namespace std; ; int f[M],vis[M],a[M…
D. Swaps in Permutation 题目连接: http://www.codeforces.com/contest/691/problem/D Description You are given a permutation of the numbers 1, 2, ..., n and m pairs of positions (aj, bj). At each step you can choose a pair from the given positions and swap…
C. Exponential notation 题目连接: http://www.codeforces.com/contest/691/problem/C Description You are given a positive decimal number x. Your task is to convert it to the "simple exponential notation". Let x = a·10b, where 1 ≤ a < 10, then in gen…
B. s-palindrome 题目连接: http://www.codeforces.com/contest/691/problem/B Description Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the…
A. Fashion in Berland 题目连接: http://www.codeforces.com/contest/691/problem/A Description According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if…
题目链接 分析:K很大,以我现有的极弱的知识储备,大概应该是快速幂了...怎么考虑这个快速幂呢,用到了dp的思想.定义表示从到的合法路径数.那么递推式就是.每次进行这样一次计算,那么序列的长度就会增加一,因此只要将这个式子做k次就行了.怎么满足相邻两个数异或值的1的个数为3倍数呢?这就是用到矩阵的时候了.枚举,建立一个的矩阵,当为3的倍数,为1,否则为零.再考虑到矩阵的乘法其实和刚才的dp递推式是一样的??!!因此只要将矩阵乘次就行了. /****************************…
在mysql,数据如下:#查询某一用户该日抽奖时间 select draw_time from user_draw_log where user_id = 1 and draw_date='2016-03-09' order by id; +---------------------+ | draw_time | +---------------------+ | 2016-03-09 13:52:46 | | 2016-03-09 13:52:53 | | 2016-03-09 13:53:0…
D. Two Paths 题目连接: http://codeforces.com/contest/14/problem/D Description As you know, Bob's brother lives in Flatland. In Flatland there are n cities, connected by n - 1 two-way roads. The cities are numbered from 1 to n. You can get from one city t…
题目链接: http://codeforces.com/contest/14/problem/D D. Two Paths time limit per test2 secondsmemory limit per test64 megabytes 问题描述 As you know, Bob's brother lives in Flatland. In Flatland there are n cities, connected by n - 1 two-way roads. The citie…
题目大意: 给定一棵树 树上每个点有对应的点权 树上每条边有对应的边权 经过一个点可得到点权 经过一条边必须花费边权 即从u到v 最终得分=u的点权-u到v的边权+v的点权 求树上一条路径使得得分最大 看注释 #include <bits/stdc++.h> #define LL long long #define INf 0x3f3f3f3f using namespace std; ; bool vis[N]; LL w[N], ans; int n; ]; int head[N], to…
D. Turtles Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/547/problem/B Description You've got a table of size n × m. We'll consider the table rows numbered from top to bottom 1 through n, and the columns numbered from le…
E. Wizards and Bets 题目连接: http://www.codeforces.com/contest/167/problem/E Description In some country live wizards. They like to make weird bets. Two wizards draw an acyclic directed graph with n vertices and m edges (the graph's vertices are numbere…
A:二分答案,从左往右考虑每个人,选尽量靠左的钥匙即可. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; #define ll long long #define int long long #define N 2010 #de…
B. Connecting Universities 大意: 给定树, 给定2*k个点, 求将2*k个点两两匹配, 每个匹配的贡献为两点的距离, 求贡献最大值 单独考虑每条边$(u,v)$的贡献即可, 最大贡献显然是左右两侧点的最小值. #include <iostream> #include <algorithm> #include <cstdio> #include <math.h> #include <set> #include <m…
[题解] 题意就是判断树上两条链是否有交.口诀是“判有交,此链有彼祖”.即其中一条链的端点的Lca在另一条链上. 我们设两条链的端点的Lca中深度较大的为L2,对L2与另一条链的两个端点分别求Lca,若满足其中一个Lca等于L2,即表示两链有交. #include<cstdio> #include<algorithm> #include<cstring> #define LL long long #define rg register #define N 500010…
推荐博客 :https://blog.csdn.net/qq_25576697/article/details/81138213 链接:https://www.nowcoder.com/acm/contest/139/A来源:牛客网 题目描述Count the number of n x m matrices A satisfying the following condition modulo (109+7).* Ai, j ∈ {0, 1, 2} for all 1 ≤ i ≤ n, 1 ≤…
LCA求树上两点最短距离,如果a,b之间距离小于等于k并且奇偶性与k相同显然YES:或者可以从a先走到x再走到y再走到b,并且a,x之间距离加b,y之间距离+1小于等于k并且奇偶性与k相同也输出YES:或者从a走到y再走到x再走到b,并且总距离+1小于等于k并且奇偶性与k相同同样输出YES:否则输出NO. #define HAVE_STRUCT_TIMESPEC #include <bits/stdc++.h> using namespace std; ]; int cnt; struct e…
Two Paths time limit per test 2 seconds memory limit per test 64 megabytes input standard input output standard output As you know, Bob's brother lives in Flatland. In Flatland there are n cities, connected by n - 1 two-way roads. The cities are numb…
tiyi:给你n个节点和n-1条边(无环),求在这个图中找到 两条路径,两路径不相交,求能找的两条路径的长度的乘积最大值: #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <vector> #include <queue> #include <stack>…
Codeforces Round #588 (Div. 2)-E. Kamil and Making a Stream-求树上同一直径上两两节点之间gcd的和 [Problem Description] 给你一棵树,树上每个节点都有一个权值.定义\(1\sim v\)的最短路径所经过的所有节点\(u\)称为\(v\)节点的祖先.定义函数\(f(u,v)=gcd(u,t1,t2,\dots,v)\),其中\(u,t1,t2,\dots\)都是\(v\)的祖先.求\(\sum f(u,v)\). […
Codeforces Beta Round #14 (Div. 2) http://codeforces.com/contest/14 A 找最大最小的行列值即可 #include<bits/stdc++.h> using namespace std; #define lson l,mid,rt<<1 #define rson mid+1,r,rt<<1|1 #define sqr(x) ((x)*(x)) #define maxn 500005 typedef lon…
Educational Codeforces Round 41 (Rated for Div. 2) E. Tufurama (CDQ分治 求 二维点数) time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One day Polycarp decided to rewatch his absolute favourite epi…
题目链接: http://codeforces.com/contest/673/problem/D 题意: 给四个不同点a,b,c,d,求是否能构造出两条哈密顿通路,一条a到b,一条c到d. 题解: 构造法,看例子: input: 5 6 5 2 4 1 output: 5 4 3 1 2 4 5 3 2 1 所以只要满足k>=n+1,就可以构造出来答案. #include<iostream> #include<cstring> #include<cstdio>…