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 617. Merge Two Binary Tree (合并两个二叉树)

    Given two binary trees and imagine that when you put one of them to cover the other, some nodes of t ...

  2. linux系统莫名被黑的诡异经历

    2017年10月28日,ssh登录本地虚拟机之后发现主机名被改成了HUAIWEI_P10. 我一个同事用的此款手机,起初怀疑是他,没放心上. 今天(10月30)发现自己ssh登录不上了.恼火了办公室开 ...

  3. IntentService学习

    IntentService是一个Service,主要就是Service和HandlerThread的结合 一.使用 不用多说和使用Service差不多,但是比Service多个一个方法实现: publ ...

  4. Google Guava

    公司用到了 Joiner  HashMultimap 等  都是属于Google Guava包中的东西 官方文档 http://ifeve.com/google-guava/ 有时间了整理一下

  5. Java中Double保留后小数位的几种方法

    最近做个小实验,其中一部分要求将表单提交的数据转换为double,这个功能其实很简单直接一句Double.parseDouble(request.getParameter("chinese& ...

  6. continous integration environment (Jenkins and bitbucket configuration)

    ================================================================================ continous integrati ...

  7. 数据库Oracle

    一. 表空间和数据文件的关系: 文件组成:数据文件,控制文件,数据库日志文件 数据文件:.dbf 包含全部数据库数据(表,索引等),一个数据文件仅与一个数据库关联.一旦建立,只增不减. 表空间(Tab ...

  8. zabbix 3.2 高可用实现方式一,亲测无坑

    1.架构设计图 2.设计说明 1. 基础架构为LAMP环境,采用keepalived实现zabbix服务器高可用,保证主server的mysql或者httpd宕掉后能切换到从server. 2.数据库 ...

  9. 一:Spring Boot、Spring Cloud

    上次写了一篇文章叫Spring Cloud在国内中小型公司能用起来吗?介绍了Spring Cloud是否能在中小公司使用起来,这篇文章是它的姊妹篇.其实我们在这条路上已经走了一年多,从16年初到现在. ...

  10. 将Excel文件数据导入到SqlServer数据库的三种方案

    方案一: 通过OleDB方式获取Excel文件的数据,然后通过DataSet中转到SQL Server,这种方法的优点是非常的灵活,可以对Excel表中的各个单元格进行用户所需的操作. openFil ...