Codeforces Round #432 (Div. 2)
Arpa is researching the Mexican wave.
There are n spectators in the stadium, labeled from 1 to n. They start the Mexican wave at time 0.
- At time 1, the first spectator stands.
- At time 2, the second spectator stands.
- ...
- At time k, the k-th spectator stands.
- At time k + 1, the (k + 1)-th spectator stands and the first spectator sits.
- At time k + 2, the (k + 2)-th spectator stands and the second spectator sits.
- ...
- At time n, the n-th spectator stands and the (n - k)-th spectator sits.
- At time n + 1, the (n + 1 - k)-th spectator sits.
- ...
- At time n + k, the n-th spectator sits.
Arpa wants to know how many spectators are standing at time t.
The first line contains three integers n, k, t (1 ≤ n ≤ 109, 1 ≤ k ≤ n, 1 ≤ t < n + k).
Print single integer: how many spectators are standing at time t.
10 5 3
3
10 5 7
5
10 5 12
3
In the following a sitting spectator is represented as -, a standing spectator is represented as ^.
- At t = 0 ----------
number of standing spectators = 0.
- At t = 1 ^---------
number of standing spectators = 1.
- At t = 2 ^^--------
number of standing spectators = 2.
- At t = 3 ^^^-------
number of standing spectators = 3.
- At t = 4 ^^^^------
number of standing spectators = 4.
- At t = 5 ^^^^^-----
number of standing spectators = 5.
- At t = 6 -^^^^^----
number of standing spectators = 5.
- At t = 7 --^^^^^---
number of standing spectators = 5.
- At t = 8 ---^^^^^--
number of standing spectators = 5.
- At t = 9 ----^^^^^-
number of standing spectators = 5.
- At t = 10 -----^^^^^
number of standing spectators = 5.
- At t = 11 ------^^^^
number of standing spectators = 4.
- At t = 12 -------^^^
number of standing spectators = 3.
- At t = 13 --------^^
number of standing spectators = 2.
- At t = 14 ---------^
number of standing spectators = 1.
- At t = 15 ----------
number of standing spectators = 0.
题意:给定一种波浪,求每一时刻有多少个站起来了;
#include <bits/stdc++.h> using namespace std; int main()
{
int n,k,t;
scanf("%d%d%d",&n,&k,&t); if(t<=k)
printf("%d\n",t);
else if(t<=n)
printf("%d\n",k);
else if(t<=n+k)
printf("%d\n",n-t+k);
else puts("");
t++; return ;
}
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points a, b, c.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old position of b, and the new position of b is the same as the old position of c.
Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.
The only line contains six integers ax, ay, bx, by, cx, cy (|ax|, |ay|, |bx|, |by|, |cx|, |cy| ≤ 109). It's guaranteed that the points are distinct.
Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower).
0 1 1 1 1 0
Yes
1 1 0 0 1000 1000
No
In the first sample test, rotate the page around (0.5, 0.5) by .
In the second sample test, you can't find any solution.
题意:给三个点的坐标a,b,c,看是否经过绕顶点旋转,a 旋转到 b,b到c;
分析:刚开始考虑三个点的外接圆,然后比较圆形角,麻烦了,而且不删除计算几何。
其实,就是 b 到 a,c的距离相等,还要不能在同一条直线上。
距离很好判断,判断三个点是否在同一条直线上,斜率的判定,不能有除以0,于是我转为求余弦,但是结果是long long double 精度都不够,
最好是分类讨论:
#include <bits/stdc++.h> using namespace std; int main()
{
long long int ax,ay,bx,by,cx,cy;
cin>>ax>>ay>>bx>>by>>cx>>cy; long long int l1 = (by-ay)*(by-ay) + (bx-ax)*(bx-ax);
long long int l2 = (cy-by)*(cy-by) + (cx-bx)*(cx-bx); int mark = ; if( (ax==bx&&ax==cx) || (ay==by&&ay==cy) )
mark = ;
else {
double k1 = (by-ay)*1.0/(bx-ax);
double k2 = (cy-by)*1.0/(cx-bx); if(k1==k2)
mark = ;
} if(mark==)
puts("No");
else if (l1!=l2)
puts("No");
else puts("Yes"); return ;
}
Arpa has found a list containing n numbers. He calls a list bad if and only if it is not empty and gcd (see notes section for more information) of numbers in the list is 1.
Arpa can perform two types of operations:
- Choose a number and delete it with cost x.
- Choose a number and increase it by 1 with cost y.
Arpa can apply these operations to as many numbers as he wishes, and he is allowed to apply the second operation arbitrarily many times on the same number.
Help Arpa to find the minimum possible cost to make the list good.
First line contains three integers n, x and y (1 ≤ n ≤ 5·105, 1 ≤ x, y ≤ 109) — the number of elements in the list and the integers x and y.
Second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the elements of the list.
Print a single integer: the minimum possible cost to make the list good.
4 23 17
1 17 17 16
40
10 6 2
100 49 71 73 66 96 8 60 41 63
10
In example, number 1 must be deleted (with cost 23) and number 16 must increased by 1 (with cost 17).
A gcd (greatest common divisor) of a set of numbers is the maximum integer that divides all integers in the set. Read more about gcd here.
题意:给定一个序列,和 x,y,将这个序列删除任意一个花费 x,将任意一个元素+1花费y;求一些操作以后整个序列的gcd!=1;
分析:
最近数论题做的很少了,没有啥想法,大牛们下了一个定理,什么调和级数一搞,推出这个gcd一定是一个素数。
然后枚举这个10^6里面的素数,我就直接暴力了,稍微剪了一下。
大佬们是求两个区间和,在一定区间内删掉,一定区间内补上,这样的贪心就O(1)内求出花费。
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = ;
const int maxnum = 1e6 + ; int a[maxn];
int sum[maxnum];
int vis[maxnum]; int main()
{
int n,x,y;
scanf("%d%d%d",&n,&x,&y); for(int i = ; i < n; i++) {
scanf("%d",&a[i]);
sum[a[i]] ++;
} ll cnt = 0x3f3f3f3f3f3f3f3fll; for(int i = ; i <= ; i++) {
if(!vis[i]) {
ll ans = sum[i]; for(int j = *i; j<=; j+=i) {
vis[j] = ;
ans += sum[j];
} if((n-ans)*min(x,y)<cnt) {
ll tans = ;
for(int j = ; j<n; j++) {
if(a[j]%i) {
ll t = a[j]%i;
tans += min((ll)*x,(ll)*y*(i-t));
}
}
cnt = min(cnt,tans);
}
}
} printf("%lld\n",cnt); return ;
}
Codeforces Round #432 (Div. 2)的更多相关文章
- D. Arpa and a list of numbers Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)
http://codeforces.com/contest/851/problem/D 分区间操作 #include <cstdio> #include <cstdlib> # ...
- Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)ABCD
A. Arpa and a research in Mexican wave time limit per test 1 second memory limit per test 256 megaby ...
- Codeforces Round #432 Div. 1 C. Arpa and a game with Mojtaba
首先容易想到,每种素数是独立的,相互sg就行了 对于一种素数来说,按照的朴素的mex没法做... 所以题解的简化就是数位化 多个数同时含有的满参数因子由于在博弈中一同变化的,让他们等于相当于,那么这样 ...
- Codeforces Round #432 (Div. 1) B. Arpa and a list of numbers
qtmd的复习pat,老子不想看了,还不如练几道cf 这题首先可以很容易想到讨论最后的共因子为素数 这个素数太多了,1-1e6之间的素数 复杂度爆炸 所以使用了前缀和,对于每个素数k的每个小区间 (k ...
- Codeforces Round #432 Div. 1
A:大胆猜想合法点不会很多,于是暴力检验,一旦发现不合法就break,可以random_shuffle一下. #include<iostream> #include<cstdio&g ...
- Codeforces Round #432 (Div. 1, based on IndiaHacks Final Round 2017) D. Tournament Construction(dp + 构造)
题意 一个竞赛图的度数集合是由该竞赛图中每个点的出度所构成的集合. 现给定一个 \(m\) 个元素的集合,第 \(i\) 个元素是 \(a_i\) .(此处集合已经去重) 判断其是否是一个竞赛图的度数 ...
- 【前缀和】【枚举倍数】 Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) D. Arpa and a list of numbers
题意:给你n个数,一次操作可以选一个数delete,代价为x:或者选一个数+1,代价y.你可以进行这两种操作任意次,让你在最小的代价下,使得所有数的GCD不为1(如果全删光也视作合法). 我们从1到m ...
- 【推导】【暴力】Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) C. Five Dimensional Points
题意:给你五维空间内n个点,问你有多少个点不是坏点. 坏点定义:如果对于某个点A,存在点B,C,使得角BAC为锐角,那么A是坏点. 结论:如果n维空间内已经存在2*n+1个点,那么再往里面添加任意多个 ...
- 【推导】Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) B. Arpa and an exam about geometry
题意:给你平面上3个不同的点A,B,C,问你能否通过找到一个旋转中心,使得平面绕该点旋转任意角度后,A到原先B的位置,B到原先C的位置. 只要A,B,C构成等腰三角形,且B为上顶点.那么其外接圆圆心即 ...
随机推荐
- 6个Unity 开源项目分享!
http://gad.qq.com/article/detail/38279?sessionUserType=BFT.PARAMS.249034.TASKID&ADUIN=991655778& ...
- java并发编程 - Exexctors 工具类
Executors 类提供了一系列静态工厂方法用于创建各种线程池. newFixedThreadPool 创建固定大小的线程池.每次提交一个任务就创建一个线程,直到线程达到线程池的最大大小.线程池的大 ...
- nyoj 600——花儿朵朵——【离散化、线段树插线问点】
花儿朵朵 时间限制:1000 ms | 内存限制:65535 KB 难度:5 描述 春天到了,花儿朵朵盛开,hrdv是一座大花园的主人,在他的花园里种着许多种鲜花,每当这个时候,就会有一大群游 ...
- 获取全球dns统计信息
# -*- coding:UTF-8 -*- import requests, time import json from bs4 import BeautifulSoup as bp t3 = ti ...
- Python远程连接Windows,并调用Windows命令(类似于paramiko)
import winrm win2012 = winrm.Session(')) r = win2012.run_cmd('D: &' ' cd python &' ' type s. ...
- php 不用第三个变量 交换两个变量的值汇总
//方法一:$a ="abc";$b="def"; $a = $a^$b;$b = $b^$a;$a = $a^$b; //方法二:list($a, $b)= ...
- 数组和矩阵(1)——Find the Duplicate Number
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), pro ...
- jQuery三——筛选方法、事件
一.jquery常用筛选方法 以下为jquery的常用筛选方法: 代码示例如下: <!DOCTYPE html> <html lang="en"> < ...
- sort遇到的问题
var arr = [2,10,6,9,7,8]; var arr1 = arr.sort(); var arr2 = arr.sort(function(a,b){ if (a>b){ ret ...
- gsap
TweenMax借助于css,轻量级的js库 下面是简单的demo <!DOCTYPE html> <html lang="en"> <head> ...