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(立方), ...
 
随机推荐
- GRE Over IPSec配置
			
路由器GRE over IPSec站点到站点VPN 问题分析:对于前面的经典的IPSec VPN的配置来说,兼容性较好,适合于多厂商操作的时候,但是这种经典的配置方式不适合在复杂的网路 ...
 - Educational Codeforces Round 82 C. Perfect Keyboard
			
Polycarp wants to assemble his own keyboard. Layouts with multiple rows are too complicated for him ...
 - EBCDIK,EBCDIC,ASCII,shift JIS間の変換
			
http://itdoc.hitachi.co.jp/manuals/3020/3020759580/G5950334.HTM#ID01056
 - FFplay 命令
			
1. 查看支持的格式: ffplay.exe -formats 2. 播放PCM裸流: ffplay.exe - -channels -f s16le -i pcm_file_path 根据PCM文件 ...
 - RestTemplate HttpMessageConverter报错的解决方案no suitable HttpMessageConverter
			
错误 no suitable HttpMessageConverter found for response type and content type [text/html;charset=UTF- ...
 - leetCode练题——21. Merge Two Sorted Lists(照搬大神做法)
			
1.题目 21. Merge Two Sorted Lists Merge two sorted linked lists and return it as a new list. The new l ...
 - Oracle忘记密码怎么办?
			
1.打开cmd,输入sqlplus /nolog,回车:输入“conn / as sysdba”;输入“alter user sys identified by 新密码”,注意:新密码最好以字母开头, ...
 - PAT T1010 Lehmer Code
			
跟1009几乎是同一道题~ #include<bits/stdc++.h> using namespace std; ; int a[maxn]; ]; int r[maxn]; int ...
 - 十八 OGNL特殊符号的作用,#,%,$
			
主要有哪些字符? #:获取Context的数据,构建map %: 强制解析OGNL,强制不解析OGNL $ : 在配置文件中(xml,属性文件(国际化))使用OGNL #的用法: <body&g ...
 - SQL模糊匹配之正则表达式
			
− 方括号[ ]:指定一个字符.字符串.匹配他们中的任意一个. − 示例1:查询用户名以J或者以M开头的用户信息 − SELECT user_name FROM ecs_ ...