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]的更多相关文章

  1. 苏州大学ICPC集训队新生赛第二场

    A - Score UVA - 1585 水 #include<bits/stdc++.h> using namespace std; int main(){ int n; cin> ...

  2. 2016广东工业大学新生杯决赛网络同步赛暨全国新生邀请赛 题解&源码

    Problem A: pigofzhou的巧克力棒 Description 众所周知,pigofzhou有许多妹子.有一天,pigofzhou得到了一根巧克力棒,他想把这根巧克力棒分给他的妹子们.具体 ...

  3. 湖南大学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 ...

  4. 湖南大学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 ...

  5. 湖南大学ACM程序设计新生杯大赛(同步赛)L - Liao Han

    题目描述 Small koala special love LiaoHan (of course is very handsome boys), one day she saw N (N<1e1 ...

  6. 湖南大学ACM程序设计新生杯大赛(同步赛)B - Build

    题目描述 In country  A, some roads are to be built to connect the cities.However, due to limited funds, ...

  7. 湖南大学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 ...

  8. 湖南大学ACM程序设计新生杯大赛(同步赛)E - Permutation

    题目描述 A mod-dot product between two arrays with length n produce a new array with length n. If array ...

  9. 湖南大学ACM程序设计新生杯大赛(同步赛)D - Number

    题目描述 We define Shuaishuai-Number as a number which is the sum of a prime square(平方), prime cube(立方), ...

随机推荐

  1. ➡️➡️➡️IELTS reading by Simon on Bili

    高分必备 雅思考官Simon手把手教你做阅读 p1 https://www.bilibili.com/video/av40131278?p=2 p2 https://www.bilibili.com/ ...

  2. 【PAT甲级】1047 Student List for Course (25 分)

    题意: 输入两个正整数N和K(N<=40000,K<=2500),接下来输入N行,每行包括一个学生的名字和所选课程的门数,接着输入每门所选课程的序号.输出每门课程有多少学生选择并按字典序输 ...

  3. cmake 环境安装与使用

    CMake是一个跨平台的安装(编译)工具,可以用简单的语句来描述所有平台的安装(编译过程).他能够输出各种各样的makefile或者project文件,能测试编译器所支持的C++特性,类似UNIX下的 ...

  4. 图解jvm--(四)内存模型

    内存模型 java 内存模型 很多人将[java 内存结构]与[java 内存模型]傻傻分不清,[java 内存模型]是 Java Memory Model(JMM)的意思. 简单的说,JMM 定义了 ...

  5. 对于使用javaweb技术制作简单管理系统的学习

    近期在老师的引导下我们学习了利用Javaweb技术制作简单的管理系统,其中涉及到的技术很多,由于大多都是自学 对这些技术的理解还太浅显但能实现一些相关功能的雏形. (一).登录功能 在登陆功能中通过与 ...

  6. hbase入门-相关概念

    hbase入门-概念理解 参考文档: https://blog.csdn.net/luanpeng825485697/article/details/80319552 1.      hbase概念 ...

  7. PPT页面动画制作

    因为武汉新型冠状肺炎的影响,今年自从2月3号开工以来,就在家办公.我的任务刚好是安排做PPT,虽说之前做过PPT,但大家都知道,作为一个IT测试工程师,更多的是测试工作,只有在培训,还有年终汇报的时候 ...

  8. LeetCode困难题(一)

    题目一: 给你一个链表,每 k 个节点一组进行翻转,请你返回翻转后的链表. k 是一个正整数,它的值小于或等于链表的长度. 如果节点总数不是 k 的整数倍,那么请将最后剩余的节点保持原有顺序. 示例 ...

  9. 列表推导式、生成器表达式以及zip()max()max()/min()sum()sort()map()filter()的用法

    列表推导式: 基本格式: variable = [out_exp_res for out_exp in input_list if out_exp == 2] #out_exp_res: 列表生成元素 ...

  10. 六、linux基础-计算机网络_线程_进程

    6 计算机网络-线程和进程6.1 TCP/IP协议 TCP/IP是Unix/Linux世界的网络基础,在某种意义上,Unix网络就是Tcp/ip,而且Tcp/ip就是网络互连的标准他不是一个独立的协议 ...