文章目录

  • H. Hard Calculation
  • I. Mr. Main and Windmills
  • L. Simone and graph coloring
  • J.Parallel Sort

补题链接:https://ac.nowcoder.com/acm/contest/12548

H. Hard Calculation

链接:https://ac.nowcoder.com/acm/contest/12548/H
来源:牛客网

题目描述
Hooray! It is the first time that Kunming holds an ICPC regional contest. Suppose that everything goes on well and the Kunming Regional Contest is held each year. In which year will the xx-th Kunming Regional Contest be held?
输入描述:
The first and only line of input contains a single integer x(1\leq x\leq 100)x(1≤x≤100).
输出描述:
Output a single integer, denoting the year when the xx-th Kunming Regional Contest will be held.
示例1
输入
复制
1
输出
复制
2021
示例2
输入
复制
100
输出
复制
2120
备注:
Note that it is the year 2021 right now.

题意:

  • 给出一个x,求2020后的第x个年是第几年

思路:

  • 直接输出2020+x
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e5+10;
int main(){int x;  cin>>x;cout<<2020+x<<"\n";return 0;
}

I. Mr. Main and Windmills

题目描述
Mr. Main took a train from city to city and passed a plain full of windmills. The train ran in a straight line. A windmill is a machine used for wind power generation. Its fan blades rotate when the wind blows. From his perspective, colorful windmills lined up on the horizon from left to right.

As the train was running, the order of windmills from his perspective was constantly changing: a windmill was originally on the left/right of another, and then changed to its right/left;

Given the coordinates of the windmills, please find the coordinate of him when he just observed the -th windmill exchanged order with other windmills for the -th times. It is guaranteed that any three of the points given, the cities and the windmills, were not collinear, and that all of the windmills were on the same side of the line that the train ran along.

As shown in the picture, in Mr. Mian’s perspective, B was initially to the left of A, and later to the right of A.
输入描述:
The first line of input contains two integers and , where is number of windmills, and is number of queries.

The second line contains four integers x_s, y_s, x_t and y_t (), which are the coordinates of the starting city s and destination city t.

The next lines describe the windmills, the -th of which contains two integers x_i,
y_i (), which are the coordinates of the -th windmill.

The next lines describe the queries, the -th of which contains two integers, h_i and k_i (), denoting a query for the coordinates when observing the k_i-th pass of the h_i-th windmill.
输出描述:
Output m lines, each containing two real numbers x_i, y_i, representing the coordinates when the h_i-th windmill is observed to exchange order with other windmills for k times; if it does not exist, output -1. Your answer is considered correct if its absolute or relative error with the standard answer is less than .
示例1
输入
复制
4 2
0 0 5 0
1 3
2 4
4 1
4 5
1 2
3 2
输出
复制
-1
4.6666666667 0.0000000000

题意:

  • 给出n个点的坐标,以及额外的起点和终点。从起点沿直线走到终点,从过程中的每个点看这n个点都会看到相对位置的变化。
  • 给出m个询问,对于第h个点,从起点走到终点的过程中,有多少个点相对于他的左右位置发生了变化,求第k个点的坐标,如果小于k就-1.

思路:

  • 对于询问点hi,枚举其他所有点j,求他们连线与起点终点的交点,如果交点在起点终点上,那么就会发生变化,反之不会。
#include <bits/stdc++.h>
using namespace std;//精度
const double eps=1e-9;
int sign(double k){if(k>eps)return 1;else if(k<-eps)return -1; return 0;}
int cmp(double k1,double k2){return sign(k1-k2);}//向量
struct point{double x, y;point operator + (const point& k1)const{return point{x+k1.x,y+k1.y};}point operator - (const point& k1)const{return point{x-k1.x,y-k1.y};}point operator * (double k1)const{return point{x*k1,y*k1};}point operator / (double k1)const{return point{x/k1,y/k1};}
};
double cross(point k1,point k2){return k1.x*k2.y-k1.y*k2.x;}//题目
int check(point k1, point k2, point k3, point k4){return cmp(cross(k3-k1,k4-k1),cross(k3-k2,k4-k2))!=0;
}
int inmid(double k1,double k2,double k3){return sign(k1-k3)*sign(k2-k3)<=0;}
int inmid(point k1,point k2,point k3){return inmid(k1.x,k2.x,k3.x)&&inmid(k1.y,k2.y,k3.y);}
point getp(point k1,point k2,point k3,point k4){double w1=cross(k1-k3,k4-k3),w2=cross(k4-k3,k2-k3); return (k1*w2+k2*w1)/(w1+w2);
}int main(){int n, m;  cin>>n>>m;point s, t;  cin>>s.x>>s.y>>t.x>>t.y;vector<point>p(n+1);for(int i = 1; i <= n; i++)cin>>p[i].x>>p[i].y;for(int i = 1; i <= m; i++){int h, k;  cin>>h>>k;vector<point>vc;for(int j = 1; j <= n; j++){if(j==h)continue;if(check(p[h],p[j],s,t)){//是否相交point q = getp(p[h], p[j], s, t);if(inmid(s,t,q)){//是否在线段上vc.push_back(q);}}}if(s.x==t.x){//竖直线sort(vc.begin(), vc.end(), [&](point a, point b){return a.y<b.y;});if(s.y>t.y)reverse(vc.begin(), vc.end());}else{sort(vc.begin(), vc.end(), [&](point a, point b){return a.x<b.x;});if(s.x>t.x)reverse(vc.begin(), vc.end());}if(vc.size()>=k)printf("%.10lf %.10lf\n",vc[k-1].x,vc[k-1].y);else cout<<"-1\n";}return 0;
}

L. Simone and graph coloring

链接:https://ac.nowcoder.com/acm/contest/12548/L
来源:牛客网

题目描述
Simone, a student of Graph Coloring University, is interested in permutation. Now she is given a permutation of length nn, and she finds that if she connects each inverse pair, she will get a graph. Formally, for the given permutation, if i<jia_ja
i

a
j

, then there will be an undirected edge between node ii and node jj in the graph.

Then she wants to color this graph. Please achieve poor Simone’s dream. To simplify the problem, you just need to find a way of coloring the vertices of the graph such that no two adjacent vertices are of the same color and minimize the number of colors used.

输入描述:
There are multiple test cases. The first line of the input contains an integer T(1\leq T\leq 10^6)T(1≤T≤10
6
), indicating the number of test cases.

For each test case, the first line contains an integer n(1 \leq n \leq 10^6)n(1≤n≤10
6
), indicating the length of the permutation.

The second line contains nn integers a_1,a_2,…,a_na
1

,a
2

,…,a
n

, indicating the permutation.

It is guaranteed that the sum of nn over all test cases does not exceed 10^610
6
.
输出描述:
For each test case, the first line contains an integer cc, the chromatic number(the minimal number of colors been used when coloring) of the graph.

The second line contains nn integers c_1,c_2,…,c_nc
1

,c
2

,…,c
n

, the color of each node.

Notice that c_ic
i

should satisfy the limit that 1 \leq c_i \leq c1≤c
i

≤c.

If there are several answers, it is acceptable to print any of them.
示例1
输入
复制
2
4
1 3 4 2
2
1 2
输出
复制
2
1 1 1 2
1
1 1

题意:

  • 给出一个长度为n的排列,对于i<j且ai>aj的点连一条无向边。
  • 求给该图染色需要的最少颜色数,构造一种染色方案,输出每个点的颜色。

思路:

  • 就强行暴力,从后往前枚举,每次找到在当前数右边中比当前数小的数中颜色最大的数,颜色加一。
  • 因为查找的复杂度不够所以用rmq维护。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6+10;int n, a[maxn], c[maxn];int f[maxn];
void add(int i, int v){ for(;i<=n;i+=i&(-i))f[i]=max(f[i],v);}
int query(int i){int ans=0;for(;i>0;i-=i&(-i))ans=max(ans,f[i]);return ans;}int main(){//ios::sync_with_stdio(false);//TLEint T;  scanf("%d",&T);while(T--){//memset(f,0,sizeof(f));for(int i = 1; i <= n; i++)f[i] = 0;scanf("%d",&n);for(int i = 1; i <= n; i++)scanf("%d",&a[i]);int ans = 0;for(int i = n; i >= 1; i--){c[i] = query(a[i])+1;add(a[i],c[i]);ans = max(ans, c[i]);}//cout<<ans<<"\n";printf("%d\n",ans);for(int i = 1; i <= n; i++)printf("%d ",c[i]);printf("\n");}return 0;
}

J.Parallel Sort

As a master of parallel computing, schwer is recently considering about the method to achieve quick sorting on parallel computers. He needs your help!

Given a permutation (p_1,\cdots,p_n)(p
1

,⋯,p
n

), you need to sort the permutation with minimum number of rounds. In a single round, one can take many pairs of integers (x_1,y_1),\cdots,(x_k,y_k)(x
1

,y
1

),⋯,(x
k

,y
k

) as long as the values of x_1,y_1,\cdots,x_k,y_kx
1

,y
1

,⋯,x
k

,y
k

are pairwise distinct. Then with the help of kk CPUs, for each i\in [1,k]i∈[1,k], the value of p_{x_i}p
x
i


and p_{y_i}p
y
i


will be switched immediately. Note that a permutation (p_1,\cdots,p_n)(p
1

,⋯,p
n

) is sorted if for every integer i\in [1,n]i∈[1,n], p_i=ip
i

=i holds.

Take some examples. Assume that n=4n=4. For p=(1,2,3,4)p=(1,2,3,4), the minimum number of round is 00 as it is already sorted. For p=(4,3,2,1)p=(4,3,2,1), the answer is 11, as you can swap the indices (1,4)(1,4) and (2,3)(2,3) simultaneously.

题意:

  • 给出一个排列,每次可以交换任意对数(a[i],a[j])。
  • 求最小交换次数让其变成升序,并输出每次交换的数对

思路:

  • 对于每个环:如果环中只有两个数,那么一次交换即可.
    如果环中超过两个数,那么两次交换即可比如(2,3,n,1),只需要两步(1,n,n-1,2),(1,2,3,n)就可以有序,如4567123,3217654,1234567。
  • 因为无序序列是由若干个独立环交换后形成的,所以答案最多两次交换,构造环的时候每次去查找即可。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
int a[maxn], p[maxn], vis[maxn];int x[maxn], y[maxn], cnt;
void swp(int i, int j){x[++cnt] = i;  y[cnt] = j;swap(a[i],a[j]);p[a[i]] = i;  p[a[j]] = j;
}
void dfs(int i){if(a[a[i]]!=i){int j = a[i], k = p[i];swp(j,k); vis[j] = vis[k] = 1;dfs(k);}
}int main(){int n;  cin>>n;for(int i = 1; i <= n; i++){cin>>a[i];  p[a[i]] = i;}int cc = 0;for(int i = 1; i <= n; i++){if(a[i]!=i)cc= max(cc, 1);if(a[a[i]]!=i)cc = 2;}cout<<cc<<"\n";while(1){int ok = 1;for(int i = 1; i <= n; i++)if(a[i]!=i){ok=0;break;}if(ok==1)break;cnt = 0;for(int i = 1; i <= n; i++){if(!vis[i] && a[i]!=i){if(a[a[i]]==i){if(!vis[a[i]]){vis[i] = vis[a[i]] = 1;swp(i,a[i]);}}else{vis[i] = 1;dfs(i);   }}}cout<<cnt<<" ";for(int i = 1; i <= cnt; i++)cout<<x[i]<<" "<<y[i]<<" ";cout<<"\n";for(int i = 1; i <= n; i++)vis[i]=0;}return 0;
}

第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(昆明),签到题4题相关推荐

  1. 第45届国际大学生程序设计竞赛(ICPC)银川站太原理工大学收获4枚奖牌

    第45届国际大学生程序设计竞赛(ICPC)银川站,由宁夏理工学院承办,于2021年5月15-16日在宁夏的石嘴山市进行. 太原理工大学在比赛中获得2银2铜共4枚奖牌的好成绩. 参加本次比赛的四个队,涵 ...

  2. 第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(济南)(重现赛)

    第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(济南)(重现赛) 导语 涉及的知识点 题目 C D G J M 参考文献 导语 日常的队内集训,开始的时候状态其实很好,但是到了后两题就出现了 ...

  3. 第45届国际大学生程序设计竞赛(ICPC)沈阳站太原理工大学收获1枚铜牌

    第45届ICPC沈阳区域赛,于2021年7月18日在东北大学南湖校区举行.太原理工大学2个队参加比赛,由20级中学没有学过编程的3名同学组成的队,首次参加现场赛并获得铜奖.

  4. 第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(南京)签到题K Co-prime Permutation,L Let‘s Play Curling

    序 emmm因为没时间补题(虽然签到有四题),所以只能先放两个签到. 这是比赛链接:https://ac.nowcoder.com/acm/contest/10272 这是题解链接:2020年ICPC ...

  5. 第 45 届国际大学生程序设计竞赛(ICPC)亚洲网上区域赛模拟赛 题解(除了C、G之后补)

    整理的算法模板合集: ACM模板 这次比赛好多原题呀-(就是那种稍微拓展了一点的原题) 目录 A.Easy Equation B.XTL's Chessboard D.Pokemon Ultra Su ...

  6. 第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(昆明),签到题HIL

    H. Hard Calculation 链接:https://ac.nowcoder.com/acm/contest/12548/H 来源:牛客网 题目描述 Hooray! It is the fir ...

  7. 第 45 届国际大学生程序设计竞赛(ICPC)亚洲网上区域赛模拟赛 B.XTL‘s Chessboard(思维)

    题目链接:https://ac.nowcoder.com/acm/contest/8688/B 题目描述 Xutianli is a perfectionist, who only owns &quo ...

  8. 【第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛】Simone and Graph Coloring

    #include <bits/stdc++.h> using namespace std; const int maxn = 1000005, INF = 0x7f7f7f7f; int ...

  9. 第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(昆明) AC(带悔贪心)

    下面两个题都是选择iii有个价值如果选择iii则不能选择i−1,i+1i-1,i+1i−1,i+1,让价值最大或最小 P1792 [国家集训队]种树 野心qwq 的博客 #include<bit ...

最新文章

  1. ICRA2021| 自动驾驶相关论文汇总
  2. 如何用 Python 进行基于深度学习的计算机视觉项目开发?
  3. openStack镜像制作
  4. oracle数据导入-dblink方式
  5. PHP svn开发环境搭建,手把手搭建WAMP+PHP+SVN开发环境,wampsvn_PHP教程
  6. EOJ_1094_寻找航海路线
  7. 基于JAVA+SpringBoot+Vue+Mybatis+MYSQL的物资管理系统
  8. mysql mmm安装管理详解
  9. CSS基础之 文字和文本元素
  10. Flex Builder中创建的项目4种
  11. 机器学习:训练集和测试集
  12. 安装打印机时出现无法安装,打印处理器不存在
  13. 求网络号、子网号、主机号、子网网络地址、子网广播地址
  14. python检测ipa证书过期时间
  15. java memcached incr_Redis与Memcached的incr/decr差异对比
  16. 智慧警务:如何利用视频智能分析技术助力城市警务可视化综合监管与指挥系统
  17. vue 快速入门、常用指令(1)
  18. 【CS224n】(lecture7)机器翻译NMT,seq2seq和attention
  19. 单片机学习笔记————51单片机实现带数码管显示的象棋比赛专用计时器
  20. caplusDB君 · 行业新闻汇编(12月25号)

热门文章

  1. 2.PasswordEncoder
  2. SwiftUI和Python一起从数据提取到App展示(做个世界国旗App)
  3. 【原创】nbsp;程序员===索马里海盗
  4. iPhone 12怎么查看重要联系人信息「图文教程」
  5. 人脸识别三种经典算法总结
  6. 转载:集电极开路、漏极开路、上拉电阻、下拉电阻等接口相关基本概念
  7. C语言初学时可能会遇到的问题(一)
  8. sql面试笔试题大全
  9. WeCube开源监控插件Open-monitor介绍
  10. 李力,清华大学多车协同讲座:笔记