喵哈哈村的魔法考试 Round #18 (Div.2) 题解
喵哈哈村的古怪石碑(一)
题解:暴力check一下是等比数列还是等差数列,然后输出答案即可。注意如果数据范围是1e9的话,就要快速幂了。
代码:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
//#define LOCAL
const int N=100+10;
const int MOD=100007;
using namespace std;
long long a1,a2,a3,n,an;
void init(){
}
void dc(){
long long d=a2-a1;
an=a1+d*(n-1);
printf("%lld\n",an%MOD);
}
long long pow(long long a,long long b){
if (b==0) return 1;
if (b==1) return a%MOD;
long long tmp=pow(a,b/2);
if (b%2==0) return (tmp*tmp)%MOD;
else return ((tmp*tmp)%MOD*a)%MOD;
}
void db(){
long long q=a2/a1;
an=a1*pow(q,n-1);
printf("%lld\n",an%MOD);
}
int main(){
while(scanf("%lld%lld%lld%lld",&a1,&a2,&a3,&n)!=EOF){
if (a1!=1 || (a1==1 && a2-a1==a3-a2)) dc();
else db();
}
return 0;
}
喵哈哈村的古怪石碑(二)
题解:题目翻译过来,其实就是动态求全局第k大。小数据就直接暴力找第k大就好了。大数据你可以分块,也可以写个平衡树。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<ctime>
#include<queue>
#include<vector>
using namespace std;
#define clr(f,x) memset(f,x,sizeof f)
#define rep(it,a,b) for(int it=a;it<=b;++it)
#define _rep(it,a,b) for(int it=a;it>=b;--it)
#define vrep(it,a) for(int it=a;it--;)
#define PII pair<int,int>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define LL long long
const int maxn=20010;
int n;
int f[maxn],l[maxn],r[maxn],sz[maxn],v[maxn];
int root,tt;
inline void update(int x){
sz[x]=(l[x]>0)*sz[l[x]]+(r[x]>0)*sz[r[x]]+1;
}
inline void lt(int x){
int y=f[x],z=f[y];
f[x]=z;
if(z)l[z]==y?l[z]=x:r[z]=x;
f[r[y]=l[x]]=y;
f[l[x]=y]=x;
update(y);
}
inline void rt(int x){
int y=f[x],z=f[y];
f[x]=z;
if(z)l[z]==y?l[z]=x:r[z]=x;
f[l[y]=r[x]]=y;
f[r[x]=y]=x;
update(y);
}
inline void splay(int x){
while(f[x]){
int y=f[x],z=f[y];
if(!z){l[y]==x?rt(x):lt(x);break;}
if(l[z]==y)
if(l[y]==x)rt(y),rt(x);
else lt(x),rt(x);
if(r[z]==y)
if(r[y]==x)lt(y),lt(x);
else rt(x),lt(x);
}
update(x);
root=x;
}
inline int rk(int x){
int y=root;
while(1){
if(sz[l[y]]+1==x)return y;
if(sz[l[y]]<x){
x-=sz[l[y]]+1;
y=r[y];
}else y=l[y];
}
}
inline void del(int x){
splay(x);
if(r[x]==0){
f[root=l[x]]=0;
return;
}
int y=r[x];
f[y]=0;
while(l[y])y=l[y];
f[l[y]=l[x]]=y;
splay(l[x]);
}
inline void ins(int &x,int y){
if(!x){
v[x=++tt]=y;
return;
}
if(y>=v[x])ins(r[x],y),f[r[x]]=x;
else ins(l[x],y),f[l[x]]=x;
}
inline void work(){
scanf("%d",&n);
int x,y,z;
tt=0;
LL total=0;
int ans=0;
rep(i,1,n){
scanf("%d%d",&x,&y);
if(!x){
total+=y;
ins(root,y);
splay(tt);
}else{
z=rk(sz[root]-y+1);
ans^=v[z];
if((LL)v[z]*sz[root]<=total){
total+=v[z];
ins(root,v[z]);
splay(tt);
}else{
total-=v[z];
del(z);
}
}
}
printf("%d\n",ans);
}
int main(){
work();
return 0;
}
喵哈哈村的古怪石碑(三)
题解:实际上翻译过来就是求最大生成树,这个和求最小生成树是一样的,我们还是用克鲁斯卡尔来做就好了。
代码:
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
const double eps = 1e-10;
const int INF = ~0U>>1;
using namespace std;
int n, nes, sg;
int ap[5010], bp[5010];
int f[5010];
double ans;
struct quk
{
double dis;
int a, b;
} e[12502510];
struct point
{
double x, y;
} p[5010];
double dist(point a, point b)
{
return (a.x * b.x + a.y * b.y + abs(a.x - b.x) + abs(a.y - b.y) + sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y))) / 3;
}
int father(int u)
{
return f[u] == u ? u : f[u] = father(f[u]);
}
bool marge(int p)
{
int u = father(e[p].a), v = father(e[p].b);
if (u == v) return false;
ap[++nes] = e[p].a; bp[nes] = e[p].b; ans += e[p].dis;
f[u] = v;
return true;
}
bool cmp(const quk &a, const quk &b)
{
return a.dis > b.dis;
}
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
scanf("%lf %lf", &p[i].x, &p[i].y), f[i] = i;
for (int i = 1; i <= n; ++i)
for (int j = i + 1; j <= n; ++j)
e[++sg].dis = dist(p[i], p[j]), e[sg].a = i, e[sg].b = j;
sort(e + 1, e + sg + 1, cmp);
int nop = 0;
for (int i = 1; i < n; ++i)
while (!marge(++nop));
printf("%.4f\n", ans);
}
喵哈哈村的奇怪石碑(四)
题解:实际上是模拟题,我们对于每一个基因,我们都能够分析出概率是多少,然后所有的乘起来,再化简就好了。
但是这道题要高精度,注意~
代码:
#include <iostream>
using namespace std;
const int max_num = 100000000l;
typedef struct { bool flag; int cnt2, cnt3; } Cell;
typedef struct { Cell unisex[2] , gene[6][3]; } Table;
typedef struct { int len, num[80];} Gjd;
class Node
{
Table genotype[4];
void makenum();
void makelist();
public:
int ans2, ans3;
Gjd num2[2081], num3[2081];
void init() { makenum(); makelist(); }
void reclear() { ans2 = ans3 = 0; }
bool calc(int x, int y, int z)
{
if(z >= 4)
{
z -= 4;
if(!genotype[x].unisex[z].flag) return false;
ans2 += genotype[x].unisex[z].cnt2;
ans3 += genotype[x].unisex[z].cnt3;
}
else
{
if(!genotype[x].gene[y][z].flag) return false;
ans2 += genotype[x].gene[y][z].cnt2;
ans3 += genotype[x].gene[y][z].cnt3;
}
return true;
}
} You;
ostream& operator << (ostream &out, const Gjd &x)
{
int i = x.len - 1;
out << x.num[i];
while(i--) out.width(8), out << x.num[i];
return out;
}
int main()
{
int T, n;
string ma, fa, me;
ios::sync_with_stdio(false);
cin >> T;
if(T <= 0 || T > 20) return 1;
cout.fill('0');
You.init();
while(T--)
{
cin >> n >> ma >> fa >> me;
if(n <= 0 || n > 520 || (int)ma.length() != n || (int)fa.length() != n || (int)me.length() != n) return 1;
You.reclear();
while(n--)
{
if(me[n] == '3' || (me[n] >= '4' && !((ma[n] < '4') ^ (fa[n] < '4')))) return 1;
if(ma[n] <= fa[n])
{ if(!You.calc((int)ma[n] - '0', (int)fa[n] - '0', (int)me[n] - '0')) break; }
else if(!You.calc((int)fa[n] - '0', (int)ma[n] - '0', (int)me[n] - '0')) break;
}
if(n >= 0) cout << "0/0" << endl;
else cout << You.num3[You.ans3] << "/" << You.num2[You.ans2] << endl;
}
return 0;
}
void Node::makenum()
{
int i, j;
num2[0].len = num2[0].num[0] = num3[0].len = num3[0].num[0] = 1;
for(i = 1; i <= 2080; ++i)
{
num2[i].len = num2[i - 1].len;
for(j = 0; j < num2[i].len; ++j)
{
num2[i].num[j] += num2[i - 1].num[j] << 1;
if(num2[i].num[j] >= max_num)
{
num2[i].num[j + 1] += num2[i].num[j] / max_num;
num2[i].num[j] %= max_num;
}
}
if(num2[i].num[num2[i].len]) ++num2[i].len;
num3[i].len = num3[i - 1].len;
for(j = 0; j < num3[i].len; ++j)
{
num3[i].num[j] += num3[i - 1].num[j] * 3;
if(num3[i].num[j] >= max_num)
{
num3[i].num[j + 1] += num3[i].num[j] / max_num;
num3[i].num[j] %= max_num;
}
}
if(num3[i].num[num3[i].len]) ++num3[i].len;
}
}
void Node::makelist()
{
//unisex
genotype[0].unisex[0].flag = true;
genotype[1].unisex[0].flag = genotype[1].unisex[1].flag = true;
genotype[1].unisex[0].cnt2 = genotype[1].unisex[1].cnt2 = 1;
genotype[2].unisex[1].flag = true;
genotype[3].unisex[0].flag = genotype[3].unisex[1].flag = true;
genotype[3].unisex[0].cnt2 = genotype[3].unisex[1].cnt2 = 2;
genotype[3].unisex[0].cnt3 = 1;
//gene
genotype[0].gene[0][0].flag = true;
genotype[0].gene[1][0].flag = genotype[0].gene[1][1].flag = true;
genotype[0].gene[1][0].cnt2 = genotype[0].gene[1][1].cnt2 = 1;
genotype[0].gene[2][1].flag = true;
genotype[0].gene[3][0].flag = genotype[0].gene[3][1].flag = true;
genotype[0].gene[3][0].cnt2 = genotype[0].gene[3][1].cnt2 = 2;
genotype[0].gene[3][0].cnt3 = 1;
genotype[0].gene[4][0].flag = true;
genotype[0].gene[5][1].flag = true;
genotype[1].gene[1][0].flag = genotype[1].gene[1][1].flag = genotype[1].gene[1][2].flag = true;
genotype[1].gene[1][0].cnt2 = genotype[1].gene[1][2].cnt2 = 2;
genotype[1].gene[1][1].cnt2 = 1;
genotype[1].gene[2][1].flag = genotype[1].gene[2][2].flag = true;
genotype[1].gene[2][1].cnt2 = genotype[1].gene[2][2].cnt2 = 1;
genotype[1].gene[3][0].flag = genotype[1].gene[3][1].flag = genotype[1].gene[3][2].flag = true;
genotype[1].gene[3][0].cnt2 = genotype[1].gene[3][2].cnt2 = 3;
genotype[1].gene[3][1].cnt2 = 1;
genotype[1].gene[3][0].cnt3 = 1;
genotype[1].gene[4][0].flag = genotype[1].gene[4][1].flag = true;
genotype[1].gene[4][0].cnt2 = genotype[1].gene[4][1].cnt2 = 1;
genotype[1].gene[5][1].flag = genotype[1].gene[5][2].flag = true;
genotype[1].gene[5][1].cnt2 = genotype[1].gene[5][2].cnt2 = 1;
genotype[2].gene[2][2].flag = true;
genotype[2].gene[3][1].flag = genotype[2].gene[3][2].flag = true;
genotype[2].gene[3][1].cnt2 = genotype[2].gene[3][2].cnt2 = 2;
genotype[2].gene[3][1].cnt3 = 1;
genotype[2].gene[4][1].flag = true;
genotype[2].gene[5][2].flag = true;
genotype[3].gene[3][0].flag = genotype[3].gene[3][1].flag = genotype[3].gene[3][2].flag = true;
genotype[3].gene[3][0].cnt2 = genotype[3].gene[3][2].cnt2 = 4;
genotype[3].gene[3][1].cnt2 = 3;
genotype[3].gene[3][0].cnt3 = 2;
genotype[3].gene[3][1].cnt3 = 1;
genotype[3].gene[4][0].flag = genotype[3].gene[4][1].flag = true;
genotype[3].gene[4][0].cnt2 = genotype[3].gene[4][1].cnt2 = 2;
genotype[3].gene[4][0].cnt3 = 1;
genotype[3].gene[5][1].flag = genotype[3].gene[5][2].flag = true;
genotype[3].gene[5][1].cnt2 = genotype[3].gene[5][2].cnt2 = 2;
genotype[3].gene[5][1].cnt3 = 1;
}
喵哈哈村的魔法考试 Round #18 (Div.2) 题解的更多相关文章
- 喵哈哈村的魔法考试 Round #2 (Div.2) 题解
喵哈哈村的魔法考试 Round #2 (Div.2) 题解 A.喵哈哈村的战争 题解: 这道题就是for一遍,统计每个村子的战斗力的和,然后统计哪个村子的战斗力和大一点就好了. 唯一的坑点,就是这道题 ...
- 喵哈哈村的魔法考试 Round #1 (Div.2) 题解
喵哈哈村的魔法考试 Round #1 (Div.2) 题解 特别感谢出题人,qscqesze. 也特别感谢测题人Xiper和CS_LYJ1997. 没有他们的付出,就不会有这场比赛. A 喵哈哈村的魔 ...
- 喵哈哈村的魔法考试 Round #7 (Div.2) 题解
喵哈哈村的魔法考试 Round #7 (Div.2) 注意!后四道题来自于周日的hihocoder offer收割赛第九场. 我建了个群:欢迎加入qscoj交流群,群号码:540667432 大概作为 ...
- 喵哈哈村的魔法考试 Round #1 (Div.2) 题解&源码(A.水+暴力,B.dp+栈)
A.喵哈哈村的魔法石 发布时间: 2017年2月21日 20:05 最后更新: 2017年2月21日 20:06 时间限制: 1000ms 内存限制: 128M 描述 传说喵哈哈村有三种神 ...
- 喵哈哈村的魔法考试 Round #19 (Div.2) 题解
题解: 喵哈哈村的魔力源泉(1) 题解:签到题. 代码: #include<bits/stdc++.h> using namespace std; int main(){ long lon ...
- 喵哈哈村的魔法考试 Round #14 (Div.2) 题解
喵哈哈村的四月半活动(一) 题解: 唯一的case,就是两边长度一样的时候,第三边只有一种情况. #include <iostream> #include <cstdio> # ...
- 喵哈哈村的魔法考试 Round #4 (Div.2) 题解
有任何疑问,可以加我QQ:475517977进行讨论. A 喵哈哈村的嘟嘟熊魔法(1) 题解 这道题我们只要倒着来做就可以了,因为交换杯子是可逆的,我们倒着去模拟一遍就好了. 有个函数叫做swap(a ...
- 喵哈哈村的魔法考试 Round #20 (Div.2) 题解
题解: A 喵哈哈村的跳棋比赛 题解:其实我们要理解题意就好了,画画图看看这个题意.x<y,那么就交换:x>y,那么x=x%y. 如果我们经过很多次,或者y<=0了,那么就会无限循环 ...
- 喵哈哈村的魔法考试 Round #13 (Div.2) 题解
喵哈哈村的木星传说(一) 旋转90°,找找规律就知道(x,y)->(n-1-y,x) 然后输出就好了. #include<bits/stdc++.h> using namespace ...
随机推荐
- 路由器中继(repeater)模式 和 AP+WDS模式区别?
理论上的 中继(repeater)模式, 只有连接的最后一个才会有信号发出,中间的连接节点是没有信号发出的. AP+WDS模式:就是每一个路由都有信号发出,可以进行信号的全方位覆盖.
- Linux学习指导
初次学习Linux,首先在虚拟机中尝试它. 虚拟机我推荐Virtual Box,我并不主张使用VM,原因是VM是闭源的,并且是收费的,而Virtual Box很小巧,Windows平台下安装包在80M ...
- LeetCode(63):不同路径 II
Medium! 题目描述: 一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为“Start” ). 机器人每次只能向下或者向右移动一步.机器人试图达到网格的右下角(在下图中标记为“F ...
- Laravel API 限速异常 HTTPException Too Many Attemps
最近线上 Laravel 错误日志发现了一个异常 HTTPException Too Many Attemps 而我一个同事在本地开发的过程中也频繁遇到这个异常.测试环境:Laravel 5.5. 网 ...
- python 全栈开发,Day127(app端内容播放,web端的玩具,app通过websocket远程遥控玩具播放内容,玩具管理页面)
昨日内容回顾 1. 小爬爬 内容采集 XMLY 的 儿童频道 requests 2. 登陆 注册 自动登陆 退出 mui.post("请求地址",{数据},function(){} ...
- each()遍历
在<jQuery教程/理解选取更新范围>一节中,我们知道:当选择器返回了多个元素时,可以使用一个方法来更新所有的元素,不再需要使用循环. 然后有的时候需要遍历元素,怎么办? 使用each( ...
- DDD领域模型数据访问之对象(十一)
在工程DDD.Domain中文件夹ModelPermission新建类:BAS_Object public partial class BAS_Obejct:AggreateRoot { //仓储接口 ...
- SpringBank 开发日志 一种简单的拦截器设计实现
当交易由Action进入Service之前,需要根据不同的Service实际负责业务的不同,真正执行Service的业务逻辑之前,做一些检查工作.这样的拦截器应该是基于配置的,与Service关联起来 ...
- [ZJOI2012]数列
超级水的题还wa了一次 首先很容易发现其实就只有两个值并存 然后 要注意把数组初始化啊...可能后面有多余的元素(对拍的时候由于从小到大就没跑出错) #include <bits/stdc++. ...
- python常用内建模块--base64
Base64是一种任意二进制到文本字符串的编码方法,常用于在URL.Cookie.网页中传输少量二进制数据. import base64 a = 'abcdef/+'b= base64.b64enco ...