begin

[题解]NOIP2018_赛道修建(二分/树形dp/set/贪心

醉酒当歌 提交于 2019-12-03 01:38:15
部分分:m=1 直径,菊花图 对边权排序,每次取最大最小合并,链 dp覆盖啥的 二叉树的话,二分答案,每个儿子要么和x连在一起往上传,要么和另外一个儿子合并(长度和大于mid),(统计以点x为lca的),x取大的儿子的f值,因为 正解把菊花图和二叉树合在一起,对每个点的儿子不断取两个边权加起来刚好大于mid的,然后剩下的取一个最大的传给父亲,用set实现 说起来容易做起来难.... #include<bits/stdc++.h> #define ll long long using namespace std; const int maxn=50009; int n,m,ans; struct node{ int v,nxt,w; }e[maxn<<1]; int head[maxn],cnt; inline void add(int u,int v,int w){ e[++cnt].v=v;e[cnt].w=w;e[cnt].nxt=head[u];head[u]=cnt; } multiset<int>s[maxn]; ll dfs(int x,int fa,int k){ s[x].clear(); int val; for(int i=head[x];i;i=e[i].nxt){ int y=e[i].v;if(y==fa)continue; val=dfs(y,x,k)

Is it possible to erase elements of a std::list in a c++11 for each loop

匿名 (未验证) 提交于 2019-12-03 01:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I want to use the new C++11 for each loop to iterate over all elements of a list and erase certains elements. For example std :: list <int> myList ; myList . push_back ( 1 ); myList . push_back ( 13 ); myList . push_back ( 9 ); myList . push_back ( 4 ); for ( int element : myList ) { if ( element > 5 ) { //Do something with the element //erase the element } else { //Do something else with the element } } Is it possible to do this using the for each loop or do I have to go back to iterators to achive this? 回答1: You should be able to

R: xtable caption (or comment)

匿名 (未验证) 提交于 2019-12-03 01:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to put a comment under a table printed out by xtable. I figured that the best option would be to use the "caption" option: xtable(tablename, caption="This is a caption") . But this is somehow putting in a "Table 1" automatically, so that the output looks like: Table 1: This is a caption. Is there any way to suppress this or any simpler way of putting in a comment simply as an additional last row in the table? 回答1: First, some mock data: x Now here's a somewhat clumsy solution, using print.xtable 's add.to.row argument. comment If you

Count the number of times each word occurs in a file

匿名 (未验证) 提交于 2019-12-03 01:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Hi I am writing a program that counts the number of times each word occurs in a file. Then it prints a list of words with counts between 800 and 1000, sorted in the order of count. I am stuck on keeping a counter to see if the first word matches the next until a new word appears. In the main I am trying to open the file, read each word by word and call sort in the while loop to sort the vector. Then, in the for loop go through all the words and if the first word equals the second count++. I don't think that is how you keep a counter. Here is

Select values that begin with a number

匿名 (未验证) 提交于 2019-12-03 01:27:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a table with a column containing data that begin with numbers too, on MySQL How can I select the rows that begin only with a number? 回答1: SELECT * FROM YourTable WHERE YourColumn regexp '^[0-9]+' 回答2: You can do: SELECT * FROM MyTable WHERE MyColumn REGEXP '^[0-9]'; The regular expression used is ^[0-9] . ^ - Start anchor, used to ensure the pattern matches start of the string. [ - Start of character class. 0-9 - Any digit ] - End of character class Effectively we are trying to select those values in the column that begin with a digit

Using parameters with ADO Query (mysql/MyConnector)

匿名 (未验证) 提交于 2019-12-03 01:25:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Today I downloaded and installed MyConnector so I can use Mysql with ADO, everything installed, OK!, I can make connection with ODBC and do a connection from my delphi environment. when I build my Query at runetime, I get an error saying : Project Project1.exe raised exception class EOleException with message 'Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another'. Process stopped. Use Step or Run to continue. function TForm1 . CreateSQL : TADOQuery ; begin result := TADOQuery . create (

How to add element by element of two STL vectors?

匿名 (未验证) 提交于 2019-12-03 01:23:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: The question is quite dumb, but I need to do it in a very efficient way - it will be performed over an over again in my code. I have a function that returns a vector, and I have to add the returned values to another vector, element by element. Quite simple: vector result; vector result_temp for(int i=0; i The mathematical operation that I'm trying to do is u[i] = u[i] + v[i] for all i What can be done? Thanks EDIT: added a simple initialization, as that is not the point. How should result be initialized? 回答1: If you are trying to append one

How to put begin-commit transaction in controller: cakephp?

匿名 (未验证) 提交于 2019-12-03 01:22:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm working on a controller that will update a few tables. I am able to call my model from my controller and inside the model function I can make a begin and commit my query, it can rollback should an error happen. Here is my sample: Controller: //update table when update button is clicked if (! empty ( $this -> data )) { if ( $this -> Item -> update ( $this -> data )) { $this -> Item -> create (); $this -> redirect ( '/sample' ); return ; } else { $this -> set ( 'data' , $this -> data ); } } Model: function update ( $data ) {

std::vector insert without knowing the type of the elements

匿名 (未验证) 提交于 2019-12-03 01:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Suppose I have a templated function that takes various kinds of vectors (but for various reasons I can't mention this in the template parameter). Here's what I'm trying to do: insert a new, default constructed element at a specific spot, without knowing its type: template < typename T > void foo ( T * v ) { v -> insert ( v -> begin () + 5 , decltype ( v -> at ( 0 ))()); } This doesn't work, but gives you an idea of what I'm trying to do. I also tried to use value_type from std::vector but I ran into problems there as well. Any

Differences between “BEGIN RSA PRIVATE KEY” and “BEGIN PRIVATE KEY”

匿名 (未验证) 提交于 2019-12-03 01:12:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Hi I was writing a program that imports private keys from a .pem file and create a private key object to use it later.. the problem I have faced is that some pem files header begin with -----BEGIN PRIVATE KEY----- while others begin with -----BEGIN RSA PRIVATE KEY----- through my search I knew that the first ones are PKCS#8 formatted but I couldn't know what format does the other one belongs to. 回答1: See https://polarssl.org/kb/cryptography/asn1-key-structures-in-der-and-pem (search the page for "BEGIN RSA PRIVATE KEY") ( archive link for