【题目链接】:http://vj.bit-studio.cn/contest/205664#overview

A:

【给你一个长度为n的序列,尾部插入再反转,求n次后最终序列】【规律/思维】

【分析】:STL-deque会超时,只能找规律。

【代码】:

#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+;
int a[maxn],ans[maxn];
int n;
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
}
int l=,r=n,k=n,cnt=;
for(int i=n;i>=;i--){
if(cnt&)
ans[l++]=a[k--];
else
ans[r--]=a[k--];
cnt++;
}
for(int i=;i<=n-;i++)
printf("%d ",ans[i]);
printf("%d\n",ans[n]);
}
/*
1 2 3 4
4 2 1 3 0 6 7 6 7 0
n-2 3 n-1 2 n 1

0 6 6 0 7 7
*/

规律

B:

【将长度为n的序列分为两部分,满足这两部分差值的绝对值最小】【前缀和】

【分析】:求出前缀和,然后打擂台求某部分前缀和sum[i]和n-sum[i]的差值abs最小值,注意防爆int。

【代码】:

#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int maxn = 2e5+;
LL a[maxn],sum[maxn],tot;
LL Min = 1000000000000000000LL;
int n;
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%lld",&a[i]);
sum[i]=sum[i-]+a[i];
tot+=a[i];
}
for(int i=;i<n;i++){
Min=min(Min,abs(*sum[i]-tot));
}
printf("%lld\n",Min);
}

前缀和

C:

【判断重排后的序列是否能够相邻元素乘积为4的倍数】【规律/思维】

【分析】:分成4的倍数,2的倍数,奇数。只要奇数和4的倍数可以交叉相邻即可。

【代码】:

#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int maxn = 2e5+;
int a[maxn],cnt1,cnt2,cnt4;
int n;
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
if(a[i]%==) cnt4++;
else if(a[i]%==) cnt2++;
else cnt1++;
}
if(cnt1>cnt4+ || (cnt2 && (cnt1==cnt4+)))
puts("No");
else puts("Yes"); }

规律

D:

【类似蛇形填数】【模拟】

【代码】:

E:

【区间相交长度】【贪心】

【分析】:选取b/d较小-a/c较大,不小于0输出,否则说明不相交输出0

【代码】:

#include <bits/stdc++.h>

using namespace std;

#define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=1e9+; int a,b,c,d;
LL ans;
int main()
{
cin>>a>>b>>c>>d;
ans=min(b,d)-max(a,c);
if(ans<) ans=;
cout<<ans<<'\n';
return ;
}

贪心

CSU-ACM2018寒假集训选拔-入门题的更多相关文章

  1. CSU-ACM寒假集训选拔-入门题

    CSU-ACM寒假集训选拔-入门题 仅选择部分有价值的题 J(2165): 时间旅行 Description 假设 Bobo 位于时间轴(数轴)上 t0 点,他要使用时间机器回到区间 (0, h] 中 ...

  2. 中南大学2019年ACM寒假集训前期训练题集(入门题)

    A: 漫无止境的八月 Description 又双叒叕开始漫无止境的八月了,阿虚突然问起长门在这些循环中团长哪几次扎起了马尾,他有多少次抓住了蝉等等问题,长门一共回复n个自然数,每个数均不超过1500 ...

  3. 中南大学2019年ACM寒假集训前期训练题集(基础题)

    先写一部分,持续到更新完. A: 寒衣调 Description 男从戎,女守家.一夜,狼烟四起,男战死沙场.从此一道黄泉,两地离别.最后,女终于在等待中老去逝去.逝去的最后是换尽一生等到的相逢和团圆 ...

  4. hdu 3695:Computer Virus on Planet Pandora(AC自动机,入门题)

    Computer Virus on Planet Pandora Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 256000/1280 ...

  5. poj 2524:Ubiquitous Religions(并查集,入门题)

    Ubiquitous Religions Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 23997   Accepted:  ...

  6. poj 3984:迷宫问题(广搜,入门题)

    迷宫问题 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7635   Accepted: 4474 Description ...

  7. hdu 1754:I Hate It(线段树,入门题,RMQ问题)

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  8. poj 3254 状压dp入门题

    1.poj 3254  Corn Fields    状态压缩dp入门题 2.总结:二进制实在巧妙,以前从来没想过可以这样用. 题意:n行m列,1表示肥沃,0表示贫瘠,把牛放在肥沃处,要求所有牛不能相 ...

  9. zstu.4194: 字符串匹配(kmp入门题&& 心得)

    4194: 字符串匹配 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 206  Solved: 78 Description 给你两个字符串A,B,请 ...

随机推荐

  1. poj 2533Longest Ordered Subsequence

    Longest Ordered Subsequence Description A numeric sequence of ai is ordered if a1 < a2 < - < ...

  2. HDOJ 2120 Ice_cream's world I

    Ice_cream's world I ice_cream's world is a rich country, it has many fertile lands. Today, the queen ...

  3. Win7系统桌面便签怎么添加?

    参考:http://jingyan.baidu.com/article/ab69b270c207432ca7189f99.html Win7系统桌面便签怎么添加?有时候工作.学习忙起来就会忘记要办的事 ...

  4. #3 working with data stored in files && securing your application (PART II)

    Security problems is more and more important on the internet today. You can see the problems . This ...

  5. TCP/IP网络编程之多线程服务端的实现(二)

    线程存在的问题和临界区 上一章TCP/IP网络编程之多线程服务端的实现(一)的thread4.c中,我们发现多线程对同一变量进行加减,最后的结果居然不是我们预料之内的.其实,如果多执行几次程序,会发现 ...

  6. OpenResty安装与hello world

    安装环境:CentOS 7.0 1. 安装编译工具.依赖库 yum -y install readline-devel pcre-devel openssl-devel gcc 2. 下载openre ...

  7. Pre 自动换行和手动换行

    pre { white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre ...

  8. 【Two Sum】cpp

    题目: Given an array of integers, find two numbers such that they add up to a specific target number. ...

  9. Marketing learning-3

    Part five brand mantra: the elevator speed 1.mental map:Portrays brand associations and responses fo ...

  10. (转载)django 访问url报错Forbidden (CSRF cookie not set.): xxx 问

    原地址:http://www.cnblogs.com/meitian/p/7016336.html 问题:页面访问时报错 Forbidden (CSRF cookie not set.): xxx   ...