暑假训练day1 : 2016 USP-ICMC

2023-12-26 08:38
文章标签 训练 暑假 day1 2016 usp icmc

本文主要是介绍暑假训练day1 : 2016 USP-ICMC,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

发挥还算不错。。。

传送门:http://codeforces.com/gym/101063

https://vjudge.net/contest/169377#overview


A. Giant Snail Maze
time limit per test
3 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

It is the year of 2016 and Mars is still not colonized. A daring group of immortal, rich explorers based in São Carlos decided that it is about time to do something about it, so they founded a space exploration company called GEMA - Go Explore Mars Already!

Fast forward to 2017. The first mission of GEMA has finally landed on Mars, but it seems like the rocket fell in the middle of some ancient ruins that form a giant maze resembling a snail. The maze is composed of Ncircular sectors all centered at the crash site of the rocket.

The circular sectors of the maze all have a railway running through their middle, and some portions of the walls are open, making it possible to leave to the next sector. The rails connecting sectors are straight, radial lines through the opening, connecting the rails of the two sectors. There is always a straight line connecting the crash site to the first sector railway through the openings. The only safe way to travel in this maze is by using these rails.

The crew of the GEMA mission wants to leave the maze as soon as possible. Luckily, they are in possession of small carts that fit the railway. Help them find the path with the minimum length to leave the maze. You are out of the maze as soon as you cross the boundary of the outermost wall.

The above figure illustrates the first sample test case. Dashed lines represent the railways that run through the middle of the sectors, whose boundaries are represented by solid circles. The best solution in this case is to go from points A, B, C, D and then E, going through the sectors railways through points X, Y, W and Z, as indicated by the green line.

Input

The input begins with an integer N (1 ≤ N ≤ 105), the number of circular sectors of the Snail Maze. The next line has N integers r, the radius of each of the sectors (1 ≤ r ≤ 109). The next line contains an integer Q (N ≤ Q ≤ 105), the number of openings. The next Q lines contains an integer and a real number each. The first integer, ri (1 ≤ ri ≤ 109) gives the radius of a wall (that radius will be one of the N numbers given in the second line), and the real number d, gives the angle, in radians, where the opening is located (0 ≤ d ≤ 2π). The angle is measured in clockwise direction with respect to west (the positive x-axis).

It is guaranteed that there is a path to leave the maze, i.e., every wall has at least one opening. There will not be two openings closer than 10 - 4 radians.

Output

Output the length of the shortest path to leave the maze. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

Example
input
3
4 10 6
4
4 1.0472
4 1.5707
6 4.7123
10 4.1857
output
27.30323
因为从内到外的直线距离固定,所以只需要关注圆环的长度。角度相同的圆环,内环比外环短,因此对于每个点,到下一层只需要取外环与它相邻最近的两个点。之后做一个最短路即可。

构图比较难搞,待补

B. Martian Sunrise
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Life on a different planet is hard. It is usually all about science, research and cold nights and days. It is no different on Mars.

To entertain people, GEMA brought with the mission a group of talented musicians to write ballads about the new and exciting world. They were instructed to write a very long and optimistic song called Martian Sunrise and play it all day around the research and living facilities.

No musician could write, alone, a song with thousands of notes, so they divided their task. GEMA was on a tight budget, and ended up hiring musicians that can only write and play songs in their own favourite single key signature. A key signature is a set (out of 16 possible sets) of notes that can be used. In the end, the ballad was composed of different parts in various key signatures.

Now that cash is flowing in, the high commanders have decided to bring new, more talented musicians that can play up to two different key signatures to play the Mars Jam. It was decided that the musicians will take turns playing, and no musician will play again after having finished their part. GEMA has all the musicians on Earth at their disposal, since the mission is very highly regarded. This means that for any pair of key signatures, they can find infinitely many musicians that can play it.

Even with endless cash, it is good to be optimal. It is up to you to figure out the minimum number of musicians necessary to play the whole song.

Input

The input will begin with an integer M, the number of existing key signatures (1 ≤ M ≤ 16). The next Mlines of the input will be composed of a set of 7 words each, denoting the notes used in this signature. The words representing notes will have a maximum of two characters each, and will be in the format [A-G][b#]?, that is, start with an uppercase character between 'A' and 'G' and optionally have a '#' or a 'b', for a sharp or flat.

The next line of the input contains an integer N (1 ≤ N ≤ 104). The following line contains the N notes of the original Martian Sunrise, separated by a space. Every note of the song is present in at least one of the M key signatures.

Please note that, although in musical terms C# equals Db, in this problem a musician that can play C# cannot necessarily play Db.

Output

Output the minimum number of musicians necessary to play the Martian Sunrise.

Examples
input
10
C# D# E# F# G# A# B#
Cb Db Eb F Gb Ab Bb
C# D# E F# G# A B
C D E F G A B
C D E F# G A B
C D Eb F G A Bb
C# D E F# G# A B
C D E F G A Bb
C Db Eb F G Ab Bb
C# D# E# F# G# A# B
3
F# Bb B#
output
1
input
8
Cb Db Eb F Gb Ab Bb
C# D# E F# G# A# B
C# D# E# F# G# A# B
C D Eb F G Ab Bb
C# D# E# F# G# A# B#
C Db Eb F Gb Ab Bb
C D E F# G A B
C# D E F# G A B
6
C F# G# D B# Db
output
2

比较水的模拟。。。

比赛时候超时还以为是复杂度太高,用位运算搞了个O(n)算法,其实是死循环,没有考虑m=1。还好最后一分钟绝杀此题。

#include <cstdio>
#include <iostream>
#include <string.h>
#include <queue>
#include <vector>
#include <math.h>
#include <map>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long double ld;
int a[256][25],b[20][25],pitch[10005];
char s[23];int main() {int n,m,i,j,k;char c;scanf("%d",&m);map<char,int> my;my['A']=1;my['B']=2;my['C']=3;my['D']=4;my['E']=5;my['F']=6;my['G']=7;my['#']=7;my['b']=14;memset(a,0,sizeof(a));memset(b,0,sizeof(b));for (i=1;i<=m;i++) {for (j=1;j<=7;j++) {scanf("%s",s);if (strlen(s)==1) {b[i][my[s[0]]]=1;} else {b[i][my[s[0]]+my[s[1]]]=1;}}}int l=0;if (m!=1)for (i=1;i<=m;i++) {for (j=i+1;j<=m;j++) {l++;for (k=1;k<=21;k++) {a[l][k]=b[i][k]+b[j][k];if (a[l][k]) a[l][0]=a[l][0]|(1<<(k-1));}}}else {l=1;for (k=1;k<=21;k++) {a[l][k]=b[1][k];if (a[l][k]) a[l][0]=a[l][0]|(1<<(k-1));}}scanf("%d",&n);for (i=1;i<=n;i++) {scanf("%s",s);if (strlen(s)==1) {pitch[i]=my[s[0]];} else {pitch[i]=my[s[0]]+my[s[1]];}}int maxlen=1,maxcondition,cnt=0;while (maxlen<=n) {cnt++;maxcondition=0;for (j=1;j<=l;j++) {if (maxcondition!=(maxcondition&a[j][0])) continue;while (a[j][pitch[maxlen]]&&maxlen<=n) {maxcondition=(maxcondition|(1<<(pitch[maxlen]-1)));maxlen++;}}}printf("%d\n",cnt);return 0;
}

C. Sleep Buddies
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

It is nighttime in the Earth Colony on Mars and everyone is getting ready to sleep. It is common to sleep in pairs, so that if anything were to happen during the night people could aid each other.

To decide who is a suitable candidate to sleep with whom, the leaders of GEMA asked everyone to answer a questionnaire about attributes they desire their partner to have from a list of M possible items.

To choose the pairs, GEMA uses the Jaccard index between the desired attributes of both persons. The Jaccard index for two sets A and B is defined as , that is, the size of the intersection between A and B divided by the size of their union. They allow a pair to be formed if the Jaccard index of the two attribute sets for the pair is at least K.

Thanks to GEMA, there are too many people living on Mars these days. Help the high commanders decide how many allowed pairs there are out of the N people living there.

Input

The input begins with two integers, N and M (1 ≤ N ≤ 1051 ≤ M ≤ 10), the number of people on Mars and the number of possible attributes on the questionnaire.

Then follow N lines, each beginning with an integer Q (1 ≤ Q ≤ M), the number of desired attributes on the list of the i-th person. Then follow Q integers q (1 ≤ q ≤ M), encoding these attributes. There numbers are all different.

The last line of input contains a real number K (0 ≤ K ≤ 1), the minimum required Jaccard index for a pair.

Output

Output the number of pairs that are allowed.

Examples
input
2 5
2 1 3
5 3 1 5 4 2
0.66489
output
0
input
3 1
1 1
1 1
1 1
0.85809
output
3
把集合转成十位的二进制,再用位运算搞。

#include <cstdio>
#include <iostream>
#include <string.h>
#include <queue>
#include <vector>
#include <stack>
using namespace std;
typedef long double ld;
typedef long long ll;
const int maxn=100005; 
int a[maxn][11],b[maxn];
ll c[(1<<10)+5],d[maxn];int main() {int n,m,q,i,j;ld k;scanf("%d%d",&n,&m);memset(c,0,sizeof(c));for (i=1;i<=n;i++) {scanf("%d",&a[i][0]);b[i]=0;for (j=1;j<=a[i][0];j++) {scanf("%d",&a[i][j]);b[i]+=(1<<(a[i][j]-1));}c[b[i]]++;}cin >> k;ll ans=0;for (i=1;i<=1023;i++) {int l=i;d[i]=0;while (l>0) {if (l%2) d[i]++;l/=2;}}for (i=1;i<=1023;i++) {for (j=i;j<=1023;j++) {int q=i&j,w=i|j;ld ratio=(ld)d[q]/(ld)d[w];if (ratio>=k) {if (i!=j) ans+=c[i]*c[j]; else ans+=c[i]*(c[i]-1)/2;}}}printf("%I64d\n",ans);
}

F. Bandejao
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

It is lunch time on Mars! Everyone has got that big smile on their faces, all eager to see what the GEMA restaurant is serving for dessert. Everything is pretty much like Earth, but nobody knows why, GEMA decided to invent new types of utensils. Somehow, the food research group concluded that the usual fork, knife and spoon would not be so adequate on Mars.

There are K types of utensils and if you want to have some food, you must use all K of them (one of each). You like to have lunch with your N friends, and when you are leaving, you want to distribute the utensils among you and all your friends equally (everyone having the same amount of utensils). In addition to that, you want each one of your friends (you included) to carry only one type of utensil (it speeds up the process of leaving the restaurant, and your friends get really mad when it takes more time than usual for them to get back to work).

Given N and K, answer if it is possible for you and your friends to leave the restaurant with everyone carrying the same number of utensils and each one carrying only one type of utensil.

Input

Two integers N and K (0 ≤ NK ≤ 100 and K > 0). (You and your friends form a group of N + 1 people).

Output

Print "yes" (if it is possible) or "no" without quotes.

Examples
input
1 2
output
yes
input
1 3
output
no

最水的一道题,还有15分钟结束时才做出来,花样作死

#include <cstdio>
#include <iostream>
#include <string.h>
#include <queue>
#include <vector>
#include <stack>
using namespace std;
int a[105][105];int main() {int n,k;	cin >> n >> k;if ((n+1)%k==0) cout << "yes\n"; else cout << "no\n";	return 0;
}

H. Reporting on Mars
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A lot of people, still living on Earth, dream of one day getting the opportunity to go to Mars and be a GEMA explorer. It's so glamorous and important, everything is so exciting, so different from the regular boring life on Earth.

However, the reality of the regular folk on Mars is not as nearly glamorous as everyone thinks. A day of an average explorer is at least as boring as a day of any Earth-living human. Every week, GEMA assigns tasks to each explorer in the expedition. Most of the times, these tasks are just very long and detailed reports they have to make. The worst part is that, after completing it, you would still have to review reports from your colleagues and correct them if mistakes are found.

One type of report consists of reporting collected data, but, before making the report, one should verify the consistency of the data. This is obviously the most boring part, so it is not surprising that some people prefer to skip it and just write the report without any verification.

To make matters worse, when reviewing a report containing contradictory data, instead of canceling the report, some explorers choose to manipulate the data, changing some numbers, so it would become consistent. This happens because canceled reports are seen as a great incompetence of the whole team who worked on it.

You are a GEMA explorer and you've just received a report. You need to manipulate the data on it, in order to make it seem correct. The data of the report is a bunch of positive or negative numbers. The data is considered consistent if and only if every sub-array of length k has a positive result when all numbers in it are multiplied together.

Formally, if the report is an array A of N positive and/or negative numbers, the report is consistent, if and only if, for all 1 ≤ i ≤ N - k + 1, we have:

Answer what is the least number of changes you have to make in the report so it would become consistent. A change in the report is changing the value of one of its numbers.

Input

The input begins with two integers N and k (1 ≤ k ≤ N ≤ 5 × 105) in a single line. The next line will contain N integers ai ( - 100 ≤ ai ≤ 100 and ai ≠ 0).

Output

One integer, the answer to the task.

Examples
input
3 1
10 -100 33
output
1
input
5 5
1 -1 -2 3 4
output
0
input
5 3
1 -1 -2 3 4
output
1

只考虑正负性即可。

序号相差k的数字,满足题中式子时正负性一定相等。把极性相同的数字改成同一符号即可。取正还是负呢?枚举前k个数有0,2,...2n个负数的情况,贪心更新最优解。

#include <cstdio>
#include <iostream>
#include <string.h>
#include <queue>
#include <vector>
#include <math.h>
#include <stack>
#include <algorithm>
using namespace std;
const int maxn=500005;
int a[maxn];struct Node {int b,c;
} node[maxn];bool cmp(Node x,Node y) {return x.b-x.c>y.b-y.c;
}int main() {int n,i,k,j,ans=0,sum=0;memset(node,0,sizeof(node));scanf("%d%d",&n,&k);for (i=1;i<=n;i++) {scanf("%d",&a[i]);if (a[i]<0) node[i%k].b++; else node[i%k].c++;}sort(node,node+k,cmp);for (i=0;i<k;i++) {sum+=node[i].b;}ans=sum;for (i=1;i<k;i+=2) {sum+=node[i].c+node[i-1].c;sum-=node[i].b+node[i-1].b;ans=min(ans,sum);}printf("%d",ans);return 0;
}

J. The Keys
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Out of all science labs constructed by the GEMA mission on Mars, the DSL - Dangerous Species Lab is the most dangerous of them all. The laboratory is so dangerous that you have to go through N doors in succession to get to it. Each one of those doors can only be opened by one key di (notice, however, that there may be different doors that can be opened by the same key).

A nameless lazy biologist (we'll call him LB) from GEMA needs to open all those doors first thing in the morning, every day. He has all the keys necessary to open them, but he finds carrying all of them in his pockets too much of a mess.

To be more organized and lose the title of being a lazy biologist, LB purchased K key-chains and is planning to distribute all the keys among them. His plan of distribution is very simple. For each key, randomly choose a key-chain with uniform probability and put this key on it.

When opening the doors, LB will hold one key-chain and will keep the others in his pocket (initially all of them are in his pocket). Whenever he gets to a door that needs a key that is not on the key-chain he is holding, he will swap it with the key-chain that has this key. Getting the first key-chain from his pocket is not considered a swap.

You have to help LB and find what is the expected number of key-chain swaps he will have to do when opening the doors the next morning.

Input

Input begins with N and K (1 ≤ N ≤ 1051 ≤ K ≤ N), the number of doors and the number of key-chains. On the next line there are N numbers di (1 ≤ di ≤ 106), the identifier of the key that opens the i-th door.

Output

Output the expected number of swaps. Your answer will be considered correct if the absolute and relative error are less than 10 - 6.

Examples
input
3 3
1 2 3
output
1.333333333
input
1 1
2
output
0.000000000
input
5 2
1 2 3 2 1
output
2.000000000

数学题,草稿纸上推个公式。

#include <cstdio>
#include <iostream>
#include <string.h>
#include <queue>
#include <vector>
#include <stack>
#include <iomanip>
using namespace std;
typedef long double ld;
const int maxn=100005;
int a[maxn];int main() {int n,k,i,j,q=0;scanf("%d%d",&n,&k);for (i=1;i<=n;i++) {scanf("%d",&a[i]);if (i>1&&a[i]!=a[i-1]) q++;}ld ans=(ld)(k-1)/(ld)k;ans*=(ld)q;cout << setiosflags(ios::fixed) << setprecision(9);cout << ans;return 0;
}

K. Dire, Dire Docks
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Half a century after the Mars arrival by GEMA, we are finally here. The mission is finally starting to build artificial rivers on mars.

That is possibly the most important event on Mars since the GEMA arrival.

In order to carry on with it, the mission have mapped the surface as 2-dimensional plane, and has identified N points in it that are going to work as reference points to build a river system. There will be a dock constructed in each of these points to help on transportation efforts and collect data for the mission.

The goal of the mission is to connect all the docks with rivers. The lead researcher of the team responsible for that, doctor Maya Waters, has identified the main requirements to build a healthy river system. These are:

  • There are N docks. There should be a way to navigate between any two docks only through water;
  • The system must have exactly N rivers - no more, no less;
  • At most four rivers can meet at any single dock;
  • Any river should flow in a straight line between points A and B;
  • There should be no river crossings apart from the rivers meeting at docks. Note that a river passing through a dock counts as a crossing.

Help doctor Maya figure out which points to connect to build such river system and finally Make Mars Wet Again!

Input

Input begins with N (3 ≤ N ≤ 103), the number of points. Follows N lines, each with two integers xiyi( - 109 ≤ xi, yi ≤ 109), the coordinates of the pivotal points.

Output

Output N lines. In each line, output two integers , a and b - the indexes of the pivotal points that must be connected by a river. Indexing begins in 1. If there are multiple solutions, output any.

If it is an impossible task, output -1.

Examples
input
5
-1 0
2 3
3 2
5 4
6 1
output
3 2
3 4
5 3
1 5
2 4
input
3
0 0
1 2
3 6
output
-1
除了所有点在一条直线,其他情况都有解。

先按坐标排个序,按顺序连起来,再找一条线就可以。剩下的一条线,一端为第一个点,依次枚举。


这篇关于暑假训练day1 : 2016 USP-ICMC的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/538753

相关文章

MiniGPT-3D, 首个高效的3D点云大语言模型,仅需一张RTX3090显卡,训练一天时间,已开源

项目主页:https://tangyuan96.github.io/minigpt_3d_project_page/ 代码:https://github.com/TangYuan96/MiniGPT-3D 论文:https://arxiv.org/pdf/2405.01413 MiniGPT-3D在多个任务上取得了SoTA,被ACM MM2024接收,只拥有47.8M的可训练参数,在一张RTX

Spark MLlib模型训练—聚类算法 PIC(Power Iteration Clustering)

Spark MLlib模型训练—聚类算法 PIC(Power Iteration Clustering) Power Iteration Clustering (PIC) 是一种基于图的聚类算法,用于在大规模数据集上进行高效的社区检测。PIC 算法的核心思想是通过迭代图的幂运算来发现数据中的潜在簇。该算法适用于处理大规模图数据,特别是在社交网络分析、推荐系统和生物信息学等领域具有广泛应用。Spa

SigLIP——采用sigmoid损失的图文预训练方式

SigLIP——采用sigmoid损失的图文预训练方式 FesianXu 20240825 at Wechat Search Team 前言 CLIP中的infoNCE损失是一种对比性损失,在SigLIP这个工作中,作者提出采用非对比性的sigmoid损失,能够更高效地进行图文预训练,本文进行介绍。如有谬误请见谅并联系指出,本文遵守CC 4.0 BY-SA版权协议,转载请联系作者并注

Detectorn2预训练模型复现:数据准备、训练命令、日志分析与输出目录

Detectorn2预训练模型复现:数据准备、训练命令、日志分析与输出目录 在深度学习项目中,目标检测是一项重要的任务。本文将详细介绍如何使用Detectron2进行目标检测模型的复现训练,涵盖训练数据准备、训练命令、训练日志分析、训练指标以及训练输出目录的各个文件及其作用。特别地,我们将演示在训练过程中出现中断后,如何使用 resume 功能继续训练,并将我们复现的模型与Model Zoo中的

多云架构下大模型训练的存储稳定性探索

一、多云架构与大模型训练的融合 (一)多云架构的优势与挑战 多云架构为大模型训练带来了诸多优势。首先,资源灵活性显著提高,不同的云平台可以提供不同类型的计算资源和存储服务,满足大模型训练在不同阶段的需求。例如,某些云平台可能在 GPU 计算资源上具有优势,而另一些则在存储成本或性能上表现出色,企业可以根据实际情况进行选择和组合。其次,扩展性得以增强,当大模型的规模不断扩大时,单一云平

神经网络训练不起来怎么办(零)| General Guidance

摘要:模型性能不理想时,如何判断 Model Bias, Optimization, Overfitting 等问题,并以此着手优化模型。在这个分析过程中,我们可以对Function Set,模型弹性有直观的理解。关键词:模型性能,Model Bias, Optimization, Overfitting。 零,领域背景 如果我们的模型表现较差,那么我们往往需要根据 Training l

如何创建训练数据集

在 HuggingFace 上创建数据集非常方便,创建完成之后,通过 API 可以方便的下载并使用数据集,在 Google Colab 上进行模型调优,下载数据集速度非常快,本文通过 Dataset 库创建一个简单的训练数据集。 首先安装数据集依赖 HuggingFace datasetshuggingface_hub 创建数据集 替换为自己的 HuggingFace API key

【YOLO 系列】基于YOLOV8的智能花卉分类检测系统【python源码+Pyqt5界面+数据集+训练代码】

前言: 花朵作为自然界中的重要组成部分,不仅在生态学上具有重要意义,也在园艺、农业以及艺术领域中占有一席之地。随着图像识别技术的发展,自动化的花朵分类对于植物研究、生物多样性保护以及园艺爱好者来说变得越发重要。为了提高花朵分类的效率和准确性,我们启动了基于YOLO V8的花朵分类智能识别系统项目。该项目利用深度学习技术,通过分析花朵图像,自动识别并分类不同种类的花朵,为用户提供一个高效的花朵识别

深度学习与大模型第3课:线性回归模型的构建与训练

文章目录 使用Python实现线性回归:从基础到scikit-learn1. 环境准备2. 数据准备和可视化3. 使用numpy实现线性回归4. 使用模型进行预测5. 可视化预测结果6. 使用scikit-learn实现线性回归7. 梯度下降法8. 随机梯度下降和小批量梯度下降9. 比较不同的梯度下降方法总结 使用Python实现线性回归:从基础到scikit-learn 线性

使用openpose caffe源码框架训练车辆模型常见错误及解决办法

错误1:what():  Error: mSources.size() != mProbabilities.size() at 51, OPDataLayer, src/caffe/openpose/layers/oPDataLayer.cpp 原因:这是因为在网络模型中数据源sources和probabilities设置的参数个数不一样导致的,一个数据源对应一个概率 解决方法:只需要将网络文