点我看题目

题意 : 就是有n个人,m对关系,每对关系的两个人是好朋友,这个关系是相互的,如果有两个人的共同好朋友超过k个,那这两个人也会是好朋友的,给你m对关系,给你足够长的时间,问你还能增加几对关系。

思路 : 暴力,一开始忘了增加了新关系之后要回到第0个点开始找,因为时间足够长。

#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h> using namespace std; const int maxn = ;
int a[maxn],map[maxn][maxn] ; int main()
{
int T,n,m,k ;
scanf("%d",&T) ;
for(int i = ; i < T ; i++)
{
memset(map,,sizeof(map)) ;
scanf("%d %d %d",&n,&m,&k) ;
int x,y ;
for(int j = ; j < m ; j++)
{
scanf("%d %d",&x,&y) ;
map[x][y] = map[y][x] = ;
}
int cnt = ,sum = ,flag = ,s;
for(int j = ; j < n ; j++)
{
for(int h = j+ ; h < n ; h++)
{
if(!map[j][h])
{
cnt = ;
for(s = ; s < n ; s++)
{
if(map[j][s] && map[h][s])
cnt++ ;
if(cnt >= k)
break ;
}
if(s != n)
{
map[j][h] = map[h][j] = ;//新增加的关系
j = - ;//因为你回去之后要++一次,所以这里要从-1开始,从0开始WA了一次
sum ++ ;
break ;
}
}
}
}
printf("%d\n",sum) ;
}
return ;
}

ZOJ 3170 Friends的更多相关文章

  1. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  2. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  3. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

  4. ZOJ Problem Set - 1392 The Hardest Problem Ever

    放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...

  5. ZOJ Problem Set - 1049 I Think I Need a Houseboat

    这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...

  6. ZOJ Problem Set - 1006 Do the Untwist

    今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...

  7. ZOJ Problem Set - 1001 A + B Problem

    ZOJ ACM题集,编译环境VC6.0 #include <stdio.h> int main() { int a,b; while(scanf("%d%d",& ...

  8. zoj 1788 Quad Trees

    zoj 1788 先输入初始化MAP ,然后要根据MAP 建立一个四分树,自下而上建立,先建立完整的一棵树,然后根据四个相邻的格 值相同则进行合并,(这又是递归的伟大),逐次向上递归 四分树建立完后, ...

  9. ZOJ 1958. Friends

    题目链接: ZOJ 1958. Friends 题目简介: (1)题目中的集合由 A-Z 的大写字母组成,例如 "{ABC}" 的字符串表示 A,B,C 组成的集合. (2)用运算 ...

随机推荐

  1. android之手工建立代码工程

    文件夹及文件架构: AndroidManifest.xml Android.mk res/layout/main.xml res/values/strings.xml src/com/liuzw/he ...

  2. hasLayout与Block formatting contexts的学习(上)

    hasLayout与Block formatting contexts的学习 @(css BFC)[IE hasLayout|妙瞳] hasLayout是什么? haslayout 是Windows ...

  3. NC参照查那个表

    select * from bd_refinfo where name like '%人员工作记录全职树(行政树)%';select * from bd_refinfo where name like ...

  4. 轮子来袭 vJine.Core 之 AppConfig<T>

    1.引用vJine.Core; 2.定义配置类; using System; using System.Collections.Generic; using System.Text; using Sy ...

  5. JavaScript解析json

    后台数据经常以json数据格式传回前台,解析当然首选JSON对象. JSON对象有两个方法,使用JSON.parse(str)可以将json字符串解析成js中的对象. var o = JSON.par ...

  6. 关于char 指针变量char *=p;这个语句的输出问题

    学习指针的时候我一直有个疑惑,请看下面的代码: #include <iostream> using std::cout; void main() { ; int *nPtr=&nu ...

  7. CAF(C++ actor framework)使用随笔(send sync_send)(二)

    a). 发完就忘, 就像上面anon_send 以及send #include <iostream> #include "caf/all.hpp" #include & ...

  8. 第36条:坚持使用Override注解

    @Override 注解只能用在方法声明中,表示被注解的方法声明覆盖了超类型中的一个声明. @Target(ElementType.METHOD) @Retention(RetentionPolicy ...

  9. cocos2dx 初探 - VS2012 HELLOWORLD

    最近决定用cocos2dx 来做些试验性的东西,先装了个vs2012 再从网上下了cocos2dx-2.1.4就开工了. 仅是Windows 桌面调试还是很简单的. 上面三个项目源: Hellocpp ...

  10. 一套帮助你理解C语言的测试题(转)

    前言 原文链接:http://www.nowamagic.net/librarys/veda/detail/775 内容 在这个网站(http://stevenkobes.com/ctest.html ...