Codeforces Round #221 (Div. 2) C. Divisible by Seven(构造 大数除法 )
上几次的一道cf题。
题目:http://codeforces.com/contest/376/problem/C
性质:
题目给出的 1 6 8 9的组合正好能构成%7后的 0 1 2 3 4 5 6的余数,所有根据上面的性质,可以
分两种情况,
1、除了1 6 8 9外都是0的情况,这时把1 6 8 9放到前面(性质5)
2、除了1 6 8 9外还有其他的非0数的情况,这时可以吧1 6 8 9放到后面(性质4)
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
using namespace std; char s[];
int num[];
char f[][]={"","","","","","",""};
int main()
{
int len,i,ant;
int a[];
while(~scanf("%s",s))
{
ant=;
len=strlen(s);
for(i=; i<len; i++)
{
num[i]=s[i]-;
}
memset(a,,sizeof(a));
for(i=; i<len; i++)
{
if(num[i]==&&a[]==)
{
num[i]=; a[]=;
}
if(num[i]==&&a[]==)
{
num[i]=; a[]=;
}
if(num[i]==&&a[]==)
{
num[i]=; a[]=;
}
if(num[i]==&&a[]==)
{
num[i]=; a[]=;
}
}
sort(num,num+len);
for(i=len-; i>=; i--)
{
ant=ant*+num[i];
ant%=;
}
if(num[len-]==) //情况1
{
printf("%s",f[(-ant)%]);
for(i=; i<len-; i++)
printf("");
printf("\n");
}
else //情况2
{
for(i=len-; i>=; i--)
printf("%d",num[i]);
printf("%s",f[(-ant)%]);
printf("\n");
}
}
return ;
}
Codeforces Round #221 (Div. 2) C. Divisible by Seven(构造 大数除法 )的更多相关文章
- Codeforces Round #275 (Div. 2) C - Diverse Permutation (构造)
题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数 ...
- Codeforces Round #221 (Div. 1) B. Maximum Submatrix 2 dp排序
B. Maximum Submatrix 2 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset ...
- Codeforces Round #221 (Div. 2) Lever I.O.U.
这场cf 做的很差,,第一题犯了一个很低级的错误..把i写成了J.... 第二题 想的太复杂了...其实我们只需要 考虑每个人自己的负债情况就行了,就是假设每个人把别人 欠他的钱,拿过来还给别人..这 ...
- [Codeforces Round #221 (Div. 1)][D. Tree and Queries]
题目链接:375D - Tree and Queries 题目大意:给你一个有n个点的树,每个点都有其对应的颜色,给出m次询问(v,k),问v的子树中有多少种颜色至少出现k次 题解:先对所有的询问进行 ...
- Codeforces Round #221 (Div. 2) D
有点郁闷的题目,给了2000ms,可是n,m的范围已经是5000了.5000 * 5000一般在别的OJ已经是超了2000ms,一開始不敢敲.看了下别人有n*m的潜逃循环,原来CF的机子如此的强大,一 ...
- Codeforces Round #828 (Div. 3) E2. Divisible Numbers (分解质因子,dfs判断x,y)
题目链接 题目大意 给定a,b,c,d四个数,其中a<c,b<c,现在让你寻找一对数(x,y),满足一下条件: 1. a<x<c,b<y<d 2. (x*y)%(a ...
- Codeforces Round #381 (Div. 2) A B C 水 构造
A. Alyona and copybooks time limit per test 1 second memory limit per test 256 megabytes input stand ...
- Codeforces Round #384 (Div. 2) C. Vladik and fractions 构造题
C. Vladik and fractions 题目链接 http://codeforces.com/contest/743/problem/C 题面 Vladik and Chloe decided ...
- Codeforces Round #381 (Div. 1) A. Alyona and mex 构造
A. Alyona and mex 题目连接: http://codeforces.com/contest/739/problem/A Description Alyona's mother want ...
随机推荐
- preventDefault()、stopPropagation()、return false 之间的区别
“return false”之所以被误用的如此厉害,是因为它看起来像是完成了我们交给它的工作,浏览器不会再将我们重定向到href中的链接,表单也不会被继续提交,但这么做到底有什么不对呢? 可能在你刚开 ...
- Redis源码研究--字符串
之前看的内容,占个位子,以后补上. ------------8月2日------------- 好久没看了,惭愧,今天抽了点时间重新看了Redis的字符串,一边写博客,一边看. Redis的字符串主要 ...
- 2015年1月最新中国行政区划县及以上代码mysql数据库
中华人民共和国国家统计局>> 行政区划代码>>mysql数据格式 截图如下 行政区划mysql数据库文件下载:nation.zip 转载:http://www.sdhack.c ...
- @Html.TextBox 的使用
@Html.TextBox( }); //限制 text 的最大输入字符数为 10个 @Html.TextBox("users","",new {@class= ...
- 【转】 GDB 常用调试方法
一.多线程调试 多线程调试可能是问得最多的.其实,重要就是下面几个命令: info thread 查看当前进程的线程. thread <ID> 切换调试的线程为指定ID的线程. break ...
- Postgresql 技巧
备份 pg_dump -f "F:/dump.sql"<file name> -U postgres<database name> -h 10.38.197 ...
- Servlet一次乱码排查后的总结(转)
原文地址:http://my.oschina.net/looly/blog/287255 由来 在写一个小小的表单提交功能的时候,出现了乱码,很奇怪request上来的参数全部是乱码,而从数据库查询出 ...
- [摘] SQLPLUS Syntax
You use the SQLPLUS command at the operating system prompt to start command-line SQL*Plus: SQLPLUS [ ...
- C#结合js 上传文件和删除文件(技术点有:asp.net mvc ,nhibernate,ajax等)
之前做项目的时候要用到上传文件的功能,现在我总结一下,上传文件和删除文件的代码,在以后的使用的过程中也更方便查找. [HttpPost] public ActionResult EditUser() ...
- jquery下拉列表选中项改变时获取新选项的属性值
$("#textSel").change(funtion(){ var selVal=$(this).val(); var selText=$("#textSel opt ...