Problem F. Grab The Tree

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)

Total Submission(s): 2004    Accepted Submission(s): 911

Problem Description

Little Q and Little T are playing a game on a tree. There are n vertices on the tree, labeled by 1,2,...,n, connected by n−1 bidirectional edges. The i-th vertex has the value of wi.

In this game, Little Q needs to grab some vertices on the tree. He can select any number of vertices to grab, but he is not allowed to grab both vertices that are adjacent on the tree. That is, if there is an edge between x and y, he can't grab both x and y. After Q's move, Little T will grab all of the rest vertices. So when the game finishes, every vertex will be occupied by either Q or T.

The final score of each player is the bitwise XOR sum of his choosen vertices' value. The one who has the higher score will win the game. It is also possible for the game to end in a draw. Assume they all will play optimally, please write a program to predict the result.

Input

The first line of the input contains an integer T(1≤T≤20), denoting the number of test cases.

In each test case, there is one integer n(1≤n≤100000) in the first line, denoting the number of vertices.

In the next line, there are n integers w1,w2,...,wn(1≤wi≤109), denoting the value of each vertex.

For the next n−1 lines, each line contains two integers u and v, denoting a bidirectional edge between vertex u and v.

Output

For each test case, print a single line containing a word, denoting the result. If Q wins, please print Q. If T wins, please print T. And if the game ends in a draw, please print D.

Sample Input

1

3

2 2 2

1 2

1 3

Sample Output

Q

#include <bits/stdc++.h>
#define ios1 ios::sync_with_stdio(0);
#define ios2 cin.tie(0);
#define LL long long
using namespace std;
const int maxn = 1e6 + 10;
int w[maxn]; int main() {
int T, n;
scanf("%d", &T);
while(T--) {
scanf("%d", &n);
int u, v, p = -1;
int Max = -1;
for(int i = 1; i <= n; i++) {
scanf("%d", &w[i]);
if(Max < w[i]) {
Max = w[i];
p = i;
}
}
for(int i = 1; i <= n-1; i++)scanf("%d%d", &u, &v);
int r = 0;
for(int i = 1; i <= n; i++) {
if(i != p)r ^= w[i];
}
if(r == Max) printf("D\n");
else printf("Q\n");
}
return 0;
}

Problem D. Euler Function

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)

Total Submission(s): 1474    Accepted Submission(s): 1062

Problem Description

In number theory, Euler's totient function φ(n) counts the positive integers up to a given integer n that are relatively prime to n. It can be defined more formally as the number of integers k in the range 1≤kn for which the greatest common divisor gcd(n,k) is equal to 1.

For example, φ(9)=6 because 1,2,4,5,7 and 8 are coprime with 9. As another example, φ(1)=1 since for n=1 the only integer in the range from 1 to n is 1itself, and gcd(1,1)=1.

A composite number is a positive integer that can be formed by multiplying together two smaller positive integers. Equivalently, it is a positive integer that has at least one divisor other than 1 and itself. So obviously 1 and all prime numbers are not composite number.

In this problem, given integer k, your task is to find the k-th smallest positive integer n, that φ(n) is a composite number.

Input

The first line of the input contains an integer T(1≤T≤100000), denoting the number of test cases.

In each test case, there is only one integer k(1≤k≤109).

Output

For each test case, print a single line containing an integer, denoting the answer.

Sample Input

2

1

2

Sample Output

5

7

题意:给出一个复合数的定义,相当于就是合数, 求第k个最小正整数n, 并且使φ(n)为复合数.

题解:知道欧拉函数的,一下就能发现只有当k == 1时,n == 5, 其他的在 n >= 7之后的数都为复合数.

#include<bits/stdc++.h>
using namespace std; int main() {
int T, k;
scanf("%d", &T);
while(T--) {
scanf("%d", &k);
if(k == 1) printf("5\n");
else printf("%d\n", k + 5);
}
return 0;
}

2018 Multi-University Training Contest 3(部分题解)的更多相关文章

  1. 2018 Multi-University Training Contest 2(部分题解)

    Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  2. 2018 Multi-University Training Contest 1(部分题解)

    Maximum Multiple Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. 2018 Multi-University Training Contest - Team 1 题解

    Solved A HDU 6298 Maximum Multiple Solved B HDU 6299 Balanced Sequence Solved C HDU 6300 Triangle Pa ...

  4. 2018 Nowcoder Multi-University Training Contest 2

    目录 Contest Info Solutions A. run D. monrey G. transform H. travel I. car J. farm Contest Info Practi ...

  5. 2016 Multi-University Training Contest 3 部分题解

    1001,只要枚举区间即可.签到题,要注意的是输入0的话也是“TAT”.不过今天补题的时候却WA了好几次,觉得奇怪.原来出现在判断条件那里,x是一个int64类型的变量,在进行(x<65536* ...

  6. 2016 Multi-University Training Contest 1 部分题解

    第一场多校,出了一题,,没有挂零还算欣慰. 1001,求最小生成树和,确定了最小生成树后任意两点间的距离的最小数学期望.当时就有点矛盾,为什么是求最小的数学期望以及为什么题目给了每条边都不相等的条件. ...

  7. 2016 Multi-University Training Contest 4 部分题解

    1001,官方题解是直接dp,首先dp[i]表示到i位置的种类数,它首先应该等于dp[i-1],(假设m是B串的长度)同时,如果(i-m+1)这个位置开始到i这个位置的这一串是和B串相同的,那么dp[ ...

  8. 2018 Nowcoder Multi-University Training Contest 1

    Practice Link J. Different Integers 题意: 给出\(n\)个数,每次询问\((l_i, r_i)\),表示\(a_1, \cdots, a_i, a_j, \cdo ...

  9. 2018 Nowcoder Multi-University Training Contest 5

    Practice Link A. gpa 题意: 有\(n\)门课程,每门课程的学分为\(s_i\),绩点为\(c_i\),要求最多删除\(k\)门课程,使得gpa最高. gpa计算方式如下: \[ ...

随机推荐

  1. java代码之美(13)--- Predicate详解

    java代码之美(13)--- Predicate详解 遇到Predicate是自己在自定义Mybatis拦截器的时候,在拦截器中我们是通过反射机制获取对象的所有属性,再查看这些属性上是否有我们自定义 ...

  2. 【Kubernetes 系列三】Kubernetes 学习文档推荐

    标题 地址 备注 Kubernetes 官方文档 https://kubernetes.io/docs 英文文档,全面 Kubernetes Handbook ttps://jimmysong.io/ ...

  3. Json串与实体的相互转换 (不依赖于jar包 只需Eclipse环境即可)

    Json串与实体的相互转换 (不依赖于jar包 只需Eclipse环境即可) 最近学习了javaWeb开发,用的是ssh框架里面自己整合了hibernate 和Struts2 和spring框架,其中 ...

  4. [Spring cloud 一步步实现广告系统] 18. 查询返回广告创意

    根据三个维度继续过滤 在上一节中我们实现了根据流量信息过滤的代码,但是我们的条件有可能是多条件一起传给我们的检索服务的,本节我们继续实现根据推广单元的三个维度条件的过滤. 在SearchImpl类中添 ...

  5. 笑谈CSS的伪元素

    今晚上我们来简单的聊一聊CSS的伪元素,多说无益,开聊 GG: 话说盘古开天辟地之时. QQ:嗨,咱今天还能讲的完吗?您给来点实际的啊. GG:要听实际的是吧,得嘞,那今天咱就来聊一聊CSS里的伪元素 ...

  6. ASP.NET Core on K8S深入学习(3-2)DaemonSet与Job

    本篇已加入<.NET Core on K8S学习实践系列文章索引>,可以点击查看更多容器化技术相关系列文章. 上一篇<3-1 Deployment>中介绍了Deployment ...

  7. python --- 零碎

    1.匿名输出: lambda x : print(x))(100) #冒号前输入量 ,冒号后是输出量结果:100 2.导入调用其他python文件: test1.py #第一个python文件 def ...

  8. Yii的srbac拓展中“用户已经获授权项”无法查看

    Yii的srbac拓展中“用户已经获授权项”点下拉框,选择一个有权限的用户时,根本无法列出权限. 原因是srbac把数据库的表中的ID默认为数字,像 123这样,但如果不是数字像这样 'y0f22ff ...

  9. 《统计学习方法》极简笔记P5:决策树公式推导

    <统计学习方法>极简笔记P2:感知机数学推导 <统计学习方法>极简笔记P3:k-NN数学推导 <统计学习方法>极简笔记P4:朴素贝叶斯公式推导

  10. 既然synchronized是"万能"的,为什么还需要volatile呢?

    在我的博客和公众号中,发表过很多篇关于并发编程的文章,之前的文章中我们介绍过了两个在Java并发编程中比较重要的两个关键字:synchronized和volatile 我们简单回顾一下相关内容: 1. ...