目录

A

思路:这个题的话我们把负数和整数分别求出来,比较绝对值的大小,用较大的那个减去较小的那个就可以了。

#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; #define int long long signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T--)
{
int n;
cin >> n;
int zheng = 0, fu = 0;
for (int i = 1; i <= n; i++)
{
int x;
cin >> x;
if (x > 0)
zheng += x;
else
fu += x;
}
fu = abs(fu);
if (fu > zheng)
cout << fu - zheng << endl;
else
cout << zheng - fu << endl;
}
return 0;
}

B

思路:这个题一开始的时候想的是把全部的N放到前面,结果第二个测试点就WA了。其实这个题的正解是把全N和B换位置,但是有的N是不用动的,我们需要判断有几个N是不需要动的,要动的N的下标是从几开始。具体细节放在代码里。

#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; void solve()
{
int n;
cin >> n;
if (n == 1)
{
cout << 1 << endl;
cout << 1 << ' ' << 3 << endl;
return ;
}
int k = n - n / 2;
cout << k << endl;
int j = 1;
for (int i = (n / 2 + 1) * 3; i <= 3 * n; i += 3)
{
cout << j << ' ' << i << endl;
j += 3;
}
} int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T--)
{
solve();
}
return 0;
}

C

思路:这个是个博弈的题,通过观察样例的话我们可以发现,我们想要让对手输的话,我们只需要一直把那个最小的数换给他,他只能把最小的那个数-1然后换出去,所以一直反复的话最小的那个数变成0的时候,那么那个人就输了。Alice是先手没所以只要第一个不是最小的那一个那么Alice就会赢反之Bob就会赢。如果第一个和后面的最小值相等的话还是Bob赢

#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; const int N = 1e6 + 10;
int a[N]; void solve()
{
int Min = 0x3f3f3f3f;
int n;
cin >> n;
int sum = 0;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
if (i >= 2)
Min = min(a[i], Min);
}
if (a[1] > Min)
{
cout << "Alice" << endl;
}
else
{
cout << "Bob" << endl;
}
} int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T--)
{
solve();
}
return 0;
}

最新文章

  1. WinServer2008R2 部署.NET4.0程序 注意事项
  2. Xshell连接虚拟机
  3. 『WPF』实现拖动文件到窗体(控件)
  4. SQL Server存储过程复习(一)
  5. ListBox1控件
  6. SQL2008 R2 SP3中使用pivot实现行转列
  7. JAVA 命令参数详解System.setProperty(
  8. 第十七篇 基于Bootstarp 仿京东多条件筛选插件的开发(展示下)
  9. 3891: [Usaco2014 Dec]Piggy Back
  10. Python 条件、循环、异常处理
  11. LeetCode专题-Python实现之第9题:Palindrome Number
  12. jquery 第四章
  13. 字符串与NUll的拼接问题
  14. Tree Traversals Again
  15. webpack--配置output
  16. Python3练习题 018:打印星号菱形
  17. spring cloud+.net core搭建微服务架构:服务发现(二)
  18. document.querySelector获取不到html标签对象实例的原因
  19. MCS-51与8086指令系统比较
  20. Kafka学习之路 (一)Kafka的简介

热门文章

  1. HDU6623 Minimal Power of Prime (简单数论)
  2. RabbitMQ 入门系列:9、扩展内容:死信队列:真不适合当延时队列。
  3. Keepalived之简单有效的配置
  4. 使用ESP8266nodeMCU 向微信推送模板数据
  5. HCIA-STP原理与配置
  6. Elasticsearch:Elasticsearch SQL介绍及实例 (一)
  7. day46-JDBC和连接池02
  8. 齐博x1云市场注意事项
  9. day03-2-拓展
  10. 【React】学习笔记(二)——组件的生命周期、React脚手架使用