Codeforces 272
来源:互联网 发布:linux 发行版 编辑:程序博客网 时间:2024/05/18 15:55
One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were x details in the factory storage, then by the end of the day the factory has to produce (remainder after dividing x by m) more details. Unfortunately, no customer has ever bought any mythical detail, so all the details produced stay on the factory.
The board of directors are worried that the production by the given plan may eventually stop (that means that there will be а moment when the current number of details on the factory is divisible by m).
Given the number of details a on the first day and number m check if the production stops at some moment.
The first line contains two integers a and m (1 ≤ a, m ≤ 105).
Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No".
1 5
No
3 6
Yes
暴力来一发:
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<vector>typedef long long LL;using namespace std;#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )#define CLEAR( a , x ) memset ( a , x , sizeof a )const int maxn=1e5+100;int hash[maxn];int main(){ LL a,m; while(cin>>a>>m) { CLEAR(hash,0); LL sum=a; int flag=1; for(int i=1;i<=m;i++) { sum+=sum%m;// cout<<"2333 "<<sum<<endl; if(hash[sum]) break; if(sum%m==0) { flag=0; break; } } if(flag) cout<<"No"<<endl; else cout<<"Yes"<<endl; } return 0;}
Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.
Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square.
Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city.
The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct.
Print the minimum area of the city that can cover all the mines with valuable resources.
20 02 2
4
20 00 3
9
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<vector>typedef long long LL;typedef unsigned long long ULL;using namespace std;#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )#define CLEAR( a , x ) memset ( a , x , sizeof a )const int maxn=1100;LL x,y;int n;int main(){ std::ios::sync_with_stdio(false); while(cin>>n) { LL x1,x2,y1,y2; x1=y1=1000000000;//一定要足够大。 x2=y2=-1000000000; REP(i,n) { cin>>x>>y; if(x<x1) x1=x; if(y<y1) y1=y; if(x>x2) x2=x; if(y>y2) y2=y; }// cout<<"233 "<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<endl; ULL s=max(abs(x2-x1),abs(y2-y1));// cout<<"233 "<<s<<endl; cout<<s*s<<endl; } return 0;}
Let's denote as the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≤ x ≤ r, and is maximum possible. If there are multiple such numbers find the smallest of them.
The first line contains integer n — the number of queries (1 ≤ n ≤ 10000).
Each of the following n lines contain two integers li, ri — the arguments for the corresponding query (0 ≤ li ≤ ri ≤ 1018).
For each query print the answer in a separate line.
31 22 41 10
137
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<vector>typedef long long LL;//typedef unsigned long long ULL;using namespace std;#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )#define CLEAR( a , x ) memset ( a , x , sizeof a )int t;LL l,r;int main(){ std::ios::sync_with_stdio(false); cin>>t; while(t--) { cin>>l>>r; LL p=1; REP(i,64) { LL t=p|l; if(t>r) break; l=t;p<<=1; } cout<<l<<endl; } return 0;}
You are given a sequence a consisting of n integers. Find the maximum possible value of (integer remainder of ai divided by aj), where 1 ≤ i, j ≤ n and ai ≥ aj.
The first line contains integer n — the length of the sequence (1 ≤ n ≤ 2·105).
The second line contains n space-separated integers ai (1 ≤ ai ≤ 106).
Print the answer to the problem.
33 4 5
2
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<vector>typedef long long LL;using namespace std;#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )#define CLEAR( a , x ) memset ( a , x , sizeof a )const int maxn=1e5+100;int a[maxn*2];int main(){ int n; std::ios::sync_with_stdio(false);// cout<<(5%3)<<" "<<(3%5)<<endl; while(cin>>n) { REP(i,n) cin>>a[i]; sort(a,a+n); int ans=0; REP(i,n-1) if(i==0||a[i]!=a[i-1]){ int t=a[i]+a[i]; ans=max(ans,a[n-1]%a[i]); while(t<=a[n-1]) { int p=lower_bound(a,a+n,t)-a; if(p>0) ans=max(ans,a[p-1]%a[i]); t+=a[i]; } } cout<<ans<<endl; } return 0;}
- Codeforces 272
- CodeForces 272B
- CodeForces 272B
- Codeforces 272 div2
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- 20 个整数的和
- Ubuntu下安装配置 PPTP
- hibernate简介
- JMeter入门1---安装
- spring简介
- Codeforces 272
- [c++,小练习] 日常小程序_1
- JMeter入门2---录制脚本
- 已知圆心,半径,角度,求圆上的点坐标
- 汇编-串操作-字符串拷贝
- 使用htmlunit 获取百度新闻搜索结果的url
- IOS中如何判断当前网络状态是否可用
- 【FFT】 HDOJ 1402 A * B Problem Plus
- 面试 - MFC的类结构