当前位置:网站首页>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("");
}
}
边栏推荐
- Auto. JS to realize automatic unlocking screen
- 使用Adb连接设备时提示设备无权限
- BPF_ PROG_ TYPE_ SOCKET_ Filter function implementation
- 力扣每日一题-第26天-496.下一个更大元素Ⅰ
- 推荐模型之多任务模型:ESMM、MMOE
- TCP Jprobe utilization problem location
- 2022 international women engineers' Day: Dyson design award shows women's design strength
- [camera Foundation (I)] working principle and overall structure of camera
- C语言实现DNS请求器
- Pattern recognition - 1 Bayesian decision theory_ P1
猜你喜欢

XTransfer技术新人进阶秘诀:不可错过的宝藏Mentor
Visit Amazon memorydb and build your own redis memory database

即构「畅直播」上线!提供全链路升级的一站式直播服务

About transform InverseTransformPoint, transform. InverseTransofrmDirection
![在每个树行中找最大值[分层遍历之一的扩展]](/img/5b/81ff20b61c0719ceb6873e44878859.png)
在每个树行中找最大值[分层遍历之一的扩展]

2022国际女性工程师日:戴森设计大奖彰显女性设计实力

如何做到全彩户外LED显示屏节能环保

Multi view function in blender

【Camera基础(一)】Camera摄像头工作原理及整机架构
![[camera Foundation (II)] camera driving principle and Development & v4l2 subsystem driving architecture](/img/b5/23e3aed317ca262ebd8ff4579a41a9.png)
[camera Foundation (II)] camera driving principle and Development & v4l2 subsystem driving architecture
随机推荐
C语言-关键字1
介绍BootLoader、PM、kernel和系统开机的总体流程
MySQL optimizes query speed
Li Kou daily question - day 26 -496 Next larger element I
Shengzhe technology AI intelligent drowning prevention service launched
EditText 控制软键盘出现 搜索
memcached全面剖析–2. 理解memcached的内存存储
EditText controls the soft keyboard to search
SYSCALL_ Define5 setsockopt code flow
福建省发改委福州市营商办莅临育润大健康事业部指导视察工作
Pattern recognition - 0 introduction
直击“三夏”生产:丰收喜报频传 夏播紧锣密鼓
Mysql优化查询速度
【Camera基础(二)】摄像头驱动原理和开发&&V4L2子系统驱动架构
Network layer & IP
图的邻接表存储 数组实现
Docking of arkit and character creator animation curves
VirtualBox虚拟机安装Win10企业版
About transform InverseTransformPoint, transform. InverseTransofrmDirection
Memcached comprehensive analysis – 3 Deletion mechanism and development direction of memcached