当前位置:网站首页>刷题-洛谷-P1146 硬币翻转
刷题-洛谷-P1146 硬币翻转
2022-07-25 13:32:00 【宋向上_UP】
P1146 硬币翻转-C语言
1、问题

2、解题过程
(1)第一次 输出格式不对 忘了输出翻转次数了
结果:
代码:
//洛谷 P1146 硬币翻转
#include <stdio.h>
#define MAX 100 //表示硬币的个数
int main() {
int n;//不大于100的偶数
int s;//最少需要操作的次数
int coin[MAX] = {
1};//硬币状态 1表示反面朝上 0表示正面朝上
int i,j;
//int turn;//每次翻转的次数 n-1次
scanf("%d", &n);
for (i = 0; i < n; i++) {
//对硬币状态进行初始化
coin[i] = 0;//正面朝上
}
//限制n为偶数 减低了本题的难度
for (i = 0; i < n; i++) {
//n枚硬币最少需要翻转n次
for (j = 0; j < n; j++) {
if (j != i) {
//翻转
coin[j] = (coin[j] == 0) ? 1 : 0;//翻转
}
printf("%d", coin[j]);
}
if (i < n - 1) {
//最后一行不打印换行符
printf("\n");
}
}
return 0;
}
(2)第二次
结果:
代码:
//洛谷 P1146 硬币翻转
#include <stdio.h>
#define MAX 100 //表示硬币的个数
int main() {
int n;//不大于100的偶数
//int s;//最少需要操作的次数
int coin[MAX] = {
1};//硬币状态 1表示反面朝上 0表示正面朝上
int i,j;
//int turn;//每次翻转的次数 n-1次
scanf("%d", &n);
for (i = 0; i < n; i++) {
//对硬币状态进行初始化
coin[i] = 0;//正面朝上
}
//需要翻转n次
printf("%d\n", n);
//限制n为偶数 减低了本题的难度
for (i = 0; i < n; i++) {
//n枚硬币最少需要翻转n次
for (j = 0; j < n; j++) {
if (j != i) {
//翻转
coin[j] = (coin[j] == 0) ? 1 : 0;//翻转
}
printf("%d", coin[j]);
}
if (i < n - 1) {
//最后一行不打印换行符
printf("\n");
}
}
return 0;
}
边栏推荐
- hcip第十天笔记
- 0716RHCSA
- mujoco_ Py Chinese document
- 【AI4Code】《Unified Pre-training for Program Understanding and Generation》 NAACL 2021
- R language GLM generalized linear model: logistic regression, Poisson regression fitting mouse clinical trial data (dose and response) examples and self-test questions
- Shell common script: check whether a domain name and IP address are connected
- R语言GLM广义线性模型:逻辑回归、泊松回归拟合小鼠临床试验数据(剂量和反应)示例和自测题
- 一味地做大元宇宙的规模,已经背离了元宇宙本该有的发展逻辑
- 0717RHCSA
- 基于百问网IMX6ULL_PRO开发板移植LCD多点触摸驱动(GT911)
猜你喜欢

arm架构移植alsa-lib和alsa-utils一路畅通

Date and time function of MySQL function summary

Shell common script: judge whether the file of the remote host exists

ES6 array de duplication new set()

【GCN】《Adaptive Propagation Graph Convolutional Network》(TNNLS 2020)

QGIS加载在线地图:高德、天地图等

Excel record macro

0710RHCSA

Any time, any place, super detective, seriously handle the case!

基于百问网IMX6ULL_PRO开发板移植LCD多点触摸驱动(GT911)
随机推荐
0710RHCSA
【GCN-RS】Learning Explicit User Interest Boundary for Recommendation (WWW‘22)
【GCN-RS】Towards Representation Alignment and Uniformity in Collaborative Filtering (KDD‘22)
Numpy简介和特点(一)
Any time, any place, super detective, seriously handle the case!
并发编程之并发工具集
Uncaught SyntaxError: Octal literals are not allowed in strict mode.
Convolutional neural network model -- lenet network structure and code implementation
QingChuang technology joined dragon lizard community to build a new ecosystem of intelligent operation and maintenance platform
【GCN】《Adaptive Propagation Graph Convolutional Network》(TNNLS 2020)
mujoco+spinningup进行强化学习训练快速入门
QGIS加载在线地图:高德、天地图等
Based on Baiwen imx6ull_ Pro development board transplants LCD multi touch driver (gt911)
【GCN-RS】Region or Global? A Principle for Negative Sampling in Graph-based Recommendation (TKDE‘22)
6.27 uniapp项目历程
为提高效率使用ParallelStream竟出现各种问题
hcip第八天实验
How to solve the problem of taking up too much space when recording and editing videos?
The whole process of 6w+ word recording experiment | explore the economical data storage strategy of alluxio
录制和剪辑视频,如何解决占用空间过大的问题?