#include<bits/stdc++.h>#defineendl'\n'usingnamespace std;constint N =50010;int n;int a[N];boolcheck(int X){unordered_map<int,int> cnt;for(int i =1; i <= X; i ++) cnt[a[i]]++;if(cnt.size()== X)returntrue;returnfalse;}intmain(){cin >> n;for(int i =1; i <= n; i ++) cin >> a[i];int l =1, r = n;while(l < r){int mid = l + r +1>>1;if(check(mid)) l = mid;else r = mid -1;}cout << r << endl;return0;}
T2(思维,双指针)
#include<bits/stdc++.h>#defineendl'\n'usingnamespace std;typedeflonglong ll;constint N =50010;int n;int a[N];intmain(){cin >> n;for(int i =1; i <= n; i ++) cin >> a[i];sort(a +1, a + n +1);ll ans =0, last =0;for(int i =1; i <= n; i ++){int j = i;while(j <= n && a[j]== a[i]) j ++;int cnt = j - i;bool flag =false;if(last >= a[i]) ans +=(last +1- a[i])*1ll* cnt, flag =true;ans +=(cnt -1)*1ll* cnt /2;if(flag) a[i]= last +1; last = a[i]+ cnt -1; i = j -1;}cout << ans << endl;return0;}
T3(模拟,前缀和)
应该是数据出小了,按理不应该能直接过的,算是捡漏了吧 hh
#include<bits/stdc++.h>#defineendl'\n'usingnamespace std;typedeflonglong ll;constint N =100010;int n, u, v;int a[N]; ll pre[N];intmain(){scanf("%d%d%d",&n,&u,&v);for(int i =1; i <= n; i ++)scanf("%d",&a[i]);for(int i =1; i <= n; i ++) pre[i]= pre[i -1]+0ll+ a[i];int ans =0;for(int len = v; len <= n; len += v){for(int i =1; i + len -1<= n; i ++){if((pre[i + len -1]- pre[i -1])*1ll* v == len *1ll* u) ans ++;}}cout << ans << endl;return0;}
1、采用 CAS 分配重试的方式来保证更新操作的原子性
2、每个线程在 Java 堆中预先分配一小块内存,也就是本地线程分配缓冲(Thread Local AllocationBuffer,TLAB),要分配内存的线程,先在本地缓冲区中分配&a…
粗略版快速总结 条件熵 H ( Q ∣ P ) 联合熵 H ( P , Q ) − H ( P ) 条件熵H(Q∣P)联合熵H(P,Q)−H(P) 条件熵H(Q∣P)联合熵H(P,Q)−H(P) 信息增益 I ( P , Q ) H ( P ) − H ( P ∣ Q ) H ( P ) H ( Q ) − H ( P , Q ) 信息增益 I(P,Q)H(P)−H(P∣Q)H(P)H(Q)-H(P,Q) 信息…
设备树(DTS:device tree source),字面意思就是一块电路板上设备如上图中CPU、DDR、I2C、GPIO、SPI等,按照树形结构描绘成的一棵树。按照策略和功能分离的思路,就是驱动代码(功能)和设备树DTS配置…