B. Wet Shark and Bishops time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input output: standard output Today, Wet Shark is given n bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from…
记录一下每个对角线上有几个,然后就可以算了 #include<cstdio> #include<cstring> #include<cmath> #include<ctime> #include<vector> #include<algorithm> using namespace std; +; int n; long long w1[maxn]; long long w2[maxn]; long long ans; int mai…
B. Wet Shark and Bishops time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Today, Wet Shark is given n bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 t…
Today, Wet Shark is given n bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right. Wet Shark thinks that two bishops attack e…
http://codeforces.com/problemset/problem/621/E E. Wet Shark and Blocks time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are b blocks of digits. Each one consisting of the same n digit…
E. Wet Shark and Blocks time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are b blocks of digits. Each one consisting of the same n digits, which are given to you in the input. Wet Sha…
题意:处在同一对角线上的主教(是这么翻译没错吧= =)会相互攻击 求互相攻击对数 由于有正负对角线 因此用两个数组分别保存每个主教写的 x-y 和 x+y 然后每个数组中扫描重复数字k ans加上kC2就行了 wa了两发的原因是没考虑到如果整个数组都是重复的 那要最后额外加一次 #include <cstdio> #include <cmath> #include <cstring> #include <queue> #include <vector&…
题 题意 1000*1000的格子里,给你n≤200 000个点的坐标,求有多少对在一个对角线上. 分析 如果求每个点有几个共对角线的点,会超时. 考虑到对角线总共就主对角线1999条+副对角线1999条,我们可以求每个对角线有几对点. 同一条主对角线上的元素有a[i]个,就有C(a[i],2)对点: 同一条副对角线上的元素有b[i]个,就有C(b[i],2)对点. 读入x和y后, x+y相同的就在同一副对角线,x+y范围是(2,2000), x-y相同的就是同一主对角线,x-y范围是(-999…
对角线 x1+y1=x2+y2 或者x1-y1=x2-y2 #include<iostream> #include<string> #include<algorithm> #include<cstdlib> #include<cstdio> #include<set> #include<map> #include<vector> #include<cstring> #include<stack…
B. Chocolate time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Bob loves everything sweet. His favorite chocolate bar consists of pieces, each piece may contain a nut. Bob wants to break the…
方法可以转化一下,先计算每一个鲨鱼在自己范围内的数能被所给素数整除的个数有几个,从而得到能被整除的概率,设为f1,不能被整除的概率设为f2. 然后计算每相邻两只鲨鱼能获得钱的期望概率,f=w[id1].f1*w[id2].f2+w[id1].f2*w[id2].f1+w[id1].f1*w[id2].f1; f*2000就是这两只鲨鱼能获得的期望金钱,然后枚举一下所有相邻的鲨鱼,累加即可. #include<cstdio> #include<cstring> #include<…
水题 #include<cstdio> #include<cstring> #include<cmath> #include<ctime> #include<vector> #include<algorithm> using namespace std; int n; +]; int main() { scanf("%d",&n); ;i<n;i++) scanf("%lld",&…
题意: 有b个blocks,每个blocks都有n个相同的0~9的数字,如果从第一个block选1,从第二个block选2,那么就构成12,问对于给定的n,b有多少种构成方案使最后模x的余数为k. 分析: dp+矩阵快速幂. 假如现在的数是m,模x余数是n,那么再从下一个block中选一个数a,a模x余数为b,那么新的数的余数就为(m∗10+a)%x,也就是(n∗10+b)%x,所以实际上我们只需要直接对余数进行操作.容易得到状态转移方程,其中dp[i][j]表示从第i个block中选择一个数后…
 B. Wet Shark and Bishops time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Today, Wet Shark is given n bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from…
题目链接: http://codeforces.com/problemset/problem/621/E E. Wet Shark and Blocks time limit per test2 secondsmemory limit per test256 megabytes 问题描述 There are b blocks of digits. Each one consisting of the same n digits, which are given to you in the inp…
题 Today, Wet Shark is given n integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark. Note, that if Wet Shark uses no integers from the n …
题 There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks i andi + 1 are neighbours for all i from 1 to n - 1. Sharks n and 1 are neighbours too. Each shark will grow some number of flowers si. For i…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output There are b blocks of digits. Each one consisting of the same n digits, which are given to you in the input. Wet Shark must choose exactly one d…
C. Wet Shark and Flowers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks i and i …
A. Wet Shark and Odd and Even time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Today, Wet Shark is given n integers. Using any of these integers no more than once, Wet Shark wants to get ma…
题意: 不概括了..太长了.. 额第一次做这种问题 算是概率dp吗? 保存前缀项中第一个和最后一个的概率 然后每添加新的一项 就解除前缀和第一项和最后一项的关系 并添加新的一项和保存的两项的关系 这里关系指的是两者相邻会产生的额外收入(其中一个满足条件就能得到 因此公式是 2000 * (rate[a] * rate[b] + rate[a] * ( 1 - rate[b]) + rate[b] * (1 - rate[a])) 至于一开始为什么老是调不过去呢..我发现添加第三项的时候前两项是不…
题意是得到最大的偶数和 解决办法很简单 排个序 取和 如果是奇数就减去最小的奇数 #include <cstdio> #include <cmath> #include <cstring> #include <queue> #include <vector> #include <algorithm> #define INF 0x3f3f3f3f #define mem(str,x) memset(str,(x),sizeof(str)…
题目大意:有m (m<=1e9) 个相同的块,每个块里边有n个数,每个数的范围是1-9,从每个块里边取出来一个数组成一个数,让你求组成的方案中 被x取模后,值为k的方案数.(1<=k<x<=100) 思路:刚开始把m看成了1e5,写了一发数位dp,果断RE,然后我在考虑从当块前状态转移到下一个块状态模数的改变都用的是一套规则,因为 每个块里面的数字都是一样的,那么我们就可以很开心地构造出一个x*x的矩阵进行快速幂啦. #include<bits/stdc++.h> #d…
题目链接:http://codeforces.com/problemset/problem/723/B 题目大意: 输入n,给出n个字符的字符串,字符串由 英文字母(大小写都包括). 下划线'_' .括号'(' ')' 组成.[括号不会嵌套] 求括号外面的连续字符串最大的字符串长度和括号内的连续字符串的个数. 举例: input 37_Hello_Vasya(and_Petya)__bye_(and_OK) output 5 4 括号外面的连续的字符串最长的字符串长度为 5 括号内有 4 个连续…
题目链接: http://codeforces.com/problemset/problem/546/C 题意: 总共有n张牌,1手中有k1张分别为:x1, x2, x3, ..xk1,2手中有k2张,分别为:y1, y2, ...yk2:(n<=10&&k1+k2==n,所有牌的数字都不同): 依次比较x1, y1的大小,若x1>y1,依次将x1, y1加入x牌最底下:反之则将y1,x1依次加入y牌最底下:直至有方的牌输完为止:输出总共游戏的步数和赢方: 如果两方都不能赢,则…
http://codeforces.com/problemset/problem/749/C 题意:有n个人投票,分为 D 和 R 两派,从1~n的顺序投票,轮到某人投票的时候,他可以将对方的一个人KO,被KO的人不能投票了,这样循环,直到某一派的人全部被KO,问哪方赢. 思路:模拟..代码好懂.. #include <cstdio> #include <algorithm> #include <iostream> #include <cstring> #i…
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…
B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segmen…
题目链接:http://codeforces.com/problemset/problem/797/C 题意: 给你一个非空字符串s,空字符串t和u.有两种操作:(1)把s的首字符取出并添加到t的末尾.(2)把t的尾字符取出并添加到u的末尾. 问你当经过一系列操作后,s和t均为空时,字典序最小的u. 题解: 操作的本质: s为队列,t为栈. 贪心思路: (1)找到s中的最小字符c,不断出队并加入t,直至有一次出队的字符等于c,停止出队. (2)当t的尾字符小于等于s中的最小字符时,优先弹出t的尾…
C. Tic-tac-toe 题目连接: http://www.codeforces.com/contest/3/problem/C Description Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3 × 3 grid (one player always draws…