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 ...
随机推荐
- Facebook SDK
<?php session_start(); header('Content-type:text/html; charset=UTF-8'); require_once './facebook- ...
- ecshop 全站自定义title标题
对于SEO来说,能让标题自定义的将会大大增加SEO效果,提高独立商城的流量,今天小编就收集从网上弄来ecshop全站自定义代码,很全哦! 1.Ecshop商品分类页如何实现自定义Title 最近发现很 ...
- ubuntu14.04 中文输入法无法使用
说下我的解决方法吧,我是忘了在All Settings -> Text Entry 的 Input sources to use中添加Chinese(Pinyin)了,添加后就好了. from: ...
- 实现c++的string的split功能
今天写程序,遇到了一个要实现string.split()这个的一个函数.python里面有,qt里面有,c++里面没有.照着网上抄了一个,放在这里.有需要的时候直接拽过去用,否则老是写了小例子就扔,用 ...
- 零基础学Python 3之环境准备
一. 配置python 3 环境 1. Python 3 下载 64位 https://www.python.org/ftp/python/3.4.2/python-3.4.2.amd64.msi 3 ...
- ofbiz进阶之框架配置文件指导
The Open For Business Project: Framework Configuration Guide 原文链接:http://ofbiz.apache.org/docs/corec ...
- Session_set_save_handler 之 文本模式实现
1.构建session抽象类,实现Session_set_save_hanlder函数必须的基础函数 <?php /* 实现session利用文件形式或者数据库等其它形式进行存储操作 * aut ...
- easy ui datagrid 设置冻结列
为了冻结列,您需要定义 frozenColumns 属性.frozenColumn 属性和 columns 属性一样. $('#tt').datagrid({ title:'Frozen Column ...
- EXTJS 4.2 资料 跨域的问题
关于跨域,在项目开发中难免会遇到:之前笔者是用EXTJS3.0开发项目的,在开发过程中遇到了关于跨域的问题,但是在网上找到资料大部分都是ExtJs4.0以上版本的 在ExtJs中 例如:Ext.Aja ...
- 运行windows系统工具命令
appwiz.cpl 卸载/安装程序 wscui.cpl 操作中心 inetcpl.cpl 查看Internet属性 eventvwr 查看监视消息和疑难解答消息 taskmgr 任 ...