Colin's blog

A football fan,an English lover and a coder


  • 首页

  • 分类

  • 关于

  • 归档

  • 标签

ACM周练-10.30

发表于 2016-11-21   |   分类于 acm
第一题原题:hdoj 5971算法思想dfs二分染色,先将已知身份的人涂色,再从剩下的人中开始染色,最后如果还有剩下的人未被染色,那就是NO,否则是YES 程序代码//#define LOCAL #include <iostream> #include <cstdio> #include <cstring> #include <vector> #include <memory.h> #define mem(a,b) memset(a,b,sizeof(a)) using namespace std; const int MAX=1010; vector<int> G[MAX]; int color[MAX]; int n,m,x,y; bool dfs(int v,int c) { color[v]=c; for(int i=0;i<G[v].size();i++) { if(color[G[v][i]]==c) return false; if ...
阅读全文 »

No names,no bias?

发表于 2016-10-08   |   分类于 English
No names,no bias?  “If you’ve got the grades, the skills and the determination, this government will ensure you can succeed,” trumpeted David Cameron, the British prime minister, on October 26th, as he unveiled plans to tackle discrimination in the workplace. Ten big employers in the public and private sectors—including the civil service, HSBC and Deloitte—have agreed to start recruiting on a “name-blind” basis in Britain;others may also follow suit. In such schemes,those drawing up shortlists o ...
阅读全文 »

hdu 1042 N!

发表于 2016-09-01   |   分类于 acm
原题:hdoj 1042 原题大意题意很简单就是求阶乘.但数据要求能求到10000. 算法分析这题因为数据大,所以用数组保存,用大数相乘的思想.每个数组元素的值在0~9999间,过了就进一位,每个数组元素应当有4位(除了开头部分),不够用0补. 注意:我一开始是从n往1乘,结果超时了,只有用1往n乘才能通过.同时0!=1不能忽略. 代码程序#include <iostream> using namespace std; #define N 10000 int main(){ int a[N],n,m,len; while(scanf("%d",&n)!=EOF) { if(n==0) //0!=1 {printf("1\n");continue;} len=1; a[0]=n;m=0; for(int t=1;t<n;t++) { for(int i=0;i<len;i++ ...
阅读全文 »

hdu 1015 Safecracker

发表于 2016-08-16   |   分类于 acm
原题:hdoj 1015 原题大意题中给了一个式子 v - w^2 + x^3 - y^4 + z^5 = target 要求输入一个数(即作为target),再给出一个字符串,字符串由从A到Z,26个大写字母组成(A=1, B=2, …, Z=26),式子中的v,w,x,y,z由给出的字符串中的5个字符组成,使得式子能够成立.但是符合条件的有很多时,则按字典顺序且逆序输出一种,若无,则打印”no solution”. 算法分析因为要按字典序输出最大的一组,所以先要将输进去的字符串重新排序,用C++中stl里sort函数就可以了.下面可以用枚举(5重循环)或dfs. 程序代码枚举#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> #define target(v,w,x,y,z) v-w*w+x*x*x-y*y*y*y+z*z*z*z*z using namespace std; char str[30]; int num[30]; ...
阅读全文 »

Ignatius and the Princess I

发表于 2016-08-12   |   分类于 acm
原题:hdoj 1026 原题大意迷宫题,要求求出最短时间,同时打印每一个步骤. 算法分析看到这题,我的第一反应就是bfs,但是,还要打印每一步,我没什么办法,百度后普遍算法是,用优先队列bfs得出最小路径后,递归打印.首先优先队列的优先级别要能改 struct Point{ int x,y; int time; friend bool operator<(Point a,Point b) { return a.time>b.time; } }; 注意:stl里优先队列只能对<重载.记录路径的方法是:用数组Point,当前数组的值为上一步的坐标,打印时递归. 程序代码#include <iostream> #include <queue> using namespace std; int n,m;//对应N,M int dx[]={1,-1,0,0}; int dy[]={0,0,1,-1}; char lab[110][110];//迷宫 struct Point{ int x,y; int time; fr ...
阅读全文 »
1…192021…23
Shen Hao

Shen Hao

Colin's blog | acm |c++

114 日志
6 分类
71 标签
GitHub
© 2017 Shen Hao
由 Hexo 强力驱动
主题 - NexT.Muse