rated

Educational Codeforces Round 73 (Rated for Div. 2)

天大地大妈咪最大 提交于 2019-11-30 04:23:06
传送门 F. Choose a Square 题意: 二维平面上给出 \(n\) 个点,每个点都有个权值。现在要求选择一个正方形,满足其中一根对角线的两顶点在 \(y=x\) 这条直线上。 问所选正方形包含了的点的权值和减去边长的最大值。 类似于这样: 答案为 \(4\) 。 思路: 因为正方形具有对称性,所以我们可以考虑将 \(y=x\) 这条直线下方的点对称过去处理,那么我们现在就相当于选择一个等腰直角三角形的区域,类似于这样: 注意到最终三角形的边上一定存在至少一个点,那么也就是说有用的横纵坐标就为这些点的坐标。 直接枚举 \(x,y\) 显然复杂度不能承受,考虑当我们枚举 \(x\) 时,选择一个最大的 \(y\) ,就类似于维护一个区间最大值。 对于一个位置 \(x=x_0\) ,显然随着 \(y\) 增大包含的点越多,并且对于一个 \(y=y_0\) 而言,与 \(y=x\) 这条直线所形成的三角形区域是必选的。类似于这样: 所以线段树的做法就很显然了,横坐标直接从后往前枚举,依次加点并且不断在线段树中插入点的信息并更新区间信息,查询的时候就直接查询最大值以及纵坐标即可。 为什么是更新区间最大值? 因为每插入一个点,它会影响在它右上方的点,当选择右上方的点时,它也必然被包含,类似于这样:(所以直接更新在其上方的区间信息即可) 注意一个细节,因为最后还要减去正方形的边长

Educational Codeforces Round 72 (Rated for Div. 2)E(线段树,思维)

*爱你&永不变心* 提交于 2019-11-29 12:42:49
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; #define BUF_SIZE 100000 bool IOerror=0;//加了读入挂才1900ms+卡ddl过的,不加读入代码tleT_T inline char nc(){ static char buf[BUF_SIZE], *p1=buf+BUF_SIZE, *pend=buf+BUF_SIZE; if(p1==pend){ p1=buf; pend=buf+fread(buf, 1, BUF_SIZE, stdin); if(pend==p1){ IOerror=1; return -1; } } return *p1++; } inline bool blank(char ch){ return ch==' '||ch=='\n'||ch=='\r'||ch=='\t'; } inline void read(int &x){ char ch; int sign=1; while(blank(ch=nc())); if(IOerror)return; if(ch=='-'){ sign=-1; ch=nc(); } for(x=ch-'0'; (ch=nc())>='0'&&ch<='9'; x=x*10+ch-'0'

Educational Codeforces Round 72 (Rated for Div. 2)

若如初见. 提交于 2019-11-29 12:07:12
Solutaion A. Creating a Character 题意: 给出初始体力值 \(str\) 和智力值 \(int\) ,然后你可以把 \(exp\) 分别分配给这两个数值,使得分配后 \(str > int\) ,求有多少种分配方案。 思路: 特判不可能情况: \(str + exp <= int\) \(str <= int\) ,乱搞 \(str > int\) ,乱搞 正解: 假设分别分配给 \(str,int\) 的数值为 \(Adds,Addi\) ,那么有 \[ \begin{align*} & str + Adds > int + Addi \\ {\Rightarrow}{\quad} & str + Adds > int + (exp - Adds)\\ {\Rightarrow}{\quad} &2{\ast}Adds > int + exp - str\\ {\Rightarrow}{\quad} &2{\ast}Adds\ {\geq}\ int + exp - str + 1\\ {\Rightarrow}{\quad} &Adds\ {\geq}\ {\lceil}{\frac{int + exp - str + 1}{2}}{\rceil}\\ {\Rightarrow}{\quad} &Adds\ {\geq}\ {\frac{int

Educational Codeforces Round 33 (Rated for Div. 2) C题·(并查集变式)

你。 提交于 2019-11-29 09:38:40
C. Rumor Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it. Now he tries to solve a quest. The task is to come to a settlement named Overcity and spread a rumor in it. Vova knows that there are n characters in Overcity. Some characters are friends to each other, and they share information they got. Also Vova knows that he can bribe each character so he or she starts spreading the rumor; i-th character

Educational Codeforces Round 72 (Rated for Div. 2) Solution

喜夏-厌秋 提交于 2019-11-29 07:32:25
传送门 A. Creating a Character 设读入的数据分别为 $a,b,c$ 对于一种合法的分配,设分了 $x$ 给 $a$ 那么有 $a+x>b+(c-x)$,整理得到 $x>(b+c-a)/2$ 因为 $x \in [0,c]$ ,所以求一下区间交的大小即可,注意 (b+c-a) 可能小于 0 #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> using namespace std; typedef long long ll; inline int read() { int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); } return x*f; } int T,a,b,c; int main() { T=read(); while(T--) { a=read(),b=read(),c=read(); if(b+c-a<0) printf("%d\n",c+1); else

Educational Codeforces Round 72 (Rated for Div. 2)

不想你离开。 提交于 2019-11-29 07:31:58
四题就可以当大爷了,一共才六道题。 A、你有一个角色,a点力量b点智力,你现在有c点经验值,1点经验值可以把力量或智力增加1 你现在需要用掉所有的经验值,问你有多少种使用经验值的方案,使得最后力量大于智力 首先如果力量一开始小于智力,先消耗经验值增加力量直到力量大于智力 然后考虑方程组: (a+x)>(b+y) (x+y)=c x和y分别是增加的力量和智力 稍微改动一下: (a+x)>=(b+y+1) 这样可以求的最小的x满足上述方程组 那么得到2x>=c+b-a+1 注意一下(c+b-a+1)不一定是偶数,所以实际上x=((c+b-a+1)+1)/2 即向上取整。 最后解出y=c-x,总方案数就是[0,y]这个区间中的数字个数,每一个y都可以满足条件 似乎做完了,但是有个坑点需要特判: 如果(b+c)<a,说明不管怎么加一定满足条件,此时应当输出c+1 代码: #include <bits/stdc++.h> #define int long long #define sc(a) scanf("%lld",&a) #define scc(a,b) scanf("%lld %lld",&a,&b) #define sccc(a,b,c) scanf("%lld %lld %lld",&a,&b,&c) #define schar(a) scanf("%c",&a) #define

Educational Codeforces Round 71 (Rated for Div. 2)

蹲街弑〆低调 提交于 2019-11-28 20:45:03
A. There Are Two Types Of Burgers 水题。题意:给你面包片数,两种不同的肉饼数(制作一个汉堡要消耗两片面包和一片肉饼),之后再给你两种不同的汉堡售价,问你如何取得最大收益。 思路:照题意模拟即可 ,简单贪心。 #include <iostream> #include <sstream> #include <cstring> #include <string> #include <cstdio> #include <cstdlib> #include <vector> using namespace std; int main() { int t; scanf("%d", &t); while (t--) { int b, p, f; int h, c; cin >> b >> p >> f; cin >> h >> c; if (h > c) { int sum = 0; while (b >= 2 && p) sum += h, b -= 2, p--; while (b >= 2 && f) sum += c, b -= 2, f--; cout << sum << endl; } else { int sum = 0; while (b >= 2 && f) sum += c, b -= 2, f--; while (b >= 2 && p)

Educational Codeforces Round 71 (Rated for Div. 2)E. XOR Guessing

孤者浪人 提交于 2019-11-28 20:35:16
一道容斥题 如果直接做就是找到所有出现过递减的不同排列,当时硬钢到自闭,然后在凯妹毁人不倦的教导下想到可以容斥做,就是:所有的排列设为a,只考虑第一个非递减设为b,第二个非递减设为c+两个都非递减的情况设为d,那么正解就是a-b-c+d; 然后在text4上wa了无数次,为什么全开long long还会出现负数结果呢,这时候一位美男子(没错又是凯妹)提示:因为我们的结果是mod998244353,如果a%998244353后是0,那么a-b-c+d就会出现负数,而答案必为正,故wa。 注意到结果必为正,而且因为(b+c-d)为b,c在a范围内的补集,不可能大于a,所以我们如果每一步都不mod(当然这会溢出),那么最后结果必然是正数,所以我们在这里加个判断 if(ans>=0) cout<<ans; else cout<<998244353+ans;//显然0-b-c+d不可能>0, 最后AC了,感谢凯妹大佬,以下是代码 题目链接 https://codeforces.com/contest/1207/problem/D #include <bits/stdc++.h> #define ll long long using namespace std; const int inf=1e9+7; const int maxn=3e5+90; const int mod

Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块

久未见 提交于 2019-11-28 19:48:34
Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块 【Problem Description】 ​ 初始 \([1,500000]\) 都为0,后续有两种操作: ​ \(1\) 、将 \(a[x]\) 的值加上 \(y\) 。 ​ \(2\) 、求所有满足 \(i\ mod\ x=y\) 的 \(a[i]\) 的和。 【Solution】 ​ 具体做法就是,对于前 \(\sqrt{500000}=708\) 个数,定义 \(dp[j][k]\) 表示所有满足 \(i\ mod\ j=k\) 的 \(a[i]\) 的和。每次进行 \(1\) 操作的时候, \(O(\sqrt{500000})\) 预处理一下。查询时可 \(O(1)\) 查询。 ​ 对于大于 \(O(\sqrt{500000})\) 的数,可暴力求解: \(i\ mod\ x=y\Leftrightarrow i+x\cdot t=y\) 。所以只需要枚举 \(\frac{500000}{x}\) 次即可。而 \(x\) 不小于 \(\sqrt{500000})=708\) ,所以枚举次数不大于 \(708\) 次,所以总复杂度为 \(O(500000^{\frac{3}{2}})\) 。 【Code】 /* *

Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 19:39:53
Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题 【Problem Description】 ​ 总共两次询问,每次询问给出 \(100\) 个不同的数,评测系统对于每次询问,随机从 \(100\) 个数中选择一个数 \(a\) ,返回 \(x\oplus a\) 。让你通过两次返回的值猜出 \(x\) 值是多少。要求两次询问的 \(200\) 个数互不相同,且题目保证 \(x\) 值固定不变。 【Solution】 ​ 题目要求所有询问数据,即 \(x\) 的值在 \([0,2^{14}-1]\) 范围内,且只能询问两次,根据异或的性质, \(0\) 异或任何数都不改变。所以可以分两次得到答案,即第一次先确定 \(x\) 二进制中的高 \(7\) 位,也就是第一次询问时,所有询问的数的高 \(7\) 位全为 \(0\) ,这样保证评测系统选任何数异或后返回的值的高 \(7\) 位一定与 \(x\) 的高 \(7\) 位相同,同理,第二次只要保证所有询问的数的低 \(7\) 位全为 \(0\) ,最终将两次得到的值合并即可。 【Code】 /* * @Author: Simon * @Date: 2019-08-27 20:36:36 * @Last Modified by: Simon *