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(立方), ...
随机推荐
- Follow somebody
networkersdiary A personnel blog with Network Engineering articles https://networkersdiary.com/cisco ...
- Cisco AP-ROMMON升级AP镜像
Rommon is Cisco bootloader for their Router devices >>>ROMMON是思科设备的引导加载程序while U-boot is a ...
- 迭代器对象numpy.nditer在数组上进行迭代——修改数组的值
nditer对象有另一个可选参数op_flags,默认情况下,nditer将视待迭代遍历的数组为只读对象(read-only),为了在遍历数组的同时,实现对数组元素值得修改,必须指定op_flags= ...
- 【转载】五分钟让你彻底了解TDD、ATDD、BDD&RBE
在目前比较流行的敏捷开发模式(如极限编程.Scrum方法等)中,推崇“测试驱动开发(Test Driven Development,TDD)”——测试在先.编码在后的开发实践.TDD有别于以往的“先编 ...
- Day11 - B - Dice (III) LightOJ - 1248
设dp_i为已经出现了i面,需要的期望次数,dp_n=0 那么dp_i= i/n*dp_i + (n-i)/n*dp_(i+1) + 1 现在已经i面了,i/n的概率再选择一次i面,(n-i)/n的概 ...
- 「ZJOI2011」最小割
「ZJOI2011」最小割 传送门 建出最小割树,然后暴力计算任意两点之间最小割即可. 多组数据记得初始化. 参考代码: #include <algorithm> #include < ...
- 一个简单的PHP文件下载方法 download
<?php /* * *@param function downloadFile 文件下载 * *@param string $filename 下载文件的路径(根目录下的绝对路径) * *@p ...
- scrapy 和 scrapy-redis
1.scrapy 是一个 Python 爬虫框架,爬取效率极高,但是不支持分布式.而 scrapy-redis 时一套基于 redis 数据库.运行在 scrapy 框架之上的组件,可以让 scrap ...
- linux 添加与修改用户归属组
参考资源:https://cnzhx.net/blog/linux-add-user-to-group/ 一:已存在的用户 1.要以root进行登录 2.打开终端 3.修改分组 usermod -a ...
- python 连接oracle基础环境配置方法
配置基础: 1.python3.7 2.oracle server 11g 64位 3.PLSQL 64位 4.instantclient-basic-windows.x64-11.2.0.4.0这个 ...