cf Round 594
A.Warrior and Archer(思维)
战士一定会ban掉当前边缘的位置。而战士和射手就会选择剩下的最远的两点。
我们让剩下的最远的两点最近就达到了均衡。
于是我们枚举战士ban掉的边缘,ban的次数是一定的。
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-
# define MOD
# define INF
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<,l,mid
# define rch p<<|,mid+,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
int Scan() {
int res=, flag=;
char ch;
if((ch=getchar())=='-') flag=;
else if(ch>=''&&ch<='') res=ch-'';
while((ch=getchar())>=''&&ch<='') res=res*+(ch-'');
return flag?-res:res;
}
void Out(int a) {
if(a<) {putchar('-'); a=-a;}
if(a>=) Out(a/);
putchar(a%+'');
}
const int N=;
//Code begin... int a[N]; int main ()
{
int n;
scanf("%d",&n);
FOR(i,,n) scanf("%d",a+i);
sort(a+,a+n+);
int ans=INF;
int k=n-(n-)/;
FOR(i,,n+-k) ans=min(ans,a[i+k-]-a[i]);
printf("%d\n",ans);
return ;
}
B.Max and Bike(二分)
二分时间t,然后用控制精度check就行了。关键是这题的单调性不明显。
另外用fabs控制精度不行,浮点数误差。。。以后就控制二分次数吧。
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-
# define MOD
# define INF
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<,l,mid
# define rch p<<|,mid+,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
int Scan() {
int res=, flag=;
char ch;
if((ch=getchar())=='-') flag=;
else if(ch>=''&&ch<='') res=ch-'';
while((ch=getchar())>=''&&ch<='') res=res*+(ch-'');
return flag?-res:res;
}
void Out(int a) {
if(a<) {putchar('-'); a=-a;}
if(a>=) Out(a/);
putchar(a%+'');
}
const int N=;
//Code begin... int n;
double s, f, r, v;
bool check(double t)
{
double S=v*t, l=*pi*r;
double ss=S-floor(S/l)*l;
double T=S+fabs(sin(ss//r))**r;
return T>=f-s;
}
int main ()
{
scanf("%d%lf%lf",&n,&r,&v);
while (n--) {
scanf("%lf%lf",&s,&f);
double l=, r=1e12;
int tot=;
while (tot--) {
double mid=(l+r)/;
if (check(mid)) r=mid;
else l=mid;
}
printf("%.7lf\n",l);
}
return ;
}
C.Edo and Magnets(贪心)
求平面n个点至多减少k个点后,用一个矩形覆盖它们,求这个矩形面积的最小值。(k<=10)
显然把边界的点先减掉最好,于是我们枚举四个边界上的点减少多少个后更新答案就ok了。
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-
# define MOD
# define INF
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<,l,mid
# define rch p<<|,mid+,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
int Scan() {
int res=, flag=;
char ch;
if((ch=getchar())=='-') flag=;
else if(ch>=''&&ch<='') res=ch-'';
while((ch=getchar())>=''&&ch<='') res=res*+(ch-'');
return flag?-res:res;
}
void Out(int a) {
if(a<) {putchar('-'); a=-a;}
if(a>=) Out(a/);
putchar(a%+'');
}
const int N=;
//Code begin... struct node{int x, y;}p[N];
bool cmp1(int a,int b){return p[a].x<p[b].x;}
bool cmp2(int a,int b){return p[a].x>p[b].x;}
bool cmp3(int a,int b){return p[a].y<p[b].y;}
bool cmp4(int a,int b){return p[a].y>p[b].y;}
int pos1[N], pos2[N], pos3[N], pos4[N], last[N]; int main()
{
int n, k;
scanf("%d%d",&n,&k);
FO(i,,n) {
int x1,y1,x2,y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
p[i].x=(x1+x2); p[i].y=(y1+y2);
pos1[i]=pos2[i]=pos3[i]=pos4[i]=i;
}
sort(pos1,pos1+n,cmp1); sort(pos2,pos2+n,cmp2);
sort(pos3,pos3+n,cmp3); sort(pos4,pos4+n,cmp4);
int now=;
LL ans = 1LL<<;
FOR(a,,k) FOR(b,,k) FOR(c,,k) FOR(d,,k) {
now++;
int cnt = ;
FO(i,,a) if(last[pos1[i]]!=now) last[pos1[i]]=now,cnt++;
FO(i,,b) if(last[pos2[i]]!=now) last[pos2[i]]=now,cnt++;
FO(i,,c) if(last[pos3[i]]!=now) last[pos3[i]]=now,cnt++;
FO(i,,d) if(last[pos4[i]]!=now) last[pos4[i]]=now,cnt++;
if(cnt!=k) continue;
LL Maxx=-1LL<<,Maxy=-1LL<<,Minx=1LL<<,Miny=1LL<<;
FO(i,,n) {
if(last[i]!=now) {
Maxx=max(Maxx,p[i].x*1LL);
Minx=min(Minx,p[i].x*1LL);
Maxy=max(Maxy,p[i].y*1LL);
Miny=min(Miny,p[i].y*1LL);
}
}
LL x=Maxx-Minx, y=Maxy-Miny;
x=max(x,2LL); y=max(y,2LL);
ans=min(ans,x*y);
}
printf("%lld\n",ans/);
}
D.REQ(BIT+积性函数+逆元)
询问区间积[l,r]的欧拉函数。n,q<=2e5,ai<=1e6
因为欧拉函数是积性函数,我们化解一下式子,把不同的素因子拿出来维护一下就行了。
离散化后用树状数组离线处理区间[l,r]内的不同质因子,类似于HH的项链。
之后求答案的时候用逆元搞搞就行了。
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-
# define MOD
# define INF
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<,l,mid
# define rch p<<|,mid+,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
int Scan() {
int res=, flag=;
char ch;
if((ch=getchar())=='-') flag=;
else if(ch>=''&&ch<='') res=ch-'';
while((ch=getchar())>=''&&ch<='') res=res*+(ch-'');
return flag?-res:res;
}
void Out(int a) {
if(a<) {putchar('-'); a=-a;}
if(a>=) Out(a/);
putchar(a%+'');
}
const int N=;
//Code begin... typedef struct{int l, r, id;}Node;
Node qq[N];
int a[N], pri[N*], n;
LL sum[N], isum[N], mul[N], imul[N], tree[N], res[N];
queue<int> to[N];
map<int, int> vis;
VI vc[N]; void get_prim()
{
FOR(i,,) {
if (!pri[i]) pri[++pri[]]=i, vis[i]=pri[];
for (int j=; j<=pri[]&&pri[j]<=/i; ++j) {
pri[pri[j]*i]=;
if (i%pri[j]==) break;
}
}
}
bool comp(Node a, Node b){return a.l<b.l;}
LL inv(LL a, LL m){
if (a==) return ;
return inv(m%a,m)*(m-m/a)%m;
}
void add(int x, LL val)
{
while (x<=n) tree[x]=tree[x]*val%MOD, x+=lowbit(x);
}
LL query(int x)
{
LL ans=;
while (x) ans=ans*tree[x]%MOD, x-=lowbit(x);
return ans;
}
int main ()
{
get_prim();
FO(i,,pri[]) mul[i]=(LL)(pri[i]-)*inv(pri[i],MOD)%MOD, imul[i]=(LL)pri[i]*inv(pri[i]-,MOD)%MOD;
int q;
n=Scan();
FOR(i,,n) tree[i]=;
sum[]=isum[]=;
FOR(i,,n) {
a[i]=Scan(), sum[i]=sum[i-]*a[i]%MOD, isum[i]=isum[i-]*inv(a[i],MOD)%MOD;
int temp=a[i];
for (int j=; pri[j]*pri[j]<=temp; ++j) {
if (temp%pri[j]==) {
to[j].push(i), vc[i].pb(j), temp/=pri[j];
while (temp%pri[j]==) temp/=pri[j];
}
}
if (temp>) to[vis[temp]].push(i), vc[i].pb(vis[temp]);
}
q=Scan();
FOR(i,,q) qq[i].l=Scan(), qq[i].r=Scan(), qq[i].id=i;
sort(qq+,qq+q+,comp);
FO(i,,pri[]) if (!to[i].empty()) add(to[i].front(),mul[i]);
int now=;
FOR(i,,q) {
while (now<qq[i].l) {
int size=vc[now].size();
for (int j=; j<size; ++j) {
int k=vc[now][j];
add(to[k].front(),imul[k]), to[k].pop();
if (!to[k].empty()) add(to[k].front(),mul[k]);
}
now++;
}
res[qq[i].id]=sum[qq[i].r]*isum[qq[i].l-]%MOD*query(qq[i].r)%MOD;
}
FOR(i,,q) printf("%lld\n",res[i]);
return ;
}
E.Cutting the Line(待填坑)
cf Round 594的更多相关文章
- CF Round #551 (Div. 2) D
CF Round #551 (Div. 2) D 链接 https://codeforces.com/contest/1153/problem/D 思路 不考虑赋值和贪心,考虑排名. 设\(dp_i\ ...
- CF Round #510 (Div. 2)
前言:没想到那么快就打了第二场,题目难度比CF Round #509 (Div. 2)这场要难些,不过我依旧菜,这场更是被\(D\)题卡了,最后\(C\)题都来不及敲了..最后才\(A\)了\(3\) ...
- UOJ #30. [CF Round #278] Tourists
UOJ #30. [CF Round #278] Tourists 题目大意 : 有一张 \(n\) 个点, \(m\) 条边的无向图,每一个点有一个点权 \(a_i\) ,你需要支持两种操作,第一种 ...
- 竞赛题解 - CF Round #524 Div.2
CF Round #524 Div.2 - 竞赛题解 不容易CF有一场下午的比赛,开心的和一个神犇一起报了名 被虐爆--前两题水过去,第三题卡了好久,第四题毫无头绪QwQ Codeforces 传送门 ...
- 【前行&赛时总结】◇第4站&赛时9◇ CF Round 513 Div1+Div2
◇第4站&赛时9◇ CF Round 513 Div1+Div2 第一次在CF里涨Rating QWQ 深感不易……作blog以记之 ( ̄▽ ̄)" +Codeforces 的门为你打 ...
- CF Round #600 (Div 2) 解题报告(A~E)
CF Round #600 (Div 2) 解题报告(A~E) A:Single Push 采用差分的思想,让\(b-a=c\),然后观察\(c\)序列是不是一个满足要求的序列 #include< ...
- CF Round #580(div2)题解报告
CF Round #580(div2)题解报告 T1 T2 水题,不管 T3 构造题,证明大约感性理解一下 我们想既然存在解 \(|a[n + i] - a[i]| = 1\) 这是必须要满足的 既然 ...
- CF round #622 (div2)
CF Round 622 div2 A.简单模拟 B.数学 题意: 某人A参加一个比赛,共n人参加,有两轮,给定这两轮的名次x,y,总排名记为两轮排名和x+y,此值越小名次越前,并且对于与A同分者而言 ...
- cf Round#273 Div.2
题目链接,点击一下 Round#273 Div.2 ================== problem A Initial Bet ================== 很简单,打了两三场的cf第一 ...
随机推荐
- 安卓开发-使用XML菜单布局简单介绍
使用xml布局菜单 目前为止我们都是通过硬编码来增加菜单项的,android为此提供了一种更便利的方式,就是把menu也定义为应用程序的资源,通过android对资源的本地支持,使我们可以更方便地 ...
- RatingBar
题记:保持旺盛的求知欲.希望会一直这样. 说明:来了新控件了.就是经常用的打分的那种东东. 说明:1.看上图分别是系统自带的和自己做的.rating就是设置小星星的数目. 2.用系统自带的必须是Wra ...
- cocos2d3.8.1 使用prebuild提升发布android速度
1.生成cocos prebuild库 cocos gen-libs -m debug或 cocos gen-libs -m release 2.使用命令创建test项目 cocos new test ...
- 平移关节(Prismatic Joint)
package{ import Box2D.Common.Math.b2Vec2; import Box2D.Dynamics.b2Body; import Box2D.Dynamics.Joints ...
- HDU 3691 Nubulsa Expo
无向图的最小割.套了个模板. #include<iostream> #include<cstdio> #include<cstring> #include<a ...
- zencart hosts本地解析
C:\WINDOWS\system32\drivers\etc\hosts 127.0.0.1 www.aberc220.com 别人 192.168.1.64 www.aberc220.com ...
- windows下spark开发环境配置
http://www.cnblogs.com/davidwang456/p/5032766.html windows下spark开发环境配置 --本篇随笔由同事葛同学提供. windows下spark ...
- PHP的json_encode中文被转码的问题
在php5.2中做json_encode的时候.中文会被unicode编码, php5.3加入了options参数, 5.4以后才加入JSON_UNESCAPED_UNICODE,这个参数,不需要做e ...
- new关键字的理解-问题型
//输出的结果是?????????//The answer is good and gbc public class Example { String str=new String("goo ...
- OpenGL学习--------颜色的选择
OpenGL支持两种颜色模式:一种是RGBA,一种是颜色索引模式.无论哪种颜色模式,计算机都必须为每一个像素保存一些数据.不同的是,RGBA模式中,数据直接就代表了颜色:而颜色索引模式中,数据代表的是 ...