博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
(数据结构 )【自我修炼】 紫薯 煤油。。 uva12100 【样例的意思】 多做才多总结啊!!!
阅读量:4144 次
发布时间:2019-05-25

本文共 4483 字,大约阅读时间需要 14 分钟。

紫薯上的5-2和5-7的习题。

【最近三次了,题目读错,其实并不是样例的意思,然后就写题目去了】

uva12100其实并没有很难呀,就是优先极低的扔在后面,直到遇到优先极高的打印。

遇到了一些问题:

(1 )“直到” 优先极高的 最开始理解错了,错了很久。。。  

(2)有关修炼

在纸上写出来真的很有用吧,对我来说

而且要分析题目,我们有什么条件,在最低限度上能得到什么,一点点写出来。

如果把过程都写好,最好清楚了,然后上手会容易很多。

虽然徒手写代码的能力会因此变差。。。 

不过debug三小时也不好哇!!!!!

(3)【星号】结构体记得写构造函数。有时候有问题。

(4)会乱星人还是使用1-n吧,用的时候如果给的是0,再自行+1即可。代码在下面

前天做的,map和vector的妙用。。。

可以用来存储出现的次序.. 需要注意一下下就是set不行,因为顺序丢失了

我的写法最后检验全0的时候,要塞入等量的0进去然后看map里面是不是count

有的时候要好好用set。。  key 和value

5-7 uva 1594

#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long ll;int n,m; int cnt;///int a[35][35][35][35][35];int main() { //关键是保存是否插入过的状态.... 用一堆set来存吗??? int t; cin >> t; while (t--) { scanf("%d", &n);//cin >> n;// >> m; int aa[20005]; int bb[20005]; // set
s; map
, int> mm; //cin >> a1 >> a2 >> a3 >> a4; //唔.. 判断程序的话 我们其实只要简单judge一下就好了 for (int i = 1; i <= n; i++)scanf("%d",&aa[i]);//cin >> aa[i]; for (int j = 1; j <= 1008; j++) { vector
ss; for (int i = 1; i <= n; i++) { if (i != n) bb[i] = abs(aa[i + 1] - aa[i]); //从 2-1 3-2 直到(n-1)-(n-2) n- (n-1) //最后一次是 1-n else bb[n] = abs(aa[1] - aa[n]); } for (int i = 1; i <= n; i++) { aa[i] = bb[i]; ss.push_back(aa[i]); //cout << bb[i] << " "; }//cout << endl; if (mm.count(ss) == 0)// mm[ss] = 1; else // 就是1啦 { vector
aaaaa; for(int i=1;i<=n;i++) aaaaa.push_back(0); if (mm.count(aaaaa) == 1)printf("ZERO\n");// cout << "ZERO" << endl; else printf("LOOP\n");//cout << "LOOP" << endl; break; } //竟然是因为重名 我亏不亏啊 //啊... 顺序 我没存顺序 } } return 0;}

 

5-2  uva12100

#include
#include
#include
#include
#include
#include
using namespace std;typedef long long ll;struct node { int v; int id; node(int v = 0, int id = 0) : v(v), id(id) {}}nodee[105];int n, pos,cnt;int pr[11];int vis[105];int main() { int t; cin >> t; while (t--) { cin >> n >> pos; queue
q; for (int i = 0; i <= 9; i++)pr[i] = 0; for (int i = 1; i <= n; i++) { cin >> nodee[i].v; nodee[i].id = i; pr[nodee[i].v]++; q.push(nodee[i]); } cnt = 0; memset(vis, 0, sizeof(vis)); while (q.size() >= 0) {//empty 可能会出问题 //cnt++; int reci=0; node reccc; while (vis[q.front().id]== 1)//&&!q.empty()) q.pop();//用过的我都拿出去了 node tmp = q.front(); for (int i = tmp.v; i <= 9; i++) {//找到最大的优先级 if (pr[i] != 0) reci = i; } // for (int i = 1; i <= 9; i++)cout << pr[i]; cout << endl; if (tmp.v == reci) {// 如果非常愉快的话 直接pop就好了 q.pop(); reccc = tmp; pr[tmp.v]--; vis[tmp.id] = 1; cnt++; } else { q.pop(); q.push(tmp); }if (reccc.id == pos + 1) { //cout << cnt << endl; break; } //}reccc是本次进行的操作 }cout << cnt << endl; } return 0;}

最后放一下错误的代码吧,一多了就很容易乱。

这个emmm如果按照我的理解,如果当前的不是最优的,就打印最优 的应该是对的

。。。脑子呢 当前的不是最优的怎么找到最优的啊。。 大部分情况下 这些东西都还是要符合生活实际的!!!!

#include
#include
#include
#include
#include
#include
using namespace std;typedef long long ll;struct node { int v; int id; node(int v = 0, int id = 0) : v(v), id(id) {}}nodee[105];int n, pos,cnt;int pr[11];int vis[105];int main() { int t; cin >> t; while (t--) { cin >> n >> pos; queue
q; for (int i = 0; i <= 9; i++)pr[i] = 0; for (int i = 1; i <= n; i++) { cin >> nodee[i].v; nodee[i].id = i; pr[nodee[i].v]++; q.push(nodee[i]); } cnt = 0; memset(vis, 0, sizeof(vis)); while (q.size() >= 0) {//empty 可能会出问题 cnt++; int reci=0; node reccc; while (vis[q.front().id]== 1)//&&!q.empty()) q.pop();//用过的我都拿出去了 node tmp = q.front(); for (int i = tmp.v; i <= 9; i++) {//找到最大的优先级 if (pr[i] != 0) reci = i; } //for (int i = 1; i <= 9; i++)cout << pr[i]; cout << endl; if (tmp.v == reci) {// 如果非常愉快的话 直接pop就好了 q.pop(); reccc = tmp; pr[tmp.v]--; vis[tmp.id] = 1; } else { for (int i = 1; i <= n; i++) {//先找到优先级最大的是谁 if (nodee[i].v == reci && !vis[nodee[i].id]) { // recc = i; reccc = nodee[i]; vis[nodee[i].id] = 1; pr[nodee[i].v]--; q.pop(); q.push(tmp); break; } } } //if (flag == false) { if (tmp.id == pos + 1) break; } //else { if (reccc.id == pos + 1) { //cout << cnt << endl; break; } //}reccc是本次进行的操作 }cout << cnt << endl; } return 0;}

1,对于lower_bound 

只有set、multiset、map、multimap能这么写,好像因为这是它们的函数
int k = *(a.lower_bound(y));

2,set可以直接用 *a.end()和*a.begin()访问, 或者-- ++ 
 if (y>*(--a.end()))
这里, set里面end是末尾+1的位置
想要拿到的话要-- 很多stl都是这样
数组和向量不能这么用
数组的话lower_bound(左边,右边+1,你要找的) 得到的是a[k]在内存中的位置

sort(begin,end)

左臂右开的

3,洛谷这个题,还是要理解一下这里,本来以为一个set足够了的

n虽然是8000 ,但是有这样的限制,所以要注意一下如果领养者累计的话,也是要等候的。

你可能感兴趣的文章
Study of Source code
查看>>
如何使用BBC英语学习频道
查看>>
spring事务探索
查看>>
浅谈Spring声明式事务管理ThreadLocal和JDKProxy
查看>>
初识xsd
查看>>
java 设计模式-职责型模式
查看>>
构造型模式
查看>>
svn out of date 无法更新到最新版本
查看>>
java杂记
查看>>
RunTime.getRuntime().exec()
查看>>
Oracle 分组排序函数
查看>>
删除weblogic 域
查看>>
VMware Workstation 14中文破解版下载(附密钥)(笔记)
查看>>
日志框架学习
查看>>
日志框架学习2
查看>>
SVN-无法查看log,提示Want to go offline,时间显示1970问题,error主要是 url中 有一层的中文进行了2次encode
查看>>
NGINX
查看>>
Qt文件夹选择对话框
查看>>
1062 Talent and Virtue (25 分)
查看>>
1061 Dating (20 分)
查看>>