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;
int len=s.length(),sum=0;
for(int i=0;i<len;++i) {
if(s[i]=='A') {
int num1,num2;
num1=num2=0;
for(int j=0;j<i;++j) if(s[j]=='Q') num1++;
for(int j=i+1;j<len;++j) if(s[j]=='Q') num2++;
if(num1&&num2) sum+=num1*num2;
}
}
cout<<sum<<endl;
return 0;
}

B. Ralph And His Magic Field

  • 题目大意:给一个\(n*m\)的格子,使得每一行与每一列都等于给定的k值,k取1或者-1
  • 我比较笨,没做出来,下来之后补题用达标发现规律
  • 最后的方案数为\(res = 2 ^{(n-1)*(m-1)}\)当\(n,m\)一个是奇数一个是偶数,且\(k==-1\)时直接输出0即可
  • 注意先计算\(2^{(n-1)}\)再计算\((2^{(n-1)})^{m-1}\),不然直接计算会使得中途的结果就不一样
  • 最终程序:
#include <iostream>
#include <stdio.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
ll n,m,k;
ll qpow(ll base, ll num) {
ll res=1;
while(num) {
if(num&1) res=((res%mod)*(base%mod))%mod;
num>>=1;
base=((base%mod)*(base%mod))%mod;
}
return res;
}
int main() {
scanf("%I64d %I64d %I64d",&n,&m,&k);
if(((n&1)!=(m&1))&&k==-1) {
printf("0\n");
return 0;
}
printf("%I64d\n", qpow(qpow(2,n-1),m-1));
return 0;
}
  • 打表程序
#include <iostream>
using namespace std;
int a[14][14];
int b[2]={-1,1};
int n,m,num,sum=0;
bool check() {
int temp;
for(int i=1; i<=n; ++i) {
temp=1;
for(int j=1; j<=m; ++j) {
temp*=a[i][j];
}
if(temp!=num) return false;
}
for(int i=1; i<=m; ++i) {
temp=1;
for(int j=1; j<=n; ++j) {
temp*=a[j][i];
}
if(temp!=num) return false;
}
return true;
}
void dfs(int x, int y) {
for(int i=0; i<=1; ++i) {
a[x][y]=b[i];
if(x<n&&y<m) dfs(x,y+1);
else if(x<n&&y==m) dfs(x+1,1);
else if(x==n&&y<m) dfs(x,y+1);
else if(x==n&&y==m) {
if(check()) sum++;
}
}
}
int main() {
while(cin>>n>>m>>num) {
sum=0;
dfs(1,1);
cout<<sum<<endl;
}
return 0;
}

C. Marco and GCD Sequence

  • 题目大意:给定已经求出的区间gcd,看是否存在序列满足求出的gcd
  • 思路:因为给定了gcd,那么可使最小的数要成为其他区间的gcd(插
  • 入),这是一定满足要求的解法。如果其他数不能被最小数整除,这
  • 说明给定gcd缺少了元素。
  • eg_1: 2 3 6 10
  • 其中3不能被2整除,说明给定gcd缺少了元素,添加1:1 2 3 6 10才可以
  • answer:1 (1) 2 (1) 3 (1) 6 (1) 10 gcd(ai,aj)=1;
  • eg_2:1 3 5 6 10 15 把最小数插入中间即可满足
  • answer:1 (1) 3 (1) 5 (1) 6 (1) 10 (1) 15 gcd(ai,aj)=1;
#include <iostream>
using namespace std;
int main() {
int n,ans[1005];
cin>>n;
for(int i=1;i<=n;++i) cin>>ans[i];
for(int i=1;i<=n;++i) {
if(ans[i]%ans[1]) {
cout<<"-1"<<endl;
return 0;
}
}
cout<<n+(n-1)<<endl;
for(int i=1;i<n;++i) cout<<ans[i]<<" "<<ans[1]<<" ";
cout<<ans[n]<<endl;
return 0;
}

codeforces #447 894A QAQ 894B Ralph And His Magic Field 894C Marco and GCD Sequence的更多相关文章

  1. Codeforces 894B - Ralph And His Magic Field

    894B - Ralph And His Magic Field 思路: 当k为1时,如果n和m奇偶性不同,那么没有答案. 可以证明,在其他情况下有答案,且答案为2^(n-1)*(m-1),因为前n- ...

  2. codeforces 894B - Ralph And His Magic Field - [数学题]

    题目链接:https://cn.vjudge.net/problem/CodeForces-894B Ralph has a magic field which is divided into n × ...

  3. Codeforces Round #447 (Div. 2) B. Ralph And His Magic Field【数论/组合数学】

    B. Ralph And His Magic Field time limit per test 1 second memory limit per test 256 megabytes input ...

  4. Codeforces Round #447 (Div. 2) B. Ralph And His Magic Field 数学

    题目链接 题意:给你三个数n,m,k;让你构造出一个nm的矩阵,矩阵元素只有两个值(1,-1),且满足每行每列的乘积为k,问你多少个矩阵. 解法:首先,如果n,m奇偶不同,且k=-1时,必然无解: 设 ...

  5. codeforces 894C - Marco and GCD Sequence - [有关gcd数学题]

    题目链接:https://cn.vjudge.net/problem/CodeForces-894C In a dream Marco met an elderly man with a pair o ...

  6. Codeforces 894.B Ralph And His Magic Field

    B. Ralph And His Magic Field time limit per test 1 second memory limit per test 256 megabytes input ...

  7. 【Codeforces Round #447 (Div. 2) B】Ralph And His Magic Field

    | [链接] 我是链接,点我呀:) [题意] 给你一个n*m矩阵,让你在里面填数字. 使得每一行的数字的乘积都为k; 且每一列的数字的乘积都为k; k只能为1或-1 [题解] 显然每个位置只能填1或- ...

  8. Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence【构造/GCD】

    C. Marco and GCD Sequence time limit per test 1 second memory limit per test 256 megabytes input sta ...

  9. 【Codeforces Round #447 (Div. 2) C】Marco and GCD Sequence

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 把gcd(a[1..n])放在输入的n个数之间. [代码] /* 1.Shoud it use long long ? 2.Have ...

随机推荐

  1. LeetCode 531. Longly Pixel I (孤独的像素之一) $

    Given a picture consisting of black and white pixels, find the number of black lonely pixels. The pi ...

  2. CodeForces - 556A Case of the Zeros and Ones

    //////////////////////////////////////////////////////////////////////////////////////////////////// ...

  3. 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest J Cleaner Robot

    Cleaner RobotCrawling in process... Crawling failed Time Limit:2000MS     Memory Limit:524288KB     ...

  4. linux中必会的目录

    第1章 find命令扩展 1.1 方法一 |xargs 通过|xargs将前面命令的执行结果传给后面. [root@znix ~]# find /oldboy/ -type f -name " ...

  5. Java:求字符串中邻接的数字为一个整体

    public static void main(String[] args) { String strNumbers = "0123456789";//用来进行判断数字的 Syst ...

  6. 英语学习笔记---01---新概念第一册---Lesson 1 Excuse me!

    Lesson 1   Excuse me!   [词汇] excuse [iks5kju:z]                      v. 原谅      劳驾.借光 me             ...

  7. 完善tab页面定位

    当我们用锚点定位到页面某个元素时,接下来按tab的话是想进入到目前元素( id="content")的下一个连接 <a href="#content"&g ...

  8. Python模糊查询本地文件夹去除文件后缀(7行代码)

    Python模糊查询本地文件夹去除文件后缀 import os,re def fuzzy_search(path): word= input('请输入要查询的内容:') for filename in ...

  9. 【APP问题定位(二)】Charles定位工具

    Charles工具是APP测试中简单有使用的一款测试工具,可以通过捕获request和response的信息初步确定bug的原因所在. 本文将从安装.使用两个方面来介绍. 安装 点击这里进入下载页,注 ...

  10. SVN服务迁移备份操作步骤

    SVN服务备份操作步骤 1.准备源服务器和目标服务器 源服务器:192.168.1.250 目标服务器:192.168.1.251 root/rootroot 2.对目标服务器(251)装SVN服务器 ...