http://codeforces.com/contest/1030

B. Vasya and Cornfield

判断点是否在矩形内(包括边界)

把每条边转化为一个不等式

  public static void main(String[] args) {
IO io = new IO();
int n = io.nextInt(), d = io.nextInt();
int t = io.nextInt();
while (t-- > 0) {
int x = io.nextInt(), y = io.nextInt();
io.println(d <= x + y && x + y <= 2 * n - d &&
-d <= y - x && y - x <= d ? "YES" : "NO");
}
}

C. Vasya and Golden Ticket

给你一串数列,问该数列是否可以分为若干相邻且不相交的区间,每个区间和相等

枚举第一个区间的所有情况

     public static void main(String[] args) {
IO io = new IO();
int n = io.nextInt();
int[] sum = new int[n + 1];
int s = 0, k = 0, j;
for (int i = 1; i <= n; i++) sum[i] = io.nextChar() - '0' + sum[i - 1];
for (int i = 1; i < n; i++)
for (k = i, j = i + 1; j <= n; j++)
if (sum[j] - sum[k] == sum[i]) {
k = j;
if (sum[k] == sum[n]) {
io.println("YES");
return;
}
}
io.println("NO");
}

D. Vasya and Triangle

问是否存在三个点,每个点的横纵坐标范围是[0,n]、[0,m],且三个点围成的三角形面积为n*m/k

我们选择坐标轴上的点(0,0)、(x,0)、(0,y),得到x*y=2*m*n/k,关键是k的消去可能是2、n、m都贡献了因子,所以才要求最大公约数保证整除,2m算一个数还是2n算一个数要分情况讨论,不然乘以2了还只除以gcd=1会超过范围

     public static void main(String[] args) {
IO io = new IO();
long n = io.nextInt(), m = io.nextInt(), k = io.nextInt();
if (n * m * 2 % k != 0) io.println("NO");
else {
long g = gcd(2 * n, k);
if (g == 1) m = 2 * m / k;
else {
n = 2 * n / g;
m = m * g / k;
}
io.println("YES");
io.println("0 0");
io.println(n + " 0");
io.println("0 " + m);
}
}

E. Vasya and Good Sequences

给你一个数列,对于每个数,你可以任意交换它的二进制表示里的任意一对01,问这个数列最多有几个连续的区间,使其操作后的数字异或和为0

当区间内所有数的1的总和为偶数且不会出现一半以上的1都在1个数里时,该区间合法 。具体做法:求出所有可能,然后减去区间1的总和为偶数且一半以上的1都在1个数里的情况;

a[i]:将每个数替换为其二进制表示中1的个数

s[i]:a[i]前缀和,此时每个区间都可表示为si-sj的形式。当si为奇数时sj必须存在且也为奇数,这样组成的区间[j,i]里1的个数和才为偶数,此时si的贡献为[1,i)里奇数项的个数;当s[i]为偶数时,其贡献为[1,i]里偶数项的个数,多出来的情况是sj不存在的[1,i]。

(该题有个小却一缺即超的优化,已在代码里标出)

     public static void main(String[] args) {
IO io = new IO();
int n = io.nextInt();
int[] a = new int[n + 1];
int[] s = new int[n + 1];
int[] s1 = new int[n + 1];
int[] s0 = new int[n + 1];
long ans = 0, t, max;
for (int i = 1; i <= n; i++)
for (t = io.nextLong(); t != 0; t >>= 1)
a[i] += (t & 1);
for (int i = 1; i <= n; i++) {
s[i] = s[i - 1] + a[i];
s1[i] = s1[i - 1];
s0[i] = s0[i - 1];
if (s[i] % 2 == 1) ans += s1[i]++;
else ans += ++s0[i];
}
for (int i = 1; i <= n; i++) {
max = 0;
//j - i + 1 < 65
for (int j = i; j <= n && j - i + 1 < 65; j++) {
max = Math.max(max, a[j]);
if ((s[j] - s[i - 1]) % 2 == 0 && s[j] - s[i - 1] < max * 2) ans--;
}
}
io.println(ans);
}

F. Putting Boxes Together

一列上有n个盒子,每个盒子有自己的重量,移动一个重量为wi的盒子一个单位花费能量wi,现在有两种操作:1、改变某个盒子的重量,2、输出把第[l,r]的盒子放在一起(起点任意,只要每个都挨在一起)所需的最小能量

(树状数组:https://www.cnblogs.com/towerbird/p/9941030.html

不妨首先把盒子都移到[1,n],我们贪心地认为能量最少的方案应该是[l,r]里wi正好把总w分成最均等的两部分的盒子mid不移动,则答案是把所有盒子移动到[1,n]的能量减去右移a[mid]-mid的能量,注意mid左边的盒子贡献要取负数,右边的取正数。用二分查找找出mid。

(a、w下标以0开始怎么都错……为什么啊)

     private static final int c = (int) (2e5 + 10), mod = (int) (1e9 + 7);
static int n, q;
static long[] a = new long[c];
static long[] w = new long[c];
static long[][] tre = new long[c][2]; static void update(int i, long x, int j) {
while (i <= n) {
tre[i][j] += x;
if (j == 1) tre[i][j] %= mod;
i += i & -i;
}
} static long query(int i, int j) {
long s = 0;
while (i > 0) {
s += tre[i][j];
if (j == 1) s %= mod;
i -= i & -i;
}
return s;
} public static void main(String[] args) {
IO io = new IO();
n = io.nextInt();
q = io.nextInt();
for (int i = 0; i < n; i++) a[i] = io.nextLong();
for (int i = 0; i < n; i++) {
update(i + 1, w[i] = io.nextLong(), 0);
update(i + 1, w[i] * (a[i] - i), 1);
}
while (q-- > 0) {
int x = io.nextInt(), y = io.nextInt();
if (x < 0) {
x = -x - 1;
update(x + 1, y - w[x], 0);
update(x + 1, (y - w[x]) * (a[x] - x), 1);
w[x] = y;
} else {
long s = query(y, 0) + query(x - 1, 0), c = 0;
int mid = 0;
for (int i = 17; i >= 0; i--)
if (mid + (1 << i) < n && (c + tre[mid + (1 << i)][0]) * 2 < s) {
mid += 1 << i;
c += tre[mid][0];
}
long a1 = query(y, 1) - 2 * query(mid, 1) + query(x-1, 1);
long a2 = query(y, 0) - 2 * query(mid, 0) + query(x-1, 0);
//+ 2 * mod是出现了负无穷大的情况
long ans = a1 % mod - a2 % mod * (a[mid] - mid) % mod + 2 * mod;
io.println(ans % mod ); }
}
}

G. Linear Congruential Generator——我选择狗带o( ̄┰ ̄*)ゞ

Technocup 2019 - Elimination Round 1的更多相关文章

  1. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)

    Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) #include <bits/stdc++ ...

  2. Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)B. Personalized Cup

    题意:把一长串字符串 排成矩形形式  使得行最小  同时每行不能相差大于等于两个字符 每行也不能大于20个字符 思路: 因为使得行最小 直接行从小到大枚举即可   每行不能相差大于等于两个字符相当于  ...

  3. Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) C. Playing Piano

    题意:给出一个数列 a1 a2......an  让你构造一个序列(该序列取值(1-5)) 如果a(i+1)>a(i) b(i+1)>b(i) 如果a(i+1)<a(i)  那么b( ...

  4. Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) D. Barcelonian Distance 几何代数(简单)

    题意:给出一条直线 ax +by+c=0  给出两个整点 (x1,y1) (x2,y2) 只有在x,y坐标至少有一个整点的时 以及   给出的直线才有路径(也就是格子坐标图的线上) 问 两个整点所需要 ...

  5. Technocup 2019 - Elimination Round 2

    http://codeforces.com/contest/1031 (如果感觉一道题对于自己是有难度的,不要后退,懂0%的时候敲一遍,边敲边想,懂30%的时候敲一遍,边敲边想,懂60%的时候敲一遍, ...

  6. (AB)Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round

    A. Right-Left Cipher time limit per test 1 second memory limit per test 256 megabytes input standard ...

  7. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path

    http://codeforces.com/contest/1072/problem/D bfs 走1步的最佳状态 -> 走2步的最佳状态 -> …… #include <bits/ ...

  8. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path(字典序)

    https://codeforces.com/contest/1072/problem/D 题意 给你一个n*n充满小写字母的矩阵,你可以更改任意k个格子的字符,然后输出字典序最小的从[1,1]到[n ...

  9. Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) Solution

    A. Kitchen Utensils Water. #include <bits/stdc++.h> using namespace std; #define N 110 int n, ...

随机推荐

  1. ClickOnce一项Winform部署

    先建一个Winform 控制台程序 建好后从工具箱里拖出来个 文本框 在属性中把TEXT改了 鼠标放到项目上点击右键——>属性 如下图所示,有两个发布位置. 发布位置可以选择本地文件夹,也可以选 ...

  2. redis数据库安装 redis持久化及主从复制

    ----------------------------------------安装redis-5.0.4---------------------------------------- wget h ...

  3. 我的第一个python web开发框架(36)——后台菜单管理功能

    对于后台管理系统来说,要做好权限管理离不开菜单项和页面按钮控件功能的管理.由于程序没法智能的知道有什么菜单和控件,哪些人拥有哪些操作权限,所以首先要做的是菜单管理功能,将需要管理的菜单项和各个功能项添 ...

  4. 前端之DOM

    老师的博客:https://www.cnblogs.com/liwenzhou/p/8011504.html DOM(Document Object Model)是一套对文档的内容进行抽象和概念化的方 ...

  5. express+sequelize 做后台

    第一部分:安装express 第一步:执行 npm install -g express-generator note:必须安装这个,不然创建express项目的时候会提示express命令没有找到 ...

  6. MYSQL的information_schema数据库中你可以得到的信息!!!

    1.COLUMNS 记录了所有表字段的一些基本信息,例如权限信息等. 2:TABLES :使用该表可以查询每一个表的详细信息,例如数据占用空间大小.索引大小以及表的更新时间以及表的行数等 3:视图 可 ...

  7. 【技术说明】iOS10来了,AppCan已全面适配!

    IPhone 7出了,你的肾还好吗?别紧张,不买肾7,同样可以体验最新的iOS10! AppCan对引擎.插件.编译系统等都进行了重要升级,让你的APP轻松适配iOS10!具体如何,请往下看! 引擎 ...

  8. springfox-swagger之swagger-bootstrap-ui

    swagger-bootstrap-ui是国内的一个swagger开源项目,从发起到现在已经有三年了.初次体验了一下,觉得还是挺不错的,就如当初使用mybatis-plus那样,因为有了mybatis ...

  9. python open 函数的读写追加

  10. EXT 设置编辑框为只读

    Ext.getCmp("processResult").setReadOnly(ture);   //processResult是属性的id,setReadOnly(ture)设置 ...