- 博客(32)
- 收藏
- 关注
原创 PAT 1033. To Fill or Not to Fill (贪心)
PAT-A的最后一题,终于做出来了... 是贪心,通过局部最优获得全局最优。1.
2014-05-31 07:57:31 2133
原创 LeetCode 150. Evaluate Reverse Polish Notation
后缀表达式。1. 用一个stack维护数字栈,mei
2014-05-29 06:13:33 813
原创 LeetCode 151. Reverse Words in a String
1. 句子开头和末尾的空格要去掉2. 单词间的多个空格要变为一个空格带阿妈
2014-05-29 05:33:44 738
原创 PAT-B 1024. 科学计数法(同PAT 1073. Scientific Notation)
同PAT 1073. Scientific Notation字符串模拟,不难的。先用字符串digits记录所有的数字,可确保有效位数不变;再用整型exp记录指数大小。我在处理那种结果中不带小数点的时候出现了错误 —— exp + 1 >= digits.size(), 即exp + 1 时就会出现不带小数点的情况,此时cout.width的参数应为(
2014-05-27 04:59:47 725
原创 PAT-B 1021. 个位数统计
用字符串存输入,遍历后输出即可。代码:#include #include using namespace std;int main(){ string s; int cnt[10] = {0, 0}; cin >>s; for (size_t i = 0; i < s.size(); ++ i) { ++ cnt[s[i]-48]; } for (
2014-05-27 04:45:53 726
原创 PAT-B 1020. 月饼(同PAT 1070. Mooncake)
给出n堆月饼的重量和总价 -- 可求每吨的均价给出总共的购买量d, 求可获得的最大利润很简单的。求均价后排降序,从均价最高的开始购入。1. 基础知识不牢固,scanf double时是用 %lf 标识2. 对struct排序时,并不调用struct的成员函数代码:
2014-05-26 14:21:11 956
原创 PAT-B 1016. 部分A+B
依题意做就行。da:#include using namespace std;int main(){ int a, da, b, db, pa=0, pb=0; cin >> a >> da >> b >> db; for ( ; a != 0; a /= 10) { if (a % 10 == da) { pa = pa*10 + da; }
2014-05-25 12:28:57 726
原创 PAT-B 1015. 德才论(同PAT 1062. Talent and Virtue)
和A-level的1062. Talent and Virtue相同,依照ti
2014-05-25 11:05:50 1288
原创 PAT-B 1014. 福尔摩斯的约会(python, C++)
python提交后竟然WA: 返回非零,不知道怎么搞,还是回到C的怀抱做题好了 —— py
2014-05-25 03:19:18 1163
原创 PAT-B 1011. A+B和C(python)
python好像不用考虑溢出?或者说能表示范围很大的数(用字符串的形式),suo;C++的话用long long即可
2014-05-21 00:28:08 1366
原创 PAT-B 1008. 数组元素循环右移问题(python)
if __name__ == "__main__" : num = raw_input().split(' ') n = int(num[0]) m = - int(num[1]) num = raw_input().split(' ') while m + n <= 0 : m = m + n for i in range(n)
2014-05-19 04:47:53 3445
转载 python中print的不换行即时输出解决方案
本文原创自esbat的博客,转载请注明出处python中的print默认是换行的想要不换行输出有两种办法:1.print后加上","############################>>>print "Hello World",############################2.使用sys.stdout.write命令#################
2014-05-15 13:18:22 3092
原创 PAT-B 1002. 写出这个数 (python)
1. dictionary初始化 dic = {}2. list初始化 ans = {}3. list遍历时两种方法1)
2014-05-15 13:15:44 1875
原创 PAT-B 1001. 害死人不偿命的(3n+1)猜想 (python)
1. 到python主页下载py2 -- py3的话库可能少些,之前书本里的例子也跑不起来。2. python用空格缩进,不用分号分割语句3. while, if后要加冒号4. input, print函数的使用5. main函数不用return ...源码:if __name__ == "__main__": n = input() cnt = 0
2014-05-14 11:12:39 2686 1
原创 PAT 1018. Public Bike Management (dijkstra + dfs + 剪枝)
If there are more than one shortest path, the one that requires the least number of bikes sent from PBMC will be chosen.Note that if such a path is not unique, output the one that requires min
2014-05-07 12:24:10 1624
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人