Kirarrr

导航

2019年2月25日 #

PAT A1020

摘要: PAT A1020 标签(空格分隔): PAT include include using namespace std; const int maxn = 100; int pos[maxn], in[maxn]; int n; struct node { int data; node lchild 阅读全文

posted @ 2019-02-25 16:42 Kirarrr 阅读(50) 评论(0) 推荐(0) 编辑

2019年2月19日 #

PAT A1103

摘要: PAT A1103 标签(空格分隔): PAT 解题思路 : DFS include include using namespace std; int n, k, p; int maxFacSum = 1; //记录最大因子和 vector ans, temp, fac; int power(int 阅读全文

posted @ 2019-02-19 11:14 Kirarrr 阅读(141) 评论(0) 推荐(0) 编辑

2019年2月15日 #

PAT A1046 Shortest Distance

摘要: PAT A1046 Shortest Distance 标签(空格分隔): PAT TIPS : 最后一个数据点可能会超时 阅读全文

posted @ 2019-02-15 18:15 Kirarrr 阅读(123) 评论(0) 推荐(0) 编辑

2019年2月8日 #

PAT A1059

摘要: PAT A1059 标签(空格分隔): PAT 解题思路 :先打印出素数表。利用结构体数组来存贮质因子的值和个数 如果i是x的质因子,就令fac[index].x = i(index是某个下标), fac[index].cnt = 0,然后 n = n / i。若又遇到i是x的质因子,则cnt++。 阅读全文

posted @ 2019-02-08 00:48 Kirarrr 阅读(97) 评论(0) 推荐(0) 编辑

2019年2月7日 #

PAT B1013

摘要: PAT B1013 标签(空格分隔): PAT 解法 :埃氏筛法 注意点: 1. 由于不知道第n个素数有多大,所以要用一个大的数组来储存结果。 2. 注意输出格式,末尾不能有多余空格 include const int maxn = 1000001; int prime[maxn], num = 0 阅读全文

posted @ 2019-02-07 10:45 Kirarrr 阅读(86) 评论(0) 推荐(0) 编辑

2019年1月31日 #

二分查找

摘要: ``` #include int binarySearch(int a[], int left, int right, int x) { int mid; while (left x) { right = mid - 1; } else { left = mid + 1; } } ... 阅读全文

posted @ 2019-01-31 01:02 Kirarrr 阅读(53) 评论(0) 推荐(0) 编辑

2019年1月30日 #

PAT B1023

摘要: PAT B1023 标签(空格分隔): PAT 解决方法 :贪心法 include int num[15]; int main() { for (int i = 0; i 0) { printf("%d", i); num[i] ; } } return 0; } 错误点在于,当不满足while条件 阅读全文

posted @ 2019-01-30 22:23 Kirarrr 阅读(90) 评论(0) 推荐(0) 编辑

PAT B1020

摘要: PAT B1020 解决思路 :贪心法,每次选取单价最高的月饼。 先上一个自己错误的解法 然后是题解 include include using namespace std; struct mooncake { double store; //库存 double sell; //总价 double 阅读全文

posted @ 2019-01-30 21:08 Kirarrr 阅读(145) 评论(0) 推荐(0) 编辑

回溯 八皇后

摘要: 回溯 八皇后 题意 棋子不能在同一行,同一列,以及同一对角线。 输出所有符合要求的情况。 步骤 :用计数器统计次数,按列写出全排列,再枚举任意两个棋子,如果不符合条件,则计数器不变。与直接递归不同的是,用到了剪枝技巧,如果不符合要求,则立即开始下一个状况 include include const 阅读全文

posted @ 2019-01-30 00:25 Kirarrr 阅读(80) 评论(0) 推荐(0) 编辑

递归 八皇后

摘要: 递归 八皇后 题意 棋子不能在同一行,同一列,以及同一对角线。 输出所有符合要求的情况。 步骤 :用计数器统计次数,按列写出全排列,再枚举任意两个棋子,如果不符合条件,则计数器不变。 include include const int maxn = 100; int n, p[maxn], hash 阅读全文

posted @ 2019-01-30 00:23 Kirarrr 阅读(100) 评论(0) 推荐(0) 编辑