3.1
谷歌新推的15小时速成机器学习教程
学了一会儿发现比看论文专注多了qaqaq
3.2
可以免费考ccf于是还是想去试一下
在官网刷了一套...发现也没有那么简单的qaqaqa
3.3
由于基础太差所以要换组了qaq
3.4
2013.12ccf
A.出现次数最多的数
水
B.ISBN号码
水
C.最大的矩形
正解是扫一遍,自己写的线段树查询一个区间的最小值,就O(n2logn)水果
D.有趣的数
这题不会qaq,最开始一直想组合的方法...想的很麻烦...然后是dp来做,状态定义没有想到
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; typedef long long LL; const int mod = 1e9 + 7; LL dp[1005][15]; int n; int main() { scanf("%d",&n); memset(dp,0,sizeof(dp)); for (int i = 1;i <= n;i++) { dp[i][1] = 1; dp[i][2] = (dp[i-1][2] * 2 + dp[i-1][1]) % mod; dp[i][3] = (dp[i-1][3] + dp[i-1][1]) % mod; dp[i][4] = (dp[i-1][4] * 2 + dp[i-1][2]) % mod; dp[i][5] = (dp[i-1][5] * 2 + dp[i-1][2] + dp[i-1][3]) % mod; dp[i][6] = (dp[i-1][6] * 2 + dp[i-1][5] + dp[i-1][4]) % mod; } //cout << dp[n][6] << "\n"; //printf("%I64d\n",dp[n][6]); printf("%lld\n",dp[n][6]); return 0; }
E.I’m stuck!
bfs
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <queue> using namespace std; int n,m,d1[505][505],d2[505][505],vis[505][505],sx,sy,ex,ey; char g[105][105]; const int INF = (1 << 30) - 1; int dx[4] = {0,0,1,-1}; int dy[4] = {1,-1,0,0}; void bfs(int _x,int _y,int d[505][505]) { for (int i = 1;i <= n;i++) for (int j = 1;j <= m;j++) d[i][j] = INF; memset(vis,0,sizeof(vis)); d[_x][_y] = 0; queue<pair<int,int> > q; q.push(make_pair(_x,_y)); while(!q.empty()) { pair<int,int> u = q.front();q.pop(); int x = u.first,y = u.second; for (int i = 0;i < 4;i++) { int nx = x + dx[i]; int ny = y + dy[i]; // printf("nx = %d ny = %d\n",nx,ny); if (nx < 1 || nx > n || ny < 1 || ny > m) continue; if (g[nx][ny] == '#') continue; if (g[x][y] == '+' || g[x][y] == 'T' || g[x][y] == 'S') { if (!vis[nx][ny]) { d[nx][ny] = d[x][y] + 1; q.push(make_pair(nx,ny)); vis[nx][ny] = 1; } } if (g[x][y] == '-') { if (i == 0 || i == 1) { if (!vis[nx][ny]) { d[nx][ny] = d[x][y] + 1; q.push(make_pair(nx,ny)); vis[nx][ny] = 1; } } } if (g[x][y] == '|') { if (i == 2 || i == 3) { if (!vis[nx][ny]) { d[nx][ny] = d[x][y] + 1; q.push(make_pair(nx,ny)); vis[nx][ny] = 1; } } } if (g[x][y] == '.') { if (i == 2) { if (!vis[nx][ny]) { d[nx][ny] = d[x][y] + 1; q.push(make_pair(nx,ny)); vis[nx][ny] = 1; } } } } } } int main() { scanf("%d %d",&n,&m); for (int i = 1;i <= n;i++) { scanf("%s",g[i] + 1); for (int j = 1;j <= m;j++) { if (g[i][j] == 'S') sx = i,sy = j; if (g[i][j] == 'T') ex = i,ey = j; } } bfs(sx,sy,d1); if (d1[ex][ey] == INF) { puts("I'm stuck!"); } else { int ans = 0; for (int i = 1;i <= n;i++) { for (int j = 1;j <= m;j++) { if (g[i][j] == 'S' || g[i][j] == '#') continue; bfs(i,j,d2); if (d1[i][j] != INF && d2[ex][ey] == INF) { ans++; // printf("i = %d j = %d\n",i,j); } } } printf("%d\n",ans); } return 0; } /* 5 5 --+-+ ..|#. ..|## S-+-T ####. */
3.5
组里代码用的pytorch 从0开始qaq
pytorch入门教程
2014.3 ccf
A.相反数
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <map> using namespace std; int n,a[1005]; int main() { scanf("%d",&n); for (int i = 1;i <= n;i++) scanf("%d",&a[i]); map<int,int> h; int ans = 0; for (int i = 1;i <= n;i++) { ans += h[-a[i]]; h[a[i]]++; } printf("%d\n",ans); return 0; }
B.窗口
模拟
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; struct node { int sx,sy,ex,ey; int id; }a[105]; node b[105]; int n,m; int main() { scanf("%d %d",&n,&m); for (int i = 1;i <= n;i++) { scanf("%d %d %d %d",&a[i].sx,&a[i].sy,&a[i].ex,&a[i].ey); a[i].id = i; } int x,y; for (int kase = 1;kase <= m;kase++) { scanf("%d %d",&x,&y); int ok = 0; for (int i = n;i >= 1;i--) { if (x >= a[i].sx && x <= a[i].ex && y >= a[i].sy && y <= a[i].ey) { ok = i; break; } } if (ok == 0) printf("IGNORED\n"); else { printf("%d\n",a[ok].id); b[n] = a[ok]; for (int j = n;j > ok;j--) b[j-1] = a[j]; for (int j = ok-1;j >= 1;j--) b[j] = a[j]; for (int j = 1;j <= n;j++) a[j] = b[j]; } } return 0; }
C.命令行选项
不难...可是恶心...wa了半个下午...考试要是碰到的话就凉了叭qaq
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <map> #include <vector> using namespace std; int n; string s; int main() { cin >> s; map<char,int> h; int pos = 0,len = s.length(); s = s + '#'; for (int i = 0;i < len;i++) { if (s[i] == ':') continue; if (s[i+1] != ':') h[s[i]] = 1; else h[s[i]] = -1; } cin >> n; getchar(); string line; for (int kase = 1;kase <= n;kase++) { getline(cin,line); //printf("kase = %d line = %s\n",kase,line.c_str()); int cnt = 0; string a[505]; string tmp = ""; for (int i = 0;i < line.length();i++) { if (line[i] == ' ') { a[++cnt] = tmp;tmp.clear();} else tmp = tmp + line[i]; } if (tmp != "") a[++cnt] = tmp; // for (int i = 1;i <= cnt;i++) printf("a[%d] = %s\n",i,a[i].c_str()); map<string,string> ans; int flag = 0; for (int i = 1;i <= cnt;i++) { if (a[i][0] != '-' && i == 1) continue; if (a[i][0] == '-' && a[i].length() == 2) { if (h[a[i][1]] == 1) { ans[a[i]] = ""; } else if (h[a[i][1]] == -1) { if (i < cnt) ans[a[i]] = a[i+1],i++; else break; } else break; } else break; } printf("Case %d:",kase); int tot = ans.size(),tt = 0; for(map<string,string>::iterator iter = ans.begin(); iter != ans.end(); iter++) { cout << " " << iter->first; if(iter->second != "") cout << " " << iter->second; } printf("\n"); } return 0; } /* albw:x 4 ls -a -l -a documents -b ls ls -w 10 -x -w 15 ls -a -b -c -d -e -l albw:x 1 ls abcd:w 3 -a -a -a */
D.无线网络
E.任务调度
3.6
迷茫
3.7
懒得配环境于是用服务器..可是好像因为网速原因用起来有点卡卡
于是 还是给自己电脑win10 配pytorch,前几天搜的教程是在线下载 安装 老是提示找不到xxxx ,然后这个是下载下来离线装 就好啦
----
晚上回宿舍发现楼下好多汉子人手一束花送给班里妹子qwq 哈哈哈哈哈 年轻真好呀qwq
女生节快乐w
3.8
numpy 与 torch
import torch import numpy as np np_data = np.arange(6).reshape((2,3)) torch_data = torch.from_numpy(np_data) tensor2array = torch_data.numpy() print( '\nnumpy array:\n',np_data, 'ntorch tensor:\n',torch_data, '\ntensor to array:\n',tensor2array, ) #abs data = [-1,-2,2,2] tensor = torch.FloatTensor(data) print( '\nabs', '\nnumpy: \n',np.abs(data), '\ntorch: ',torch.abs(tensor) ) #sin print( '\nsin', '\nnumpy: \n',np.sin(data), '\ntorch: ',torch.sin(tensor) ) # mean print( '\nmean', '\nnumpy: ',np.mean(data), '\ntorch: ',torch.mean(tensor) ) # matrix multiplication data = [[1,2],[3,4]] tensor = torch.FloatTensor(data) print( '\n matrix multiplication', '\n numpy: \n',np.matmul(data,data), '\ntorch: \n',torch.mm(tensor,tensor) ) data = np.array(data) print ('datattatat \n',data) print( ' dot', '\n numpy \n',data.dot(data), '\n torch \n',tensor.dot(tensor) )
3.9
pytorch variable
import torch from torch.autograd import Variable tensor = torch.FloatTensor([[1,2],[3,4]]) variable = Variable(tensor,requires_grad = True) print ('tensor',tensor) print ('variable',variable) t_out = torch.mean(tensor * tensor) v_out = torch.mean(variable * variable) print ('t_out',t_out) print ('v_out',v_out) v_out.backward() print ('variable now',variable) print ('variable.grad: \n',variable.grad) print ('variable.data: \n',variable.data) print ('data.numpy \n',variable.data.numpy())
pytorch 激励函数
import torch import torch.nn.functional as F from torch.autograd import Variable import matplotlib.pyplot as plt x = torch.linspace(-5,5,200) x_variable = Variable(x) x_np = x_variable.data.numpy() y_relu = F.relu(x_variable).data.numpy() y_sigmoid = F.sigmoid(x_variable).data.numpy() y_tanh = F.tanh(x_variable).data.numpy() y_softplus = F.softplus(x_variable).data.numpy() plt.figure(1,figsize = (8,6)) plt.subplot(221) plt.plot(x_np,y_relu,c = 'red',label = 'relu') plt.ylim(-1,5) plt.legend(loc = 'best') plt.subplot(222) plt.plot(x_np,y_sigmoid,c = 'red',label = 'sigmoid') plt.ylim(-0.2,1.2) plt.legend(loc = 'best') plt.subplot(223) plt.plot(x_np,y_tanh,c = 'red',label = 'tanh') plt.ylim(-1.2,1.2) plt.legend(loc = 'best') plt.subplot(224) plt.plot(x_np,y_softplus,c = 'red',label = 'softplus') plt.ylim(-0.2,6) plt.legend(loc = 'best') plt.show()
3.10
一个小例子,随机 的二次函数的数据,预测
import torch from torch.autograd import Variable import torch.nn.functional as F import matplotlib.pyplot as plt x = torch.unsqueeze(torch.linspace(-1, 1, 100), dim=1) # 将1维的数据转换为2维数据 y = x.pow(2) + 0.2 * torch.rand(x.size()) # 将tensor置入Variable中 x, y = Variable(x), Variable(y) # plt.scatter(x.data.numpy(), y.data.numpy()) # plt.show() # 定义一个构建神经网络的类 class Net(torch.nn.Module): # 继承torch.nn.Module类 def __init__(self, n_feature, n_hidden, n_output): super(Net, self).__init__() # 获得Net类的超类(父类)的构造方法 # 定义神经网络的每层结构形式 # 各个层的信息都是Net类对象的属性 self.hidden = torch.nn.Linear(n_feature, n_hidden) # 隐藏层线性输出 self.predict = torch.nn.Linear(n_hidden, n_output) # 输出层线性输出 # 将各层的神经元搭建成完整的神经网络的前向通路 def forward(self, x): x = F.relu(self.hidden(x)) # 对隐藏层的输出进行relu激活 x = self.predict(x) return x # 定义神经网络 net = Net(1, 10, 1) print(net) # 打印输出net的结构 # 定义优化器和损失函数 optimizer = torch.optim.SGD(net.parameters(), lr=0.5) # 传入网络参数和学习率 loss_function = torch.nn.MSELoss() # 最小均方误差 # 神经网络训练过程 plt.ion() # 动态学习过程展示 plt.show() for t in range(300): prediction = net(x) loss = loss_function(prediction,y) optimizer.zero_grad() loss.backward() optimizer.step() if (t+1) % 10 == 0: plt.cla() plt.scatter(x.data.numpy(), y.data.numpy()) plt.plot(x.data.numpy(), prediction.data.numpy(), 'r-', lw=5) plt.text(0.5, 0, 'L=%.4f' % loss.data[0], fontdict={'size': 20, 'color': 'red'}) plt.pause(0.1)
3.12
几乎一样的时间,同一个hr,可是一年过去.... 菜鸡lizishu依然没有什么长进呢
3,13
为了见到男神老师,每周都去上懵逼分析课qwq
--- UPD
男神老师曰,做题目,是锻炼你们独立思考的能力
3.15
今天是 第二次 见到 把 bfs 写在 main 里面的人 !
3.16
完成v1 可是 读了 别人 的文章.... 实在觉得自己的水的不行qaqaqaqqaqaqaqaqaqaaaaaaaa
3.17
很多latex 的板 这里
3.23
2018年的第二次面试w (叫第一次更好qaq,上次那个不太算
还是记录一下经验教训叭
今天群里也有人分享了一篇推文,讲了几个面试的小技巧
自己还需要注意的地方
1. 首先面试官说完题目之后,不要就急着 去想 赶紧把题目想出来,
首先该用自己的话向 面试官 复述一遍题意,确保没有理解错题意,在复述的过程中,
可以询问 N (如果给了的话 )的范围,还有题目中给出的别的数的范围,确保后面写代码的过程用int 还是long long
假定输入都合法吗 ? (确保后面写代码的时候 要不要写上对特殊情况的处理
输入会超限制吗?
... 暂时想到这些
2. 没有思路的话,可以一步一步的说自己的想法,同时在这个过程 可以接着想 更好的做法
不要什么都不说,
3. 编一些简单的样例 帮助想题目 和 写代码
4.想一些优化,时间,空间都想一想,还能不能再优化
5.写完代码之后,检查自己的代码有没有一些小细节的错误,争取bugfree
总之,就是感觉比去年难好多啊....还是菜菜喔...加油加油qwqwq
------ 菜菜的昏割线-------------------
这里有个leetcode 链表专题
3.28
在本地测试写的leetcode的链表
#include <stdlib.h> #include <time.h> #include <iostream> using namespace std; struct ListNode { int val; ListNode *next; ListNode(int x): val(x),next(NULL) {} }; void addToTail(ListNode **head,int val) { ListNode *node =new ListNode(val); if (!*head) { *head = node; } else { ListNode *tmp=*head; while (tmp->next) tmp=tmp->next; tmp->next=node; } } void printList(ListNode *head) { ListNode* tmp; tmp=head; if (tmp==NULL) cout<<"empty list"; else { while (tmp!=NULL) { cout<<tmp->val<<','; tmp=tmp->next; } cout<<endl; } } //write your function below ListNode * removeNthNodeFromEnd(ListNode *head,int m,int n) { } int main() { int lt = time(NULL); srand(lt); int len = rand() % 5 + 5; ListNode *root=NULL; for (int i=0;i<len;i++) addToTail(&root,rand()%100); printList(root); // fill the parameters in your function below ListNode *resultList=removeNthNodeFromEnd(root,4); printList(resultList); return 0; }
翻转链表
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <ctime> using namespace std; struct ListNode { int val; ListNode *next; ListNode(int x): val(x),next(NULL) {} }; void addToTail(ListNode **head,int val) { ListNode *node =new ListNode(val); if (!*head) { *head = node; } else { ListNode *tmp=*head; while (tmp->next) tmp=tmp->next; tmp->next=node; } } void printList(ListNode *head) { ListNode* tmp; tmp=head; if (tmp==NULL) cout<<"empty list"; else { while (tmp!=NULL) { cout<<tmp->val<<','; tmp=tmp->next; } cout<<endl; } } //write your function below ListNode * removeNthNodeFromEnd(ListNode *head,int m,int n) { ListNode* l = head; ListNode* front = head; ListNode* cur = head; ListNode* pre = head; for (int i = 1;i < m;i++) { l = l->next; front = front->next; cur = cur->next; pre = pre->next; } for (int i = m;i <= n;i++) { } } ListNode* Reverse(ListNode* head) { if (head == NULL) return NULL; ListNode* rhead = NULL; ListNode* cur = head; ListNode* pre = NULL; while(cur != NULL) { ListNode* nxt = cur->next; printf("--- cur->val = %d\n",cur->val); cur->next = pre; pre = cur; if (nxt != NULL) cur = nxt; else break; } return cur; } int main() { int lt = time(NULL); srand(lt); int len = rand() % 5 + 5; ListNode *root=NULL; for (int i=0;i<len;i++) addToTail(&root,rand()%100); printList(root); // fill the parameters in your function below // ListNode *resultList=removeNthNodeFromEnd(root,4); ListNode *resultList = Reverse(root); printList(resultList); return 0; }