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 ...
随机推荐
- Web开发常见的漏洞
SQL注入漏洞 跨站脚本攻击漏洞 登陆后台管理页面 IIS短文件/文件夹漏洞 系统敏感信息泄露
- Apache多站点设定
多端口 vi httpd.conf Listen 8090 <VirtualHost *:8090> ServerName localhost Documentroot "/Us ...
- 搭建pptpd实现vpn
PPTP(Point to Point Tuneling Protocol,点对点隧道协议)是一种主要用于VPN的数据链路层网络协议. 环境:debian 7.0 在linux下安装pptpd服务实现 ...
- Openvpn完美解决公司网络没有固定公网IP的问题
方案背景: 公司办公网络使用长城宽带上网有一段时间了,有4个固定IP(2个电信,2个网通),链路不太稳定,经常有问题,因此考虑取消长城宽带,采用原来的adsl上网.但是有个问题,因为公司内网有几台服务 ...
- 008.ComputeReplacement
Delphi function ComputeReplacement: UTF8String; 类型:function 可见性:public 所在单元:System.RegularExpression ...
- Android UI学习前言:Android UI系统的知识结构
Android UI系统的知识结构如下图所示: 对于 一个GUI系统地使用,首先是由应用程序来控制屏幕上元素的外观和行为,这在各个GUI系统中是不相同的,但是也具有相通性.Android系统在这方面, ...
- 电网SVG简介
目 录1. 范围 12. 规范性引用文件 13. 缩略语 14. 本标准涉及的图形交换特征 ...
- 【转】perl如何避免脚本在windows中闪一下就关闭
写好了perl程序,运行后,准备等待结果输出时,结果双击后,看到屏幕闪了一下,然后什么都没有了,根本没有机会然你看到输出的结果 当你刚开始学习perl的时候,写好了程序,准备兴高采烈的等待结果输出时, ...
- 备份了一个nginx的虚拟主机配置文件报错
[root@localhost vhost]# service nginx restart 停止 nginx:[确定] 正在启动 nginx:nginx: [warn] conflicting ser ...
- C#时间戳与时间互转
/// <summary> /// 时间戳转成时间类型 /// </summary> /// <param name="timeStamp">& ...