Divisible by Seven CodeForces - 376C (数论)
You have number a, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divisible by 7.
Number a doesn't contain any leading zeroes and contains digits 1, 6, 8, 9 (it also can contain another digits). The resulting number also mustn't contain any leading zeroes.
The first line contains positive integer a in the decimal record. It is guaranteed that the record of number a contains digits: 1, 6, 8, 9. Number a doesn't
contain any leading zeroes. The decimal representation of number a contains at least 4 and at most 106 characters.
Print a number in the decimal notation without leading zeroes — the result of the permutation.
If it is impossible to rearrange the digits of the number a in the required manner, print 0.
- 1689
- 1869
- 18906
- 18690
- //这道题的思路就是(1).如果在没有0的情况下把1689的任意组合放在后四位,而且1689的组合对1,6,8,9都只取一次
- //然后把剩下的数放在前面,这些数对7取余只有0~6这几种情况,所以把这些数对7取余之后的余数再与
- //1689的任意组合放在一起,看看哪种组合可以对7取余等于0.
- //(2).当输入的数中有0的话,计算一共有多少个0,然后再进行1中的过程,不过把0最后输出就行了
- #include<queue>
- #include<stack>
- #include<vector>
- #include<math.h>
- #include<stdio.h>
- #include<numeric>//STL数值算法头文件
- #include<stdlib.h>
- #include<string.h>
- #include<iostream>
- #include<algorithm>
- #include<functional>//模板类头文件
- using namespace std;
- const int INF=1e9+7;
- const int maxn=1010000;
- char str[maxn],a[maxn];
- char xsk[10][5]= {"1869","1968","1689","6198","1698","1986","1896"};//对7取余,余数为0~6的组合情况
- int s1,s2,s3,s4;
- int main()
- {
- while(~scanf("%s%*c",str))
- {
- s1=s2=s3=s4=1;
- int t=0,sum1=0,sum2=0;
- int len=strlen(str);
- for(int i=0; i<len; i++)
- if(str[i]=='0')
- sum1++;
- for(int i=0; i<len; i++)
- {
- if(str[i]=='0') continue;
- if(str[i]=='1'&&s1)
- {
- s1--;
- continue;
- }
- if(str[i]=='6'&&s2)
- {
- s2--;
- continue;
- }
- if(str[i]=='8'&&s3)
- {
- s3--;
- continue;
- }
- if(str[i]=='9'&&s4)
- {
- s4--;
- continue;
- }
- a[t++]=str[i];
- sum2=(sum2*10+str[i]-'0')%7;
- }
- printf("%s",a);
- if(sum2==0)printf("%s",xsk[0]);
- if(sum2==1)printf("%s",xsk[3]);
- if(sum2==2)printf("%s",xsk[6]);
- if(sum2==3)printf("%s",xsk[2]);
- if(sum2==4)printf("%s",xsk[5]);
- if(sum2==5)printf("%s",xsk[1]);
- if(sum2==6)printf("%s",xsk[4]);
- for(int i=0; i<sum1; i++)
- printf("0");
- printf("\n");
- }
- return 0;
- }
Divisible by Seven CodeForces - 376C (数论)的更多相关文章
- CodeForces 300C --数论
A - A Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- CodeForces 359D (数论+二分+ST算法)
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=47319 题目大意:给定一个序列,要求确定一个子序列,①使得该子序 ...
- Codeforces 264B 数论+DP
题目链接:http://codeforces.com/problemset/problem/264/B 代码: #include<cstdio> #include<iostream& ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem F (Codeforces 831F) - 数论 - 暴力
题目传送门 传送门I 传送门II 传送门III 题目大意 求一个满足$d\sum_{i = 1}^{n} \left \lceil \frac{a_i}{d} \right \rceil - \sum ...
- CodeForces 1202F(数论,整除分块)
题目 CodeForces 1213G 做法 假设有\(P\)个完整的循环块,假设此时答案为\(K\)(实际答案可能有多种),即每块完整块长度为\(K\),则\(P=\left \lfloor \fr ...
- Vasya and Beautiful Arrays CodeForces - 354C (数论,枚举)
Vasya and Beautiful Arrays CodeForces - 354C Vasya's got a birthday coming up and his mom decided to ...
- Neko does Maths CodeForces - 1152C 数论欧几里得
Neko does MathsCodeForces - 1152C 题目大意:给两个正整数a,b,找到一个非负整数k使得,a+k和b+k的最小公倍数最小,如果有多个k使得最小公倍数最小的话,输出最小的 ...
- Codeforces 716C[数论][构造]
/* CF傻逼构造题 某人要经过n回合游戏,初始分值是2,等级为1. 每次有两种操作 1.无条件,分值加上自己的等级数. 2.当目前的数字是完全平方数并且该数字开方以后是等级数加1的整数倍,那么可以将 ...
- Codeforces 376C. Socks
C. Socks time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
随机推荐
- JAVA多线程提高二:传统线程的互斥与同步&传统线程通信机制
本文主要是回顾线程之间互斥和同步,以及线程之间通信,在最开始没有juc并发包情况下,如何实现的,也就是我们传统的方式如何来实现的,回顾知识是为了后面的提高作准备. 一.线程的互斥 为什么会有线程的互斥 ...
- SSM框架整合遇到的问题
1.Maven中Dubbo集成spring2.5以上版本 项目中dubbo集成spring4.x,配置pom时需要注意排除spring的依赖,我这里用的是tomcat,所以把jboss也排除了: &l ...
- Spring 5.0
Spring 5.0都有什么新功能? 1.最低要求支持JDK8+, J2EE 7+. 2.移除了一些包.类及方法. 3.核心功能加强:全面应用jdk8并兼容jdk9等. 4.SpringMVC:支持s ...
- 51nod 1161 Partial Sums
给出一个数组A,经过一次处理,生成一个数组S,数组S中的每个值相当于数组A的累加,比如:A = {1 3 5 6} => S = {1 4 9 15}.如果对生成的数组S再进行一次累加操作,{1 ...
- [BZOJ2809&1455&1367]解题报告|可并堆
其实非常好理解..就是可以可以合并起来的两个堆嘛>< 2809: [Apio2012]dispatching Description 在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依 ...
- Oracle笔记之用户管理
1. 创建用户 创建用户使用create user语句,需要DBA权限: CREATE USER tom IDENTIFIED BY mot; 2. 更改用户密码 修改别人的密码需要DBA权限,或者a ...
- kendo method:destroy 解决有些在kendo.all.js 的js 库里报错问题
首先,不得不承认,kendo UI 是个不错的东西,特别对于一个前端开发到行不足的程序猿来说.而在我们使用过程中貌似还是会遇到各种奇怪的问题.比如我们会经常用到对一些控件进行重赋值. destroy ...
- git服务器的简单搭建
安装git 安装git,参考:https://git-scm.com/book/zh/v1/%E8%B5%B7%E6%AD%A5-%E5%AE%89%E8%A3%85-Git 创建git仓库 使用ro ...
- python 协程嵌套
import asyncio import time now = lambda: time.time() async def do_some_work(x): print('Waiting: ', x ...
- Ubuntu下安装Sublime Text3
1. 下载软件 Ctrl+Alt+T 调出命令窗口执行下面命令下载安装包: sudo add-apt-repository ppa:webupd8team/sublime-text-3 2. 更新软件 ...