Codeforces 894B - Ralph And His Magic Field】的更多相关文章

894B - Ralph And His Magic Field 思路: 当k为1时,如果n和m奇偶性不同,那么没有答案. 可以证明,在其他情况下有答案,且答案为2^(n-1)*(m-1),因为前n-1行和m-1列确定后,最后一列和最后一行可以确定,且确定的最后一格不矛盾. 可以采用在全为1的格子中把一些1换成-1的方法来证明以上两条结论. 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define…
题目链接:https://cn.vjudge.net/problem/CodeForces-894B Ralph has a magic field which is divided into n × m blocks. That is to say, there are n rows and m columns on the field. Ralph can put an integer in each block. However, the magic field doesn't alway…
A.QAQ 题目大意:从给定的字符串中找出QAQ的个数,三个字母的位置可以不连续 思路:暴力求解,先找到A的位置,往前扫,往后扫寻找Q的个数q1,q2,然 后相乘得到q1*q2,这就是这个A能够找到的QAQ个数,依次累加即可 #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s; cin>>s;…
B. Ralph And His Magic Field time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Ralph has a magic field which is divided into n × m blocks. That is to say, there are n rows and m columns on th…
B. Ralph And His Magic Field time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Ralph has a magic field which is divided into n × m blocks. That is to say, there are n rows and m columns on th…
题目链接 题意:给你三个数n,m,k;让你构造出一个nm的矩阵,矩阵元素只有两个值(1,-1),且满足每行每列的乘积为k,问你多少个矩阵. 解法:首先,如果n,m奇偶不同,且k=-1时,必然无解: 设n为奇数,m为偶数,且首先要满足每行乘积为-1,那么每行必然有奇数个-1,那么必然会存在有偶数个-1..满足每列乘积为-1,那么每列必然有奇数个-1,那么必然存在奇数个-1.互相矛盾. 剩下的就是有解的情况了. 我们可以在n-1m-1的矩阵中随意放置-1,1.在最后一列和最后一行控制合法性即可. #…
| [链接] 我是链接,点我呀:) [题意] 给你一个n*m矩阵,让你在里面填数字. 使得每一行的数字的乘积都为k; 且每一列的数字的乘积都为k; k只能为1或-1 [题解] 显然每个位置只能填1或-1 如果只考虑前n-1行和前m-1列. 那么我们对这(n-1)*(m-1)的范围. 先任意填入数字; 则一共有\(2^{(n-1)*(m-1)}\)种方法. 然后把最后一行的前m-1列填一下. 使得前m-1列满足,每一列的乘积为k 然后把最后一列的前n-1行填一下使前n-1行每一行的乘积都为k 最后…
题目链接:http://codeforces.com/contest/894/problem/B 题目大意: 往一个 \(n \times m\) 的网格中填数字 \((1 \le n,m \le 10^{18})\),使得网格的任意一行和任意一列的乘积均为 \(k (k \in \{-1, 1\}).\)问有多少种方案. 知识点: 费马小定理.快速幂 解题思路: 1.网格中的数字,要么是 1,要么是 -1: 2.如果网格中 \((n-1) \times (m-1)\) 的子网格上的数字已经确定…
题目:在网格某一处填入一个正整数,使得网格每行,每列以及两条主对角线的和都相等 题目链接:http://codeforces.com/contest/711/problem/B 分析:题目不难,找到要填的那个数填进去,然后循环比较每行每列以及对角线的和是否相等,题目提交上去卡了几次要注意几点 注意:1.答案数据范围$1\leq x \leq 1e18$,要用 long long 2.特殊情况,$n \equiv 1$时,由于一定有要填的数,所以一定有解 3.反正就是要注意看清楚题目和数据边界情况…
题目链接: B. Chris and Magic Square 题意: 问在那个空位子填哪个数可以使行列对角线的和相等,就先找一行或者一列算出那个数,再验证是否可行就好; AC代码: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <bits/stdc++.h> #includ…
[题目链接]:http://codeforces.com/contest/711/problem/B [题意] 让你在矩阵中一个空白的地方填上一个正数; 使得这个矩阵两个对角线上的和; 每一行的和,每一列的和都相同; [题解] 对于n=1的情况,任意输出一个数字就好; 对于n>1的情况; 先算出不包括空白格子的行的所有元素的和->he; 然后对于其他的可行的行和列,算出它们的和; 一旦与he不一样,直接输出-1无解; 然后包括空白格子的行和列,它们除了那个空白格子的和也要相同->设为sp…
题意:一张有向图,每条边上都有wi个蘑菇,第i次经过这条边能够采到w-(i-1)*i/2个蘑菇,直到它为0.问最多能在这张图上采多少个蘑菇. 分析:在一个强连通分量内,边可以无限次地走直到该连通块内蘑菇被采完为止,因此每个强连通分量内的结果是确定的. 设一条边权值为w,最大走过次数为t,解一元二次方程得 t = (int)(1+sqrt(1+8w)):则该边对所在连通块的贡献为w*t - (t-1)*t*(t+1)/6. 而不在任何一个强连通分量内的边,最多只能走一次.所以在缩点后的DAG上进行…
time limit per test 2 second memory limit per test 256 megabytes input standard inputoutput standard output You a captain of a ship. Initially you are standing in a point (x1,y1)(x1,y1) (obviously, all positions in the sea can be described by cartesi…
传送门:QAQQAQ 题意:给一个01矩阵A,他的相反矩阵为B,每一次变换都会将原矩阵面积乘4成为: AB BA 矩阵的左上角固定,变换无限次,现有q个询问,即求一个矩阵内的1的个数. 思路:因为反转,所以A,B矩阵拼起来刚好是一个全都为1的矩阵,所以答案就是匹配的A,B矩阵总点数/2和右下角1的个数之和 注意点: 1.因为数据较大,要用前缀和思想 2.要开longlong 3.注意询问时各个变量的重置 代码: #include<iostream> #include<cstdio>…
BC都被hack的人生,痛苦. 下面是题解的表演时间: A. QAQ "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of leng…
我感觉这场CF还是比较毒的,虽然我上分了... Problem A  QAQ 题目大意:给你一个由小写字母构成的字符串,问你里面有多少个QAQ. 思路:找字符串中的A然后找两边的Q即可,可以枚举找Q,也可以前缀和优化一下. #include<bits/stdc++.h> using namespace std; ]; ]; long long ans; int main() { scanf(); ); ;i<=n;i++) { sum[i]=sum[i-]; if(s[i]=='Q')…
Problem A:QAQ 给一个字符串,求出可非连续的QAQ序列有多少个. Analysis:比较水的一道题,记录每一个Q的位置,预处理A的个数即可 然而还是fst了,原因是未考虑一个Q都没有的极端情况,导致vector().size-1溢出! 以后一定要注意,当对unsigned int类型的vector().size作减法时考虑是否可能出现负数情况 #include <bits/stdc++.h> using namespace std; ]; string s; vector<i…
QAQ #include<stdio.h> #include<string.h> #include<stdlib.h> #include<vector> #include<algorithm> using std::vector; using std::sort; int cmp(const void * x, const void * y) { //x < y #define datatype int : -; #undef dataty…
题目链接:http://codeforces.com/contest/922 B. Magic Forest time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Imp is in a magic forest, where xorangles grow (wut?) A xorangle of order n is such a…
PerlGuts Illustrated Version 0.49, for perl 5.20 and older This document is meant to supplement the perlguts(1) manual page that comes with Perl. It contains commented illustrations of all major internal Perl data structures. Having this document han…
The two most important days in your life are the day you are born and the day you find out why. -- Mark Twain 转自 Jaminzzhang的博客“你是谁?从哪里来?到哪里去?”,这三个富有哲学气息的问题,是每一个人在不断解答的问题.我们Code,Build,Run,一个活生生的App跃然方寸屏上,这一切是如何发生的?从用户点击App到执行main函数这短短的瞬间发生了多少事呢?探寻App…
Little Elephant and Magic Square CodeForces - 259B Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table…
需求 数据: [主表]:存放在log.txt中 -------------------------------------------------------- 手机号码 品牌类型 登录时间 在线时长 13512435454 1 2018-11-12 12:32:32 50 ....... -------------------------------------------------------- [从表]:存放在type.txt中 -----------------------------…
> 之前深入了解过.过去了一年多的时间.如今花些时间好好总结下,毕竟好记性不如烂笔头. 其次另一个目的,对于mach-o文件结构.关于动态载入信息那个数据区中,命令含义没有深刻掰扯清除,希望有同学能够指点下. 摘要:对于mach-o是Mac和iOS能够运行文件的格式.进程就是系统依据该格式将运行文件载入到内存后得到的结果.系统通过解析文件,建立依赖(动态库),初始化运行时环境,才干真正開始运行该App(进程) Start from Hello World 通过分析以下这个最熟悉的可运行文件.来好…
一.概要 大家应该都清楚,大家上线app,需要上线各种平台,比如:小米,华为,百度等等等等,我们多数称之为渠道,如果发的渠道多,可能有上百个渠道. 针对每个渠道,我们希望可以获取各个渠道的一些独立的统计信息,比如:下载量等. 那么,如何区分各个渠道呢? 我们需要一个特性的标识符与该渠道对应,这个标识符肯定是要包含在apk中的.那么,我们就要针对每个渠道包去设置一个特定的标识符,然后打一个特定的apk. 这个过程可以手动去完成,每次修改一个字符串,然后手动打包.大家都清楚打包是一个相当耗时的过程,…
转自:https://www.linuxtv.org/downloads/legacy/video4linux/API/V4L2_API/spec-single/v4l2.html Video for Linux Two API Specification Revision 2.6.32 Michael H Schimek <mschimek@gmx.at> Bill Dirks Original author of the V4L2 API and documentation. Hans V…
Carneginon was a chic bard. But when he was young, he was frivolous and had joined many gangs. Recently, Caneginon was to be crowned, because the king was shocked by his poems and decided to award him the gold medal lecturer. Therefore, Most of peopl…
As the current heir of a wizarding family with a long history,unfortunately, you find yourself forced to participate in the cruel Holy Grail War which has a reincarnation of sixty years.However,fortunately,you summoned a Caster Servant with a powerfu…
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both main diagonals are odd. 输入 The only line contains odd integer n (1 ≤ n ≤ 49). 输出 Print n lines…
题目链接:http://codeforces.com/contest/327/problem/C 首先先算出一个周期里面的值,保存在ans里面,就是平常的快速幂模m做法. 然后要计算一个公式,比如有k个部分,那么对于没一个位置i, 都有2^i + 2^(i+n) + ... + 2^(i+(k-1)*n) = 2^i(1 + 2^n + ... + 2^((k-1)*n)) = 2^i * (1-2^(n*k))/(1-2^n) 所以结果就是ans * (1-2^(n*k))/(1-2^n) %…