CodeForces - 375A Divisible by Seven(数学)
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(数学)的更多相关文章
- 【Codeforces 375A】Divisible by Seven
[链接] 我是链接,点我呀:) [题意] 让你把一个包含数字1,6,8,9的数字重新组合,使得组合成的数字能被7整除 [题解] 我们先提取出来1,6,8,9各1个 然后把剩余的len-4个数字除了0之 ...
- [Codeforces 1178D]Prime Graph (思维+数学)
Codeforces 1178D (思维+数学) 题面 给出正整数n(不一定是质数),构造一个边数为质数的无向连通图(无自环重边),且图的每个节点的度数为质数 分析 我们先构造一个环,每个点的度数都是 ...
- Codeforces 627 A. XOR Equation (数学)
题目链接:http://codeforces.com/problemset/problem/627/A 题意: 告诉你s 和 x,a + b = s a xor b = x a, b > ...
- Codeforces Beta Round #2B(dp+数学)
贡献了一列WA.. 数学很神奇啊 这个题的关键是怎么才能算尾0的个数 只能相乘 可以想一下所有一位数相乘 除0之外,只有2和5相乘才能得到0 当然那些本身带0的多位数 里面肯定含有多少尾0 就含有多少 ...
- codeforces 803C Maximal GCD(GCD数学)
Maximal GCD 题目链接:http://codeforces.com/contest/803/problem/C 题目大意: 给你n,k(1<=n,k<=1e10). 要你输出k个 ...
- Codeforces 789A Anastasia and pebbles(数学,思维题)
A. Anastasia and pebbles time limit per test:1 second memory limit per test:256 megabytes input:stan ...
- Codeforces 839C Journey - 树形动态规划 - 数学期望
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can r ...
- CodeForces 215B Olympic Medal(数学啊)
题目链接:http://codeforces.com/problemset/problem/215/B Description The World Programming Olympics Medal ...
- 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 ...
随机推荐
- Github Desktop 克隆新项目 Authentication failed. You may not have permission to access the repository or the repository may ha
原来:ssh://git@github.com/xxx.git 改成:https://git@github.com/xxx.git
- python3 字典dict
字典是用大括号{}表示 dict() 键必须是唯一的,但值则不必:键是不可变的,如字符串.数字.元组,值可以取任意数据类型: 可以迭代, del可以删除一对键值,del Dict['key'] 重复给 ...
- 【dp】P1434 [SHOI2002]滑雪
题目描述 Michael喜欢滑雪.这并不奇怪,因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道在一个区域中最长 ...
- TCP/UDP区别
一:1. 大体上来说,TCP和UDP都是通过Internet发送数据包的协议.都建立在Internet协议上.就是无论你是用TCP协议还是用UDP协议发送数据包,都会被发送到IP地址: 2.数据包的处 ...
- 在浏览器中浏览git上项目目录结构
效果如下,参考:https://gitee.com/oschina/GitCodeTree
- pandas isin
在已知id索引的情况下,如何获取所需要的行呢?已经不止一次遇到这样的情况,经历过重重筛选,所得到的最终结果是一串满足所有条件的id列表. pandas 的isin 能很好的解决这个问题, import ...
- hdu 1160 FatMouse's Speed (最长上升子序列+打印路径)
Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...
- thinkphp5 上传服务器后 Access denied
服务器报 Access denied,要么报 No input files,但是在网上查了查说是将 PHP 的cgi.fix_pathinfo 改成 1 即可,但是改成 1 显然是有解析漏洞的,尝试寻 ...
- Apache POI - Java Excel APIs
文档来源:https://www.yiibai.com/apache_poi/ POI 什么是Apache POI? Apache POI是一种流行的API,它允许程序员使用Java程序创建,修改和显 ...
- Macbook外接显示器模糊解决方法
解决方法(此方法经本人测试失败) 下载这个http://www.elias.cn/uploads/Mac/patch-edid.zip.如果链接失效可以使用https://gist.github.co ...