getchar

codeforces-1146 (div2)

巧了我就是萌 提交于 2019-12-27 04:19:55
D 题 卡数学 (常规操作) E 题 pair<int,int>的sort只设置了一个关键字导致出现bug改了一年,原因至今不明 A.答案为字符串长度和a的数量 * 2 - 1的较小值。 #include <map> #include <set> #include <ctime> #include <cmath> #include <queue> #include <stack> #include <vector> #include <string> #include <cstdio> #include <cstdlib> #include <cstring> #include <sstream> #include <iostream> #include <algorithm> #include <functional> using namespace std; #define For(i, x, y) for(int i=x;i<=y;i++) #define _For(i, x, y) for(int i=x;i>=y;i--) #define Mem(f, x) memset(f,x,sizeof(f)) #define Sca(x) scanf("%d", &x) #define Sca2(x,y) scanf("%d%d",&x,&y) #define Sca3(x,y

Codeforces Round #558 (Div. 2)

你说的曾经没有我的故事 提交于 2019-12-27 04:17:32
目录 Codeforces Round #558 (Div. 2) 题解 A Eating Soup B Cat Party C Power Transmission D Mysterious Code E Magical Permutation Codeforces Round #558 (Div. 2) 题解 A Eating Soup 分类讨论一下 \(m\) 个断点最多可以将环分成 \(m\) 段,而剩下 \(n-m\) 个点最多可以成为 \(n-m\) 段,取个 \(\min\) 即可 注意 \(m=0\) 时是一个环答案为 \(1\) // Copyright lzt #include<stdio.h> #include<cstring> #include<cstdlib> #include<algorithm> #include<vector> #include<map> #include<set> #include<cmath> #include<iostream> #include<queue> #include<string> #include<ctime> using namespace std; typedef long long ll; typedef std::pair<int, int> pii; typedef long double ld;

[HG]奋斗赛G

橙三吉。 提交于 2019-12-26 22:36:56
T1 题目描述 安娜斯塔西娅喜欢去乌日扬迪安中央公园散步。 但她对简单的散步不感兴趣,于是她开始收集公园里的鹅卵石。 一开始,她决定收集所有她能在公园里找到的鹅卵石。 她只有两个口袋。 她能在每个口袋里同时放最多k个鹅卵石。第i种鹅卵石有w[i]个。 安娜斯塔西娅很有责任感,所以她从不把不同类型的鹅卵石混在一个口袋里。 然而,她可以把不同种类的鹅卵石放在不同的口袋。 不幸的是,她不能把所有的时间都花在收集鹅卵石上,所以她每天只能从公园里收集一次鹅卵石。 考虑到安娜斯塔西娅不能把不同类型的鹅卵石放在同一个口袋里,请帮助她找到收集乌日扬甸中央公园所有鹅卵石所需的最短天数。 解法:直接模拟 #include <cstdio> #define ll long long inline ll read(){ ll x = 0; int zf = 1; char ch = ' '; while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar(); if (ch == '-') zf = -1, ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf; } int main(){ int n =

穿越栅栏 Overfencing

那年仲夏 提交于 2019-12-26 21:20:10
题解区里都是一次性走两步 这里我就说一点 按普通(每次走一步)的来最后 \(+1\) 再除以 \(2\) 就行了 另外输入时加个时间限制 ( \(q++ if(q>=w)break;\) ) /* ID:death_r2 TASK:maze1 LANG:C++ */ #include <queue> #include <cstdio> #include <string> #include <iostream> #include <algorithm> using namespace std; #define reg register int #define isdigit(x) ('0' <= x&&x <= '9') template<typename T> inline T Read(T Type) { T x = 0,f = 1; char a = getchar(); while(!isdigit(a)) {if(a == '-') f = -1;a = getchar();} while(isdigit(a)) {x = (x << 1) + (x << 3) + (a ^ '0');a = getchar();} return x * f; } string mp[210]; bool vis[3][210][210]; int cnt,ans,d[3][210]

3277: 串

时光毁灭记忆、已成空白 提交于 2019-12-26 10:46:34
很久没写过这东西了,复习一波。 3238: [Ahoi2013]差异 链接 单调栈维护height数组,由于height是递增的,所以维护单调栈中维护每个height出现的次数。(还可以两遍单调栈求一个点是最小值的区间) 1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 #include<iostream> 5 #include<cmath> 6 #include<cctype> 7 #include<set> 8 #include<queue> 9 #include<vector> 10 #include<map> 11 using namespace std; 12 typedef long long LL; 13 14 inline int read() { 15 int x=0,f=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1; 16 for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';return x*f; 17 } 18 19 const int N = 500005; 20 21 char s[N]; 22 int t1[N], t2[N], c[N], sa[N],

How are getchar() and putchar() Macros?

丶灬走出姿态 提交于 2019-12-26 09:47:33
问题 From what I understand about macros in C, they are predefined constants that will be used throughout the program with their constant value, so we go ahead and define them to avoid further complications and make the code more readable, so people reading it will understand what is supposed to stay constant and what isn't. I have read here and there (C programming A Modern Approach, K.N King) that we can define these two functions as macro. Since I'm somewhat new to C, I can't wrap my head

9.11考试总结

早过忘川 提交于 2019-12-26 05:31:58
# 9.11考试总结 细胞分裂 数学题目,因式分解后直接判断输入数据是否含有m1中分解出来的数,然后储存需要时间最大值中的最小值 #include<bits/stdc++.h> #define open(s) freopen(s".in", "r", stdin);// freopen(s".out", "w", stdout); #define IL inline #define ull unsigned long long #define ll long long using namespace std; int n, m1, m2; int a; int maxb, lenb; int b[30010]; struct date { int su, add; }d[30010]; int lend; IL int read(); IL void cut(int); IL void cutt(int); int main() { open("cell"); n = read(); m1 = read(); m2 = read(); cut(m1); if (m1 == 1) { cout << "0" << endl; return 0; } int ans = 999999999; for (int i=1; i<=n; ++i) { a = read(); int temp

reading user command to continue does not work

你离开我真会死。 提交于 2019-12-25 12:09:22
问题 I'm Writing a program for Billing System. I'm using do-while loop in my program. And the program is executed according to user input. If the user want to continue the execution, the program will be continue. But I Got a prob in Execution. I was trying my logic in simple do-while loop. The same Problem arises for simple do-while loop also. Problem is: If the input is yes, the program does not get the further input from user. That simple do-while loop is: #include <stdio.h> main() { int c; char

10.17模拟赛(湖南集训)

白昼怎懂夜的黑 提交于 2019-12-25 09:41:00
T1 reverse 题目描述 0比1小,所以一个串中如果0全在1前面,这个串就比较和谐。对于一个只包含0和1的串,你每次可以将一个0变成1,或者将一个1变成0。那么,最少需要变多少次才能把保证所有的0在1前面呢? 输入输出格式 输入格式: 一个01串 输出格式: 一个数即答案 输入输出样例 输入样例#1: 010001 输出样例#1: 1 说明 对于40%的数据,len<=20 对于70%的数据,len<=1000 对于100%的数据,len<=10^5 题解: 我好像理解错题目了,我以为必须有1和0,好像只有1或者只有0也可以。 枚举1的数量 #include<iostream> #include<cstdio> #include<cstring> #define maxn 100009 #define inf 1000090 using namespace std; char s[maxn]; int len,cnt,tmp,p,now,ans; int main(){ freopen("reverse.in","r",stdin); freopen("reverse.out","w",stdout); scanf("%s",s+1);len=strlen(s+1); for(int i=1;i<=len;i++) if(s[i]=='1')cnt++; if(cnt==0|

Using getchar to immediately retrieve keystrokes

╄→尐↘猪︶ㄣ 提交于 2019-12-25 02:04:02
问题 I'm trying to use getchar() to retrieve 1 keystroke at a time from the keyboard. Though it does this, the problem I'm having is doesn't send it immediately, it waits for the enter key to be pressed and then it reads 1 char at a time from the buffer. int main(){ char c = getchar(); putchar(c); return 0; } How do I immediately read each keystroke as it's pressed from the keyboard? Thanks 回答1: You have to pass in raw mode. I paste you code from: http://c.developpez.com/faq/?page=clavier_ecran