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 ...
随机推荐
- Linux定时任务crontab每三秒执行一次shell
第一种方法:当然首先想到的是写一个触发的脚本,在触发脚本中使用死循环来解决此问题,如下: cat kick.sh #!/bin/bash while : ;do /home/somedir/scrip ...
- Kakfa揭秘 Day7 Producer源码解密
Kakfa揭秘 Day7 Producer源码解密 今天我们来研究下Producer.Producer的主要作用就是向Kafka的brokers发送数据.从思考角度,为了简化思考过程,可以简化为一个单 ...
- 【WPF】Application应用程序启动
wpf应用程序在启动的时候会自动创建Main函数并调用Application实例的run(),从而启动Application进程.Main函数在一个App.g.cs文件中,App.g.cs文件的位置在 ...
- asp.net项目中通过Web.config配置文件及文件夹的访问权限---forms
十分全面的forms验证配置: http://blog.csdn.net/qingyun1029/article/details/6184723
- win32进程间通讯--共享内存
小白一枚,如有不对,请各位大神多多指教! 最近看了看win32进程间通讯.简单写了写利用共享内存实现进程间通讯 使用共享内存实现进程间通讯: 1.在WM_CREATE消息下创建文件映射内核对象 hMa ...
- PL/SQL数据导入导出浅谈(1)
近来需要通过PL/SQL向Oracle中导数据,特此总结一下 试例表:test 字段:id;name;org; 1.直接复制粘贴(当数据量不是特别大的时候) 1)使用select * from tes ...
- 在Qt Creator中添加OpenCV库
在项目的pro文件中添加如下代码:INCLUDEPATH += D:/opencv/build/include win32:CONFIG(debug, debug|release): {LIBS += ...
- ios NavBar+TarBar技巧
NavBar+TarBar iphone开发 NavBar+TarBar 1 改变NavBar颜色:选中Navigation Bar 的Tint属性.选中颜色. 2 隐藏“back”按钮: sel ...
- EXTJS4.2 chart 柱状图
chart 柱状图 Ext.require('Ext.chart.*'); Ext.require(['Ext.Window', 'Ext.fx.target.Sprite', 'Ext.layout ...
- chm文件打开,有目录没有内容
下载下来的一些chm文件,打开的是否提示“打开此文件前总是询问”,不理睬直接打开后,只有目录,页面内容都显示“已取消到本页的导航”.原因是该CHM文件的发行商未知,将“打开此文件前总是询问”选项取消后 ...