Codeforces Round #430

A. Kirill And The Game
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number.

For each two integer numbers a and b such that l ≤ a ≤ r and x ≤ b ≤ y there is a potion with experience a and cost b in the store (that is, there are (r - l + 1)·(y - x + 1) potions).

Kirill wants to buy a potion which has efficiency k. Will he be able to do this?

Input

First string contains five integer numbers lrxyk (1 ≤ l ≤ r ≤ 1071 ≤ x ≤ y ≤ 1071 ≤ k ≤ 107).

Output

Print "YES" without quotes if a potion with efficiency exactly k can be bought in the store and "NO" without quotes otherwise.

You can output each of the letters in any register.

Examples
input
1 10 1 10 1
output
YES
input
1 5 6 10 1
output
NO

看在[l,r]区间内是否存在[x,y]区间内某一个数的k倍。枚举即可...小心爆掉ll。

#include<bits/stdc++.h>
using namespace std;

int main(){
	long long  l,r,x,y,k;
	while(cin>>l>>r>>x>>y>>k){
		bool flag=0;
		for(long long i=x;i<=y;i++){
			if(i*k<=r&&i*k>=l)	
			{
				flag=1;
				break;	
			}
			if(i*k>=r)break;
		}
		if(flag) cout<<"YES"<<endl;
		else  cout<<"NO"<<endl;
	}
	return 0;	
}
 


B. Gleb And Pizza
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.

The pizza is a circle of radius r and center at the origin. Pizza consists of the main part — circle of radius r - d with center at the origin, and crust around the main part of the width d. Pieces of sausage are also circles. The radius of the i -th piece of the sausage is ri, and the center is given as a pair (xiyi).

Gleb asks you to help determine the number of pieces of sausage caught on the crust. A piece of sausage got on the crust, if it completely lies on the crust.

Input

First string contains two integer numbers r and d (0 ≤ d < r ≤ 500) — the radius of pizza and the width of crust.

Next line contains one integer number n — the number of pieces of sausage (1 ≤ n ≤ 105).

Each of next n lines contains three integer numbers xiyi and ri ( - 500 ≤ xi, yi ≤ 5000 ≤ ri ≤ 500), where xi and yi are coordinates of the center of i-th peace of sausage, ri — radius of i-th peace of sausage.

Output

Output the number of pieces of sausage that lay on the crust.

Examples
input
8 4
7
7 8 1
-7 3 2
0 2 1
0 -2 2
-3 -3 1
0 6 2
5 3 1
output
2
input
10 8
4
0 0 9
0 0 10
1 0 1
1 0 2
output
0
Note

Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust.


依旧暴力水题,直接算两个距离即可。

#include<bits/stdc++.h>
using namespace std;
struct Node{
	int x,y,r;	
}sau[100005];


int main(){
	int r,d,n;
	while(cin>>r>>d){
		cin>>n;
		int sum=0;
		for(int i=0;i<n;i++){
			cin>>sau[i].x>>sau[i].y>>sau[i].r;		
		}	
		for(int i=0;i<n;i++){
			if(sqrt(sau[i].x*sau[i].x+sau[i].y*sau[i].y)-sau[i].r>=(r-d)&&sqrt(sau[i].x*sau[i].x+sau[i].y*sau[i].y)+sau[i].r<=r)	
				sum++;
		}
		cout<<sum<<endl;
	}	
	return 0;	
}


C. Ilya And The Tree
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Ilya is very fond of graphs, especially trees. During his last trip to the forest Ilya found a very interesting tree rooted at vertex 1. There is an integer number written on each vertex of the tree; the number written on vertex i is equal to ai.

Ilya believes that the beauty of the vertex x is the greatest common divisor of all numbers written on the vertices on the path from the root to x, including this vertex itself. In addition, Ilya can change the number in one arbitrary vertex to 0 or leave all vertices unchanged. Now for each vertex Ilya wants to know the maximum possible beauty it can have.

For each vertex the answer must be considered independently.

The beauty of the root equals to number written on it.

Input

First line contains one integer number n — the number of vertices in tree (1 ≤ n ≤ 2·105).

Next line contains n integer numbers ai (1 ≤ i ≤ n1 ≤ ai ≤ 2·105).

Each of next n - 1 lines contains two integer numbers x and y (1 ≤ x, y ≤ nx ≠ y), which means that there is an edge (x, y) in the tree.

Output

Output n numbers separated by spaces, where i-th number equals to maximum possible beauty of vertex i.

Examples
input
2
6 2
1 2
output
6 6 
input
3
6 2 3
1 2
1 3
output
6 6 6 
input
1
10
output
10 

由于一个数的因子个数为松散的 n ,而且一条路径上的gcd会很快的将到1。所以如果我们从根节点往下dfs,记录所有可以通过把1个或0个点权值变成0得到的gcd。对于每个点,答案就是转移到当前点的所有gcd的最大值。 
  时间复杂度为 O(Vd) ,其中 V 为顶点数, d 为因子数。


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iostream>
#define M(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
using namespace std;
const int MAXN=200007;
typedef long long LL;
struct Edge
{
    int to, ne;
}e[MAXN<<1];
int head[MAXN], v[MAXN], edgenum;
inline void addedge(int u, int v)
{
    edgenum++;e[edgenum].to=v, e[edgenum].ne=head[u], head[u]=edgenum;
    edgenum++;e[edgenum].to=u, e[edgenum].ne=head[v], head[v]=edgenum;
}
vector<int> dp[MAXN];
int fgcd[MAXN];
int gcd(int a, int b) { return b==0 ? a : gcd(b, a%b); }
void dfs(int u, int fa)
{
    if(fa==-1)
    {
        fgcd[u]=v[u];
        dp[u].push_back(0);
        dp[u].push_back(v[u]);
    }
    else
    {
        fgcd[u]=gcd(fgcd[fa], v[u]);
        dp[u].push_back(fgcd[fa]);
        for(int i=0;i<dp[fa].size();i++)
            dp[u].push_back(gcd(dp[fa][i], v[u]));
        sort(dp[u].begin(), dp[u].end());
        dp[u].erase(unique(dp[u].begin(), dp[u].end()), dp[u].end());
    }
    for(int i=head[u]; ~i;i=e[i].ne)
        if(e[i].to!=fa)
            dfs(e[i].to, u);
}
int main()
{
    int n;
    while(cin>>n)
    {
        for(int i=1;i<=n;i++)
            scanf("%d", &v[i]);
        M(head, -1);edgenum=0;M(dp, 0);
        for(int i=1;i<n;i++)
        {
            int u, v;cin>>u>>v;
            addedge(u, v);
        }
        for(int i=1;i<=n;i++) dp[i].clear();
        dfs(1, -1);
        for(int i=1;i<=n;i++)
            printf("%d%c", dp[i][dp[i].size()-1], i==n ? '\n' : ' ');
    }
}

D. Vitya and Strange Lesson
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Today at the lesson Vitya learned a very interesting function — mexMex of a sequence of numbers is the minimum non-negative number that is not present in the sequence as element. For example, mex([4, 33, 0, 1, 1, 5]) = 2 and mex([1, 2, 3]) = 0.

Vitya quickly understood all tasks of the teacher, but can you do the same?

You are given an array consisting of n non-negative integers, and m queries. Each query is characterized by one number x and consists of the following consecutive steps:

  • Perform the bitwise addition operation modulo 2 (xor) of each array element with the number x.
  • Find mex of the resulting array.

Note that after each query the array changes.

Input

First line contains two integer numbers n and m (1 ≤ n, m ≤ 3·105) — number of elements in array and number of queries.

Next line contains n integer numbers ai (0 ≤ ai ≤ 3·105) — elements of then array.

Each of next m lines contains query — one integer number x (0 ≤ x ≤ 3·105).

Output

For each query print the answer on a separate line.

Examples
input
2 2
1 3
1
3
output
1
0
input
4 3
0 1 5 6
1
2
4
output
2
0
0
input
5 4
0 1 5 6 7
1
1
4
5
output
2
2
0
2

字典树。

求mex可以用trie来搞。把整个序列的trie建出来后,假如要全局异或一个x,若x的从高到低第i位为1,则trie的第i层的所有节点都要翻转左右儿子。知道了这点后,我们就可以通过打标记实现翻转来快速异或一个值,而不需要实际进行异或。因为所有数都在300000内,那么01字典树开20层就够。标记什么的类似线段树,边查询边pushdown,如果这一层对应的位是1,那么交换左右儿子。每一个节点存一个是否儿子满了的标志,查询时如果左儿子没满,mex值肯定在左子树;要是满了,就进入右子树。




基于STM32F407,使用DFS算法实现最短迷宫路径检索,分为三种模式:1.DEBUG模式,2. 训练模式,3. 主程序模式 ,DEBUG模式主要分析bug,测量必要数据,训练模式用于DFS算法训练最短路径,并将最短路径以链表形式存储Flash, 主程序模式从Flash中….zip项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明(如有)等。答辩评审平均分达到96分,放心下载使用!可轻松复现,设计报告也可借鉴此项目,该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的。 【提供帮助】:有任何使用问题欢迎随时与我联系,我会及时解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 下载后请首先打开README文件(如有),项目工程可直接复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值