头更更大
这个10月完就要去搞NOIP了。。。
10月30天也就3次测试。。。为保佑进省一我还是每次测试玩都写个总结。。
。。
昨天才说好不容易没炸这里就光速打脸orz
第一题乱搞了个三分(也不知道我怎么推出的单调性)。。
第二题最大值开小了。。。否则八十。。。
第三题。。。结果是一道模板数论题。。虽然还没懂orz
下面面详细解答:
T1(0/100): sushi
problem
题意:每组数据给一个仅由’B’,’R’构成的字符环,每次操作只能交换两个相邻的字符,询问经过最少多少次操作可以把这个环分成两段分别仅由一种字符构成的环。
样例
输入
1
BBRBBRBBBRRR输出
5
solution
只能说明对于字符串的处理我还是那么菜。。。
注意这道题很鬼畜,gets(),fgets(),cin都会挂。。不知道为什么。
T2(20/100):pyramid
problem
题意:。。。看后面,不好描述
样例:
输入
5 6
1 2 1 2
2 3 2 2
3 4 3 4
4 5 3 5
1 3 4 1
3 5 3 6
1 5输出
3 24
solution
本来是个很明显的Dp而且状态转移方程也答对了
结果附初值太小了。。。又是审题问题orz
T3(0/100):Heal
problem
题意
啥都不说自己去后面感受一下出题人的画风。
样例
输入
17 54
5 5 1 1 1 25 1 10 15 3 6 6 66 4 4 4 4
0 1 3 0 0 0 1 3 2 0 6 7 54 0 0 0 0
1 8 3
2 8 3
8 7 7
7 13 0
7 14 0
15 14 2
16 14 3
17 14 5
7 9 4
9 10 25
10 11 0
10 12 0
7 6 20
3 6 3
3 4 3
3 5 3输出
68
solution
一道数论题。。很久没搞数论的我一脸懵逼。
题目写的很玄幻,但就是 跳蚤 这道题的升级版。
感想
多练Dp。。多练模板。。。
今天大佬要是不来还真不知道自己有多差劲orz
代码:
T1:
std.cpp
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<iomanip>
#include<queue>
using namespace std;
typedef long long LL;
char s[2000005];
int T,N;
inline int readint()
{
int sum=0,f=1;char ch;
for(ch=getchar();(ch>'9'||ch<'0')&&ch!='-';ch=getchar());
if(ch=='-') {f=-1;ch=getchar();}
for(;ch>='0'&&ch<='9';ch=getchar())
sum=(sum<<3)+(sum<<1)+ch-48;
return sum*f;
}
inline void readchar()
{
N=0;
char ch=getchar();
while(ch!='R' && ch!='B') ch=getchar();
while(ch=='R' || ch=='B') s[++N]=ch,ch=getchar();
}
LL ans;
inline void work()
{
int L=0,R=0,cnt=1;
LL jud=0,tmp=0;
for(int i=N+1;i<=N*2;i++)s[i]=s[i-N];
for(int i=1;i<=N;i++)if(s[i]=='R'){jud+=N-i-R;R++;}
ans=jud;
for(int pos=1;pos<=N;pos++)
{
while(cnt<N+pos)
{
if(s[cnt]=='R')
{
tmp=jud+cnt-pos-L-(pos+N-cnt-R);
L++; R--;
if(tmp<=jud) jud=tmp;
else{L--;R++;break;}
}
cnt++;
}
ans=min(ans,jud);
if(s[pos]=='R'){L--;R++;}
else jud+=R-L;
}
}
int main()
{
T=readint();
for(int i=1;i<=T;i++)
{
readchar();
work();
cout<<ans<<endl;
}
return 0;
}
T2
my.cpp
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
using namespace std;
inline int read()
{
int X=0,w=1; char ch=0;
while(ch<'0' || ch>'9') {if(ch=='-') w=-1;ch=getchar();}
while(ch>='0' && ch<='9') X=(X<<3)+(X<<1)+ch-'0',ch=getchar();
return X*w;
}
#define U_MAX 200
inline char *stdin_get_str(char *str)
{
fgets(str,U_MAX,stdin);
if(str[strlen(str)-1] == '\n')
str[strlen(str)-1] = '\0';
return str;
}
inline void write(int x)
{
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
}
int w[21005],h[21005];
long long f[21005],g[21005];
int n,k,x,y,cnt=0,q,last1=0,last2=0;
int main()
{
// freopen("pyramid.in","r",stdin);
// freopen("pyramid.out","w",stdout);
n=read();q=read();w[0]=(~0u >> 1);
for(int i=1;i<=n;i++)
{
x=read();y=read();
if(y-x+1<w[cnt])
{
w[++cnt]=y-x+1;
f[cnt-1]=1ll*(i-1)*w[cnt-1];
h[cnt-1]=(i-1);
}
}
f[cnt]=1ll*n*w[cnt];
h[cnt]=n;
// for (int i = 1; i <= cnt; ++i) std::cout << f[i] << " " << h[i] << " " << w[i] << '\n';
for(int j=1;j<=cnt;j++) g[j]=f[j];
for(int i=2;i<=q;i++)
{
for(int j=1;j<=cnt;j++)
for(int k=0;k<j;k++)
f[j]=max(f[j], g[k]+1ll*(h[j]-h[k])*w[j]);
for(int j=1;j<=cnt;j++)
g[j]=f[j];
}
long long ans=0;
for(int i=1;i<=cnt;i++) ans=max(ans,f[i]);
cout<<ans<<endl;
return 0;
}
还是由scar_lyw发现的错误orz
std.cpp
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <ctime>
#include <map>
#include <vector>
#define LL long long
using namespace std;
inline int read() {
int i = 0, f = 1;
char ch = getchar();
while(!isdigit(ch)) {
if(ch == '-') f = -1; ch = getchar();
}
while(isdigit(ch)) {
i = (i << 3) + (i << 1) + (ch - '0'); ch = getchar();
}
return i * f;
}
const int MAXN = 20000 + 5;
const int MAXK = 100 + 5;
int w[MAXN], q[MAXN];
LL dp[MAXN][MAXK];
inline bool check(int x, int y, int z, int k) {
return (LL)(dp[y][k] - dp[x][k]) * (LL)(z - y) < (LL)(dp[z][k] - dp[y][k]) * (LL)(y - x);
}
int main() {
int n = read(), k = read();
for(int i = 1; i <= n; ++i) {
int x = read(), y = read();
w[i] = y - x + 1;
}
for(int i = 1; i <= k; ++i) {
int head = 1, tail = 0; q[tail] = 0;
for(int j = 1; j <= n; ++j) {
for(; head <= tail && (dp[q[head + 1]][i - 1] - dp[q[head]][i - 1]) > w[j] * (LL)(q[head + 1] - q[head]); ++head);
dp[j][i] = dp[q[head]][i - 1] + (LL)w[j] * (LL)(j - q[head]);
for(; head <= tail && check(q[tail - 1], q[tail], j, i - 1); --tail);
q[++tail] = j;
}
}
LL ans = 0;
for(int i = 1; i <= n; ++i)
ans = max(ans, dp[i][k]);
cout<<ans;
}
T3
3.心灵治愈
【问题描述】
“如果梦想消失了,生活就变成了积满冰雪的贫瘠之地。”
窗外微风起,羽和华走在满地落叶的小径上,蜿蜒曲折,仿佛没有尽头。
突然间,华抬起头,带着微微的笑意。
“羽,你相信人生的羁绊吗?”
“哦?”羽差异地望向华,随机笑容在脸上绽开。
“人生会遇到许许多多的挫折与磨难,但无论怎样,我们都要保持一颗乐观积极的心。”
“这么说来,我记得一个小小的测试。”华说。
“假设这里有一条长轴,在零号位置有一个小球,它代表一个人来临到了这个世界,开始了他的人生道路。”
“他将面临成功,面临失意,面临振奋,以及其他很多个人生境况,每个境况对人生可能产生多次影响。而对于每一次影响,它也许能帮助你前进,但如果你不能保持成功不骄傲,失败不气馁,那表面看起来的好的境况也许会让你后退,因此一个人可能会走到负数。”
“而大部分境况的影响是有你的后天决定的。如果你能好好认识与对待境况,它们就会让你前进相应的影响值。否则,你可能会在人生道路上后退相应的影响值。或者呆在原点。”
“但是人类无法摆脱贪婪的特点,他们始终尽可能的前进。但是,大家似乎都忽略了一点,那就是人生的终点其实就是在一号点。许许多多的人由于境况影响值的原因,无法到达生命的终点,那他的人生就是不圆满的。回到原点的前面,这大概就是人生的真谛吧。”
“另外,在生命终点的境况的影响永远是最大的,这就表明他之前没有哪一个境况的影响值是大于它的。因为在生命终点浮现在你们脑海里的永远是对你最重要的东西。并且生命结束方式和其影响值其实在你出生的时候就已经决定了。”
“那么请问,从人生的起点到终点,要求一定可达,成长羁绊的境况的影响值组合究竟有多少种情况呢?”
羽陷入了沉思。
【样例说明】
为不影响【问题描述】的优美性,题意的进一步解释将放在样例说明中。
ps:这是今天考试的压轴题
std.cpp
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<ctime>
#include<cstdlib>
using namespace std;
long long n,m,k,ans,a[200];
const long long mod = 1e+9 + 7;
inline long long pow (long long x, long long y)
{
x %= mod;
long long ans = 1;
while(y)
{
if (y&1) ans=ans*x%mod;
x = x*x%mod;
y = y>>1;
}
return ans;
}
int main ()
{
cin>>n>>m; ans = pow(m, n); k = m;
for (long long i=2;i*i<=k;i++) if(!(k%i))
{
a[++a[0]] = i;
while (!(k%i)) k /= i;
}
if (k>1) a[++a[0]] = k%mod;
for(long long i=1,tmp=1,tot=0;i<(1<<a[0]);i++,tmp=1,tot=0)
{
for (long long j=1;j<=a[0];j++)
if(i&(1<<(j-1))) ++tot,tmp*=a[j];
ans += (tot&1)?(-pow(m/tmp,n)):(pow(m/tmp,n));
(ans += mod) %= mod;
}
cout<<ans;
return 0;
}