Xeon 第一次训练赛 苏州大学ICPC集训队新生赛第二场(同步赛) [Cloned]
A.给出一个字符串,求出连续的权值递增和,断开以后权值重新计数,水题
#include<iostream>
#include<string>
#include<cmath>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>
#include<stack>
#include<sstream>
#include<cstdio>
#define INF 0x3f3f3f3f
//const int maxn = 1e6 + 5;
const double PI = acos(-1.0);
typedef long long ll;
using namespace std; char s[]; int main() {
int T;
int ans;
int cnt;
scanf("%d", &T);
getchar();
while (T--) {
ans = ;
cnt = ;
scanf("%s", s);
for (int i = ; i < strlen(s); i++) {
if (s[i] != 'X') ans += cnt, cnt++;
else cnt = ;
}
printf("%d\n", ans);
}
return ;
}
B.给出四面体ABCD,起点由D开始走n步回到D,问有多少种不同的走法(中间可以再次经过D)
考虑DP枚举,复杂度O(n)
#include<cstdio>
using namespace std;
const int maxn = 1e7+;
const int mod = 1e9+;
int dp[maxn][];
int n;
int main(){
scanf("%d",&n);
dp[][] = ;
dp[][] = dp[][] = dp[][] = ;
for (int i = ; i <= n; i++){
for (int j = ; j < ; j++){
for (int k = ; k < ; k++){
if (j == k) continue;
dp[i][j] += dp[i-][k];
dp[i][j] %= mod;
}
}
}
printf("%d",dp[n][]);
return ;
}
C.给出数字a,b,求a的重新排列以后小于b的最大值
思维题,若|a|<|b|,显然只需将a降序排列即可,否则 方法是将a升序排列,每次确定最高位,最终结果就是最优解
#include<iostream>
#include<string>
#include<cmath>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>
#include<stack>
#include<sstream>
#include<cstdio>
#define INF 0x3f3f3f3f
const int maxn = 1e9 + ;
const double PI = acos(-1.0);
typedef long long ll;
using namespace std; string a;
string b;
string t; int main() {
cin >> a >> b;
int len1 = a.length(), len2 = b.length();
sort(a.begin(), a.end());
if (len1 < len2) reverse(a.begin(), a.end());
else {
int l, r;
for (l = ; l < len1; l++) {
r = len1 - ;
t = a;
while (r > l) {
swap(a[l], a[r--]);
sort(a.begin()+l+, a.end());
if (a > b) a = t;
else break;
}
} }
printf("%s", a.c_str());
return ;
}
G.从起点出发到目标点x,步数从1开始每次严格增加1,问最短步次可达x
仍然是思维题 首先显然的是x是负数无需考虑(对称性), 接下来考虑x在数轴右侧
首先考虑x无限大的情况,那显然前期的任何一步都是浪费的(物理思维?),事实上也是如此,往左走的步数显然是用于微调的
考虑到一直往左走第一次超越x,若此时del是偶数,那么显然可以在之前的第del/2步往左走,效果相当于往左走了del步,正好可达最优解
若del是奇数,那只需至多再走1,2步就能到偶数的情况
#include<iostream>
#include<string>
#include<cmath>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>
#include<stack>
#include<sstream>
#include<cstdio>
#define INF 0x3f3f3f3f
const int maxn = 1e9 + ;
const double PI = acos(-1.0);
typedef long long ll;
using namespace std; int ans[]; int main() {
int i;
for(i=;;i++){
ans[i]=i*(i+)/;
if(ans[i]>maxn) break;
} int x;
scanf("%d",&x);
if(!x) {
printf("");
return ;
}
if(x<) x=-x;
int p=lower_bound(ans,ans+i,x)-ans;
int ret=ans[p]-x;
while(ret&) p++,ret+=p;
int Ans=p;
printf("%d",Ans);
return ;
}
F.水题, 给定n个矩形,求一点的坐标,该点满足被k个矩形包含
#include<iostream>
#include<string>
#include<cmath>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>
#include<stack>
#include<sstream>
#include<cstdio>
#define INF 0x3f3f3f3f
const int maxn = 1e9 + ;
const double PI = acos(-1.0);
typedef long long ll;
using namespace std; int a[]; int main() {
int n, k;
scanf("%d%d", &n, &k);
if (k > n) {
printf("-1"); return ;
}
for (int i = ; i < n; i++) scanf("%d", &a[i]);
sort(a, a + n);
printf("%d 0", a[n - k ]);
return ;
}
D.数学+构造
考虑到题目给的提示“不超过n+1‘,说明答案应该和n有关,策略是先让每个数变成大数,然后依次取模,只要取模数是递减的,就能保证是递增的
#include<iostream>
#include<string>
#include<cmath>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>
#include<stack>
#include<sstream>
#include<cstdio>
#define INF 0x3f3f3f3f
//const int maxn = 1e9 + 5;
const double PI = acos(-1.0);
typedef long long ll;
using namespace std; int maxn = 1e5+;
int a[]; int main() {
int n;
scanf("%d", &n); for (int i = ; i <= n; i++) {
scanf("%d", &a[i]);
a[i] += maxn;
}
printf("%d\n", n + );
printf("1 %d %d\n", n, maxn);
for (int i = ; i <= n; i++) {
printf("2 %d %d\n", i, a[i] - i);
}
return ;
}
Xeon 第一次训练赛 苏州大学ICPC集训队新生赛第二场(同步赛) [Cloned]的更多相关文章
- 苏州大学ICPC集训队新生赛第二场
A - Score UVA - 1585 水 #include<bits/stdc++.h> using namespace std; int main(){ int n; cin> ...
- 2016广东工业大学新生杯决赛网络同步赛暨全国新生邀请赛 题解&源码
Problem A: pigofzhou的巧克力棒 Description 众所周知,pigofzhou有许多妹子.有一天,pigofzhou得到了一根巧克力棒,他想把这根巧克力棒分给他的妹子们.具体 ...
- 湖南大学ACM程序设计新生杯大赛(同步赛)J - Piglet treasure hunt Series 2
题目描述 Once there was a pig, which was very fond of treasure hunting. One day, when it woke up, it fou ...
- 湖南大学ACM程序设计新生杯大赛(同步赛)A - Array
题目描述 Given an array A with length n a[1],a[2],...,a[n] where a[i] (1<=i<=n) is positive integ ...
- 湖南大学ACM程序设计新生杯大赛(同步赛)L - Liao Han
题目描述 Small koala special love LiaoHan (of course is very handsome boys), one day she saw N (N<1e1 ...
- 湖南大学ACM程序设计新生杯大赛(同步赛)B - Build
题目描述 In country A, some roads are to be built to connect the cities.However, due to limited funds, ...
- 湖南大学ACM程序设计新生杯大赛(同步赛)I - Piglet treasure hunt Series 1
题目描述 Once there was a pig, which was very fond of treasure hunting. The treasure hunt is risky, and ...
- 湖南大学ACM程序设计新生杯大赛(同步赛)E - Permutation
题目描述 A mod-dot product between two arrays with length n produce a new array with length n. If array ...
- 湖南大学ACM程序设计新生杯大赛(同步赛)D - Number
题目描述 We define Shuaishuai-Number as a number which is the sum of a prime square(平方), prime cube(立方), ...
随机推荐
- git 操作详情
Git 教程 1.Git 是一个开源的分布式版本控制系统 2.Git 是 Linux Torvalds 为了帮助管理 Linux 内核开发而开发的一个开源版本控制软件 3.Git 与常用的版本控制工具 ...
- 推荐一款好用的博客离线编辑工具——OpenLiveWriter
1.前言 我们自己一般在写博客的时候都是在博客官网后台写的,但是如果要在多个平台发布博客的话,那就要复制好前面写好的博客,然后再去其它博客平台发布,可见非常的麻烦. 这里推荐一款好用的离线多功能,多平 ...
- 温湿度传感器AM2302(DH22)
AM2302 3.3V - 5.5V,建议供电电压为 5V单总线通信模式时,SDA 上拉(开漏)后与微处理器的 I/O 端口相连.单总线通信特殊说明: 0.功耗待机40~50uA;测量1~1.5m ...
- MATLAB的安装与入门
最近安装了MATLAB来用,过程遇到很多问题,担心自己改天如果换电脑了就忘记一些安装问题,所以记录一个. 首先是资源问题,我在贴吧找到了好心人分享的破解资源(非常感谢好心人的资源(ง •_•)ง),然 ...
- [排错] SpringBoot 警告 Could not find acceptable representation
环境 Java 1.8 SpringBoot 2.1.9 Java 接口代码 @ResponseBody @RequestMapping(value = "cloud", meth ...
- 「NOI2006」最大获利
「NOI2006」最大获利 传送门 最小割. 对于每一组用户群 \(A_i, B_i, C_i\) ,连边 $S \to A_i, S \to B_i, $ 容量为成本,还有 \(i \to T\) ...
- 机器学习之SVM多分类
实验要求数据说明 :数据集data4train.mat是一个2*150的矩阵,代表了150个样本,每个样本具有两维特征,其类标在truelabel.mat文件中,trainning sample 图展 ...
- Caffe2 模型与数据集(Models and Datasets)[3]
Models and Datasets 这一节没什么有用的信息为了保证教程完整性,这里仍然保留这一节. 这一节唯一提到的一点就是: Caffe2的模型文件后缀是:.pb2 结语: 转载请注明出处:ht ...
- Python基础-4 运算符
运算符 运算符:以1 + 2为例,1和2被称为操作数,"+" 称为运算符. Python语言支持以下类型的运算符: 算术运算符 比较(关系)运算符 赋值运算符 逻辑运算符 位运算符 ...
- centso7设置防火墙
CentOS 7默认使用的是firewall作为防火墙,使用iptables必须重新设置一下 1.直接关闭防火墙 1 2 3 systemctl stop firewalld.service #停止f ...