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 ...
随机推荐
- 解决 Chrome 浏览器自动调整小于11px字体的问题
不知道说是 Chrome 智能呢?还是说它多此一举?Chrome 浏览器中存在默认会自动将小于11px大小的字体调整为12px.我在写 BlueNight 主题的最新评论时候就设置了评论发布时间为11 ...
- Redis的PHP操作手册
String 类型操作 string是redis最基本的类型,而且string类型是二进制安全的.意思是redis的string可以包含任何数据.比如jpg图片或者序列化的对象 $redis-> ...
- Spark小课堂Week1 Hello Spark
Spark小课堂Week1 Hello Spark 看到Spark这个词,你的第一印象是什么? 这是一朵"火花",官方的定义是Spark是一个高速的.通用的.分布式计算系统!!! ...
- LINQ to XML学习笔记
一.XML基础知识 1.XML:可扩展标记语言 Extensible Markup Language ,提供了一种保存数据的格式,数据可以通过这种格式很容易地在不同的应用程序之间实现共享. 2.使用X ...
- c# 赋值后最后一项数据部分丢失
赋值,赋值后 原因,在添加后立即调用clear()清除数据....
- Create a SharePoint Application Page for Anonymous Access
http://dishasharepointworld.blogspot.com/2011/07/how-to-create-sharepoint-application_1072.html http ...
- 文件/图片,批量上传【神器】--WebUploader
<system.web> <httpRuntime maxRequestLength="102400" executionTimeout="720&qu ...
- sql之透视
1.透视原理:就是将查询结果进行转置 下面就举例来说明: 执行下面语句:检查是否含有表 dbo.Orders,如果有就将表删除: if OBJECT_ID('dbo.Orders','U') is n ...
- Mybatis+SpringMVC的项目环境搭建
一.web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi=&qu ...
- 使用C#选择文件夹、打开文件夹、选择文件
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...