当前位置:网站首页>TKKC round#3
TKKC round#3
2022-06-24 19:28:00 【翁炜强】
1.题目:http://xujcoj.org/Home/Problems/status/pro_id/1590
反思:1.求解方程->二分逼近法
2.注意精度的判别 printf(".1lf",l) 保留一位小数 f:float lf:double .n保留n位小数
3.遇到精度题,统一改成double,除了幂次方
4.涉及到数学,一般采用等式化简
AC代码:
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a, c;
double _exp = 1e-2;
double qp(double x, int y)
{
double ans = 1;
while (y)
{
if (y & 1) { ans = ans * x; }
y >>= 1;
x = x * x;
}
return ans;
}
bool check(double b)
{
double res = 1 - (1.0 / (a + 1));
double q = 1.0 / (b + 1);
res += (q - qp(q, a+1))/ (1 - q);
return res >= c;
}
int main()
{
int T;
cin >> T;
while (T--)
{
cin >> a >> c;
double l = 0, r = 1e9;
while (r - l > _exp)//满足在某个误差范围内
{
double mid = (r + l) / 2;
check(mid) ? l = mid : r = mid;//大的话往右边找
}
printf("%.1fl\n", l);//保留一位有效数字
}
}
2.题目:http://xujcoj.org/Home/Problems/status/pro_id/1591/
反思:
1.并查集正确写法:
ll get(ll x)
{
return x==f[x]?x:f[x]=get(f[x])
}
//假如自己祖先不等于自己 就继续搜
void merge(ll x,ll y)
{
f[get(y)]=get(x);
}
//x祖先等于y的祖先的祖先 建立关系2.vector 开数组时 设成全局变量
3.注意判定是否有重复数字
4.stack flow 原因:1.数组过大 2.改用动态分配,用堆 3.递归进入死循环
AC代码:
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5;
ll f[N + 1];
vector<ll>v1[N + 1];
bool cmp(char x, char y)
{
return x < y;
}
ll get(ll x)
{
return x == f[x] ? x : f[x] = get(f[x]);
}
int main()
{
int T;
cin >> T;
while (T--)
{
for (int i = 0; i <= N; i++)
{
v1[i].clear();
}
for (int i = 0; i <= N; i++)
{
f[i] = i;
}
queue<int>ans;
set<ll>s;
vector<ll>v;
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++)
{
ll a, b;
scanf("%lld%lld", &a, &b);
f[get(b)] = get(a);
}
for (int j = 1; j <= n; j++)
{
bool flag = false;
ll x;
scanf("%lld", &x);
int fx = get(x);
if (s.count(fx) == 0)
{
ans.push(fx);
s.insert(fx);
}
v1[fx].push_back(x);
}
bool first = 1;
while (!ans.empty())
{
int t = ans.front();
ans.pop();
for (int i = 0; i < v1[t].size(); i++)
{
if (first)
{
printf("%lld", v1[t][i]);
first = 0;
}
else
{
printf(" %lld", v1[t][i]);
}
}
}
puts("");
}
}
边栏推荐
- Byte software testing basin friends, you can change jobs. Is this still the byte you are thinking about?
- Functional analysis of ebpf tracepoint
- 传输层 udp && tcp
- PKI notes
- LeetCode-513. 找树左下角的值
- Tdengine can read and write through dataX
- Memcached comprehensive analysis – 2 Understand memcached memory storage
- Tso hardware sharding is a header copy problem
- 即构「畅直播」上线!提供全链路升级的一站式直播服务
- 滤波数据分析
猜你喜欢

Memcached comprehensive analysis – 5 Memcached applications and compatible programs

滤波数据分析

Remove the screen recording reminder (seven cattle cloud demo)

《各行业零代码企业应用案例集锦》正式发布

多线程收尾

What does CTO (technical director) usually do?

【吴恩达笔记】卷积神经网络

Datakit 代理实现局域网数据统一汇聚

字节的软件测试盆友们你们可以跳槽了,这还是你们心心念念的字节吗?

为什么生命科学企业都在陆续上云?
随机推荐
123. the best time to buy and sell shares III
[camera Foundation (I)] working principle and overall structure of camera
EditText 控制软键盘出现 搜索
Volcano becomes spark default batch scheduler
leetcode_1365
Implementing DNS requester with C language
Analyse complète Memcached – 2. Comprendre le stockage de mémoire pour Memcached
【吴恩达笔记】多变量线性回归
【论】A deep-learning model for urban traffic flow prediction with traffic events mined from twitter
Multi task model of recommended model: esmm, MMOE
Blender's simple skills - array, rotation, array and curve
推荐模型之多任务模型:ESMM、MMOE
【吴恩达笔记】卷积神经网络
Tdengine can read and write through dataX
Li Kou daily question - day 26 -496 Next larger element I
Slider控制Animator动画播放进度
memcached全面剖析–5. memcached的应用和兼容程序
leetcode_191_2021-10-15
A field in the database is of JSON type and stores ["1", "2", "3"]
Pattern recognition - 0 introduction