↓ Skip to main content
  1. Posts/

codeforces #368 div 2 B. Bakery (暴力)

·367 words·1 min
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

题目链接

题意:n个城市,m条双向路,要从k条中选择一个,使得到其他n-k个城市中的某个城市的距离最短。

思路:直接暴力 枚举。1A

代码实现
 1/* ***********************************************
 2Author :111qqz
 3Created Time :2016年08月20日 星期六 21时02分14秒
 4File Name :code/cf/#368/B.cpp
 5************************************************ */
 6#include <cstdio>
 7#include <cstring>
 8#include <iostream>
 9#include <algorithm>
10#include <vector>
11#include <queue>
12#include <set>
13#include <deque>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27using namespace std;
28const double eps = 1E-8;
29const int dx4[4]={1,0,0,-1};
30const int dy4[4]={0,-1,1,0};
31const int inf = 0x3f3f3f3f;
32const int  N =1E5+7;
33int n,m,k;
34vector <pair <int,LL> >edge[N];
35int b[N];
36bool cangku[N];
37int main()
38{
39	#ifndef  ONLINE_JUDGE
40	freopen("code/in.txt","r",stdin);
41  #endif
42	ios::sync_with_stdio(false);
43	cin>>n>>m>>k;
44	ms(cangku,false);
45	for ( int i = 1 ; i <= m ; i++)
46	{
47	    int u,v;
48	    LL w;
49	    cin>>u>>v>>w;
50	    edge[u].push_back(make_pair(v,w));
51	    edge[v].push_back(make_pair(u,w));
52	}
53	if (k==0)
54	{
55	    cout<<-1<<endl;
56	    return 0 ;
57	}
58	for ( int i = 1 ; i <= k ; i++)
59	{
60	    cin>>b[i];
61	    cangku[b[i]] = true;
62	}
63	if (k==n)
64	{
65	    cout<<-1<<endl;
66	    return 0;
67	}
68	LL ans = inf;
69	for (int i = 1 ; i <= k ; i++)
70	{
71	    int u = b[i];
72	    int siz = edge[u].size();
73	    for (int j = 0 ; j < siz ; j++)
74	    {
75		int v = edge[u][j].fst;
76		if (cangku[v]) continue;
77		LL w = edge[u][j].sec;
78		ans = min(ans,w);
79	    }
80	}
81	if (ans==inf) ans = -1;
82	cout<<ans<<endl;
83  #ifndef ONLINE_JUDGE
84  fclose(stdin);
85  #endif
86    return 0;
87}

Related

codeforces #368 div 2 A. Brain's Photos (暴力)

·254 words·1 min
题目链接 。。。这题也能成hack题。。。。有毒啊。。然后我room里所有人都写对了。。。是我看这道题看得太早了? 代码实现 1/* *********************************************** 2Author :111qqz 3Created Time :2016年08月20日 星期六 21时01分57秒 4File Name :code/cf/#368/A.cpp 5************************************************ */ 6 7#include <cstdio> 8#include <cstring> 9#include <iostream> 10#include <algorithm> 11#include <vector> 12#include <queue> 13#include <set> 14#include <deque> 15#include <map> 16#include <string> 17#include <cmath> 18#include <cstdlib> 19#include <ctime> 20#define fst first 21#define sec second 22#define lson l,m,rt<<1 23#define rson m+1,r,rt<<1|1 24#define ms(a,x) memset(a,x,sizeof(a)) 25typedef long long LL; 26#define pi pair < int ,int > 27#define MP make_pair 28 29using namespace std; 30const double eps = 1E-8; 31const int dx4[4]={1,0,0,-1}; 32const int dy4[4]={0,-1,1,0}; 33const int inf = 0x3f3f3f3f; 34const int N=105; 35int n,m; 36int main() 37{ 38 #ifndef ONLINE_JUDGE 39 freopen("code/in.txt","r",stdin); 40 #endif 41 42 cin>>n>>m; 43 bool ok = false; 44 for ( int i = 1 ; i <= n ; i++) 45 for ( int j = 1 ; j <=m ; j++ ) 46 { 47 char col; 48 cin>>col; 49 if (col=='C'||col=='M'||col=='Y') ok = true; 50 } 51 if (ok) cout<<"#Color"<<endl; 52 else cout<<"#Black&White"<<endl; 53 54 #ifndef ONLINE_JUDGE 55 fclose(stdin); 56 #endif 57 return 0; 58}

whust 2016 warm up G ||codeforces 689C. Mike and Chocolate Thieves

·290 words·1 min
cf689C 题意:给出一个m。。问恰好使得不超过某个n的a*b^3(a,b是正整数)的方案数为m的n是多少。。。 思路:暴力+二分。。。 代码实现 1/* *********************************************** 2Author :111qqz 3Created Time :2016年07月18日 星期一 15时58分55秒 4File Name :code/2016whust/G.cpp 5************************************************ */ 6 7#include <cstdio> 8#include <cstring> 9#include <iostream> 10#include <algorithm> 11#include <vector> 12#include <queue> 13#include <set> 14#include <map> 15#include <string> 16#include <cmath> 17#include <cstdlib> 18#include <ctime> 19#define fst first 20#define sec second 21#define lson l,m,rt<<1 22#define rson m+1,r,rt<<1|1 23#define ms(a,x) memset(a,x,sizeof(a)) 24typedef long long LL; 25#define pi pair < int ,int > 26#define MP make_pair 27 28using namespace std; 29const double eps = 1E-8; 30const int dx4[4]={1,0,0,-1}; 31const int dy4[4]={0,-1,1,0}; 32const int inf = 0x3f3f3f3f; 33LL m,n; 34LL ans; 35LL cal( LL x) 36{ 37 LL res = 0LL; 38 for ( LL i =2 ; i * i * i <= x ; i++) 39 res+=x/(i*i*i); 40 return res; 41} 42int main() 43{ 44 #ifndef ONLINE_JUDGE 45 freopen("code/in.txt","r",stdin); 46 #endif 47 48 cin>>m; 49 n = 0 ; 50 51 LL cur = 1LL<<60; 52// cout<<"cur:"<<cur<<endl; 53 while (cur!=0LL) 54 { 55 LL tmp = cal(n+cur); 56 if (tmp<m) n +=cur; 57 58 cur >>=1LL; 59 } 60 n++; 61// cout<<" n:"<<n<<endl; 62 if (cal(n)!=m) ans = -1; 63 else ans = n; 64 65 cout<<ans<<endl; 66 67 68 #ifndef ONLINE_JUDGE 69 fclose(stdin); 70 #endif 71 return 0; 72}

hdu 3183 A Magic Lamp ( 暴力)

·455 words·1 min
hdu3183题目链接 题意:n位长的数字串(n<=1000),删掉m个(m<=n),使得剩下的数字串表示的数字最小。 忽略前导0. 思路:暴力搞就可以。要注意每位数字是有一定位置的范围的。比如当前是第i位数字,后面还要取n-m-i位数字,那么第i位数字最多只能取到第k位,k=m+i,因为这样才能保证后面还有n-m-i位数字。

BZOJ 1653: [Usaco2006 Feb]Backward Digit Sums(暴力)

·560 words·2 mins
1653: [Usaco2006 Feb]Backward Digit Sums # Time Limit: 5 Sec Memory Limit: 64 MB Submit: 349 Solved: 258 [Submit][Status][Discuss] Description # FJ and his cows enjoy playing a mental game. They write down the numbers from 1 to N (1 <= N <= 10) in a certain order and then sum adjacent numbers to produce a new list with one fewer number. They repeat this until only a single number is left. For example, one instance of the game (when N=4) might go like this: 3 1 2 4 4 3 6 7 9 16 Behind FJ’s back, the cows have started playing a more difficult game, in which they try to determine the starting sequence from only the final total and the number N. Unfortunately, the game is a bit above FJ’s mental arithmetic capabilities. Write a program to help FJ play the game and keep up with the cows.