自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(65)
  • 收藏
  • 关注

原创 1080. Graduate Admission (30)

在处理超出学校名额的情况仍然有可能录取的情况时,为每个学校加入一个变量以指示最后一个录入同学的排名,当后来的同学与这个排名相同时则不再考虑是否名额不够。#include #include #include #include using namespace std;struct School{ int quota; int rank; // the last one's

2016-02-28 21:05:10 578

原创 1079. Total Sales of Supply Chain (25)

建立好树结构后,从根结点走一遍DFS,碰到 retailer 加上其商品的钱数即可#include #include #include #include using namespace std;struct Node{ int id; int amount; vector neighbor; Node(){} Node(int i, int a) : id(i),

2016-02-28 19:45:03 742

原创 1078. Hashing (25)

考查散列表的二次探测再散列#include #include #include using namespace std;bool isPrime(int n){ if(n <= 1) return false; for(int i = 2; i*i <= n; ++i){ if(n%i == 0) return false; } return true;}

2016-02-28 19:08:14 284

原创 1077. Kuchiguse (20)

#include #include using namespace std;int main(){ int n; (cin >> n).get(); string common; for(int i = 0; i < n; ++i){ string s; getline(cin, s); if(i == 0) common = s; else{ stri

2016-02-28 16:24:42 298

原创 1076. Forwards on Weibo (30)

考虑BFS,需要注意的就是A follow B 形成的路径是 B->A,因为 A 关注 B 则 B发的微博可以被 A 转发,然后每次 query 的时候走一遍 BFS 查找。#include #include #include #include using namespace std;vector> graph;int main(){ int n, l, k; sca

2016-02-28 16:08:59 259

原创 1075. PAT Judge (25)

题目不难,就是加了很多限制条件,稍不留意容易出错。#include #include #include #include using namespace std;struct User{ int id, rank, total, perfect, s[6]; bool show; User() : id(0), rank(0), total(0), perfect(0

2016-02-28 15:35:47 284

原创 1073. Scientific Notation (20)

字符串处理#include #include #include using namespace std;int main(){ string s; cin >> s; if(s.empty()) return 0; bool neg = false; if(s[0] == '-'){ neg = true; s = s.substr(1); }else

2016-02-27 22:45:31 320

原创 1072. Gas Station (30)

Dijkstra计算单源出发到任意一点的最短路径,该处要找出所有加油站中离居民房的最小值最大的,故从所有的加油站出发均做一次 dijkstra 查找,然后进行后续操作。#include #include #include #include using namespace std;#define INF (~(1<<31))int n, m, k, ds;vector>

2016-02-27 21:24:19 257

原创 1071. Speech Patterns (25)

注意最后一个单词是随着字符串的结束而结尾的#include #include #include #include using namespace std;bool valid(char c){ return (c >= 'a' && c = '0' && c <= '9');}int main(){ string s; getline(cin, s); for

2016-02-27 15:06:49 372

原创 1070. Mooncake (25)

贪心选择#include #include #include #include using namespace std;struct Cake{ double tons; double money;};int main(){ int n, d; scanf("%d%d", &n, &d); vector cakes(n); for(int i = 0; i

2016-02-27 14:33:36 220

原创 1069. The Black Hole of Numbers (20)

注意保证始终是4位#include #include #include using namespace std;int str2num(string s){ int sum = 0; for(auto& c : s){ sum *= 10; sum += c - '0'; } return sum;}string num2str(int n){ str

2016-02-27 14:12:30 326

原创 1068. Find More Coins (30)

参考博客,动态规划求解,假设用 F(n, m) 表示从前 n 个硬币中挑选出能得到不超过 m 的最大和,则可以有如下递推式:F(n, m) = max(F(n-1, m), F(n-1, m - coins[n]) + coins[n])如果最终有 F(n, m) == m 则说明存在。    另外,记录路径,原博客方法比较巧妙,用 path(n, m) 表示在从前 n 个硬币选出一组

2016-02-27 13:04:47 303

原创 1067. Sort with Swap(0,*) (25)

当0在0位置时,如果其他的还未完全就位需要浪费一次交换机会。#include #include #include #include using namespace std;int findPos(vector& per, int st){ for(size_t i = st; i < per.size(); ++i){ if(per[i] != i)

2016-02-27 10:24:05 218

原创 1065. A+B and C (64bit) (20)

考虑溢出#include #include #include using namespace std;int main(){ int t; cin >> t; for(int i = 0; i < t; ++i){ long long a, b, c; cin >> a >> b >> c; bool x = a >= 0, y = b >= 0, z

2016-02-26 21:22:32 323

原创 1064. Complete Binary Search Tree (30)

将节点键值排序,然后确定根节点,每次求根节点左边节点数目,这样递归下去,然后用BFS层遍历。#include #include #include #include using namespace std;int deep(int n){ if(n <= 1) return 0; int h = 0; while(true){ if(n > (1<<h)

2016-02-26 20:16:25 297

原创 1063. Set Similarity (25)

统计出交集大小与并集大小,即可得出。#include #include #include #include using namespace std;int main(){ int n, m, k; scanf("%d", &n); vector> sets(n+1, set()); for(int i = 1; i <= n; ++i){ scanf("%d",

2016-02-26 17:13:08 319

原创 1062. Talent and Virtue (25)

考虑自定义比较#include #include #include #include using namespace std;struct man{ int id, talent, virtue; man(int i, int t, int v) : id(i), talent(t), virtue(v){}};int n, l, h;int level(ma

2016-02-26 16:47:43 201

原创 1061. Dating (20)

感觉,第一个相同的大写字母,第二个相同的字符,还是有歧义的,哎~#include #include #include using namespace std;unordered_map weekday = { {'A', "MON"}, {'B', "TUE"}, {'C', "WED"}, {'D', "THU"}, {'E', "FRI"}, {'F', "SA

2016-02-26 16:23:01 382

原创 1060. Are They Equal (25)

情况比较多,想比较快速做出来还是有难度的,索性将所有情况一一列举先判断有无小数点如果无小数点,则先去除前面的0,再做处理;如果有小数点,则分为 left 与 right 两部分,再做细分处理#include #include using namespace std;pair process(string s, int n){ auto pos = s.find('.');

2016-02-26 15:40:44 298

原创 1059. Prime Factors (25)

考虑值小于2的特殊情况#include #include #include #include using namespace std;int main(){ int n; cin >> n; if(n<=1){ printf("%d=%d", n, n); return 0; } map factors; int num = n

2016-02-26 14:07:48 314

原创 1058. A+B in Hogwarts (20)

进制加法#include #include using namespace std;int main(){ int g1,g2,s1,s2,k1,k2; scanf("%d%*c%d%*c%d %d%*c%d%*c%d", &g1, &s1, &k1, &g2, &s2, &k2); int k = (k1+k2)%29; int overflow = (k1+k2)/

2016-02-26 11:35:44 233

原创 1056. Mice and Rice (25)

模拟比赛淘汰机制#include #include #include #include using namespace std;vector> makeGroups(vector& mice, int ng){ if(mice.size() >(); int n = mice.size()/ng + (mice.size() % ng ? 1 : 0); vector

2016-02-26 11:25:19 229

原创 1055. The World's Richest (25)

先统一排序,再按照条件输出#include #include #include #include #include using namespace std;struct Person{ char name[10]; int age; int worth; Person(){} Person(char n[], int a, int w) : age(a), wo

2016-02-26 09:47:11 222

原创 1054. The Dominant Color (20)

利用直方图统计#include #include using namespace std;int colors[(1<<24)+1] = {0};int main(){ int m, n; scanf("%d%d", &m, &n); int dominant = -1; for(int j = 0; j < n; ++j){ for(int i = 0; i

2016-02-26 08:42:30 276

原创 1053. Path of Equal Weight (30)

#include #include #include #include #include using namespace std;int main(){ int n, m, s; scanf("%d%d%d", &n, &m, &s); vector weights(n); for(int i = 0; i < n; ++i){ scanf("%d", &weight

2016-02-25 23:03:16 307

原创 1052. Linked List Sorting (25)

特别注意,N虽然是正数,但并不一定都合法,所以有效节点个数可能为0,感觉这个在玩文字游戏,没意思。#include #include #include #include using namespace std;struct Node{ int address; int key; int next; Node(){} Node(int a, int k, int n

2016-02-25 21:15:17 393

原创 1051. Pop Sequence (25)

模拟压栈、弹栈操作,判断合法性#include #include #include using namespace std;int main(){ int m, n, k; scanf("%d%d%d", &m, &n, &k); for(int i = 0; i < k; ++i){ stack s; bool valid = true; int curr

2016-02-25 20:42:12 201

原创 1050. String Subtraction (20)

#include #include #include using namespace std;int main(){ string s1, s2; getline(cin, s1); getline(cin, s2); unordered_set chars; for(auto& c : s2) chars.insert(c); for(auto& c : s1)

2016-02-25 20:10:34 268

原创 1049. Counting Ones (30)

《编程之美》有具体分析。#include #include using namespace std;int ones(int n){ int sum = 0; int factor = 1; while(n/factor){ int lower = n - (n/factor)*factor; int curr = (n/factor) % 10; int h

2016-02-25 20:01:43 202

原创 1048. Find Coins (25)

#include #include #include using namespace std;int coins[1005] = {0};int main(){ int n, m, val; scanf("%d%d", &n, &m); for(int i = 0; i < n; ++i){ scanf("%d", &val); ++coins[val]; }

2016-02-25 19:19:25 244

原创 1047. Student List for Course (25)

用string存储的话会超时,故将名字Hash成整数存储#include #include #include #include #include using namespace std;int str2int(char name[]){ return (name[0]-'A'+10)*36*36*36 + (name[1]-'A'+10)*36*36 + (name[2]

2016-02-25 18:50:14 212

原创 1046. Shortest Distance (20)

#include #include #include using namespace std;int main(){ int n, m; scanf("%d", &n); vector cycle(n+1, 0); int sum = 0; for(int i = 1; i <= n; ++i){ int d; scanf("%d", &d); if(i <

2016-02-25 17:56:14 212

原创 1045. Favorite Color Stripe (30)

最长公共非连续子序列的变种#include #include using namespace std;int favorite[205] = {0};int stripe[10005] = {0};int matrix[10005][205] = {0};int n, m, l;int lcs(){ for(int i = 1; i <= l; ++i){

2016-02-25 16:22:50 672

原创 1044. Shopping in Mars (25)

直接双层循环会超时,后来才发现考察二分查找,钻石值存为和的形式,然后二分搜索。#include #include #include #include using namespace std;int search(int first, int& last, int m, vector& sum){ int left = first; int right = (int)sum

2016-02-25 14:07:28 309

原创 1043. Is It a Binary Search Tree (25)

直接对序列进行判断,第一个肯定是根结点(值为 val),然后如果第一个小于第二个元素则先假设该输入序列为一BST镜像树的preorder,若假设为BST则从序列的第二个元素开始,查找第一个 >= val 的元素,判断其后所有的元素是否也都 >= val是,则递归查找左子树,右子树,然后将val存储(模拟后序遍历)否,则直接return    若假设为BST的镜像树,则从序列

2016-02-25 10:32:42 297

原创 1042. Shuffling Machine (20)

#include #include #include using namespace std;string type[5] = {"S", "H", "C", "D", "J"};string idx[13] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13"};string num2car

2016-02-25 08:58:24 315

原创 1040. Longest Symmetric String (25)

实际是求最长公共子串#include #include #include #include using namespace std;string maxSubString(string s1, string s2){ int xlen = (int)s1.size(), ylen = (int)s2.size(); vector> m(xlen, vector(ylen,

2016-02-24 21:26:51 411

原创 1039. Course List for Student (25)

直接用 string 存储名字会由于C++的 cin, cout IO效率问题导致最后一个case超时,于是改为char数组存储名字,然后Hash为整数,再创建映射。#include #include #include #include #include using namespace std;int Hash(char *name){ return (name[0]-'

2016-02-24 20:57:11 239

原创 1038. Recover the Smallest Number (30)

#include #include #include #include using namespace std;struct Segment{ string s; Segment(string s) : s(s){} bool operator < (const Segment& rhs) const{ return s + rhs.s < rhs.s + s; }}

2016-02-24 17:33:05 226

原创 1037. Magic Coupon (25)

#include #include #include #include using namespace std;vector couponP;vector couponN;vector productP;vector productN;int main(){ int nc, np; scanf("%d", &nc); for(int i = 0; i < nc; +

2016-02-24 16:54:59 223

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除