当前位置:网站首页>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("");
}
}
边栏推荐
- RFC 793 why to send reset and when to send reset
- 多路转接select
- 手动事务的几个类
- Li Kou daily question - day 25 -496 Next larger element I
- Alibaba cloud lightweight servers open designated ports
- Auto. JS to automatically authorize screen capture permission
- Wireshark packet capturing skills summarized by myself
- (to be added) games101 job 7 improvement - knowledge you need to know to realize micro surface model
- 如何化解35岁危机?华为云数据库首席架构师20年技术经验分享
- EditText controls the soft keyboard to search
猜你喜欢
XTransfer技术新人进阶秘诀:不可错过的宝藏Mentor
Li Kou daily question - day 26 -496 Next larger element I
BPF_ PROG_ TYPE_ SOCKET_ Filter function implementation
Tutorial on obtaining JD cookies by mobile browser
memcached全面剖析–3. memcached的删除机制和发展方向
传输层 udp && tcp
推荐模型之多任务模型:ESMM、MMOE
Web project deployment
socket done
2022国际女性工程师日:戴森设计大奖彰显女性设计实力
随机推荐
Unity关于本地坐标和世界坐标之间的转换
应用实践 | 海量数据,秒级分析!Flink+Doris 构建实时数仓方案
Analyse complète Memcached – 2. Comprendre le stockage de mémoire pour Memcached
使用Adb连接设备时提示设备无权限
力扣每日一题-第25天-496.下一个更大元素Ⅰ
Pattern recognition - 1 Bayesian decision theory_ P1
[camera Foundation (II)] camera driving principle and Development & v4l2 subsystem driving architecture
【产品设计研发协作工具】上海道宁为您提供蓝湖介绍、下载、试用、教程
Functional analysis of ebpf sockops
When to send the update windows message
SYSCALL_ Define5 setsockopt code flow
Structured interview of state-owned enterprises and central enterprises employment of state-owned enterprises Modou Interactive Employment Service steward
Blender's landscape
VSCode无网环境快速迁移开发环境(VIP典藏版)
去掉录屏提醒(七牛云demo)
Call process of package receiving function
Kernel Debugging Tricks
(待补充)GAMES101作业7提高-实现微表面模型你需要了解的知识
Installing Oracle without graphical interface in virtual machine centos7 (nanny level installation)
Notes_ Vlan