有人说这一题暴力搜索,O(N^3),naive,哥只要O(N^2)
当然也差不了多少啦哈哈,因为N只有5。。。
思路:
总数,减去overlap的,就是结果
代码:
/* ID: bbsunch2 PROG: combo LANG: C++ */ #include <iostream> #include <fstream> #include <stdlib.h> #include <vector> using namespace std; int main() { ofstream fout ("combo.out"); ifstream fin ("combo.in"); int N; fin >> N; if (N == 1){ fout << 1 << endl; return 0; }else if(N == 2){ fout << 8 << endl; return 0; }else if(N == 3){ fout << 27 << endl; return 0; }else if(N == 4){ fout << 64 << endl; return 0; }else if(N == 5){ fout << 125 << endl; return 0; } int total = 250; int num_list[6]; fin >> num_list[0] >> num_list[1] >> num_list[2] >> num_list[3] >> num_list[4] >> num_list[5]; vector<int> num_candidate[6]; for(int i = 0; i < 6; i++){ //cout << i << " =========" << endl; for(int j = 0; j < 5; j++){ int a = num_list[i] - 2 + j; if (a <= 0){ a = N + a; }else if (a == N){ }else{ a = a % N; } //cout << a << endl; bool exist = false; for(int k =0; k < num_candidate[i].size(); k++){ if (a == num_candidate[i][k]){ exist = true; break; } } if (!exist){ num_candidate[i].push_back(a); } } } int overlap[3] = {0}; for(int i = 0; i < 3; i++){ int k = i + 3; //cout << num_candidate[i].size() << num_candidate[k].size() << endl; for (int m = 0; m < num_candidate[i].size(); m++){ for(int n = 0; n < num_candidate[k].size(); n++){ if(num_candidate[i][m] == num_candidate[k][n]){ overlap[i]++; break; } } } } int subtract = overlap[0] * overlap[1] * overlap[2]; fout << total - subtract << endl; return 0; }
相关推荐
USACO所有题目的题解 NOCOW整理版
USACO题解+代码+翻译,好东西,超级齐全,对大家帮助不小,特别是现在nocow挂了
Usaco总结&题解 一位大牛写的Usaco的总结,并有所有题的题解,推荐!!
USACO教程,包含USACO全部英文原题,题解(NOCOW整理版),翻译,教程,代码,测试数据。
我的USACO题解和程序
USACO月赛题解1
USACO题解(NOCOW整理版).doc
USACO1.4~2.3C语言题解 绝对能通过
丰富的USACO1.1--2.3.4的所有题解
USACO题解及中文译题1.1.1-2.4.5 题目为TXT格式文档,代码为C++语言所编写
usaco解题报告,就是usaco.training.gateway上面的题目全解
非常详细的题解,个人觉得很好,帮助非常大。nocow关闭后不太好找资源了。
usaco全部题解。 网址:blog.csdn.net/jiangshibiao
非常详细的题解,比较全的,个人觉得刷题者可以入手,帮助非常大。
非常详细的题解,比较全的,个人觉得刷题者可以入手,帮助非常大。
非常详细的题解,个人觉得比较全的,刷题者可以入手,帮助会非常大。
usaco的某道题的题解
里面有usaco前几节的程序和代码,欢迎使用,希望对你有所帮主。
数据结构机考所参考的USACO网站所有题目的解题思路,资源比较稀有!