【2018ACM/ICPC网络赛】焦作赛区
A Magic Mirror
题目链接:https://nanti.jisuanke.com/t/31710
题意:输入字符串,如果是“Jessy”就输出“Good Guy!",否则输出“Dare you say that again?”。Jessy的大小写不敏感。
题解:题意即题解。坑点就是大小写不敏感。
代码:
#include<iostream>
#include<string>
#include <algorithm> using namespace std;
int main(){
int T;
cin>>T;
while(T--){
string s;
cin>>s;
transform(s.begin(), s.end(), s.begin(), ::toupper);
if(s == "JESSIE"){
cout<<"Good guy!"<<endl;
}
else{
cout<<"Dare you say that again?"<<endl;
} }
return ;
}
I Save the Room
题目链接:https://nanti.jisuanke.com/t/31718
题意:给你A*B*C的长宽高的立方体,让你用1*1*2的方块填满,问可不可以。
题解:猜结论。。只要有一边是偶数就行。。
代码:
#include <iostream>
using namespace std; int a, b, c;
int main(){
while(cin>>a>>b>>c){
int ans = a * b * c;
if(ans & )
cout<<"No"<<endl;
else
cout<<"Yes"<<endl;
}
return ;
}
G Give Candies
题目链接:https://nanti.jisuanke.com/t/31716
题意:N个糖果给N个孩子,问有多少分法。
题解:先开始和队友讨论一发以为是整数划分。。太天真了。。推了几个发现公式显而易见2^(n-1)。由于数字太大,要用到
费马小定理:
p是质数,且gcd(a,p)=1,那么 $ a^{p-1} \equiv 1 (mod p)$
代码:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<cmath>
using namespace std;
typedef long long ll;
const int maxn = ;
const ll mod = +; ll qpow( ll a,ll n,ll mod ){
ll res = ;
while( n>= ){
if( n& ){
res = res*a%mod;
}
a = a*a%mod;
n >>= ;
}
return res%mod;
} ll GetNum( char str[],ll mod ){
ll res = ;
int len = strlen( str );
for( int i=;i<len;i++ ){
res = (res*+str[i]-'')%mod;
}
return res;
} int main(){
char str[ maxn];
int T;
cin>>T;
while( T--){
scanf("%s",str);
ll n = GetNum( str,mod- );
printf("%lld\n",qpow( ,(n-+mod)%mod,mod ));
}
return ;
}
H String and Times
题目链接:https://nanti.jisuanke.com/t/31717
题意:给你一个字符串,让你求子串出现次数在[A,B]的有多少个。
题解:啊。板子题,SAM,SA都可以。。我直接找的板子,改了两行过的。。就当存个板子吧。
相似例题:Hust1352,Hdu6194,POJ3261.
代码:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
using namespace std;
#define rank rankk
#define ll long long const int MAXN=;
int t1[MAXN],t2[MAXN],c[MAXN]; bool cmp(int *r,int a,int b,int l){
return r[a] == r[b] && r[a+l] == r[b+l];
} void da(int str[],int sa[],int rank[],int height[],int n,int m){
str[n++]=;
int i, j, p, *x = t1, *y = t2; for(i = ;i < m;i++)c[i] = ;
for(i = ;i < n;i++)c[x[i] = str[i]]++;
for(i = ;i < m;i++)c[i] += c[i-];
for(i = n-;i >= ;i--)sa[--c[x[i]]] = i;
for(j = ;j <= n; j <<= )
{
p = ; for(i = n-j; i < n; i++)y[p++] = i;
for(i = ; i < n; i++)if(sa[i] >= j)y[p++] = sa[i] - j; for(i = ; i < m; i++)c[i] = ;
for(i = ; i < n; i++)c[x[y[i]]]++;
for(i = ; i < m;i++)c[i] += c[i-];
for(i = n-; i >= ;i--)sa[--c[x[y[i]]]] = y[i];
swap(x,y); p = ; x[sa[]] = ;
for(i = ;i < n;i++)
x[sa[i]] = cmp(y,sa[i-],sa[i],j)?p-:p++;
if(p >= n)break;
m = p;
}
int k = ; n--;
for(i = ;i <= n;i++)rank[sa[i]] = i;
for(i = ;i < n;i++)
{
if(k)k--;
j = sa[rank[i]-]; while(str[i+k] == str[j+k])k++; height[rank[i]] = k;
}
}
int rank[MAXN],height[MAXN];
int RMQ[MAXN];
int mm[MAXN];
int best[][MAXN];
void initRMQ(int n)
{
mm[]=-;
for(int i=;i<=n;i++)
mm[i]=((i&(i-))==)?mm[i-]+:mm[i-];
for(int i=;i<=n;i++)best[][i]=i;
for(int i=;i<=mm[n];i++)
for(int j=;j+(<<i)-<=n;j++)
{
int a=best[i-][j];
int b=best[i-][j+(<<(i-))];
if(RMQ[a]<RMQ[b])best[i][j]=a; else best[i][j]=b;
}
}
int askRMQ(int a,int b)
{
int t; t=mm[b-a+];
b-=(<<t)-;
a=best[t][a];b=best[t][b];
return RMQ[a]<RMQ[b]?a:b;
}
int lcp(int a,int b)
{
a=rank[a];b=rank[b];
if(a>b)swap(a,b);
return height[askRMQ(a+,b)];
}
int t,k,len;
char sts[MAXN];
int st[MAXN],sa[MAXN];
multiset<int>s;
ll cal(int x)
{
ll an=;
if(x==)
{
an=1LL*len*(len+1LL)/2LL;
for(int i=;i<=len;i++)an-=height[i];
}
else
{
s.clear();
for(int i=;i<=x-;i++)s.insert(height[i]);
for(int i=x;i<=len;i++)
{
int pre=*s.begin();s.erase(s.find(height[i-x+]));s.insert(height[i]);
//printf("%d %d!\n",pre,*s.begin());
an+=max(,*s.begin()-pre);
}
}
return an;
}
int main(){
scanf("%d",&t);
while(~scanf("%s",sts)){
int l,r;
scanf("%d%d",&l,&r);
len=strlen(sts);
memset(height,,sizeof(height));
for(int i=;i<len;i++)
st[i]=sts[i]-'A'+;
da(st,sa,rank,height,len,);
/* for(int i=1;i<=len;i++)
printf("%d\n",height[i]);*/
printf("%lld\n",cal(l)-cal(r+)); }
return ;
}
L Poor God Water
题目链接:https://nanti.jisuanke.com/t/31721
题意:三种食物的顺序不同可能会中毒。每小时从肉,鱼,巧克力吃一种。
1、如果连续三小时,只吃一样会不开心。
2、如果连续三小时,每种都吃了,而且中间吃的巧克力,就会中毒。
3、如果连续三小时,中间他吃了肉或者鱼,然后另外两个小时吃了巧克力,他也会中毒。
现在求N小时内能让他开心并且不中毒的可能的组合种数。
题解:矩阵快速幂。emmm...交了7发都没过。。。赛后群里就说BM。。QAQ我敲。。黑科技。。
暴力推出前8项以上,然后丢进去自动求。当时没补题csp就GG。呵呵哒。
代码:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
const ll mod = ;
ll powmod(ll a, ll b)
{
ll res = ; a %= mod;
assert(b >= );
for (; b; b >>= )
{
if (b & )
res = res * a%mod;
a = a * a%mod;
}
return res;
}
// head int _, n;
namespace linear_seq
{
const int N = ;
ll res[N], base[N], _c[N], _md[N];
vector<int> Md;
void mul(ll *a, ll *b, int k)
{
rep(i, , k + k) _c[i] = ;
rep(i, , k)
if (a[i])
rep(j, , k)
_c[i + j] = (_c[i + j] + a[i] * b[j]) % mod;
for (int i = k + k - ; i >= k; i--)
if (_c[i])
rep(j, , SZ(Md))
_c[i - k + Md[j]] = (_c[i - k + Md[j]] - _c[i] * _md[Md[j]]) % mod;
rep(i, , k) a[i] = _c[i];
}
int solve(ll n, VI a, VI b) { // a 系数 b 初值 b[n+1]=a[0]*b[n]+...
// printf("%d\n",SZ(b));
ll ans = , pnt = ;
int k = SZ(a);
assert(SZ(a) == SZ(b));
rep(i, , k)
_md[k - - i] = -a[i]; _md[k] = ;
Md.clear();
rep(i, , k)
if (_md[i] != ) Md.push_back(i);
rep(i, , k)
res[i] = base[i] = ;
res[] = ;
while ((1ll << pnt) <= n) pnt++;
for (int p = pnt; p >= ; p--)
{
mul(res, res, k);
if ((n >> p) & )
{
for (int i = k - ; i >= ; i--) res[i + ] = res[i]; res[] = ;
rep(j, , SZ(Md)) res[Md[j]] = (res[Md[j]] - res[k] * _md[Md[j]]) % mod;
}
}
rep(i, , k) ans = (ans + res[i] * b[i]) % mod;
if (ans < ) ans += mod;
return ans;
}
VI BM(VI s)
{
VI C(, ), B(, );
int L = , m = , b = ;
rep(n, , SZ(s))
{
ll d = ;
rep(i, , L + ) d = (d + (ll)C[i] * s[n - i]) % mod;
if (d == ) ++m;
else if ( * L <= n)
{
VI T = C;
ll c = mod - d * powmod(b, mod - ) % mod;
while (SZ(C) < SZ(B) + m) C.pb();
rep(i, , SZ(B)) C[i + m] = (C[i + m] + c * B[i]) % mod;
L = n + - L; B = T; b = d; m = ;
}
else
{
ll c = mod - d * powmod(b, mod - ) % mod;
while (SZ(C) < SZ(B) + m) C.pb();
rep(i, , SZ(B)) C[i + m] = (C[i + m] + c * B[i]) % mod;
++m;
}
}
return C;
}
int gao(VI a, ll n)
{
VI c = BM(a);
c.erase(c.begin());
rep(i, , SZ(c)) c[i] = (mod - c[i]) % mod;
return solve(n, c, VI(a.begin(), a.begin() + SZ(c)));
}
}; int main()
{
int t;
scanf("%d",&t);
while (t--)
{
long long n;
scanf("%lld",&n);
vector<int>v({,,,,,,,,,});
//VI{1,2,4,7,13,24}
printf("%lld\n", linear_seq::gao(v, n - ));
}
}
【2018ACM/ICPC网络赛】焦作赛区的更多相关文章
- 【2018ACM/ICPC网络赛】沈阳赛区
这次网络赛没有打.生病了去医院了..尴尬.晚上回来才看了题补简单题. K Supreme Number 题目链接:https://nanti.jisuanke.com/t/31452 题意:输入一个 ...
- 【2018ACM/ICPC网络赛】徐州赛区
呃.自闭了自闭了.我才不会说我写D写到昏天黑地呢. I Characters with Hash 题目链接:https://nanti.jisuanke.com/t/31461 题意:给你一个字符串 ...
- 【icpc网络赛大连赛区】Sparse Graph
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Submissi ...
- Ryuji doesn't want to study 2018徐州icpc网络赛 树状数组
Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, ea ...
- Trace 2018徐州icpc网络赛 (二分)(树状数组)
Trace There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xx ...
- Supreme Number 2018沈阳icpc网络赛 找规律
A prime number (or a prime) is a natural number greater than 11 that cannot be formed by multiplying ...
- Trace 2018徐州icpc网络赛 思维+二分
There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xx , yy) ...
- Features Track 2018徐州icpc网络赛 思维
Morgana is learning computer vision, and he likes cats, too. One day he wants to find the cat moveme ...
- 2017 ICPC网络赛(西安)--- Xor
题目连接 Problem There is a tree with n nodes. For each node, there is an integer value ai, (1≤ai≤1,000 ...
随机推荐
- 用 Flask 来写个轻博客 (2) — Hello World!
Blog 项目源码:https://github.com/JmilkFan/JmilkFan-s-Blog 目录 目录 前文列表 扩展阅读 实现最简单的 Flask 应用 创建 config.py 文 ...
- Invalidate() InvalidateRect() 与 UpdateWindow()
按引:Invalidate在消息队列中加入一条WM_PAINT消息,其无效区为整个客户区.而UpdateWindow直接发送一个WM_PAINT消息,其无效区范围就是消息队列中WM_PAINT消息(最 ...
- Logic回归总结
转自http://blog.csdn.net/dongtingzhizi/article/details/15962797 当我第一遍看完台大的机器学习的视频的时候,我以为我理解了逻辑回归,可后来越看 ...
- git常用操作笔记
这是我看了廖雪峰的git教程,写的笔记,仅作为一个学习的记录 一.大多数我们面临的是已经有一个进行中的项目了,我们只需克隆下来就可以了 1.安装git,安装完后,可输入git,回车,查看是否已安装 2 ...
- selenium 滑动页面至元素可见
滚动页面 在自动化操作中,如果web页面过长,而我们需要的元素并不在当前可视页面中,那么selenium就无法对其进行操作:此时,我们就需要像平时操作浏览器一样来滚动页面,使我们需要操作的对象可见! ...
- Center OS 7安装 Apollo
声明: 每个人的情况都不一样,所以大家在看教程的时候自行斟酌,最好先扫一遍,再来根据自身情况进行操作.同时,遇到的问题也可能不尽相同,要灵活处理. 了解: Apollo是从原始ActiveMQ的基础构 ...
- java ThreadPoolExecutor 异常捕获
一,创建一个线程池 其中: public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) 饱和策略执行时的具体逻辑. p ...
- strcmp 的坑
根据百度百科的:http://baike.baidu.com/view/1026924.htm 函数简介 原型:extern int strcmp(const char *s1,const char ...
- docker一键部署zookeeper
version: '3.1' services: zoo1: image: zookeeper:3.4.11 restart: always hostname: zoo1 container_name ...
- es6学习(一)
之前一直听说es6,断断续续看过阮一峰老师的"ECMAScript 6 入门",觉得写得很好,但由于实际项目中没用到,所以并没有过多的去研究(人的惰性在我这里表现的淋漓尽致).直到 ...