Codeforces Round #277.5 (Div. 2)

题目链接:http://codeforces.com/contest/489

A:SwapSort

In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another.

Note that in this problem you do not have to minimize the number of swaps — your task is to find any sequence that is no longer than n.

题意:给出包含n个数的数组(一个数可以出现多次),每次可以交换任意两个数,最多交换n次后,要求数组变成非降序数列。求出这样的一个交换操作(不要求求出最少交换次数)

解法:首先我们需要知道,一个数列最终要变为非降序,要么原数列中最小的数一定要在排完序的数列中的首位置。剩下的就迎刃而解了。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cstdlib>
 5 #include<cmath>
 6 #include<algorithm>
 7 #define inf 0x7fffffff
 8 using namespace std;
 9 const int maxn=3000+10;
10 int an[maxn];
11 int cn[maxn][2];
12 int cnt;
13 int main()
14 {
15     int n;
16     while (scanf("%d",&n)!=EOF)
17     {
18         cnt=0;
19         for (int i=0 ;i<n ;i++) scanf("%d",&an[i]);
20         for (int i=0 ;i<n ;i++)
21         {
22             int minnum=an[i],k=i;
23             for (int j=i+1 ;j<n ;j++)
24             {
25                 if (an[j]<minnum)
26                 {
27                     minnum=an[j] ;k=j ;
28                 }
29             }
30             if (k==i) continue;
31             cn[cnt][0]=i;
32             cn[cnt][1]=k;
33             swap(an[i],an[k]);
34             cnt++;
35         }
36         printf("%d\n",cnt);
37         for (int i=0 ;i<cnt ;i++) printf("%d %d\n",cn[i][0],cn[i][1]);
38     }
39     return 0;
40 }
View Code

 

B:BerSU Ball

 

The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.

 

We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one.

 

For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls.

题意:n个男孩,每个男孩给一个值,a1,a2,,,,an;m个女孩,b1,b2,,,bm。如果abs(ai-bj)<=1,说明男孩i 和 女孩j 配对成功,配对成功的这两个人就不能再和其他人配对了,即每个人只有一次配对成功的机会。问最大成功配对数。

解法:咋一看想到了二分最大匹配,再一想想,好像贪心可以搞。对两个数组非降序排序,如果 ai > bj + 1,那么ai 后面的肯定也和bj 配对不成功;如果ai 和 bj 配对成功,ai+1 和 bj  也能配对成功,那么这时候我们把bj  和 ai 组在一起,让ai+1有机会和 bj+1 配对。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cstdlib>
 5 #include<cmath>
 6 #include<algorithm>
 7 #define inf 0x7fffffff
 8 using namespace std;
 9 const int maxn=111;
10 int an[maxn],bn[maxn];
11 int n,m;
12 int main()
13 {
14     while (scanf("%d",&n)!=EOF)
15     {
16         for (int i=0 ;i<n ;i++) scanf("%d",&an[i]);
17         scanf("%d",&m);
18         for (int i=0 ;i<m ;i++) scanf("%d",&bn[i]);
19         int cnt=0;
20         sort(an,an+n);
21         sort(bn,bn+m);
22         int j=0;
23         for (int i=0 ;i<n ;i++)
24         {
25             while (j<m && an[i]-bn[j]>1) j++;
26             if (j==m) break;
27             if (abs(an[i]-bn[j])==1 || an[i]==bn[j]) {cnt++;j++; }
28         }
29         printf("%d\n",cnt);
30     }
31     return 0;
32 }
View Code

C:Given Length and Sum of Digits...

You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.

题意:给出n 和 m ,构造出两个不含前导零的n位数,位数上值的和为m,一个是最大,另一个最小。

解法:简单构造

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cstdlib>
 5 #include<cmath>
 6 #include<algorithm>
 7 #define inf 0x7fffffff
 8 using namespace std;
 9 const int maxn=104;
10 char str[maxn],str2[maxn];
11 int m,s;
12 int main()
13 {
14     while (scanf("%d%d",&m,&s)!=EOF)
15     {
16         if (m==1 && s==0) {printf("0 0\n");continue; }
17         if (s==0) {printf("-1 -1\n");continue; }
18         memset(str,0,sizeof(str));
19         memset(str2,0,sizeof(str2));
20         int flag=0;
21         int cnt=0;
22         int ss=s;
23         str[m-1]='1';ss--;
24         for (int i=0 ;i<m-1 ;i++) str[i]='0';
25         //if (ss<0) {printf("-1 -1\n");continue; }
26         while (ss>9)
27         {
28             str[cnt++] = '9';
29             ss -= 9 ;
30         }
31         if (ss>0) {str[cnt]=str[cnt]-'0'+ ss+'0';cnt++;}
32 
33         int cnt2=0;
34         while (s>9)
35         {
36             str2[cnt2++]='9';
37             s -= 9;
38         }
39         if (s>0) str2[cnt2++]=s+'0';
40         while (cnt2<m) str2[cnt2++]='0';
41         if (cnt2!=m)
42         {
43             printf("-1 -1\n");continue;
44         }
45         str2[cnt2]=0;
46         for (int i=m-1 ;i>=0 ;i--) cout<<str[i];
47         printf(" %s\n",str2);
48     }
49     return 0;
50 }
View Code

 

D:Unbearable Controversy of Being

Tomash keeps wandering off and getting lost while he is walking along the streets of Berland. It's no surprise! In his home town, for any pair of intersections there is exactly one way to walk from one intersection to the other one. The capital of Berland is very different!

Tomash has noticed that even simple cases of ambiguity confuse him. So, when he sees a group of four distinct intersections abc andd, such that there are two paths from a to c — one through b and the other one through d, he calls the group a "damn rhombus". Note that pairs (a, b), (b, c), (a, d), (d, c) should be directly connected by the roads. Schematically, a damn rhombus is shown on the figure below:

Other roads between any of the intersections don't make the rhombus any more appealing to Tomash, so the four intersections remain a "damn rhombus" for him.

Given that the capital of Berland has n intersections and m roads and all roads are unidirectional and are known in advance, find the number of "damn rhombi" in the city.

When rhombi are compared, the order of intersections b and d doesn't matter.

题意:有向图,有四个点a,b,c,d,如果a->b , b->d ,a->c ,c->d ,这样的一个简单图称为 "damn rhombus".然后给出n个点,m条有向边,求出 "damn  rhombus"的个数

解法:暴力枚举,统计出这样一条边 a->b->d 的个数,如果 a 到 d 至少有这样的两条边,那么 a 和 d 就可以满足题中的要求,a为源点,d为汇点。

注意:如果a 到 d 有三条那样的边的话,就可以构成3个 "damn rhombus".

代码:很好懂,按照解法中的思想一步一步来,就没有给出详细解释了。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cstdlib>
 5 #include<cmath>
 6 #include<algorithm>
 7 #include<queue>
 8 #include<vector>
 9 #define inf 0x7fffffff
10 using namespace std;
11 const int maxn=3000+10;
12 typedef long long ll;
13 vector<int> vec[maxn];
14 int n,m;
15 int vis[maxn][maxn];
16 int vis2[maxn][maxn];
17 ll ans;
18 int main()
19 {
20     while (scanf("%d%d",&n,&m)!=EOF)
21     {
22         for (int i=0 ;i<maxn ;i++) vec[i].clear();
23         memset(vis,0,sizeof(vis));
24         memset(vis2,0,sizeof(vis2));
25         int a,b;
26         for (int i=0 ;i<m ;i++)
27         {
28             scanf("%d%d",&a,&b);
29             vec[a].push_back(b);
30             vis[a][b]=1;
31         }
32         ans=0;
33         for (int i=1 ;i<=n ;i++)
34         {
35             int b=vec[i].size();
36             for (int j=0 ;j<b ;j++)
37             {
38                 int u=vec[i][j];
39                 int num=vec[u].size();
40                 for (int k=0 ;k<num ;k++)
41                 {
42                     int v=vec[u][k];
43                     if (v==u || v==i) continue;
44                     vis2[i][v]++;
45                 }
46             }
47         }
48         //cout<<vis2[1][2]<<endl;
49         for (int i=1 ;i<=n ;i++)
50         {
51             for (int j=1 ;j<=n ;j++)
52             if (vis2[i][j]>1) ans += (ll)vis2[i][j]*(vis2[i][j]-1)/2;
53         }
54         printf("%I64d\n",ans);
55     }
56     return 0;
57 }
View Code

 

后续:感谢大牛提出宝贵的意见。。。

 

转载于:https://www.cnblogs.com/huangxf/p/4105486.html

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
应用背景为变电站电力巡检,基于YOLO v4算法模型对常见电力巡检目标进行检测,并充分利用Ascend310提供的DVPP等硬件支持能力来完成流媒体的传输、处理等任务,并对系统性能做出一定的优化。.zip深度学习是机器学习的一个子领域,它基于人工神经网络的研究,特别是利用多层次的神经网络来进行学习和模式识别。深度学习模型能够学习数据的高层次特征,这些特征对于图像和语音识别、自然语言处理、医学图像分析等应用至关重要。以下是深度学习的一些关键概念和组成部分: 1. **神经网络(Neural Networks)**:深度学习的基础是人工神经网络,它是由多个层组成的网络结构,包括输入层、隐藏层和输出层。每个层由多个神经元组成,神经元之间通过权重连接。 2. **前馈神经网络(Feedforward Neural Networks)**:这是最常见的神经网络类型,信息从输入层流向隐藏层,最终到达输出层。 3. **卷积神经网络(Convolutional Neural Networks, CNNs)**:这种网络特别适合处理具有网格结构的数据,如图像。它们使用卷积层来提取图像的特征。 4. **循环神经网络(Recurrent Neural Networks, RNNs)**:这种网络能够处理序列数据,如时间序列或自然语言,因为它们具有记忆功能,能够捕捉数据中的时间依赖性。 5. **长短期记忆网络(Long Short-Term Memory, LSTM)**:LSTM 是一种特殊的 RNN,它能够学习长期依赖关系,非常适合复杂的序列预测任务。 6. **生成对抗网络(Generative Adversarial Networks, GANs)**:由两个网络组成,一个生成器和一个判别器,它们相互竞争,生成器生成数据,判别器评估数据的真实性。 7. **深度学习框架**:如 TensorFlow、Keras、PyTorch 等,这些框架提供了构建、训练和部署深度学习模型的工具和库。 8. **激活函数(Activation Functions)**:如 ReLU、Sigmoid、Tanh 等,它们在神经网络中用于添加非线性,使得网络能够学习复杂的函数。 9. **损失函数(Loss Functions)**:用于评估模型的预测与真实值之间的差异,常见的损失函数包括均方误差(MSE)、交叉熵(Cross-Entropy)等。 10. **优化算法(Optimization Algorithms)**:如梯度下降(Gradient Descent)、随机梯度下降(SGD)、Adam 等,用于更新网络权重,以最小化损失函数。 11. **正则化(Regularization)**:技术如 Dropout、L1/L2 正则化等,用于防止模型过拟合。 12. **迁移学习(Transfer Learning)**:利用在一个任务上训练好的模型来提高另一个相关任务的性能。 深度学习在许多领域都取得了显著的成就,但它也面临着一些挑战,如对大量数据的依赖、模型的解释性差、计算资源消耗大等。研究人员正在不断探索新的方法来解决这些问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值