当前位置:网站首页>Atcoder beginer contest 259 partial solution
Atcoder beginer contest 259 partial solution
2022-07-18 16:17:00 【A Fusu in the mountains】
This problem solution is just a record of my problem-solving process code , Do not provide optimal solution
( In addition, all the time complexity here only analyzes a single sample , not t t t Time complexity of )
A
Click here to view the corresponding topic .
Design algorithm of this problem : simulation
Give the starting time , The height changes every year and remains the same for a period of time , Find the terminal height
Time complexity O ( 1 ) O(1) O(1)
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 5e5 + 10;
int main()
{
int n,m,x,t,d;
cin >> n >> m >> x >> t >> d;
if (m <= n && m >= x) cout << t << '\n';
else {
cout << t - (x - m) * d << '\n';
}
return 0;
}
B
Click here to view the corresponding topic .
Design algorithm of this problem : Calculation
This problem is mainly to calculate , Give the angle and starting coordinates , It is a formula of coordinate rotation
Introduction to rotation around the origin :
In rectangular coordinates , Yes p(x, y), A straight line op The length is r, A straight line op and x The positive angle of the axis is a. A straight line op Counterclockwise around the origin b The rotation of the degree of , arrive p’ (s,t), Here's the picture .

s = r cos(a + b) = r cos(a)cos(b) – r sin(a)sin(b) (1.1)
t = r sin(a + b) = r sin(a)cos(b) + r cos(a)sin(b) (1.2)
among x = r cos(a) , y = r sin(a)
Plug in (1.1), (1.2) ,
s = x cos(b) – y sin(b) (1.3)
t = x sin(b) + y cos(b) (1.4)
Finally, this formula can be obtained
s = x cos(b) – y sin(b) (1.3)
t = x sin(b) + y cos(b) (1.4)
Also pay attention to this topic sin ,cos The application of function , The built-in parameters are all true degrees multiplied by pi Divide 180; In addition, this question is accurate to six decimal places , For the convenience of judging questions , We need to make the decimal point exactly after 7 It's better to be above .
Time complexity O ( 1 ) O(1) O(1)
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
const int N = 5e5 + 10;
double pi = 3.1415926535;
int main()
{
double x,y,degree;
cin >> x >> y >> degree;
double tx = x * cos(degree * pi / 180) - y * sin(degree * pi / 180);
double ty = x * sin(degree * pi / 180) + y * cos(degree * pi / 180);
cout << fixed << setprecision(10) << tx << ' ' << ty << '\n';
return 0;
}
C
Click here to view the corresponding topic .
Design algorithm of this problem : character string
Give two strings , If s If there are two or more consecutive identical letters in the, they can be copied indefinitely
Ask if you can change to the next
Scan the source string and answer string directly , You can merge consecutive identical letters , Compare again .
Time complexity O ( n ) O(n) O(n)
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 5e5 + 10;
int main()
{
string s,t,x,y;
cin >> s >> t;
s += '0';t += '0';
vector<int> cs,ct;
for (int i = 0;i < s.size() - 1;i ++ ) {
int cnt = 0;
while (s[i] == s[i + 1]) {
i ++;cnt ++;
}
x += s[i];
cs.push_back(cnt + 1);
}
for (int i = 0;i < t.size() - 1;i ++ ) {
int cnt = 0;
while (t[i] == t[i + 1]) {
i ++;cnt ++;
}
y += t[i];
ct.push_back(cnt + 1);
}
if (x != y) {
puts("No");
return 0;
}else {
for (int i = 0;i < cs.size();i ++ ) {
if (cs[i] > ct[i] || (cs[i] == 1 && ct[i] > 1)) {
puts("No");
return 0;
}
}
puts("Yes");
}
return 0;
}
D
Click here to view the corresponding topic .
Design algorithm of this problem : Computational geometry ( round ) + shortest path
The question is ( s x s_x sx , s y s_y sy) To ( t x t_x tx , t y t_y ty) , Whether it can only pass at least N A point on the circumference of a circle
We can calculate the number of the circle where the starting point is located by using the equation of the circle .
Once each circle intersects, it is equivalent to connecting an edge , utilize bfs Shortest path algorithm , Get the shortest answer , If the shortest answer can reach the end , Then it is right
Time complexity O ( n 2 ) O(n^2) O(n2)
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
using namespace std;
typedef pair<int,int> PII;
typedef double long db;
const int N = 3010,INF = 0x3f3f3f3f;
vector<int> g[N];
int n,stx,sty,edx,edy;
struct circle
{
db x,y,r;
}c[N];
int dist[N];
int bfs(int st,int ed)
{
memset(dist, 0x3f, sizeof(dist));
dist[st] = 0;
queue<int> q;
q.push(st);
while(q.size()) {
auto t = q.front();
q.pop();
for (int i = 0;i < g[t].size();i ++ ) {
int j = g[t][i];
if (dist[j] == 0x3f3f3f3f) {
dist[j] = dist[t] + 1;
q.push(j);
}
}
}
return dist[ed];
}
int main()
{
cin >> n;
cin >> stx >> sty >> edx >> edy;
for (int i = 1;i <= n;i ++ ) cin >> c[i].x >> c[i].y >> c[i].r;
vector<int> go,halt;
for (int i = 1;i <= n;i ++ ) {
if ((stx - c[i].x) * (stx - c[i].x) + (sty - c[i].y) * (sty - c[i].y) == c[i].r * c[i].r)
go.push_back(i);
if ((edx - c[i].x) * (edx - c[i].x) + (edy - c[i].y) * (edy - c[i].y) == c[i].r * c[i].r)
halt.push_back(i);
}
for (int i = 1;i < n;i ++ ) {
for (int j = i + 1;j <= n;j ++ ) {
db val = (c[i].x - c[j].x) * (c[i].x - c[j].x) + (c[i].y - c[j].y) * (c[i].y - c[j].y);
db d = sqrt(val);
if (d == abs(c[i].r - c[j].r)) {
g[i].push_back(j),g[j].push_back(i);
}
if (c[i].r + c[j].r >= d && d >= abs(c[i].r - c[j].r)) {
g[i].push_back(j),g[j].push_back(i);
}
}
}
for (auto it : go) {
for (auto item : halt) {
int t = bfs(it,item);
if (t + 1 <= n) {
cout << "Yes" << '\n';
return 0;
}
}
}
cout << "No" << '\n';
return 0;
}
E
Click here to view the corresponding topic .
Design algorithm of this problem :LCM + Sort
The meaning of the question is given in the form of prime power n A large integer , Let's calculate from here n Choose from a few n-1 After , Their least common multiple (LCM) How many kinds?
First, a small theorem is introduced ,n The least common multiple of numbers is equal to the product of the highest power of all prime numbers in them
Examples a 1 = 7 2 , a 2 = 2 2 ∗ 5 1 , a 3 = 5 1 , a 4 = 2 1 ∗ 7 1 a_1 = 7^2,a_2 = 2^2 * 5^1,a_3 = 5^1,a_4 = 2^1 * 7^1 a1=72,a2=22∗51,a3=51,a4=21∗71
their LCM Is equal to 7 2 ∗ 2 2 ∗ 5 1 = 980 7^2 * 2^2 * 5^1 = 980 72∗22∗51=980
After knowing this theorem , It's easy to speculate that some of these numbers may be useless ( There is him or not LCM unchanged )
We just need to enumerate after each number is replaced by one , Is the prime number composed of this number the highest power , If yes , It will affect the whole LCM Value makes an impact , Record impact value ( Subtracting the current highest power from the next higher power is its influence value , In addition, if the highest power is unique, the second higher power is 0).
Finally, the prime number influence values of all numbers are sorted into one n * n You two vector Sort and remove duplicates after the table .
Get the last of all possible LCM value
Time complexity O ( n ∗ m l o g m ) O(n * mlogm) O(n∗mlogm)
#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
const int N = 2e5 + 10;
typedef long long ll;
typedef pair<int,int> PII;
int main()
{
int n;
cin >> n;
map<int,vector<int>> mp;
vector<PII> factor[N];
for (int i = 1;i <= n;i ++ ) {
int m;
cin >> m;
for (int j = 1;j <= m;j ++ ) {
int p,e;
cin >> p >> e;
factor[i].push_back({p,e});
mp[p].push_back(e);
}
}
for (auto &it : mp) sort(it.second.begin(),it.second.end(),greater<>());
vector<vector<PII>> res;
for (int i = 1;i <= n;i ++ ) {
vector<PII> v;
for (int j = 0;j < factor[i].size();j ++ ) {
int p = factor[i][j].first,e = factor[i][j].second;
if (e == mp[p][0]) {
int d = mp[p].size() == 1 ? 0 : mp[p][1];
if (d != e) v.push_back({p,d - e});// Eliminate the influence
}
}
sort(v.begin(),v.end());
res.push_back(v);// Directly add the whole vector
}
// Yes vector The operation of
sort(res.begin(),res.end());
res.erase(unique(res.begin(),res.end()),res.end());
cout << res.size() << '\n';
return 0;
}
边栏推荐
- sqoop 从mysql 导入json格式中文乱码
- CF609A USB Flash Drives
- CF514B Han Solo and Lazer Gun
- To achieve win-win results in team work efficiency and quality, this office collaboration tool is really enough!
- 玩转“私域电商”,链动2+1模式值得企业深入了解吗?
- 容器健康检查解析
- Talk about promise
- 【二叉树】两棵二叉搜索树中的所有元素
- ELK集群部署(四)之部署Logstash
- Logback different packages (business logs) are output to different log files
猜你喜欢

ValueError: The number of FixedLocator locations (7), usually from a call to set_ ticks, does not mat

实现团队工作效率与质量共赢,这款办公协同工具真够用!
聊一聊Promise

面试秘籍大放送,编测编学独家秘籍遭外泄?!

以Celsius为反面教材,手把手教大家判断产品好坏、避开投资风险

Oracle存储过程的几种调用方式

Assist developers to comprehensively interpret APIs IX test cases

jitsi manu install(三)

Graphic array calculation module numpy (trigonometric function, rounding function, converting radian to angle, statistical analysis function, median, array sorting, argsort(), lexport())

精度提升方法:自适应Tokens的高效视觉Transformer框架(已开源)
随机推荐
Tdsql PG version is upgraded again, and we are deeply involved in the construction of open source ecosystem
A collection of dichotomous (dichotomous answers) questions
7.14 dichotomy, LCA, difference, thinking structure
C# 串口与TCP客户端 STTech.BytesIO
Compressai: image compression framework based on pytorch
ELK集群部署(五)之部署FileBeat
464 sword finger offer (35, 05, 58, 03)
HCIP - GRE/MGRE、OSPF
流动性视角中 CeFi 的功与过
各国程序员薪资水平,咱有点惨...
以Celsius为反面教材,手把手教大家判断产品好坏、避开投资风险
JS变量你不知道的点
Elk cluster deployment (IV) deployment logstash
福赛生物解读2022上半年大气环境变化,VOCs治理依然是破局关键
Elk cluster deployment (II) deployment kibana
英特尔 x Datawhale联合认证发布!
HCIP --- OSPF综合实验
【重识云原生】第四章云网络4.9.4.2节——智能网卡实现
[untitled] pseudo class selector and box model
聊一聊Promise