cout

Codeforces Round #593 (Div. 2)

允我心安 提交于 2019-12-01 21:46:21
目录 Contest Info Solutions A. Stones B. Alice and the List of Presents C. Labs D. Alice and the Doll E. Alice and the Unfair Game Contest Info Practice Link Solved A B C D E F 5/6 O O O O Ø - O 在比赛中通过 Ø 赛后通过 ! 尝试了但是失败了 - 没有尝试 Solutions A. Stones 签到。 代码: view code #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> #define fi first #define se second #define endl "\n" using namespace std; using db = double; using ll = long long; using ull = unsigned long long; using pII =

Codeforces Global Round 5

时间秒杀一切 提交于 2019-12-01 21:43:51
目录 Contest Info Solutions A. Balanced Rating Changes B. Balanced Tunnel C1. Balanced Removals (Easier) C2. Balanced Removals (Harder) D. Balanced Playlist Contest Info Practice Link Solved A B C1 C2 D E F G H 5/9 O O O O O - - - - O 在比赛中通过 Ø 赛后通过 ! 尝试了但是失败了 - 没有尝试 Solutions A. Balanced Rating Changes 题意: 给出 \(n\) 个数 \(a_i\) ,保证 \(\sum a_i = 0\) ,现在需要将每个数变成 \(\left \lfloor \frac{a_i}{2} \right\rfloor\) 或者 \(\left\lceil \frac{a_i}{2} \right\rceil\) ,使得变化之后的所有数之和还是 \(0\) 思路: 考虑全都变成 \(\left \lfloor \frac{a_i}{2} \right\rfloor\) ,然后差了多少补上即可。 代码: view code #pragma GCC optimize("Ofast,unroll-loops,no

Print spaces between each element using a fold expression

偶尔善良 提交于 2019-12-01 21:19:16
I am using a fold expression to print elements in a variadic pack, but how do I get a space in between each element? Currently the output is "1 234", the desired output is "1 2 3 4" template<typename T, typename Comp = std::less<T> > struct Facility { template<T ... list> struct List { static void print() { } }; template<T head,T ... list> struct List<head,list...> { static void print() { std::cout<<"\""<<head<<" "; (std::cout<<...<<list); } }; }; template<int ... intlist> using IntList = typename Facility<int>::List<intlist...>; int main() { using List1 = IntList<1,2,3,4>; List1::print(); }

P5008 [yLOI2018] 锦鲤抄

无人久伴 提交于 2019-12-01 20:33:45
洛谷 题意: 给出一个有向图,每次可以删除存在入度的点及其出边,每次删除一个点可以获得其权值。 问最终能够获得的最大权值为多少。 思路: 考虑DAG:我们直接倒着拓扑序来选,即可将所有入度不为 \(0\) 的点选完。 若不为DAG,考虑 \(tarjan\) 求出强连通分量,分析可以发现:对于一个单独的强连通分量,假设其点数为 \(n\) ,那么可以选择 \(n-1\) 个点;若其入度不为 \(0\) ,那么强连通分量中所有点都可以选择。 然后直接这样来搞就行。 证明...我也不会,在纸上画画就行了。 #include <bits/stdc++.h> #define MP make_pair #define fi first #define se second #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() #define INF 0x3f3f3f3f // #define Local #ifdef Local #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0) void err() { std::cout << '\n'; } template<typename T, typename...Args

C++ 输入字符串

大城市里の小女人 提交于 2019-12-01 19:42:17
1、cin>> 在输入一个数字或字符时可以直接使用 输入字符串方式一: 遇“空格”、“Tab”、“回车”都结束 void Cin2() { char arr[20]; cin >> arr; cout << "arr: " << arr << endl; } 2、cin.get(字符变量名) cin.get(字符变量名)用于接收单个字符 void Cinget1() { char ch; ch = cin.get(); cout << "ch = " << ch << endl; } 输入字符串方式二: cin.get(字符数组名,接收字符数) 可用来接收一行字符串,可接收空格,自动接收一个 ‘\0’ void Cinget2() { char str[20] = { 0 }; cin.get(str, 20); //类似于 getline cout << "str: " << str << endl; } 可以用cin.get(无参数)舍弃输入流中不需要的字符,或者舍弃回车 void Cinget3() { char str[20] = { 0 }; cin.get(str, 20); cin.get(); //用于吃掉回车,相当于 getchar() cout << "str: " << str << endl; cin.get(str, 5); cout << "str: "

Strange beep when using cout

喜欢而已 提交于 2019-12-01 18:07:25
today when I was working on some code of mine I came across a beeping sound when printing a buffer to the screen. Here's the mysterious character that produces the beep: '' I don't know if you can see it, but my computer beeps when I try to print it like this: cout<<(char)7<<endl; Another point of interest is that the 'beep' doesn't originate from my on board beeper, but from my headphone/speaker Is this just my computer or there something wrong with the cout function? EDIT: But then why does printing this character produce the beep sound? does that mean that I could send other such characters

C++ cout gives undeclared identifier

自作多情 提交于 2019-12-01 17:53:37
So, I have this question. Why does cout throws error C2065: 'cout' : undeclared identifier I am using Visual Studio 2012 as an IDE and I am writing a school project. I have everything done except an example file. So I am trying to write something on the screen like this: #include "iostream" #include "stdafx.h" using namespace std; int main() { cout<<"example"; return 0; } So the problem is with cout... printf works fine, but I want to use cout. EDIT: I've changed "" to <> but it is not helping. Also I am using this code only for example... This is not the whole project. Matthieu Rouget stdafx

C++: How can i create a function that accepts concatenated strings as parameter?

对着背影说爱祢 提交于 2019-12-01 17:21:31
Can i design my logging-function in a way, that it accepts concatenated strings of the following form using C++? int i = 1; customLoggFunction("My Integer i = " << i << "."); . customLoggFunction( [...] ){ [...] std::cout << "Debug Message: " << myLoggMessage << std::endl << std::endl } Edit: Using std::string as the attribute to the function works for the concatenated string, but then a passed non-concatenated string like customLoggFunction("example string") produces a compile-time error saying the function is not applicable for char[]. When i overload the function in the following way...

C++ cout overwriting itself while in for loop

让人想犯罪 __ 提交于 2019-12-01 17:21:08
The cout statement in this for loop: for (vector<Student>::iterator qw = students.begin(); qw != students.end(); ++qw){ Student a = *qw; name = a.getName(); regno = a.getRegNo(); std::cout << "Name: "<< name << " Reg Number: " << regno << endl; } Is creating some odd behavior, what the cout should print is something like this: Name: Mike Sanderson Reg Number: 10101 However which it actually prints out it: Reg Number: 10101on It would seem to me that after the second part of the cout statement it is going back to the start of the line and overwriting itself, but why? Hope you guys can help me

C++ cout gives undeclared identifier

冷暖自知 提交于 2019-12-01 17:11:15
问题 So, I have this question. Why does cout throws error C2065: 'cout' : undeclared identifier I am using Visual Studio 2012 as an IDE and I am writing a school project. I have everything done except an example file. So I am trying to write something on the screen like this: #include "iostream" #include "stdafx.h" using namespace std; int main() { cout<<"example"; return 0; } So the problem is with cout... printf works fine, but I want to use cout. EDIT: I've changed "" to <> but it is not