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. pytorch资料

    torchvision是独立于pytorch的关于图像操作的一些方便工具库. torchvision的详细介绍在:https://pypi.org/project/torchvision/ torch ...

  2. #P4770 [NOI2018]你的名字 的题解

    题目背景 实力强大的小A 被选为了ION2018 的出题人,现在他需要解决题目的命名问题. 题目描述 小A 被选为了ION2018 的出题人,他精心准备了一道质量十分高的题目,且已经把除了题目命名以外 ...

  3. mysql 官方读写分离方案

    mysql 8.0 集群模式下的自动读写分离方案 问题 多主模式下的组复制,看起来挺好,起始问题和限制很多.而且中断一个复制就无法配置了 多主模式下,innodbcluster 等于是无用的,不需要自 ...

  4. Es查询结果集默认是10000,更新设置

    Es查询结果集默认是10000,结果集大小是int,最大为21亿左右 PUT _all/_settings?preserve_existing=true { "index.max_resul ...

  5. SpringBoot实现restuful风格的CRUD

    restuful风格: 百度百科: RESTFUL是一种网络应用程序的设计风格和开发方式,基于HTTP,可以使用XML格式定义或JSON格式定义.RESTFUL适用于移动互联网厂商作为业务使能接口的场 ...

  6. Git - 删除github上的提交历史

    参考 https://segmentfault.com/q/1010000002898735 https://stackoverflow.com/questions/1338728/delete-co ...

  7. Python - 工具

    Anaconda - 自带Conda,可以自定义环境 Pycharm zeal - API离线查看,类似于Dash

  8. lower_bound() 函数使用详解

    简介 lower_bound()函数是用来求一个容器中,第一个大于等于所要查找的元素的地址,具体的原理是二分查找,因此它只能用于非降序序列. 他有三个参数,第一个参数是容器的初始地址,第二个参数是容器 ...

  9. 什么是redis事务

    一.什么是redis事务? 可以一次性执行多条命令,本质上是一组命令的集合.一个事务中的所有命令都会序列化,然后按顺序地串行化执行,而不会被插入其他命令 二.Redis 事务可以做什么? 一个队列中, ...

  10. DVWA靶机-sql自动注入

    1. 使用dvwa靶机进行sql注入实战(注:当前靶机安全级别为low) 打开sql漏洞,发现输入不同的数字会返回不同的信息, 先尝试手工判断是否存在sql注入 一般sql注入语句像这样,我们构造的是 ...