putchar

Codeforces Round #603 (Div. 2)

我的未来我决定 提交于 2019-12-06 04:22:46
A. Sweet Problem 题目大意:你有不同数量的红绿蓝三种颜色的糖果,每天想吃两颗颜色不同的糖果,问能吃多少天。 2019ICPC沈阳赛区flowers的弱化题qwqflowers是有n种花选m种不同种类的一朵花组成一束花问最多能组成多少束。 是否可行具有单调性,二分天数,只要选的糖果数小于等于天数,就一定存在某种方案,不会出现某一天吃两只同样的糖果。 1 #include <bits/stdc++.h> 2 #define MIN(a,b) ((((a)<(b)?(a):(b)))) 3 #define MAX(a,b) ((((a)>(b)?(a):(b)))) 4 #define ABS(a) ((((a)>0?(a):-(a)))) 5 using namespace std; 6 7 template <typename T> 8 void read(T &x) { 9 int s = 0, c = getchar(); 10 x = 0; 11 while (isspace(c)) c = getchar(); 12 if (c == 45) s = 1, c = getchar(); 13 while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); 14 if (s) x =

Educational Codeforces Round 77 (Rated for Div. 2)

落爺英雄遲暮 提交于 2019-12-05 23:31:20
A. Heating (CF 1260 A) 题目大意:n组数据,每组数据有两个数c i 和sum i ,选择c i 个非负数a i ,使得$\sum ^{c_{i}}_{k=1}a_{k}\geq sum_{i}$,且最小化$\sum ^{c_{i}}_{k=1}a^{2}_{k}$,求最小值。 由均值不等式可知当每个a k =$\dfrac {sum_{i}}{c_{i}}$时有最小的$\sum ^{c_{i}}_{k=1}a^{2}_{k}$,但a i 需要整数,那我们先对前x个数取a+1,直到剩下的c i -x个数都取a时有$\sum ^{c_{i}}_{k=1}a_{i}=sum_{i}$,此时$\sum ^{c_{i}}_{k=1}a^{2}_{k}$最小。 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 template <typename T> 5 void read(T &x) { 6 int s = 0, c = getchar(); 7 x = 0; 8 while (isspace(c)) c = getchar(); 9 if (c == 45) s = 1, c = getchar(); 10 while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^

The C Programming Language, Ch.1 Exercise 1.10 (Getchar and Putchar)

戏子无情 提交于 2019-12-05 22:16:00
问题 I've been working on this for 2 hours and I am stuck... I found the answer online, but that isn't going to help me learn the concept that I'm obviously missing. Prompt: Write a program to copy its input to its output, replacing each tab by \t , each backspace by \b , and each backslash by \\ . This makes tabs and backspaces visible in an unambiguous way. Here's what I came up with, it doesn't replace a tab or \ with the indicated putchar , it just adds it in front of it.(I didn't do backspace

Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3)

女生的网名这么多〃 提交于 2019-12-05 12:13:30
A.Math Problem(CF 1262 A) 题目大意:给定n条线段,求一条线段,使得这个线段能够跟所有给定的线段都相交(端点值一样也算相交),最小化它的长度,可以是0. 很显然找出这n条线段的左端点最大值和右端点的最小值,它们的差和0的最大值即为答案。 1 #include <bits/stdc++.h> 2 #define MIN(a,b) (((a)<(b)?(a):(b))) 3 #define MAX(a,b) (((a)>(b)?(a):(b))) 4 using namespace std; 5 6 template <typename T> 7 void read(T &x) { 8 int s = 0, c = getchar(); 9 x = 0; 10 while (isspace(c)) c = getchar(); 11 if (c == 45) s = 1, c = getchar(); 12 while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); 13 if (s) x = -x; 14 } 15 16 template <typename T> 17 void write(T x, char c = ' ') { 18 int b[40], l = 0; 19

DISCO Presents Discovery Channel Code Contest 2020 Qual题解

牧云@^-^@ 提交于 2019-12-05 11:52:27
传送门 \(A\) 咕咕 int x,y; int c[4]={0,300000,200000,100000}; int res; int main(){ cin>>x>>y; if(x<=3)res+=c[x]; if(y<=3)res+=c[y]; if(x==1&&y==1)res+=4e5; cout<<res<<endl; return 0; } \(B\) 咕咕 const int N=2e5+5; typedef long long ll; int a[N],n;ll sum[N],suf[N],res; int main(){ scanf("%d",&n); fp(i,1,n)scanf("%d",&a[i]),sum[i]=suf[i]=a[i]; fp(i,1,n)sum[i]+=sum[i-1];fd(i,n,1)suf[i]+=suf[i+1]; res=1e18; fp(i,1,n-1)cmin(res,abs(sum[i]-suf[i+1])); printf("%lld\n",res); return 0; } \(C\) 一道思博题想了这么久看来脑子已经没用了 如果每行都有草莓那么每行分别考虑,对于没有草莓的行缩起来就行了 //quming #include<bits/stdc++.h> #define R register #define fp(i

getchar() and putchar()

可紊 提交于 2019-12-04 06:01:59
in the example: #include <stdio.h> main() { long nc; nc = 0; while (getchar() != EOF) ++nc; printf("%ld\n", nc); } I don't quite understand it. putchar() would put the character out, but why is it that after EOF it puts all the characters out, and where is it remembering all these characters? Thanks. It's called buffering and it's done by the operating system. Usually it does line buffering where it just saves every character you put to it in memory, and then writes it all to the file when it encounters a line break. This saves on resources because file operations take much more time than

The C Programming Language, Ch.1 Exercise 1.10 (Getchar and Putchar)

折月煮酒 提交于 2019-12-04 04:06:26
I've been working on this for 2 hours and I am stuck... I found the answer online, but that isn't going to help me learn the concept that I'm obviously missing. Prompt: Write a program to copy its input to its output, replacing each tab by \t , each backspace by \b , and each backslash by \\ . This makes tabs and backspaces visible in an unambiguous way. Here's what I came up with, it doesn't replace a tab or \ with the indicated putchar , it just adds it in front of it.(I didn't do backspace because I can't really input a backspace...): This is how I read the code. What am I missing?: "There

putchar() vs printf() - Is there a difference?

北战南征 提交于 2019-12-04 03:12:25
问题 I am currently in chapter 1.5.1 File copying and made a program like so: #include <stdio.h> /* copy input to output; 1st version */ main() { int c; c = getchar(); while (c != EOF) { putchar(c); c = getchar(); } } If I ran it like this: PS <..loc..> cc copy-0.c PS ./a Black Black White White Gray Gray The output is what I input. And here's a program I made for experimental purposes: #include <stdio.h> /* copy input to output; 1st version */ main() { int c; c = getchar(); while (c != EOF) {

C语言:getchar() & putchar()

ε祈祈猫儿з 提交于 2019-12-03 20:51:16
  getchar()和putchar()个函数是用来获取和显示字符的,并且每次只能处理一个字符。   getchar()是怎么获取字符的??(见下图)   当输入“seantest”这一串字符时,这字符会被自动存储在“缓冲区”,当按下“Enter”键,getchar()再从缓冲区读取一个字符,每次都只能处理一个字符。过程如下图所示:   文件结尾  当计算机读取文件时,需要知道文件的结尾,检测文件结尾的方法不止一种,其中一种方法是用一个特殊字符来标记文件的结尾,不同系统都会有自己标记文件结尾的字符,Windows中用Ctrl+Z来标记结尾。   在C语言中,当getchar()获取文件结尾时将返回一个特殊值“ EOF” , EOF (end of file的缩写)就是整数-1,之所以是-1是因为它不能表示任何标准字符(getchar()返回值为0~127)。由此,我们可以用while((ch=getchar())!='EOF')进行文件是否结尾判断,当按下Ctrl+Z时循环退出。 来源: https://www.cnblogs.com/baixu/p/11808497.html

How will you print any charcater, string or value of a variable without library functions in C?

故事扮演 提交于 2019-12-03 09:48:12
问题 If for example I should not use standard library functions like printf, putchar then how can I print a character to the screen easily. Is there any easy way of doing it. I dont know much about system calls and if I have to use them then how? So can any one advice an easy way of printing without using library functions?? 回答1: In standard C, you can't. The only I/O defined in C is through the C standard library functions. On a given platform, there may be ways to do it: Make kernel calls