A题,n*m根木棍,相交放置,轮流取走相交的两根,最后谁不能行动,则输掉。

min(n,m)&1 为1则先取者赢。

B题,给定一个长度为n,且各不相同的数组,问能否通过交换连续一段L....R使得变成单调递增。

如果一开始就是递增的,那么直接输出L。。。R就是1 1,交换一个就行了;否则判断中间是否有且一段单调递减,且两端交换后使得数组递增。

代码:

 //Template updates date: 20140718
#include <iostream>
#include <sstream>
#include <cstdio>
#include <climits>
#include <ctime>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <string>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#define esp 1e-6
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
#define pb push_back
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define lowbit(x) (x&(-x))
#define mp(a, b) make_pair((a), (b))
#define bit(k) (1<<(k))
#define iin freopen("pow.in", "r", stdin);
#define oout freopen("pow.out", "w", stdout);
#define in freopen("solve_in.txt", "r", stdin);
#define out freopen("solve_out.txt", "w", stdout);
#define bug puts("********))))))");
#define Inout iin oout
#define inout in out #define SET(a, v) memset(a, (v), sizeof(a))
#define SORT(a) sort((a).begin(), (a).end())
#define REV(a) reverse((a).begin(), (a).end())
#define READ(a, n) {REP(i, n) cin>>(a)[i];}
#define REP(i, n) for(int i = 0; i < (n); i++)
#define VREP(i, n, base) for(int i = (n); i >= (base); i--)
#define Rep(i, base, n) for(int i = (base); i < (n); i++)
#define REPS(s, i) for(int i = 0; (s)[i]; i++)
#define pf(x) ((x)*(x))
#define mod(n) ((n))
#define Log(a, b) (log((double)b)/log((double)a))
#define Srand() srand((int)time(0))
#define random(number) (rand()%number)
#define random_range(a, b) (int)(((double)rand()/RAND_MAX)*(b-a) + a) using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<PII> VII;
typedef vector<PII, int> VIII;
typedef VI:: iterator IT;
typedef map<string, int> Mps;
typedef map<int, int> Mpi;
typedef map<int, PII> Mpii;
typedef map<PII, int> Mpiii; const int maxn = + ;
int a[maxn]; int main() { int n;
Rep(i, scanf("%d", &n), n+) scanf("%d", a+i);
int l = , r = ;
int ok = ;
a[n+] = inf;
Rep(i, , n+) {
if(a[i] > a[i-]) {
if(!l)
continue;
else {
if(ok && !r)
r = i-;
}
} else if(a[i] < a[i-]) {
if(!ok)
ok = , l = i-;
if(r) {
cout<<"no"<<endl;
return ;
}
} else {
cout<<"no"<<endl;
return ;
}
}
if(l) {
if(a[l] < a[r+] && a[r] > a[l-]) {
cout<<"yes"<<endl;
cout<<l <<' '<<r<<endl;
} else {
cout<<"no"<<endl;
}
} else {
cout<<"yes"<<endl;
cout<<<<' '<<<<endl;
}
return ;
}

写得挫。

C题,3个球队,总共n场比赛,已进行k场,知道两个球队之间赢得场数的绝对值,如|x1-x2| = d1, |x2-x3| = d2, 问剩下的比赛中是否存在一种可能使得三个队伍赢得场数相等。

分析:题意知道每场比赛只用知道谁赢就行 ,不用顾忌各种规则,前k场中分别可能情况:

令x = x2;

x+d1, x, x+d2;

x+d1, x, x-d2;

x-d1, x, x+d2;

x-d1, x, x-d1;

对应4种情况求出x,在求出x1,x2,x3,判断满足0<=xi<=n/3 && xi <= k;

就可以了。

代码:

 //Template updates date: 20140718
#include <iostream>
#include <sstream>
#include <cstdio>
#include <climits>
#include <ctime>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <string>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#define esp 1e-6
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
#define pb push_back
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define lowbit(x) (x&(-x))
#define mp(a, b) make_pair((a), (b))
#define bit(k) (1<<(k))
#define iin freopen("pow.in", "r", stdin);
#define oout freopen("pow.out", "w", stdout);
#define in freopen("solve_in.txt", "r", stdin);
#define out freopen("solve_out.txt", "w", stdout);
#define bug puts("********))))))");
#define Inout iin oout
#define inout in out #define SET(a, v) memset(a, (v), sizeof(a))
#define SORT(a) sort((a).begin(), (a).end())
#define REV(a) reverse((a).begin(), (a).end())
#define READ(a, n) {REP(i, n) cin>>(a)[i];}
#define REP(i, n) for(int i = 0; i < (n); i++)
#define VREP(i, n, base) for(int i = (n); i >= (base); i--)
#define Rep(i, base, n) for(int i = (base); i < (n); i++)
#define REPS(s, i) for(int i = 0; (s)[i]; i++)
#define pf(x) ((x)*(x))
#define mod(n) ((n))
#define Log(a, b) (log((double)b)/log((double)a))
#define Srand() srand((int)time(0))
#define random(number) (rand()%number)
#define random_range(a, b) (int)(((double)rand()/RAND_MAX)*(b-a) + a) using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<PII> VII;
typedef vector<PII, int> VIII;
typedef VI:: iterator IT;
typedef map<string, int> Mps;
typedef map<int, int> Mpi;
typedef map<int, PII> Mpii;
typedef map<PII, int> Mpiii; LL n, k, d1, d2;
int a[][] = {{-, } ,{-, -}, {, }, {, -}}; int main() {
int T;
for(int t = scanf("%d", &T); t <= T; t++) {
scanf("%I64d%I64d%I64d%I64d", &n, &k, &d1, &d2);
if(n%) {
puts("no");
continue;
}
int ok = ;
LL nn;
REP(i, ) {
nn = k;
LL tmp = (LL)a[i][]*d1+(LL)a[i][]*d2;
nn -= tmp;
if(nn < || nn%)
continue;
nn /= ;
if(nn > n/ || nn > k)
continue;
LL x1 = nn+(LL)a[i][]*d1;
LL x2 = nn+(LL)a[i][]*d2;
if(x1 < || x1 > n/ || x2 < || x2 > n/ || x1 > k || x2 > k)
continue;
ok = ;
break;
}
puts(ok ? "yes" : "no");
}
return ;
}

D题,给定仅有‘a','a'组成的字符串,定义一种子串:通过合并连续的字母最后可以得到一个回文串。如”aaabbaaa"最后得到"aba"。

很容易想到一个字串首尾字符相等时就为这样的要求的特殊字串。

题目要求奇数长度和偶数长度这样的字串个数,统计每个字符分别用dp[0][s[i]-'a'], dp[1][s[i]-'a'],表示位于i及之前的奇数位置和偶数位置的s[i]字符个数,

这样偶数长度ans0 += dp[!(i&1)][s[i]-'a'], 奇数长度ans1 += dp[i&1][s[i]-'a'];

代码:

 //Template updates date: 20140718
#include <iostream>
#include <sstream>
#include <cstdio>
#include <climits>
#include <ctime>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <string>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#define esp 1e-6
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
#define pb push_back
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define lowbit(x) (x&(-x))
#define mp(a, b) make_pair((a), (b))
#define bit(k) (1<<(k))
#define iin freopen("pow.in", "r", stdin);
#define oout freopen("pow.out", "w", stdout);
#define in freopen("solve_in.txt", "r", stdin);
#define out freopen("solve_out.txt", "w", stdout);
#define bug puts("********))))))");
#define Inout iin oout
#define inout in out #define SET(a, v) memset(a, (v), sizeof(a))
#define SORT(a) sort((a).begin(), (a).end())
#define REV(a) reverse((a).begin(), (a).end())
#define READ(a, n) {REP(i, n) cin>>(a)[i];}
#define REP(i, n) for(int i = 0; i < (n); i++)
#define VREP(i, n, base) for(int i = (n); i >= (base); i--)
#define Rep(i, base, n) for(int i = (base); i < (n); i++)
#define REPS(s, i) for(int i = 0; (s)[i]; i++)
#define pf(x) ((x)*(x))
#define mod(n) ((n))
#define Log(a, b) (log((double)b)/log((double)a))
#define Srand() srand((int)time(0))
#define random(number) (rand()%number)
#define random_range(a, b) (int)(((double)rand()/RAND_MAX)*(b-a) + a) using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<PII> VII;
typedef vector<PII, int> VIII;
typedef VI:: iterator IT;
typedef map<string, int> Mps;
typedef map<int, int> Mpi;
typedef map<int, PII> Mpii;
typedef map<PII, int> Mpiii; const int maxn = + ;
char s[maxn];
LL dp[][];
int main() { scanf("%s", s);
LL ans1 = , ans2 = ;
REPS(s, i) {
int x = s[i]-'a';
int y = i&;
dp[y][x]++;
ans1+=dp[y][x];
ans2+=dp[y^][x];
}
cout<<ans2<<' '<<ans1<<endl;
return ;
}

E题,n个箱子装有fi朵花,箱子内花完全一样,箱子之间花看做不同,求从中选出s朵花,有多少选法?

我也不会数论,不过还是硬着头皮看懂了。以后要慢慢积累啊

分析: 设第i个箱子选出xi朵花。得到x1+x2+x3.....xn = s, 且0<=xi<=fi.

那么选花方案数就是解的组数,即(1+x+x^2+x^3+.....x^f1)*................(1+x+x^2+x^3+x^4.........x^fn)

= (1-x^(f1+1))******(1-x^(fn+1)) *(1-x)^(-n)(等比数列)中x^s系数

然后就是求里面x^s的系数了。

这个先算出前面部分各次幂的系数诚意后面(1-x)^(-n)相应系数,使得总系数为s。

其中(1-x)^(-n)幂为k的系数为C(n+k-1, k) = C(n+k-1, n-1)由于n很小(n<=20).

所以可以通过枚举法求前面的系数,然后C(n+k-1,n-1)利用逆元公式。

代码:

Codeforces 258 Div2的更多相关文章

  1. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  2. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  3. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  4. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  5. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  6. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  7. codeforces Round #258(div2) D解题报告

    D. Count Good Substrings time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  8. codeforces Round #258(div2) C解题报告

    C. Predict Outcome of the Game time limit per test 2 seconds memory limit per test 256 megabytes inp ...

  9. Codeforces #263 div2 解题报告

    比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...

随机推荐

  1. arclist底层模板字段,可以调用的字段列表

    arclist底层模板字段,可以调用的字段列表   用DedeCMS做站,arclist是用得最多的标签,因为他是调用文章的基本标签,功能也非常强大,他的底层字段比较多,我们平时使用还没有用到一半,但 ...

  2. ASP连接MYSQL数据库

    <% strconnection="driver={mysql odbc 3.51 driver};database=weste_net;server=localhost;uid=ro ...

  3. Delphi推出Delphi XE4支持IOS开发

    Delphi 新推出 Delphi XE4 ,这是一个支持 iOS 应用开发的新版本.Delphi XE4 带来 Embarcadero 全新的 ARM 编译器 下载地址

  4. Azure Redis Cache作为ASP.NET Session状态提供程序

    从上一篇博客<使用Azure Redis Cache>我们已经可以创建并使用Redis Cache为我们服务了. 作为Web开发者,我们都知道Session状态默认是保存在内存中的,它的优 ...

  5. java中的拷贝文件FileChannel

    以前用Java拷贝文件,只知道写byte数组循环拷贝,今天知道了可以用FileChannel进行拷贝,上代码: 下边是传统的byte数组拷贝方法 </pre><pre name=&q ...

  6. sqlserver 变量

    变量:分为全局变量和局部变量全部变量:以@@声明,为系统变量,所有实例都能访问,用户只能访问,不能赋值局部变量:生命周期只在一个批处理内有效, 局部变量经常使用的三种用途:1 在循环语句中记录循环的次 ...

  7. smarty半小时快速上手入门教程

    http://www.jb51.net/article/56754.htm http://www.yiibai.com/smarty/smarty_functions.html http://www. ...

  8. HW--漂亮度

    描述 给出一个名字,该名字有26个字符串组成,定义这个字符串的“漂亮度”是其所有字母“漂亮度”的总和.每个字母都有一个“漂亮度”,范围在1到26之间.没有任何两个字母拥有相同的“漂亮度”.字母忽略大小 ...

  9. Java_字符类(Character、String、StringBuffer)_char是基本数据类型,Character是其包装类型。

         在java中有三个类负责对字符的操作:Character.String.StringBuffer.其中,Character类是对单个字符进行操作,String是对一个字符序列的操作,Stri ...

  10. 在jsp中获取服务器端的时间

    以前只知道在js中这样写:var date = new Date() : 但是这得到的是客户浏览器的时间,并不是服务器的时间. 当然可以通过在Java文件中添加属性,再在js中通过document.g ...