↓ 跳过正文
  1. Posts/

codeforces croc2016 A. Amity Assessment (暴力)

·340 字·1 分钟

题目链接 题意:2×2的格子,有三个位置分别放”A“ “B” “C” ,一个位置为空。只有和空位相邻位置上的字母能移动到空位。没有其他移动规则。现在给出两个状态。问能否互相转化。 思路: 貌似可以dfs…?但是一共才2*2,可以直接暴力枚举。 手写一种变换最多能有12种。

代码实现
 1/* ***********************************************
 2Author :111qqz
 3Created Time :2016年03月19日 星期六 00时21分02秒
 4File Name :code/cf/croc2016/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 <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;
33string a,b,c,d;
34int kind (string a,string b)
35{
36    if (a=="AB") return 1;
37    if (a=="BC") return 1;
38    if (a=="CA") return 1;
39    if (b=="AC") return 1;
40    if  (b=="BA") return 1;
41    if (b=="CB") return 1;
42
43    return 2;
44}
45int main()
46{
47	#ifndef  ONLINE_JUDGE
48	freopen("code/in.txt","r",stdin);
49  #endif
50	cin>>a>>b>>c>>d;
51	int p = kind(a,b);
52	int q = kind(c,d);
53	if (p==q)
54	{
55	    puts("YES");
56	}
57	else
58	{
59	    puts("NO");
60	}
61
62
63  #ifndef ONLINE_JUDGE
64  fclose(stdin);
65  #endif
66    return 0;
67}

相关文章

codeforces #345 div 2 B. Beautiful Paintings (暴力)

·371 字·1 分钟
题目链接 题意:给出一个数列,按照最好的策略排序使得a[i+1]>a[i]的对数尽可能多,问最多的对数是多少。 思路:类似计数排序? 代码实现 1/* *********************************************** 2Author :111qqz 3Created Time :2016年03月07日 星期一 17时06分48秒 4File Name :code/cf/#345/B.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; 33const int N=1E3+7; 34int n ; 35int a[N]; 36int cnt[N]; 37int num[N]; 38int sum[N]; 39int main() 40{ 41 #ifndef ONLINE_JUDGE 42 freopen("code/in.txt","r",stdin); 43 #endif 44 45 cin>>n; 46 ms(cnt,0); 47 ms(num,0); 48 ms(sum,0); 49 for ( int i = 1 ; i <= n ; i++) 50 { 51 cin>>a[i]; 52 cnt[a[i]]++; 53 } 54 if (n==1) 55 { 56 puts("0"); 57 return 0 ; 58 } 59 if (n==2) 60 { 61 if (a[1]==a[2]) 62 { 63 puts("0"); 64 } 65 else 66 { 67 puts("1"); 68 } 69 return 0; 70 } 71 72 int mx = -1; 73 for ( int i = 1 ; i <= 1000 ; i++) 74 { 75 num[cnt[i]]++; 76 mx = max(mx,cnt[i]); 77 } 78 79 for ( int i = mx ; i >= 1 ; i --) 80 { 81 sum[i] = sum[i+1]+num[i]; 82 } 83 84 int ans = 0 ; 85 for ( int i = 1 ; i <= mx ; i++) 86 { 87 ans +=sum[i]-1; 88// cout<<"sum[i]:"<<sum[i]<<endl; 89 } 90 cout<<ans<<endl; 91 92 93 94 #ifndef ONLINE_JUDGE 95 fclose(stdin); 96 #endif 97 return 0; 98}

hdu 5630 Rikka with Chess (暴力 ,计数问题)

·287 字·1 分钟
http://acm.hdu.edu.cn/showproblem.php?pid=5630 题意:nm的棋盘,相邻格子的颜色相反,每次可以翻转一个任意大小矩形的格子,问最少需要翻转多少次使得棋盘的nm个格子颜色相同。(翻转的意思是颜色反色) 思路:手写了下。。发现。。答案就是n/2+m/2. 对应的最优策略是。。翻偶数行和偶数列,都翻一遍,颜色就一样了。

codeforces #341 div2 A. Die Roll

·470 字·1 分钟
http://codeforces.com/contest/621/problem/A A. Wet Shark and Odd and Even time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Today, Wet Shark is given n integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark. Note, that if Wet Shark uses no integers from the n integers, the sum is an even integer 0.

codeforces #341 div 2 B. Wet Shark and Bishops

·607 字·2 分钟
http://codeforces.com/contest/621/problem/B B. Wet Shark and Bishops time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Today, Wet Shark is given n bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right. Wet Shark thinks that two bishops attack each other if they share the same diagonal. Note, that this is the only criteria, so two bishops may attack each other (according to Wet Shark) even if there is another bishop located between them. Now Wet Shark wants to count the number of pairs of bishops that attack each other.

uva 120 Stacks of Flapjacks

·634 字·2 分钟
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=56 题意:给出一个长度为n的序列(无重复元素),询问经过多少次flip(i)操作,使得序列升序排列。定义flip(i)为将1到n-i+1的元素反转… 思路:先离散化,然后注意读入….