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网络赛】焦作赛区的更多相关文章

  1. 【2018ACM/ICPC网络赛】沈阳赛区

    这次网络赛没有打.生病了去医院了..尴尬.晚上回来才看了题补简单题. K  Supreme Number 题目链接:https://nanti.jisuanke.com/t/31452 题意:输入一个 ...

  2. 【2018ACM/ICPC网络赛】徐州赛区

    呃.自闭了自闭了.我才不会说我写D写到昏天黑地呢. I  Characters with Hash 题目链接:https://nanti.jisuanke.com/t/31461 题意:给你一个字符串 ...

  3. 【icpc网络赛大连赛区】Sparse Graph

    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submissi ...

  4. 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 ...

  5. Trace 2018徐州icpc网络赛 (二分)(树状数组)

    Trace There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xx ...

  6. Supreme Number 2018沈阳icpc网络赛 找规律

    A prime number (or a prime) is a natural number greater than 11 that cannot be formed by multiplying ...

  7. Trace 2018徐州icpc网络赛 思维+二分

    There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xx , yy) ...

  8. Features Track 2018徐州icpc网络赛 思维

    Morgana is learning computer vision, and he likes cats, too. One day he wants to find the cat moveme ...

  9. 2017 ICPC网络赛(西安)--- Xor

    题目连接 Problem There is a tree with n nodes. For each node, there is an integer value ai, (1≤ai​≤1,000 ...

随机推荐

  1. mac 堡垒机传文件

    安装zssh brew install zssh 上传文件 zssh登陆上跳板机 在跳板机上ssh到相应服务器 在服务器上cd至相应要放上传文件的目录 rz -bye //在远程服务器的相应目录上运行 ...

  2. fatal error C1189: #error : "No Target Architecture" 解决办法一

    在编译程序的时候发现报这个错误,在网上看到很多文章,说设置include路径,lib目录等等,都没有解决.最后调整了以下include文件的顺序,问题解决了.例如 从头文件a.h中截取的一段 type ...

  3. Linux c基本知识整理

    1.指针和引用的区别 1.指针是一个变量,变量存储一个地址指向内存中一个存储单元,需要单独分配内存空间.引用相当于变量的别名,不需要单独分配空间 2.引用必须初始化,指针可以先不进行初始化 3.指针可 ...

  4. [转] bae中thinkphp的REWRITE 正确配置方法

    URL_MODEL =2下. 官方的:app.conf不能用,害人呀.. 留意以下红色部分,正则要分开来写,坑爹的 正确的配置: handlers: handlers: - expire : .jpg ...

  5. Java原始数据类型

    Java定义了八种基本类型的数据:byte,short,int,long,char,float,double和boolean. 基本类型通常被称为简单类型.这些基本类型可以分为四组: 整数 - 包括: ...

  6. VS2015 定时服务及控制端

    一.  服务端 如下图—新建项目—经典桌面—Windows服务—起名svrr 2. 打到server1 改名为svrExecSqlInsert 右击对应的设计界面,添加安装服务目录结构如图 3. sv ...

  7. wpf mvvm datagrid 中button绑定命令方法

    <DataGridTemplateColumn Header="设备状态" IsReadOnly="True" Width="150" ...

  8. 初始化css样式

    html,body,div,ul,li,ol,a,input,textarea,p,dl,dt,dd{margin:0;padding:0;} ul li{list-style: none;} a{t ...

  9. js数组中对象去重 (reduce() 方法)

    一个数组中含有对象,并且去掉数组中重复的对象.主要代码如下: var arrData = [ {id: , name: "小明"}, {id: , name: "小张&q ...

  10. Eclipse+Marven + spring mvc 新建一个 Hello world 项目

    1. 打开Eclipse,菜单 File->New->Marven Project.               2. 点击 Next,                3. 选择 marv ...