https://vjudge.net/problem/48715/origin

题意:给出必定含1689四个数字的字符串,随意交换位置构造出能被7整除的数。

分析:数学思维题。观察发现1689的排列与7的余数恰好是0...6,那么利用这个性质去与串中其他数字相补出能被7整除的数,把1689固定在后四位,把0独自提取出来,其他数字为一组,把它们的数值*10000后mod7,根据得到的余数选择相应的1689排列,最后把0放在末尾(对结果正确性没有影响)。
代码:

 #include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <queue> #define LL long long using namespace std; char s[];
char w[]; bool mark[]; int main()
{ memset(mark,false,sizeof(mark)); LL top = ,sum = ,i,Zero = ; cin>>s; int len = strlen(s); for(i = ;i < len; ++i)
{
if((s[i] == '' || s[i] == '' || s[i] == '' || s[i] == '') && mark[s[i]-''] == false)
{
mark[s[i]-''] = true;
}
else if(s[i] == '')
{
Zero ++;
}
else
{
w[top++] = s[i];
}
} for(i = ;i < top; ++i)
{
sum *= ;
sum += (w[i]-'');
sum %= ;
} sum *= ;
sum %= ; for(i = ;i < top; ++i)
{
printf("%c",w[i]);
} switch(sum)
{
case :printf("");break;
case :printf("");break;
case :printf("");break;
case :printf("");break;
case :printf("");break;
case :printf("");break;
case :printf("");break;
} while(Zero--)
{
printf("");
}
cout<<endl; return ;
}

CodeForces - 375A Divisible by Seven(数学)的更多相关文章

  1. 【Codeforces 375A】Divisible by Seven

    [链接] 我是链接,点我呀:) [题意] 让你把一个包含数字1,6,8,9的数字重新组合,使得组合成的数字能被7整除 [题解] 我们先提取出来1,6,8,9各1个 然后把剩余的len-4个数字除了0之 ...

  2. [Codeforces 1178D]Prime Graph (思维+数学)

    Codeforces 1178D (思维+数学) 题面 给出正整数n(不一定是质数),构造一个边数为质数的无向连通图(无自环重边),且图的每个节点的度数为质数 分析 我们先构造一个环,每个点的度数都是 ...

  3. Codeforces 627 A. XOR Equation (数学)

    题目链接:http://codeforces.com/problemset/problem/627/A 题意: 告诉你s 和 x,a + b = s    a xor b = x   a, b > ...

  4. Codeforces Beta Round #2B(dp+数学)

    贡献了一列WA.. 数学很神奇啊 这个题的关键是怎么才能算尾0的个数 只能相乘 可以想一下所有一位数相乘 除0之外,只有2和5相乘才能得到0 当然那些本身带0的多位数 里面肯定含有多少尾0 就含有多少 ...

  5. codeforces 803C Maximal GCD(GCD数学)

    Maximal GCD 题目链接:http://codeforces.com/contest/803/problem/C 题目大意: 给你n,k(1<=n,k<=1e10). 要你输出k个 ...

  6. Codeforces 789A Anastasia and pebbles(数学,思维题)

    A. Anastasia and pebbles time limit per test:1 second memory limit per test:256 megabytes input:stan ...

  7. Codeforces 839C Journey - 树形动态规划 - 数学期望

    There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can r ...

  8. CodeForces 215B Olympic Medal(数学啊)

    题目链接:http://codeforces.com/problemset/problem/215/B Description The World Programming Olympics Medal ...

  9. Educational Codeforces Round 11A. Co-prime Array 数学

    地址:http://codeforces.com/contest/660/problem/A 题目: A. Co-prime Array time limit per test 1 second me ...

随机推荐

  1. 使用树莓派 Raspberry Pi 播放豆瓣 FM

    安装 mplayersudo apt-get install mplayer 安装 Python-pipsudo apt-get install python-pip 通过 python-pip 安装 ...

  2. hdu 1978 How many ways(记忆化搜索)

    这是一个简单的生存游戏,你控制一个机器人从一个棋盘的起始点(1,1)走到棋盘的终点(n,m).游戏的规则描述如下:1.机器人一开始在棋盘的起始点并有起始点所标有的能量.2.机器人只能向右或者向下走,并 ...

  3. POJ1061 青蛙的约会(扩展欧几里得)

    题目链接:http://poj.org/problem?id=1061 青蛙的约会 Time Limit: 1000MS   Memory Limit: 10000K Total Submission ...

  4. Listener监听器和Filter过滤器

    Listener监听器 WEB中的监听器 WEB 中的 Listener 和 Filter 是属于 Servlet 规范中的高级的技术.WEB中的监听器共有三类八种(监听三个域对象)* 事件源:Ser ...

  5. Docker的脚本安装

    官方镜像支持 curl -sSL https://get.docker.com/ | sh 国内镜像站 curl -sSL https://get.daocloud.io/docker | sh cu ...

  6. vue学习(1)

    前置的准备学习: ES6简单语法: 1.let和const 2.模板字符串 3.箭头函数 4.对象的单体模式 5.es6的面向对象 6.模块化 1.let和const <script type= ...

  7. Methods for follow-up research of exome analysis:外显子后续分析研究思路总结

    外显子后续分析研究思路一般有以下几种(Methods for follow-up research of exome analysis): 1.对突变频率.突变类型.突变方式进行统计分析 Mutati ...

  8. POJ 1979 Heavy Transportation (kruskal)

    Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions:46898   Accepted: 1 ...

  9. PHP实现异步处理

    resource fsockopen ( string $hostname [, int $port = -1 [, int &$errno [, string &$errstr [, ...

  10. selinux 的使用

    SELinux 的启动.关闭与查看 1,并非所有的 Linux distributions 都支持 SELinux 的 目前 SELinux 支持三种模式,分别如下: •enforcing:强制模式, ...