CF Round #348 Div. 2 A. Little Artem and Present B. Little Artem and Grasshopper C. Little Artem and
来源:互联网 发布:qq邮箱设置域名邮箱 编辑:程序博客网 时间:2024/06/07 09:20
今天起开始刷CF,不知道能坚持多久,希望不要放弃,编程这东西一放就忘。
关于解题,能用语言描述的东西就不画图了,下面进入正题。
A. Little Artem and Present
题意:
小A有一些石子,想作为礼物送给小M。小M不在意送的礼物是否为贵重,而在意送礼物的次数。如果是送石子,小M还记得上次送了几个石子,所以小A为了讨好小M,需要保证送礼物次数尽可能多并且每次送的数量和上次不同。
问当小A有n个石子的时候,最多可以送几次?
题解:
显然,每次送石头数至少为1。如果上次送1个,本次最少送2个。如果上次送2个,本次又可以送1个。即有3个石子就可以完成2次送礼,n含有m个3就可以送2*m次,剩下如果还有石子,则可以再送一次,
故送礼次数=n / 3 + ((n % 3 == 0) ? 0 : 1)
代码:
#include <iostream>using namespace std;int main() {int n;while(cin >> n) {cout << (n / 3 * 2 + ((n % 3 == 0)? 0 : 1)) << endl;}return 0;}
B. Little Artem and Grasshopper
题意:
跳格子游戏,有1 x n大小的格子,每个格子上标明跳的方向(< 和 >)以及需要跳的格子数。参与者从第一个格子开始跳,并遵循格子上的指示,问能否跳出格子(前后均算跳出)?
题解:
代码:
#include <iostream>#include <map>#include <string>using namespace std;int main() {// 获取输入 int n;cin >> n;string str;cin >> str;int* num = new int[n];for (int i = 0, tmp = 0; i < n; i++) {cin >> tmp;num[i] = (str[i] == '<') ? -tmp : tmp;}// 初始位置为0,开始跳格子 int pos = 0;map<int, int> m;for (m[0] = 0; pos >= 0 && pos < n; m[pos] = 0) {//根据当前位置需要跳格子数得到新位置 pos += num[pos];// 如果新位置以前来过,说明进入循环,怎么也跳不出去了 if (m.find(pos) != m.end()) {delete[] num;cout << "INFINITE" << endl;return 0;}}// 跳出格子 delete[] num;cout << "FINITE" << endl;return 0;}
C. Little Artem and Matrix
题意:
有一个电子设备,大小n行 x m列,与数组类似,每个位置均可存数据,并遵循如下规则:
1. 每行每列均可接收输入信号,即m+n个输入;
2. 当第 i 行收到信号时,第 i 行的元素值循环左移(第 1 个变最后 1 个,第 2 个变第 1 个);
3. 当第 j 列收到信号时,第 j 列的元素值循环上移;
操作方面,1 n 表示第 n 行收到信号,2 n 表示第 n 列收到信号,3 x y w 表示此时测得(x,y)的值为w;
问题是,该电子设备初始状态未知,即每个位置数据未知,在一系列操作后,得到另外一种状态,问原状态是什么?
题解:
代码:
#include <iostream>#include <vector>using namespace std;struct node {int type;int num;int n3;int n4;node(int type, int num, int n3 = 0, int n4 = 0) {this->type = type;this->num = num;this->n3 = n3;this->n4 = n4;}};void changeRow(vector<vector<int> >& vec, int n, int m, int row) {int tmp = vec[row][m];for (int i = m - 1; i > 0; i--) {vec[row][i + 1] = vec[row][i]; }vec[row][1] = tmp;}void changeCol(vector<vector<int> >& vec, int n, int m, int col) {int tmp = vec[n][col];for (int i = n - 1; i > 0; i--) {vec[i + 1][col] = vec[i][col];}vec[1][col] = tmp;}int main() {// 题设变量n, m, q int n, m, q;cin >> n >> m >> q;// 开辟数组存储n x m 矩阵 操作信息 vector<vector<int> > vec(n + 1, vector<int>(m + 1, 0));vector<node> opera;// 读信息 for (int i = 0; i < q; ++i) {int n1, n2, n3, n4;cin >> n1 >> n2;if (n1 != 3) {opera.push_back(node(n1, n2));continue;}cin >> n3 >> n4;opera.push_back(node(n1, n2, n3, n4));}// 反推回最初的结果 for (int i = (int)opera.size() - 1; i >= 0; --i) {if (opera[i].type == 1) {changeRow(vec, n, m, opera[i].num);} else if (opera[i].type == 2){changeCol(vec, n, m, opera[i].num);} else {vec[opera[i].num][opera[i].n3] = opera[i].n4;}}// 输出结果for (int i = 1; i <= n; ++i) {for (int j = 1; j <= m; ++j) {cout << vec[i][j] << " ";}cout << endl;} }
- CF Round #348 Div. 2 A. Little Artem and Present B. Little Artem and Grasshopper C. Little Artem and
- B. Little Artem and Grasshopper
- Little Artem and Grasshopper
- CodeForces 669B Little Artem and Grasshopper
- codeforces 669B Little Artem and Grasshopper
- Codeforces Round #348 (div 2) A. Little Artem and Presents
- Codeforces Round #348 (div 2) C. Little Artem and Matrix
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition)-B. Little Artem and Grasshopper(模拟)
- A. Little Artem and Presents
- Codeforces 669B Little Artem and Grasshopper【思维+模拟】
- CodeForces 641 A.Little Artem and Grasshopper(水~)
- CodeForces 668B Little Artem and Dance
- CodeForces 669A Little Artem and Presents
- CodeForces 669A Little Artem and Presents
- 【CodeForces】669A - Little Artem and Presents
- 【CodeForces】[669A]Little Artem and Presents
- CodeForces 668A Little Artem and Matrix
- CodeForces 669A Little Artem and Presents
- Android 自定义View(1)
- 哈工大操作系统实验5—I/O设备管理
- c++第四次作业
- UI/Application Exerciser Monkey
- ASP.NET教程收集
- CF Round #348 Div. 2 A. Little Artem and Present B. Little Artem and Grasshopper C. Little Artem and
- 网络框架的封装(二)
- C++作业4
- 剑指offer之面试题22:栈的压入、弹出序列
- TCP和UDP编程
- [汇编学习笔记][第十章 CALL和RET指令]
- select函数总结
- Android中服务里面方法的调用,开启,绑定
- web day17 JDBC入门,DAO模式mySQL时间类型转换,批处理