Codeforces Round #311 (Div. 2) D

洛谷 P1714 切蛋糕 单调队列 阅读详情

D Vitaly and Cycle

        无向图,n个点m条边。问至少添加几条边,使得图有奇环(不能是单个点),有几种添加方法。

        这里用到了一个很重要的定理:二分图没有奇环。给图染色判断是不是二分图。然后分类讨论。

#include <bits/stdc++.h>    
  
using namespace std;    

#define ll long long
const int maxn=100010;

ll n,m;
vector<int> E[maxn];
int color[maxn];
bool flag;
int tot;
ll part1,part2;

void dfs(int u,int pre){
	tot++;
	color[u]=!color[pre];
	if(color[u]==1)part1++;
	else part2++;
	for(int i=0;i<E[u].size();i++){
		int v=E[u][i];
		if(v==pre)continue;
		if(-1!=color[v]){
			if(color[v]==color[u]){
				flag=1;
				return;
			}
		}else{
			dfs(v,u);
		}
	}
}

int main(){
	memset(color,-1,sizeof(color));
	color[0]=0;
	cin>>n>>m;
	
	for(int i=1;i<=m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		E[u].push_back(v);
		E[v].push_back(u);
	}
	
	ll ans=0,ans2=0;
	for(int i=1;i<=n;i++){
		tot=0;
		part1=part2=0;
		if(-1==color[i]){
			dfs(i,0);
		}
		if(tot>2){
			ans+=part1*(part1-1)/2;
			ans+=part2*(part2-1)/2;
		}else if(tot==2){
			ans2+=(n-2);
		}
		
	}
	
	if(flag){
		printf("0 1\n");
	}else{
		if(m==0){
			printf("3 %I64d\n",n*(n-1)*(n-2)/6);
		}else{
			if(ans){
				printf("1 %I64d\n",ans);
			}else{
				printf("2 %I64d\n",ans2);
			}
		}
	}
	return 0;
}


从单应矩阵到实际距离:Apriltag测距完整实现指南 本文提供了基于Apriltag实现高精度视觉测距与姿态估计的完整指南。详细阐述了从相机标定、单应矩阵分解到欧拉角与距离计算的完整流程,并深入探讨了四个解的歧义选择、工程实践中的滤波优化与多Tag融合等关键问题,旨在帮助开发者在机器人、AR等应用中实现稳定可靠的距离检测与姿态估计。 阅读详情

相关推荐

Flutter 完整学习文档 - 从入门到精通

Widget 就像乐高积木,Flutter 中所有的东西都是 Widget。一个按钮是 Widget,一段文字是 Widget,甚至布局、边距、对齐方式也是 Widget!"万物皆 Widget"

zwjapple的专栏 2314

Codeforces Round #428 (Div. 2) A B C D

A. Arya and Bran time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Bran and his older sister Arya are from

J. Cole 609

C#实战:5分钟搞定西门子S7-1200 PLC数据读写(S7netplus保姆级教程)

本文详细介绍了如何使用C#和S7netplus库快速实现与西门子S7-1200 PLC的数据读写。从环境准备、连接管理到数据读写高级技巧,提供了保姆级教程和实战方案,帮助开发者绕过常见陷阱,提升工业自动化项目的开发效率。

weixin_28432777的博客 283

HDU 1290 切蛋糕 (献给杭电五十周年校庆的礼物) *

单单二维切圆的时候是 g(n)=g(n-1)+n 得出 g(n)=(n*n+n+2)/2 加上三维横着切最好,每次可以增加 g(n-1) 所以 f(n)=f(n-1)+g(n-1); 思路来自:http://blog.sina.com.cn/s/blog_ab20767501017kvp.html 最简单的就是用待定系数法,直接解方程 #include #include #

BRCOCOLI的博客 536

UE5实战:用Cesium插件打造逼真湖泊效果(附波纹参数调优技巧)

本文详细介绍了在Unreal Engine 5中利用Cesium插件创建逼真区域水效果(如湖泊)的实战流程。重点解析了通过材质层混合机制,精细调整波纹参数(如DistanceScale、NearScale)来模拟不同水体状态,并提供了从资产创建、地形配置到视觉调优的一站式解决方案,帮助开发者高效实现非海洋水域的动态视觉效果。

weixin_29209805的博客 160

基于光电传感的非接触式酒精浓度检测系统设计与实现

本文详细介绍了基于光电传感技术的非接触式酒精浓度检测系统设计与实现。系统利用940nm红外LED和OPT101光电传感器,结合朗伯-比尔定律,通过STM32微控制器进行信号采集与处理,实现了快速、准确的酒精浓度测量,测量精度达±1%,适用于工业检测和便携式应用场景。

y7z8a的博客 363

NYOJ 869 切蛋糕

切蛋糕 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述     有如下图半径为R的圆形蛋糕,被切一刀后(图中红色直线),分成两个部分(黄色和绿色),已知其比例为r,求刀痕长度(图中红色直线)。 输入输入包括多组测试数据,包括一个整数R(1 输出对于每组测试用例,输出一个浮点数,代表刀痕的长度,保留二位小数。 样例输

许长安 1516

高数 | 【极限与等价无穷小】两个重要极限 & 经典错误 & 什么情况下求极限可以直接带入

一. 第一个重要极限 二. 第二个重要极限 三. 导数定义式 全文见【高等数学】两个重要的极限 - 知乎

"You are worthy! You can do it!" 6万+

Codeforces Round #311 (Div. 2) A,B,C,D,E

A. Ilya and Diplomas 思路:水题了, 随随便便枚举一下,分情况讨论一下就OK了。 code: #include #include #include #include #include #include #include #define inf 1000000 #define clr(x, y) memset(x, y, sizeof x)

乐观之奋斗者 1179

Mstar的Monitor方案OSD 菜单制作(五)——icon绘制

Mstar的Monitor方案(五)————绘制icon

android 系统定制开发那些事 1807

完美解决Iframe嵌入帆软报表出现跨域cookie写不进去的问题

那报表后续的请求如何加上这个fine_auth_token,通过观察,我们发现,如果给报表url上加上fine_auth_token,后续的请求中的Refer也会有这个fine_auth_token。我们可以这样想,如果帆软内部获取token,如果从cookie中获取不到,就从url上获取,如果url上也获取不到,那么就从请求Refer请求头中获取也可以拿到这个token了。从上面看到,如果从cookie中没有获取到,就从请求头中获取,还是没有就从paramter中获取。

帆软爱好者的专栏 4059

Codeforces Round #311 (Div. 2) D. Vitaly and Cycle

题目链接:http://codeforces.com/problemset/problem/557/D 题意:给你包含n个顶点,m条边的不一定连通&amp;&amp;没有自环和重边的无向图,要你找到能够使得这个图中存在:(奇数长度&amp;&amp;顶点数&gt;1 ) 的简单圈 所需添加边的最小数量t。并且找出添加t的方法数w 禁止直接添加自环或重边 添加边的方法用所添加边的集合来区分,如果...

凝望的博客 277

vue2 - 实现移动端H5网页调用手机相册选取图片或打开摄像头相机拍照上传,如何在h5网站浏览器中打开本机相册或相机选择相片,H5调用本地相册/相机上传图片详细教程(附图片压缩功能及上传服务器示例)

vue2手机H5网页,调起安卓苹果ios手机相册和相机,H5实现调用手机摄像头相册实现图片压缩预览删除,vue项目调用摄像头和相册,H5调用手机摄像头,实时拍照上传,VUE2 H5页面如何唤起手机摄像头拍照上传,H5调起手机端的摄像头,html5调用手机摄像头,实现H5调起手机相机和相册,vue H5拍照上传,手机网站浏览器移动端调取相机或相册,实现拍照上传功能,解决苹果ios手机无法打开相册相机问题,无法唤起摄像头怎么办,调取本机系统的相册,vue h5网页调用相机拍照和相册,实现多张图片上传功能,图片压

✅ 精选推荐文章 1万+

Codeforces Round #311 (Div. 2) A B C D

A - Ilya and Diplomas给出三种奖项的上下限,使一等,二等,三等的数量依次尽量多。求分配方案 int main() { int n; int l1, r1, l2, r2, l3, r3; while( ~scanf("%d%d%d%d%d%d%d", &n, &l1, &r1, &l2, &r2, &l3, &r3 ) ) { int

uuuuuu 428

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain&#39;s apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath(&#39;DeepLearnToolbox&#39;));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand(&#39;state&#39;,0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = &#39;sigm&#39;;%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, &#39;Too big error&#39;);```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, &#39;Too big error&#39;);```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Codeforces Round #311 (Div. 2) D. Vitaly and Cycle

After Vitaly was expelled from the university, he became interested in the graph theory. Vitaly especially liked the cycles of an odd length in which each vertex occurs at most once. Vitaly was wond...

天涯沧海的博客 158

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

Codeforces Round #311 (Div. 2)--D(图

题意:给出一个图,问最少加多少条边能连出一个奇圈,还要求输出连边的方法种数。 思路:比赛的时候看了一下是图相关的就没多想,也没时间了,其实挺简单的,如果已经有奇圈,那么直接输出0 1,如果最多有两个点相连,那么就是(n-2)×m,就是每条边和另外的任意点连两条边,要么就是没有边,这个就是直接输出结果。。 稍微麻烦一点的是最后一种,联通块有多个点且没有奇圈,这时候需要把联通快黑白染色,...

aduqw1129的博客 83

Codeforces Round #311 (Div. 2) D DFS+染色

链接:戳这里 D. Vitaly and Cycle time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output After Vitaly was expelled from the university, he beca

Cross 444

Codeforces Round #311 (Div. 2) D - Vitaly and Cycle

D. Vitaly and Cycle time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output After Vitaly was expelled from the university, he be...

weixin_30511107的博客 207

Codeforces Round #311 (Div. 2) C(技巧) *D(二分图染色)

C. Arthur and Table http://codeforces.com/contest/557/problem/C 题意:一张桌子有n条桌腿,每条桌腿有相应的长度和移动花费值,要使桌子平稳,最长桌腿的数量M 与桌腿的数量关系为 M*2>N,求出使桌子平稳的最小花费值。 思路:将桌腿按照长度由大到小排序,依次以不同长度的桌腿cnt 作为桌子的平稳支撑,保留另外cnt-1条花费值

Halo 808

Codeforces Round #311 (Div. 2) D. Vitaly and Cycle 图论

D. Vitaly and Cycle Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/557/problem/D Description After Vitaly was expelled from the university, he became interested in ...

weixin_30347009的博客 92

Codeforces Round #311 (Div. 2) D. Vitaly and Cycle 图论 二分图

D. Vitaly and Cycle time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output After Vitaly was expelled from the university, he became interested in

习惯与规则决定命运 1426

Codeforces Round #311 (Div. 2) D - Vitaly and Cycle(二分图染色应用)

http://www.cnblogs.com/wenruo/p/4959509.html 给一个图(不一定是连通图,无重边和自环),求练成一个长度为奇数的环最小需要加几条边,和加最少边的方案数。 很容易知道连的边数只能是0,1,2,3。 如果是二分图一定不含长度为奇数的环。 难点是如果是二分图怎么求方案数呢? 二分图染色时能求出每一个联通块。在每一个联通块中把任意两个颜色相同的点连一条...

weixin_30673715的博客 111
上一篇: Codeforces Round #312 (Div. 2) A B C D E
下一篇: hdu 5292 Pocket Cube
squee_spoon
博客等级 码龄14年 61粉丝 455原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值