- 博客(41)
- 收藏
- 关注
原创 PAT 1099. Build A Binary Search Tree (30)
#include#include#include#includeusing namespace std;ifstream fin("1099.txt");//#define cin finstruct node{ int data; int left,right; node(){ left=right=-1; }}nd[101];queue que;void in_
2015-10-15 23:36:27 403
转载 (转) TCP为什么要三次握手,不是两次四次?
http://blog.chinaunix.net/uid-20726927-id-2455485.html关于“三次握手“的例子 讲得很好 茅塞顿开第三次握手——革命斗争中的通信故事在革命战争影片中,经常会看到英勇的解放军战士背着步话机在喊“长江长江,我是黄河,听到请回答。”很明显,这是呼号为黄河的一方想找呼号为长江的另一方说事,为了保证影片的节奏
2015-04-01 16:54:53 430
原创 PAT 1093. Count PAT's (25)
#include#include#includeusing namespace std;char s[100005];class LR{public: int cnt_p; int cnt_t;};vector list;int main(){ cin.getline(s, 100005); int size = strlen(s); int p = 0, t = 0;
2015-03-14 18:13:15 453 1
原创 PAT (MOOC) 06-5. 关键活动 (30)
#include#include#include#include#include#includeusing namespace std;//ifstream fin("06-4.txt");//#define cin fin#define MAX 101typedef struct eg *ed;typedef struct ee *e;struct ee{ int s,
2015-02-09 12:15:36 424
原创 PAT(MOOC-数据结构) 06-4. How long does it take (25)
#include#include#includeusing namespace std;//ifstream fin("06-4.txt");//#define cin fin#define MAX 101typedef struct edge *ed;struct edge{ int weight;}edge[MAX][MAX];int n, m;int start, e
2015-02-09 10:16:52 510
原创 Coursera课程-机器学习基石作业一Q18-Q20(pocket on D算法 for PLA/C++ edition)
搞了两天,到现在终于调通了~~~其实很简单 但毕竟第一次用程序实现数学问题 昨天的Q15-17(PLA)还比较顺利 后来的pocket算法就一直搞不通(always the same value---0.297999/0.391 )除了题意理解有偏差 后期程序肯定是哪个细节错了 换到笔记本上重写了一遍 很顺利啦 loop2000的情况下每次都在0.2的错误率以下噢程序肯定是不优美的,刚
2014-12-25 14:26:48 1141
原创 PAT 1089. Insert or Merge (25)
#include#include#include#include#include#include#include#include#include#include#includeusing namespace std;ifstream fin("1089.txt");//#define cin fin#define MAX 105int n;int num1[MA
2014-12-01 17:17:34 817
原创 PAT 1090. Highest Price in Supply Chain (25)
#include#include#include#include#include#include#include#include#include#include#includeusing namespace std;ifstream fin("1090.txt");//#define cin fin#define MAX 100005int n;double p
2014-11-30 16:10:44 409
原创 PAT 1088. Rational Arithmetic (20)
一个测试点错误,目前还没找出来考试时这道题都懒得做。。实在太麻烦 感觉出这种题挺没意义的#define MAX1 100005#define MAX2 1015#include#include#include#include#include#include#include#include#include#include#includeusing namespac
2014-11-30 14:15:00 596
原创 PAT 1030. Travel Plan (30)
#include#include#include#define MAX 501#define MAXWEIGHT 250005using namespace std;int n, m, s, d;int adj_dis[MAX][MAX] = { 0 };int adj_cost[MAX][MAX] = { 0 };int min_len = MAXWEIGHT, min_cos
2014-11-15 11:05:53 302
原创 PAT 1051. Pop Sequence (25)
#includeusing namespace std;#includeint m,n,k;#define MAX 1005class Stack{public: //int capacity; vector list; int top; int size() { return this->list.size(); }
2014-11-14 11:22:19 274
原创 PAT 1043. Is It a Binary Search Tree (25)
//1043. Is It a Binary Search Tree ?#includeusing namespace std;#define MAX 1005int prelist[MAX];class Node{ public: int data;Node* left,*right; Node(int data) { this->da
2014-11-13 15:30:01 363
原创 PAT 1027. Colors in Mars (20)
//很不好看的简单代码。。#includeusing namespace std;int a, b, c;char s[2];void to_13(int num){ int b0 = num / 13, b1 = num % 13; if (b0 >= 10) s[0] = b0 - 10 + 'A'; else s[0] = b0 + '0'; if (b1 >=
2014-11-04 13:23:24 356
原创 PAT 1015. Reversible Primes (20)
//AC #include#include#includeusing namespace std;int n, d;bool isprime(int m){ if (m == 1) return false; double n = sqrt(double(m)); for (int i = 2; i <= n; i++){ if (m%i == 0){ return fal
2014-10-31 20:24:24 280
原创 PAT 1014. Waiting in Line (30)
//AC//看了别人的代码模仿的,发现也并不是很复杂#include#include#include#define customer_max 1000+5using namespace std;queue que[20 + 5];int leavetime[customer_max] = { 0 };int processtime[customer_max] = { 0 };
2014-10-31 12:25:11 314
原创 PAT 1013. Battle Over Cities (25)
#includeusing namespace std;int N, M, K;int road[1000][1000] = { 0 };int tmp_road[1000][1000] = { 0 };int vst[1000] = { 0 };int cnt = 0;void dfs(int i){ vst[i] = 1; for (int j = 1; j <= N; j+
2014-10-30 16:48:21 325
原创 PAT 1009. Product of Polynomials (25)
#include#include#includeusing namespace std;float num[2001] = { 0 };int cnt = 0;int main(){ vector exp1; vector coef1; int k; cin >> k;// exp1.resize(k); 加上这两句答案会错误,为何?// coef1.resize(k);
2014-10-29 23:29:41 257
原创 PAT 1007. Maximum Subsequence Sum (25)
#includeusing namespace std;int k;int arr[10005];int sum = 0, MAX;int start = 0, dest = 0;int main(){ cin >> k; for (int i = 0; i < k; i++) cin >> arr[i]; MAX = arr[0]; for (int i = 0; i <
2014-10-29 13:39:37 269
原创 PAT 1006. Sign In and Sign Out (25)
//排序是不必要的 但是为了f也做了#include#include#include#includeusing namespace std;struct person{ char id[16]; int signin, signout;};bool cmp1(const person& p1, const person& p2){ return p1.signin < p2.s
2014-10-29 12:30:32 299
原创 PAT 1002. A+B for Polynomials (25)
#include#includeusing namespace std;//int exp[1005]={0};float coef[1005]={0};int main(){ int a,b;cin>>a; for(int i=0;i<a;i++){ int tmp;float tmp_coef; cin>>tmp>>tmp_coef; coef[tmp
2014-10-29 11:31:46 236
原创 PAT 1003. Emergency (25)
#include#includeusing namespace std;int n, m, C1, C2;vector team, path;int road[501][501] = { 0 };//如果为0是该两点间没有路int len = 0;int vst[501] = { 0 };int helpers = 0, minpath = -1, cnt = 0, maxhelp
2014-10-29 10:43:42 261
原创 PAT 1076. Forward on Weibo (30)
#include#include#includeusing namespace std;struct users{ int size; vector follow;}usr[1001];bool visit[1001] = { false };queue que;int itg_to_level[1001] = { 0 };int n, l;int k;int cnt
2014-10-26 23:40:32 403
原创 PAT 1004. Counting Leaves (30)
#include#includeusing namespace std;class Node{public: int id; int level; Node *child, *sibling; Node(int _id){ this->id = _id; this->child = NULL; this->sibling = NULL; } Node(){ th
2014-10-21 21:10:43 267
原创 PAT 1073. Scientific Notation(20)
//一次AC#include#includeusing namespace std;char num[10010];int len;bool exp_sign = true;int toitg(int i){ int result = 0; while (i < len){ result *= 10; result += num[i] - '0'; ++i; }
2014-10-18 22:34:28 277
原创 PAT 1079. Total Sales of Supply Chain (25)
//全部改成double后,还剩3 points超时。。没办法啊#includeusing namespace std;int n;double p, r;double total = 0;struct Node{ bool isretailer; int data; int parent; double amount;}node[100005] = { false, 0,
2014-10-18 10:57:27 244
原创 PAT 1078. Hashing (25)
//二次探测,只考虑正向探测//注意10001、10003都是非质数,直到10007才是质数#include#includeusing namespace std;int msize, nsize;int table[10007] = { 0 };bool first = true;bool isprime(int n){ if (n == 1){ return 0; } do
2014-10-17 20:57:53 343
原创 PAT 1074. Reversing Linked List
//PAT 1074 提交结果未出//除了依次查找交换不知道有何种排序方法//直接用sort可否实现?#include #include#includeusing namespace std;struct Node{ int address,next; int data;}node[100005];/*bool cmp(const Node& a,const Node& b){
2014-10-17 18:54:17 497
原创 PAT 1077. Kuchiguse (20)
#include#include#includeusing namespace std;char tmp1[260], tmp2[260];int len1, len2;int main(){ int n; cin >> n; getchar(); cin.getline(tmp1, 260); len1 = strlen(tmp1); fo
2014-10-16 20:00:37 654
原创 PAT 1083. List Grades(25)
#include#include#includeusing namespace std;const long N = 999999;struct student{ char name[15]; char id[15]; int grade;}stu[N];bool cmp(const student& s1, const student& s2){/
2014-10-16 17:22:06 324
原创 PAT 1082. Read Number in Chinese(25)
//3 points not passed...#include#include//#includeusing namespace std;char num[11];char chinese_digit[10][5] = { "ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu" };char ch
2014-10-16 15:49:44 265
原创 PAT 1020. Tree Traversals(25)
#include#includeusing namespace std;class Node{public: int data; Node* left, *right; Node(int data, Node* left = nullptr, Node* right = nullptr){ this->data = data; this->left
2014-10-16 10:29:27 316
原创 PAT 1081. Rational Sum(20)
#includeusing namespace std;int n;long a1, b1, a2, b2;long gcd(long a, long b){ if (b while (b != 0){ long k = a%b; a = b; b = k; } return a;}int main(){ cin >> n;
2014-10-16 10:27:26 404
原创 PAT 1086. Tree Traversal Again (25)
//树的问题核心是以不同的形式给出,让你构造出唯一的一棵(二叉)树,然后再遍历输出#include#includeusing namespace std;int n, cnt = 0;bool first = true;class Node{public: int val; Node* left; Node* right; Node(int _v
2014-10-15 21:55:49 391
原创 PAT 1085. Perfect Sequence (25)
//一开始没有理解题意 以为只是从原序列中截取 其实是从中找出数字重新组成新序列//此题考查: 排序,(二分)查找//max(a,b)可直接用#include#include#includeusing namespace std;int n;long p;long tmp;vector vt;/*int binary_search(vecto
2014-10-15 21:46:57 327
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人