菜鸡的2017CPPC网络赛
Friend-Graph
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6514 Accepted Submission(s): 1610
In a team with n members,if there are three or more members are not friends with each other or there are three or more members who are friends with each other. The team meeting the above conditions can be called a bad team.Otherwise,the team is a good team.
A company is going to make an assessment of each team in this company. We have known the team with n members and all the friend relationship among these n individuals. Please judge whether it is a good team.
The first line od each case should contain one integers n, representing the number of people of the team.(n≤3000)
Then there are n-1 rows. The ith row should contain n-i numbers, in which number aij represents the relationship between member i and member j+i. 0 means these two individuals are not friends. 1 means these two individuals are friends.
4
1 1 0
0 0
1
判断存不存在三元环,这个要拓扑排序跑一遍?emmm,wa
暴力判一下就好了,还得用bool
#include<stdio.h>
#include<string.h>
using namespace std;
bool a[][];
int n;
bool check()
{
int i,j,k;
for(i=; i<=n; i++)
{
for(j=i+; j<=n; j++)
{
if(a[i][j])
for(k=; k<=n; k++)
{
if(a[i][k]&&a[k][j])
{
return ;
}
}
}
}
return ;
}
int main()
{
int t,x,i,j,k,p,s;
scanf("%d",&t);
while(t--)
{
s=;
memset(a,false,sizeof(a));
scanf("%d",&n);
for(i=; i<=n; i++)
{
for(j=i+; j<=n; j++)
{
scanf("%d",&x);
if(x==)
a[i][j]=a[j][i]=true;
}
}
if(check())
printf("Bad Team!\n");
else printf("Great Team!\n");
}
return ;
}
CaoHaha's staff
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2089 Accepted Submission(s): 818
After shouted out that,the Force Staff appered in CaoHaha's hand.
As we all know,the Force Staff is a staff with infinity power.If you can use it skillful,it may help you to do whatever you want.
But now,his new owner,CaoHaha,is a sorcerers apprentice.He can only use that staff to send things to other place.
Today,Dreamwyy come to CaoHaha.Requesting him send a toy to his new girl friend.It was so far that Dreamwyy can only resort to CaoHaha.
The first step to send something is draw a Magic array on a Magic place.The magic place looks like a coordinate system,and each time you can draw a segments either on cell sides or on cell diagonals.In additional,you need 1 minutes to draw a segments.
If you want to send something ,you need to draw a Magic array which is not smaller than the that.You can make it any deformation,so what really matters is the size of the object.
CaoHaha want to help dreamwyy but his time is valuable(to learn to be just like you),so he want to draw least segments.However,because of his bad math,he needs your help.
Then T lines each contains one intetger S.The size of the toy(N<=1e9).
1
2
3
4
5
就是在网格纸画面积为n需要的最小的棍子数,你的边可以是√2或者1,学姐莽了一发过了
我是躺赢的
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
double f[];
int main()
{
__int64 t,n,i,j,p,q,l;
for(i=;;i+=)
{
p=i/;
q=p/;
p=p-q;
if(p<q)
swap(p,q);
f[i]=p*q*;
f[i+]=f[i]+p-0.5;
if(f[i]>=)
break;
l=i;
//printf("%d..%d\n",i,f[i]);
}
//printf("%I64d\n",l);
scanf("%I64d",&t);
while(t--)
{
scanf("%I64d",&n);
for(i=;i<l;i++)
if(f[i]>=n)break;
printf("%I64d\n",i);
}
}
Palindrome Function
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 256000/256000 K (Java/Others)
Total Submission(s): 1141 Accepted Submission(s): 390
f(n,k)=k if n is a palindrome number under k-base.
Otherwise f(n,k)=1.
Now given you 4 integers L,R,l,r,you need to caluclate the mathematics expression ∑Ri=L∑rj=lf(i,j) .
When representing the k-base(k>10) number,we need to use A to represent 10,B to represent 11,C to repesent 12 and so on.The biggest number is Z(35),so we only discuss about the situation at most 36-base number.
In the following T lines,each line consists of 4 integers L,R,l,r.
(1≤T≤105,1≤L≤R≤109,2≤l≤r≤36)
据说是原题?可是我怎么会啊,这个还卡memset,要记忆化一下,学长过的,萌新瑟瑟发抖
#include<stdio.h>
#include<string.h>
#define ll __int64
int bits[];
int dp[][][];
int dfs(int len,int l,int r,bool flag,bool ok,int b)
{
if(r > l) return !flag || (flag && ok);
if(!flag && ~dp[len][l][b+]) return dp[len][l][b+];
int end = flag ? bits[l] : b;
int res = ;
for(int i=;i<=end;i++)
{
if(l == len && i == ) continue;
bool g = ok;
if(ok) g = bits[r] >= i;
else g = bits[r] > i;
res += dfs(len,l-,r+,flag&&(i==end),g,b);
}
return flag ? res : dp[len][l][b+] = res;
}
int solve(int x,int b)
{
int tt = x;
int cnt = ;
while(tt > )
{
bits[++cnt] = tt % b;
tt /= b;
}
int ret = ;
for(int i=cnt;i>=;i--)
ret += dfs(i,i,,i==cnt,true,b-);
return ret;
}
int main()
{
int T;
int C = ;
scanf("%d",&T);
memset(dp,-,sizeof(dp));
while(T--)
{
int l,r,m,n;
__int64 ans=;
scanf("%d%d%d%d",&l,&r,&m,&n);
for(int i=m;i<=n;i++){ int sum=r-l+;
int sum1=solve(r,i)-solve(l-,i);
ans+=sum-sum1+sum1*i;
}
printf("Case #%d: %I64d\n",C++,ans);
}
return ;
}
Suffix(S2,i) = S2[i...len].Ni is the times that Suffix(S2,i) occurs in S1 and Li is the length of Suffix(S2,i).Then the secret is the sum of the product of Ni and Li.
Now SF wants you to help him find the secret.The answer may be very large, so the answer should mod 1000000007.
InputInput contains multiple cases.
The first line contains an integer T,the number of cases.Then following T cases.
Each test case contains two lines.The first line contains a string S1.The second line contains a string S2.
1<=T<=10.1<=|S1|,|S2|<=1e6.S1 and S2 only consist of lowercase ,uppercase letter.OutputFor each test case,output a single line containing a integer,the answer of test case.
The answer may be very large, so the answer should mod 1e9+7.Sample Input
2
aaaaa
aa
abababab
aba
Sample Output
13
19
Hint
case 2:
Suffix(S2,1) = "aba",
Suffix(S2,2) = "ba",
Suffix(S2,3) = "a".
N1 = 3,
N2 = 3,
N3 = 4.
L1 = 3,
L2 = 2,
L3 = 1.
ans = (3*3+3*2+4*1)%1000000007.
知道做法做不出来怎么办啊,这个KMP(看毛片)要怎么魔改啊,懵懵懵,还不是自己不了解KMP
#include <bits/stdc++.h>
using namespace std;
const int N=;
char s[N],t[N];
int nex[N],sum[N];
const int MD=1e9+;
__int64 ans;
__int64 getnum(__int64 x){
return (x+)*x/;
}
void pre(char *p)
{
int i,m,j;
m=strlen(p);
nex[]=nex[]=;
for(int i=; i<m; i++)
{
j=nex[i];
while(j&&p[i]!=p[j])j=nex[j];
nex[i+]=p[i]==p[j]?j+:;
}
}
void kmp(char *t, char *p)
{
int j=;
int n=strlen(t);
for(int i=; i<n; i++)
{
while(j&&p[j]!=t[i])
{
j=nex[j];
}
if(p[j]==t[i])
{
j++;
ans=(ans+j)%MD;
}
ans=(ans+getnum(nex[j]))%MD;
}
}
int main()
{
int T;
scanf("%d",&T);
getchar();
while(T--)
{
ans=;
scanf("%s",s);
scanf("%s",t);
reverse(s,s+strlen(s));
reverse(t,t+strlen(t));
pre(t);
kmp(s,t);
printf("%I64d\n",ans);
}
return ;
}
以下代码为昂老师写,这个思路感觉好
#include <bits/stdc++.h>
using namespace std;
const int N = ;
const int Q = 1e9 + ;
char s[N], t[N];
int n, m, f[N], cnt[N];
int main()
{
int T;
scanf("%d", &T);
while (T --)
{
scanf("%s%s", t, s);
n = strlen(t);
m = strlen(s);
reverse(s, s + m);
reverse(t, t + n);
f[] = f[] = ;
for (int i = ; i < m ; ++ i)
{
int j = f[i];
while (j && s[i] != s[j])
j = f[j];
f[i + ] = s[i] == s[j] ? j + : ;
}
memset(cnt, , sizeof(int) * (m + ));
for (int i = , j = ; i < n ; ++ i)
{
while (j && t[i] != s[j])
j = f[j];
j += (t[i] == s[j]);
++ cnt[j];
}
for (int i = m ; i > ; -- i)
{
cnt[f[i]] += cnt[i];
}
int res = ;
for (int i = ; i <= m ; ++ i)
{
res += (long long)cnt[i] * i % Q;
res %= Q;
}
cout << res << endl;
}
return ;
}
菜鸡的2017CPPC网络赛的更多相关文章
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 F. Trig Function(切比雪夫多项式+乘法逆元)
题目链接:哈哈哈哈哈哈 _(:з」∠)_ _(:з」∠)_ _(:з」∠)_ _(:з」∠)_ _(:з」∠)_ 哈哈哈哈哈哈,从9月16日打了这个题之后就一直在补这道题,今天终于a了,哈哈哈哈哈哈. ...
- ACM菜鸡退役帖——ACM究竟给了我什么?
这个ACM退役帖,诸多原因(一言难尽...),终于决定在我大三下学期开始的时候写出来.下面说两个重要的原因. 其一是觉得菜鸡的ACM之旅没人会看的,但是新学期开始了,总结一下,只为了更好的出发吧. 其 ...
- (未完结)“文远知行杯”GDET第十四届竞赛(网络赛共10题,仅整理出6题)
刚开学没多久就打了一个网络赛,通过这次网络赛我是发现我是真的菜... 放假前校赛的排名让我有些自满,寒假丝毫没有接触ACM,一直沉迷于Steam,这个真的值得好好反省. 虽然现在大一课有点多,在学校也 ...
- 2012年长春网络赛(hdu命题)
为迎接9月14号hdu命题的长春网络赛 ACM弱校的弱菜,苦逼的在机房(感谢有你)呻吟几声: 1.对于本次网络赛,本校一共6名正式队员,训练靠的是完全的自主学习意识 2.对于网络赛的群殴模式,想竞争现 ...
- 计蒜客 17119.Trig Function-切比雪夫多项式+乘法逆元 (2017 ACM-ICPC 亚洲区(西安赛区)网络赛 F)
哈哈哈哈哈哈哈哈哈哈哈哈,终于把这道题补出来了_(:з」∠)_ 来写题解啦. _(:з」∠)_ _(:з」∠)_ _(:з」∠)_ _(:з」∠)_ _(:з」∠)_ 哈哈哈哈哈哈,从9月16日打了这 ...
- 2019 ICPC南昌邀请赛网络赛比赛过程及题解
解题过程 中午吃饭比较晚,到机房lfw开始发各队的账号密码,byf开始读D题,shl电脑卡的要死,启动中...然后听到谁说A题过了好多,然后shl让blf读A题,A题blf一下就A了.然后lfw读完M ...
- 南昌网络赛C.Angry FFF Party
南昌网络赛C.Angry FFF Party Describe In ACM labs, there are only few members who have girlfriends. And th ...
- 2019杭电多校&CCPC网络赛&大一总结
多校结束了, 网络赛结束了.发现自己还是太菜了,多校基本就是爆零和签到徘徊,第一次打这种高强度的比赛, 全英文,知识点又很广,充分暴露了自己菜的事实,发现数学还是很重要的.还是要多刷题,少玩游戏. 网 ...
- Html菜鸡大杂烩
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
随机推荐
- IOS中Llabel整理
·UILable是iPhone界面最基本的控件,主要用来显示文本信息.·常用属性和方法有:1.创建CGRect rect = CGRectMake(100, 200, 50, 50);UILabel ...
- Mysql 主备配置
来自:http://blog.csdn.net/u013256816/article/details/52536283 1. 了解主备配置过程原理. http://blog.csdn.net/u013 ...
- cgi_and_fastcgi
CGI 来自维基百科 In computing, Common Gateway Interface (CGI) offers a standard protocol for web servers t ...
- ucosii(2.89)mbox 应用要点
OSMboxCreate(void *msg) 当创建一个mbox时候,消息邮箱允许(任务或者中断)向其他一个或者几个任务发送消息.初始化msg指向消息邮箱中的消息. void*OSMboxP ...
- MAC 安装汇编编译工具 NASM
直接运行nasm报错: 开始安装: brew reinstall nasm
- 【转载】WPF DataGrid 性能加载大数据
作者:过客非归 来源:CSDN 原文:https://blog.csdn.net/u010265681/article/details/76651725 WPF(Windows Presentatio ...
- linux虚拟机安装值得注意的几点
1.建立新的虚拟机时选择自定义安装并选择稍后安装操作系统 2.关键安装命令 tar -xzvf VMwareTools-10.0.6-3595377.tar.gz sudo ./wmware-ins ...
- spring中常用的注解
使用注解来构造IoC容器 用注解来向Spring容器注册Bean.需要在applicationContext.xml中注册<context:component-scan base-package ...
- IAP介绍
iOS应用调置 wjforstudy分享了IAP的一些基本知识.在论坛的地址是:http://www.cocoachina.com/bbs/read.php?tid=92060 1.在开始IAP开发 ...
- ios之UISplitViewController
iPad的屏幕比iPhone大,所以在界面上,iPad比iPhone多一个UISplitViewController,用来实现iPad在横屏时,分两栏显示所需要的界面,可以一边是目录一边是具体的内容. ...