终于开始我的博客生活了,希望博客可以让我记住学了什么,错了什么,接下来会有什么将出现。

记录写ACM生涯中的一些经验和网工经验吧,如果有人看我博客的话,希望可以留言给我提提意见,指导指导我啦~~~

正题:

 

先把洛谷写过的题解CV一下

 

 

题目来源:洛谷 P1488

 

题目描述

野猫与胖子,合起来简称肥猫,是一个班的同学,他们也都是数学高手,所以经常在一起讨论数学问题也就不足为奇了。一次,野猫遇到了一道有趣的几何游戏题目,便拿给胖子看。游戏要求在一个有n个顶点凸多边形上进行,这个凸多边形的n-3条对角线将多边形分成n-2个三角形,这n-3条对角线在多边形的顶点相交。三角形中的一个被染成黑色,其余是白色。双方轮流进行游戏,当轮到一方时,他必须沿着画好的对角线,从多边形上切下一个三角形。切下黑色三角形的一方获胜。胖子一看觉得确实很有趣,不如就一起玩玩吧。假设游戏由野猫先开始,那么野猫是否有必胜的策略呢?请写一个程序帮助野猫算一算。

输入格式

第一行为一个整数n(4<=n<=50000),表示多边形的顶点数,多边形的顶点由0至n-1顺时针标号。接着的n-2行描述组成多边形的三角形。第i+1行(1<=i<=n-2)有三个空格分隔的非负整数a、b、c,它们是第i个三角形的顶点编号。第一个给出的三角形是黑色的。

输出格式

只有一行,倘若野猫有必胜策略,输出JMcat Win;否则,输出PZ Win。(注意大小写和空格)

输入输出样例

输入 #1
6

0 1 2

2 4 3

4 2 0

0 5 4

输出 #1
JMcat Win

说明/提示

各个测试点1s

如果连接一个多边形中任意两点的线段都完全包含于这个多边形,则称这个多边形为凸多边形。

 

 

这题看起来很难,其实有点水。。。

非正解

其实就是判对角线数,如果对角线是奇数就JMcat Win,否则就是PZ Win 那么上代码

1 #include<iostream>
2 using namespace std;
3 int  main(){
4     int n;
5     cin>>n;
6     if((n-3)%2==0) cout<<"PZ Win";
7     else cout<<"JMcat Win";
8     return 0;
9 }

但是会WA!!!因为没考虑一刀切和在多边形内部; 就比如5边形,100,010(1是黑的,0是白的) 所以判断下黑的顶点是否连续就行

 1 #include<iostream>
 2 using namespace std;
 3 int  main(){
 4     int n,a,b,c;
 5     scanf("%d",&n);
 6     scanf("%d %d %d",&a,&b,&c);
 7     if(a+1==b){
 8         if(b+1==c){
 9             printf("JMcat Win");
10             return 0; 
11         }
12     }
13     if((n-3)%2==0) printf("PZ Win");
14     else printf("JMcat Win");
15     return 0;
16 }

好的AC,这不是正解!!!

 

CF629A Far Relative’s Birthday Cake

 

题目描述

Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!

The cake is a n×n n×n n×n square consisting of equal squares with side length 1 1 1 . Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be?

Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column.

输入格式

In the first line of the input, you are given a single integer n n n ( 1<=n<=100 1<=n<=100 1<=n<=100 ) — the length of the side of the cake.

Then follow n n n lines, each containing n n n characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'.

输出格式

Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column.

题意翻译

题目描述

多尔的家人正在庆祝多尔的生日派对。他们爱多尔,所以他们计划让他的生日蛋糕变得不可思议的!

蛋糕是一个由n×n的等边正方形组成的形状,长度为1。每个方块要么是空的,要么是由一个巧克力组成的。他们买了蛋糕,便开始把巧克力放在蛋糕上。“家庭之门”的幸福值等于蛋糕中同一行或同一列中装有巧克力的一对细胞的数量。多尔的家人想知道他们的幸福程度是多少?

输入输出格式

输入格式:

第一行输入一个整数n(1<=n<=100),表示蛋糕边的长度。然后输入n行数,每行有n个字符。空的细胞用'.'表示,而含有巧克力的细胞用“C”表示。

输出格式:

输出“家庭之门”幸福感的价值,即同一行或同一列的一对巧克力片的数量。

输入输出样例

输入 #1
3
.CC
C..
C.C
输出 #1
4
输入 #2
4
CC..
C..C
.CC.
.CC.
输出 #2
9

说明/提示

If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are:

  1. (1,2) (1,2) (1,2) and (1,3) (1,3) (1,3)
  2. (3,1) (3,1) (3,1) and (3,3) (3,3) (3,3)

Pieces that share the same column are: 1. (2,1)  (2,1)  (2,1) and (3,1) (3,1) (3,1) 2. (1,3) (1,3) (1,3) and (3,3) (3,3) (3,3)

代码可能因为是小白所以有点长。。。不过比较好写,因为大部分重复,CV就行,稍作改动

这个解法没有我看到的其他解法简洁,快速,但是如果新人看我的可能理解更好点吧。。。

本来准备DFS(刚学想练手),写着写着就发现更简单的写法。。。

解法就是计每行与每列的‘C’个数,然后每行每列的个数(>=2的前提下)利用组合公式求解

 1 #include <iostream>
 2 #include <cstring> 
 3 using namespace std;
 4 double jiec(int n){  //阶乘函数
 5     double sum =1;   //double防超
 6     for(int i = n;i>0;i--){
 7         sum *= i;
 8     }
 9     return sum;
10 }
11 int main() {
12     int wide;
13     double sum = 0,count = 0;  //double防超
14     scanf("%d",&wide);        //边长
15     char cake[wide+1][wide+1];
16     int nu[wide],nu2[wide];   //分别计行与列的个数(有点啰嗦的感觉,
17                     应该有优化的方法,但是我比较lazy。。。)
18 
19     memset(nu,0,sizeof(nu));
20     memset(nu2,0,sizeof(nu2));  //初始化为0
21     for(int i =0;i<wide;i++){
22         scanf("%s",&cake[i]);
23     }
24     for(int i = 0 ;i<wide;i++){   //遍历每行
25         count = 0;
26         for(int j = 0;j<wide;j++){
27             if(cake[i][j]=='C'){
28                 count += 1;
29             }
30         }
31         nu[i]=count;             //赋值个数
32     }
33     for(int i = 0 ;i<wide;i++){   //遍历每行
34         count = 0;
35         for(int j = 0;j<wide;j++){
36             if(cake[j][i]=='C'){
37                 count += 1;
38             }
39         }
40         nu2[i]=count;          //赋值个数
41     }
42     for(int i = 0;i<wide;i++){
43         if(nu[i]>=2){
44             sum += jiec(nu[i])/(2*jiec(nu[i]-2)); 
45                                     //组合公式求解行
46                                     (不会请问度娘)
47         }
48     }
49     for(int i = 0;i<wide;i++){
50         if(nu2[i]>=2){
51             sum += jiec(nu2[i])/(2*jiec(nu2[i]-2));  
52                                 //组合公式求解列
53         }
54     }
55     printf("%.0f",sum);
56     return 0;
57 }

 

 
posted on 2019-12-15 22:03  白子捡一地。  阅读(411)  评论(0编辑  收藏  举报