[Codeforces 919F]A Game With Numbers】的更多相关文章

  Imagine that Alice is playing a card game with her friend Bob. They both have exactly 88 cards and there is an integer on each card, ranging from 00 to 44. In each round, Alice or Bob in turns choose two cards from different players, let them be aa…
Description 题库链接 两个人 Van♂ 游戏,每人手上各有 \(8\) 张牌,牌上数字均为 \([0,4]\) 之间的数.每个人在自己的回合选自己手牌中数字不为 \(0\) 的一张与对方手牌中不为 \(0\) 的一张.数字相加对 \(5\) 取模,赋给自己当前选中的这张牌. \(T\) 组询问,给出先手,问谁能胜. \(1\leq T\leq 100000\) Solution 首先注意到卡牌顺序是没有影响的,我们可以按数字大小排序.这时由可重复的组合得每个人可能的方案只有 \(\b…
懒得复制,戳我戳我 Solution: 我感觉我也说不太好,看Awson的题解吧. 说一点之前打错的地方: 连边存的是hash后的数组下标 if(ans[ num( C[a.hash()] , C[b.hash()] ) ]==1){ if(f==0)printf("Alice\n");else printf("Bob\n"); continue; } if(ans[ num( C[a.hash()] , C[b.hash()] ) ]==-1){ if(f==0)…
转自大佬博客:https://www.cnblogs.com/NaVi-Awson/p/8405966.html; 题意 两个人 Van♂ 游戏,每人手上各有 8'>88 张牌,牌上数字均为 [0,4]'>[0,4][0,4] 之间的数.每个人在自己的回合选自己手牌中数字不为 0'>00的一张与对方手牌中不为 0'>00 的一张.数字相加对 5'>55 取模,赋给自己当前选中的这张牌. T'>TT 组询问,给出先手,问谁能胜. 分析 首先注意到卡牌顺序是没有影响的,我们…
题目链接:Codeforces 385C Bear and Prime Numbers 这题告诉我仅仅有询问没有更新通常是不用线段树的.或者说还有比线段树更简单的方法. 用一个sum数组记录前n项和,这个sum数组在打素数表时候就能够求出来,注意一点求素数的内层循环要改成i.不能再写成i + i或者i * i了.原因想想就明确了. 这学期最后一场比赛也结束了,结果不非常惬意但也还好. 总的来说这学收获还是蛮多的. 近期可能就不再做ACM了吧,可能要复习CET6了吧,可能要复习期末考试的内容了吧.…
Codeforces 385C Bear and Prime Numbers 其实不是多值得记录的一道题,通过快速打素数表,再做前缀和的预处理,使查询的复杂度变为O(1). 但是,我在统计数组中元素出现个数时使用了map,以至于后面做前缀和的累加时,每次都要对map进行查询,以至于TLE.而自己一直没有发现,以为是欧拉筛对于这道题还不够优,于是上网搜题解,发现别人的做法几乎一样,但是却能跑过,挣扎了许久才想起是map的原因.map的内部实现是一颗红黑树,每次查询的复杂度为O(logN),在本来时…
A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/problem/A Description You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon…
D. Magic Numbers 题目连接: http://www.codeforces.com/contest/628/problem/D Description Consider the decimal presentation of an integer. Let's call a number d-magic if digit d appears in decimal presentation of the number on even positions and nowhere els…
题目链接:http://codeforces.com/problemset/problem/556/B 题目意思:给出 n 个齿轮,每个齿轮有 n 个 teeth,逆时针排列,编号为0 ~ n-1.每按一次 button,每个齿轮都会有且仅有一个活动的tooth,对于偶数编号的齿轮,它下一个活动tooth是紧挨着当前tooth的逆时针方向的那个:而奇数编号的齿轮,下一个活动tooth是顺时针的那个.给出每个齿轮的活动tooth,问通过按下有限次的button,问能不能得到一个0,1,...,n-…
In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation F1 = 1; F2 = 1; Fn = Fn - 1 + Fn - 2 (n > 2). DZY loves Fibonacci numbers very much. Today DZY gives you an array consisting of n integers: a1, a2, ...,…
Magic Numbers 题意:给定长度不超过2000的a,b;问有多少个x(a<=x<=b)使得x的偶数位为d,奇数位不为d;且要是m的倍数,结果mod 1e9+7; 直接数位DP;前两维的大小就是mod m的大小,注意在判断是否f[pos][mod] != -1之前,要判断是否为边界,否则会出现重复计算: #include<bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f #define MS1(a) mem…
C. DZY Loves Fibonacci Numbers time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation F1 = 1; F2 …
题目链接:http://codeforces.com/problemset/problem/385/C 题目大意:给定n个数与m个询问区间,问每个询问区间中的所有素数在这n个数中被能整除的次数之和 解题思路:首先暴力打出一张素数表,最大的素数小于等于n个数中的最大值即可.在打表的过程就统计从2开始到当前素数的总的整除次数(简直简单粗暴),最后对于询问区间,找出该区间内的最小素数与最大素数在素数表中的位置,结果即为s[r]-s[l-1] 代码如下: #include<cmath> #includ…
第一眼看这道题目的时候觉得可能会很难也看不太懂,但是看了给出的Hint之后思路就十分清晰了 Consider the first sample. Overall, the first sample has 3 queries. The first query l = 2, r = 11 comes. You need to count f(2) + f(3) + f(5) + f(7) + f(11) = 2 + 1 + 4 + 2 + 0 = 9. The second query comes…
Recently, the bear started studying data structures and faced the following problem. You are given a sequence of integers x1, x2, ..., xn of length n and m queries, each of them is characterized by two integers li, ri. Let's introduce f(p) to represe…
/////////////////////////////////////////////////////////////////////////////////////////////////////// 作者:stxy-ferryman声明:本文遵循以下协议自由转载-非商用-非衍生-保持署名|Creative Commons BY-NC-ND 3.0 查看本文更新与讨论请点击:http://www.cnblogs.com/stxy-ferryman/链接被删请百度:stxy-ferryman…
洛谷 Codeforces 思路 这题知道结论就是水题,不知道就是神仙题-- 斐波那契数有这样一个性质:\(f_{n+m}=f_{n+1}f_m+f_{n}f_{m-1}\). 至于怎么证明嘛-- 即得易见平凡,仿照上例显然.留作习题答案略,读者自证不难. 反之亦然同理,推论自然成立,略去过程QED,由上可知证毕. 其实就是我不会 而且这个性质对于负数下标也是成立的. 负数下标的斐波那契数怎么求?你从\(f_{-1}+f_0=f_1\)可以得到\(f_{-1}=1\),后面的你也倒推回去就可以了…
385C - Bear and Prime Numbers 思路:记录数组中1-1e7中每个数出现的次数,然后用素数筛看哪些能被素数整除,并加到记录该素数的数组中,然后1-1e7求一遍前缀和. 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mem(a,b) memset((a),(b),sizeof(a)) const int INF=0x3f…
D. Pair of Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l…
Description In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation F1 = 1; F2 = 1; Fn = Fn - 1 + Fn - 2 (n > 2). DZY loves Fibonacci numbers very much. Today DZY gives you an array consisting of n integers: …
DZY Loves Fibonacci Numbers Time Limit:4000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Appoint description:  System Crawler  (2014-07-14) Description In mathematical terms, the sequence Fn of Fibonacci numbers is defi…
题目链接: A. Mashmokh and Numbers time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh. In this game Mashmokh wri…
B. Case of Fake Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of…
题目:DZY Loves Fibonacci Numbers 题意比較简单,不解释了. 尽管官方的题解也是用线段树,但还利用了二次剩余. 可是我没有想到二次剩余,然后写了个感觉非常复杂度的线段树,还是mark一下吧. 我是这样考虑这个问题的,首先准备三个数组F,G,K,功能后面解释. 然后对它们有这样一个计算: F[0] = G[0] = 0; F[1] = 1; G[1] = 0; K[0] = 1; K[1] = 0; for(int i=2; i<N; i++){ F[i] = (F[i-…
A. Bad Ugly Numbers time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a integer nn (n>0n>0). Find any integer ss which satisfies these conditions, or report that there are no s…
Codeforces 题目传送门 & 洛谷题目传送门 你可能会疑惑我为什么要写 *2400 的题的题解 首先一个很明显的想法是,看到斐波那契数列和 \(10^9+9\) 就想到通项公式,\(F_i=\dfrac{1}{\sqrt{5}}((\dfrac{1+\sqrt{5}}{2})^n-(\dfrac{1-\sqrt{5}}{2})^n)\).并且 \(5\) 在模 \(10^9+9\) 意义下的二次剩余存在,为 \(383008016\). 我们建两棵线段树分别维护展开式中 \((\dfra…
假如F[1] = a, F[2] = B, F[n] = F[n - 1] + F[n - 2]. 写成矩阵表示形式可以很快发现F[n] = f[n - 1] * b + f[n - 2] * a. f[n] 是斐波那契数列 也就是我们如果知道一段区间的前两个数增加了多少,可以很快计算出这段区间的第k个数增加了多少 通过简单的公式叠加也能求和 F[n]  = f[n - 1] * b + f[n - 2] * a F[n - 1] = f[n - 2] * b + f[n - 3] * a ..…
打开题目链接 题意:输入一个字符串,用,或:分隔输出字符串和整数(不含前导0和浮点数) ACcode: #include <iostream> #include <cstdio> #include <cstring> using namespace std; string s,digit,seq,temp; int main() { cin>>s; for(int i=0; i<s.length(); i++) if(s[i] == ',' || s[…
题意:转换模型之后,就是1~n个数中选k个,放到一个容量为n的背包中,这个背包还特别神奇,相同的物品摆放的位置不同时,算不同的放法(想象背包空间就是一个长度为n的数组,然后容量为1的物体放一个格子,容量为n的物体放在相邻的n个格子里.问方案数. 方法: 选k个物品放在背包中有多少种放法. 然后就是k个物品放了以后,还剩下几个空位,空位的位置不同,则方案数也不同.所以要求出几个空位放在几个地方有多少方案数 最后相乘,再乘上阶乘就好了. #include <cstdio> #include <…
题面 这种比赛时只有11个人做出来的题一般来说都是暴难的, 我也不知道我怎么搞出来的www 看完这个题第一感觉就是要容斥,至少有一条某种边的方案已经比较难求了,而直接算三种边都至少存在一条的方案数就更难了2333 那么不妨考虑从反面容斥吧 设把三种边的存在情况表示成三进制的话,1表示至少有一条 ,0表示一条都没有,?表示这种边没有限制,那么容斥可以得到的是 : f[111] = f[???] - (f[0??]+f[?0?]+f[??0]) + (f[00?]+f[0?0]+f[?00]) -…