随笔分类 -  Sicily

摘要:#include using namespace std; int TIME; double X, Y; double MIN; double MIN_X, MIN_Y; double SQRT = sqrt(0.5); double DIR[8][2] = {{1,0}, {SQRT, -1*SQRT}, {0, -1}, {-1*SQRT, -1*SQRT}, ... 阅读全文
posted @ 2017-05-11 17:26 Vincent_Bryan 阅读(328) 评论(0) 推荐(0)
摘要:1 #include 2 using namespace std; 3 4 struct Vertex{ 5 int start, end; 6 int weight; 7 }; 8 Vertex arr[10000]; 9 int par[10000]; 10 int n, m; 11 int find(int n){ 12 while(par[n... 阅读全文
posted @ 2017-04-29 01:04 Vincent_Bryan 阅读(360) 评论(0) 推荐(0)
摘要:#include using namespace std; struct Vertex{ int start, end; int weight; }; Vertex arr[200010]; int par[200010]; int n, m; long long cost = 0; int find(int n){ while(par[n] != n){ ... 阅读全文
posted @ 2017-04-28 23:48 Vincent_Bryan 阅读(313) 评论(0) 推荐(0)
摘要:#include using namespace std; struct Node{ int val; Node *left; Node *right; Node(){ val = 0; left = NULL; right = NULL; } }arr[200000]; void insert(No... 阅读全文
posted @ 2017-04-24 22:59 Vincent_Bryan 阅读(514) 评论(0) 推荐(0)
摘要:#include using namespace std; int main(){ int t; cin >> t; while(t--){ int s1, s2; cin >> s1 >> s2; int arr1[s1+1], arr2[s2+1]; for(int i = 1; i > arr1[i... 阅读全文
posted @ 2017-04-09 10:32 Vincent_Bryan 阅读(429) 评论(0) 推荐(0)
摘要:#include using namespace std; int main(){ int n; int t = 0; while(cin >> n && n){ int arr[n+1]; memset(arr, 0, sizeof(arr)); for(int i = 1; i > arr[i]; ... 阅读全文
posted @ 2017-04-04 15:59 Vincent_Bryan 阅读(311) 评论(0) 推荐(0)
摘要:#include using namespace std; int main(){ int n; while(cin >> n){ int arr[n]; for(int i = 0; i > arr[i]; int dp[n][n+1]; //使用dp[i][j]代表从第i个数字往后合并j位的最大能量 ... 阅读全文
posted @ 2017-04-04 13:12 Vincent_Bryan 阅读(605) 评论(0) 推荐(0)
摘要:#include using namespace std; int main(){ int T, M; while(cin >> T >> M){ int dp[T+1]; int time[M+1], value[M+1]; for(int i = 1; i > time[i] >> value[i]; mem... 阅读全文
posted @ 2017-03-26 14:44 Vincent_Bryan 阅读(245) 评论(0) 推荐(0)
摘要:#include using namespace std; struct Node{ int M, V; friend bool operator > N >> K){ Node arr[N]; for(int i = 0; i > arr[i].M >> arr[i].V; sort(arr, arr+N, cmp); ... 阅读全文
posted @ 2017-03-22 01:22 Vincent_Bryan 阅读(442) 评论(0) 推荐(0)
摘要:#include using namespace std; int fun(double countA, double countB, double maxA, double maxB){ if(maxA == 0)return min(maxB, countB); if(maxB == 0)return min(maxA, countA); in... 阅读全文
posted @ 2017-03-19 18:26 Vincent_Bryan 阅读(334) 评论(0) 推荐(0)
摘要:题意:给出n根火柴,求其能拼成的最小正整数和最大正整数。求最大正整数时,尽量让位数多一点,而数字“1”消耗的火柴数最少,所以尽量尽量用“1”,求最小正整数时,尽量让位数少一点,而数字“8”消耗的火柴数最少,所以尽量用“8”,不过有许多特殊情况需要判断: 阅读全文
posted @ 2017-03-17 12:35 Vincent_Bryan 阅读(1182) 评论(0) 推荐(0)
摘要:这道题按照题意直接BFS即可,主要要注意题意中的相遇是指两种情况:一种是同时到达同一格子,另一种是在移动时相遇,如Paris在(1,2),而Helen在(1,2),若下一步Paris到达(1,1),而Helen达到(1,2),这种情况也算是相遇。 阅读全文
posted @ 2017-01-07 16:48 Vincent_Bryan 阅读(411) 评论(0) 推荐(0)
摘要:这道题没有找到一条回路,所以不能跟1152一样用数组储存后输出。我采用的方法是DFS加剪枝,直接DFS搜索会超时,优化的方法是在搜索是优先走出度小的路径,比如move1和move2都可以走,但是如走了move1后下一步有7种方向可以走,而走了move2后有2种方向可以走,那我们就优先走move2,具 阅读全文
posted @ 2017-01-07 10:22 Vincent_Bryan 阅读(458) 评论(0) 推荐(0)
摘要:这道题嘛,直接使用DFS搜索,然后莫名其妙地AC了。后来看了题解,说是move的顺序不同的话可能会导致超时,这时便需要剪枝,真是有趣。原来自己是误打误撞AC了,hhh。题解还有另一种解法是先把一条完整的路储存在数组里,输入i的时候,就从i位置起把数组循环输出一遍,真是666的解法呀,果然不能被传统的 阅读全文
posted @ 2017-01-06 23:27 Vincent_Bryan 阅读(414) 评论(0) 推荐(0)
摘要:题意是给出一个3*3的黑白网格,每点击其中一格就会使某些格子的颜色发生转变,求达到目标状态网格的操作。可用BFS搜索解答,用vector储存每次的操作 阅读全文
posted @ 2017-01-06 19:51 Vincent_Bryan 阅读(229) 评论(0) 推荐(0)
摘要:题意为给出两个四位素数A、B,每次只能对A的某一位数字进行修改,使它成为另一个四位的素数,问最少经过多少操作,能使A变到B。可以直接进行BFS搜索 阅读全文
posted @ 2017-01-06 19:34 Vincent_Bryan 阅读(304) 评论(0) 推荐(0)
摘要:相对1150题来说,这道题的N可能超过10,所以需要进行排重,即相同状态的魔板不要重复压倒队列里,这里我用map储存操作过的状态,也可以用康托编码来储存状态,这样时间缩短为0.03秒。关于康托展开可以参考,其可用数学归纳法证明:http://www.cnblogs.com/1-2-3/archive 阅读全文
posted @ 2017-01-06 19:21 Vincent_Bryan 阅读(311) 评论(0) 推荐(0)
摘要:此题可以使用BFS进行解答,使用8位的十进制数来储存魔板的状态,用BFS进行搜索即可 阅读全文
posted @ 2017-01-06 19:03 Vincent_Bryan 阅读(398) 评论(0) 推荐(0)
摘要:这是一道典型的最短路问题,直接用Dijkstra算法便可求解,主要是需要考虑输入的点是不是在已给出的地图中,具体看代码 阅读全文
posted @ 2017-01-06 18:24 Vincent_Bryan 阅读(278) 评论(0) 推荐(0)