Friend-Graph

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6514    Accepted Submission(s): 1610

Problem Description
It is well known that small groups are not conducive of the development of a team. Therefore, there shouldn’t be any small groups in a good team.
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.
 
Input
The first line of the input gives the number of test cases T; T test cases follow.(T<=15)
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.

 
Output
Please output ”Great Team!” if this team is a good team, otherwise please output “Bad Team!”.
 
Sample Input
1
4
1 1 0
0 0
1
 
Sample Output
Great Team!
 

判断存不存在三元环,这个要拓扑排序跑一遍?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

Problem Description
"You shall not pass!"
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.
 
Input
The first line contains one integer T(T<=300).The number of toys.
Then T lines each contains one intetger S.The size of the toy(N<=1e9).
 
Output
Out put T integer in each line ,the least time CaoHaha can send the toy.
 
Sample Input
5
1
2
3
4
5
 
Sample Output
4 4 6 6 7

就是在网格纸画面积为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

Problem Description
As we all know,a palindrome number is the number which reads the same backward as forward,such as 666 or 747.Some numbers are not the palindrome numbers in decimal form,but in other base,they may become the palindrome number.Like 288,it’s not a palindrome number under 10-base.But if we convert it to 17-base number,it’s GG,which becomes a palindrome number.So we define an interesting function f(n,k) as follow:
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.
 
Input
The first line consists of an integer T,which denotes the number of test cases.
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)
 
Output
For each test case, output the answer in the form of “Case #i: ans” in a seperate line.
 
Sample Input
3
1 1 2 36
1 982180 10 10
496690841 524639270 5 20
 
Sample Output
Case #1: 665
Case #2: 1000000
Case #3: 447525746
 

据说是原题?可是我怎么会啊,这个还卡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 ;
}
 
Today is the birthday of SF,so VS gives two strings S1,S2 to SF as a present,which have a big secret.SF is interested in this secret and ask VS how to get it.There are the things that VS tell: 
  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网络赛的更多相关文章

  1. 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 F. Trig Function(切比雪夫多项式+乘法逆元)

    题目链接:哈哈哈哈哈哈 _(:з」∠)_ _(:з」∠)_ _(:з」∠)_ _(:з」∠)_ _(:з」∠)_ 哈哈哈哈哈哈,从9月16日打了这个题之后就一直在补这道题,今天终于a了,哈哈哈哈哈哈. ...

  2. ACM菜鸡退役帖——ACM究竟给了我什么?

    这个ACM退役帖,诸多原因(一言难尽...),终于决定在我大三下学期开始的时候写出来.下面说两个重要的原因. 其一是觉得菜鸡的ACM之旅没人会看的,但是新学期开始了,总结一下,只为了更好的出发吧. 其 ...

  3. (未完结)“文远知行杯”GDET第十四届竞赛(网络赛共10题,仅整理出6题)

    刚开学没多久就打了一个网络赛,通过这次网络赛我是发现我是真的菜... 放假前校赛的排名让我有些自满,寒假丝毫没有接触ACM,一直沉迷于Steam,这个真的值得好好反省. 虽然现在大一课有点多,在学校也 ...

  4. 2012年长春网络赛(hdu命题)

    为迎接9月14号hdu命题的长春网络赛 ACM弱校的弱菜,苦逼的在机房(感谢有你)呻吟几声: 1.对于本次网络赛,本校一共6名正式队员,训练靠的是完全的自主学习意识 2.对于网络赛的群殴模式,想竞争现 ...

  5. 计蒜客 17119.Trig Function-切比雪夫多项式+乘法逆元 (2017 ACM-ICPC 亚洲区(西安赛区)网络赛 F)

    哈哈哈哈哈哈哈哈哈哈哈哈,终于把这道题补出来了_(:з」∠)_ 来写题解啦. _(:з」∠)_ _(:з」∠)_ _(:з」∠)_ _(:з」∠)_ _(:з」∠)_ 哈哈哈哈哈哈,从9月16日打了这 ...

  6. 2019 ICPC南昌邀请赛网络赛比赛过程及题解

    解题过程 中午吃饭比较晚,到机房lfw开始发各队的账号密码,byf开始读D题,shl电脑卡的要死,启动中...然后听到谁说A题过了好多,然后shl让blf读A题,A题blf一下就A了.然后lfw读完M ...

  7. 南昌网络赛C.Angry FFF Party

    南昌网络赛C.Angry FFF Party Describe In ACM labs, there are only few members who have girlfriends. And th ...

  8. 2019杭电多校&CCPC网络赛&大一总结

    多校结束了, 网络赛结束了.发现自己还是太菜了,多校基本就是爆零和签到徘徊,第一次打这种高强度的比赛, 全英文,知识点又很广,充分暴露了自己菜的事实,发现数学还是很重要的.还是要多刷题,少玩游戏. 网 ...

  9. Html菜鸡大杂烩

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

随机推荐

  1. POSTGRESQL 存储过程实战

    转了N多的SQL语句,可是自己用时,却到处是坑啊,啊,啊!!!!!!!!!!!!!!! 想写一个获取表中最新ID值. 上代码 CREATE TABLE department( ID INT PRIMA ...

  2. 从零开始利用vue-cli搭建简单音乐网站(三)

    1.利用router-link在组件之间传递数据 如上图,MainPage.vue中主要有8个推荐曲目数据,主要实现方式是建立好主页面模板,然后用v-for循环获取返回的music对象,然后分别绑定曲 ...

  3. java.util.concurrent中的常用组件

    一. CountDownLatch 一个同步辅助类,在完成一组正在其他线程中执行的操作之前,它允许一个或多个线程一直等待. CountDownLatch的一个非常典型的应用场景是:有一个任务想要往下执 ...

  4. MySQL性能优化奇技淫巧

    1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引.   2.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使 ...

  5. URL URI URN的区别

    下面这张图可以完美的解释他们三者之间的关系 URI包含URL和URN Uniform Resource Identifier :统一资源标志符,用于标识某一互联网资源 Uniform Resoutce ...

  6. 47.Number of Islands(岛的数量)

    Level:   Medium 题目描述: Given a 2d grid map of '1's (land) and '0's (water), count the number of islan ...

  7. POI 读取 Excel 文件

    import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.io.Out ...

  8. PHP 递归无限极下级

    下面是自己用到的一些递归方法,当然都是借鉴的,各位看官请勿怪 第一种 有层级 $array = array( array('id' => 1, 'pid' => 0, 'n' => ...

  9. webpack执行命令的不同方式

    如使用webpack3及之前的版本只需安装webpack3即可,因为之前的webpack里面集成了webpack-cli 1. 使用局部安装webpack和webpack-cli,使用package. ...

  10. tkinter学习-事件绑定与窗口

    阅读目录: 事件绑定 Toplevel组件 标准对话框 事件绑定: 说明:对于每个组件来说,可以通过bind()方法将函数或方法绑定到具体的事件上. 事件序列: 说明:用户需要使用bind()方法将具 ...