Codeforces 375A
这是一道数学题,真是很考验数学思维,之前也遇到过相似的问题,但是依然是想不到点子上,就这提而言,最重要的就是
能否发现由 1, 6, 8,9这四个数字组成的排列对7取模是可以得到0, 1, 2, 3, 4, 5, 6的。
也许这就是经验。。。。
找到思路了。
不要高兴太早。随之而来的就是效率问题。py效率本来就是被人们诟病的,提交的n次全TLE。。。我当然知道py的字符串是很慢的
所以应该减少字符串的操作。。然后就顺利的擦边了。。842ms
附上我的AC代码,有朋友效率更高的话,欢迎指点,谢谢!
a = map(int, raw_input());
cnt = [0] * 10;
c = [1869, 1968, 1689, 6198, 1698, 1986, 1896];
sz = len(a); for i in xrange(sz):
cnt[a[i]] += 1;
if cnt[0] == sz - 4:
print "" + "" * cnt[0];
else:
cnt[1] -= 1;
cnt[8] -= 1;
cnt[6] -= 1;
cnt[9] -= 1;
res = 0;
s = "";
for i in xrange(9, -1, -1):
s += str(i) * cnt[i];
for j in xrange(0, cnt[i]):
res = (res * 10 + i) % 7;
print s + str(c[(7 - res * 10000 % 7) % 7]);
Codeforces 375A的更多相关文章
- CodeForces - 375A Divisible by Seven(数学)
https://vjudge.net/problem/48715/origin 题意:给出必定含1689四个数字的字符串,随意交换位置构造出能被7整除的数. 分析:数学思维题.观察发现1689的排列与 ...
- 【Codeforces 375A】Divisible by Seven
[链接] 我是链接,点我呀:) [题意] 让你把一个包含数字1,6,8,9的数字重新组合,使得组合成的数字能被7整除 [题解] 我们先提取出来1,6,8,9各1个 然后把剩余的len-4个数字除了0之 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
随机推荐
- js 面向对象类
类的声明 继承的几种方法 类的声明 第一种 function car(){ this.name = 'name'; } 第二种.es6中新添加的 class car(){ constructor(){ ...
- intellij idea中去除@Autowired注入对象带来的下划线提示
场景: idea中通过@Autowired注入的对象一直有下划线提示,虽然不影响运行 解决:改变@Autowired的检查级别即可. 快捷键:Ctrl+Alt+s,进入idea设置界面,输入inspe ...
- Windows API 第四篇 文件操作
创建或打开文件(也可用于打开管道,油槽,硬件设备等): HANDLE CreateFile( LPCTSTR lpFileName, // file name DWORD dwDesiredAcces ...
- 廖雪峰Java10加密与安全-4加密算法-1对称加密算法
1.对称加密算法 加密和解密使用同一个密钥,例如WinRAR. WinRAR在对文件进行打包的时候,可以设置一个密码,在解压的时候需要使用同样的密码才能正确的解压. 加密:encrypt(key,me ...
- 理解最短路径-Dijkstra算法
最短路径—Dijkstra算法和Floyd算法 透彻理解迪杰斯特拉算法 Dijkstra算法的使用条件:图中不存在负权边. ---------------------------有待验证------- ...
- Ionic Cordova Sqlite 实现保存用户名登陆
1.添加sqlite 组件 cordova plugin add https://github.com/litehelpers/Cordova-sqlite-storage.git --save 2. ...
- BM线性递推
#include<bits/stdc++.h> using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++) #defi ...
- Ubuntu为什么远程连接不上
因为没有安装ssh,输入以下命令, sudo apt-get install openssh-server openssh-client执行完再用xshell就可以连接上了
- python collections 模块 之namedtuple
namedtuple collections.namedtuple(typename, filed_name, *, rename=False, module=None) 创建一个以 typename ...
- SpringBoot防XSS攻击
1 . pom中增加依赖 <!-- xss过滤组件 --> <dependency> <groupId>org.jsoup</groupId> < ...