机器翻译

  题解:模拟

 #include <cstdio>
#include <cstring> const int MAXN = ; int n, m, cj, now, MinV, MinId, Pri, a[MAXN+], in[MAXN+]; int main(){
memset(in, -, sizeof(in));
scanf("%d %d", &n, &m), now = Pri = ;
for (int i=; i<m; i++){
scanf("%d", &cj);
if (~in[cj]) continue;
Pri ++;
if (now+<=n) now ++, in[cj] = i;
else {
MinV = 0x3f3f3f3f;
for (int j=; j<=MAXN; j++)
if (in[j]<MinV && in[j]!=-) MinV = in[j], MinId = j;
in[MinId] = -, in[cj] = i;
}
}
printf("%d\n", Pri);
}

translate.cpp

乌龟棋

  题解:dp

 #include <cstdio>
#include <cstring> const int MAXN = +;
const int MAXE = +; int n, m, cj, a[MAXN], b[], dp[MAXE][MAXE][MAXE][MAXE]; int main(){
memset(dp, , sizeof(dp)); scanf("%d %d", &n, &m);
for (register int i=; i<n; i++)
scanf("%d", &a[i]);
for (register int i=; i<m; i++)
scanf("%d", &cj), b[cj] ++; dp[][][][] = a[];
for (register int A=; A<=b[]; A++)
for (register int B=; B<=b[]; B++)
for (register int C=; C<=b[]; C++)
for (register int D=; D<=b[]; D++){
cj = A+B+B+C+C+C+D+D+D+D;
if (A && dp[A-][B][C][D]+a[cj]>dp[A][B][C][D]) dp[A][B][C][D] = dp[A-][B][C][D]+a[cj];
if (B && dp[A][B-][C][D]+a[cj]>dp[A][B][C][D]) dp[A][B][C][D] = dp[A][B-][C][D]+a[cj];
if (C && dp[A][B][C-][D]+a[cj]>dp[A][B][C][D]) dp[A][B][C][D] = dp[A][B][C-][D]+a[cj];
if (D && dp[A][B][C][D-]+a[cj]>dp[A][B][C][D]) dp[A][B][C][D] = dp[A][B][C][D-]+a[cj];
}
printf("%d\n", dp[b[]][b[]][b[]][b[]]);
}

tortoise.cpp

关押罪犯

  题解:并查集。既然只有两个监狱,那么如果a和b没有在一个监狱,b和c没有在一个监狱,那么a和c一定在一个监狱

  把怒气值从大到小拍个序,依次处理

  并查集[1, n]表示和自己一起的,[n+1, 2n]表示不和自己一起的

 #include <cstdio>
#include <algorithm>
using std::sort; const int MAXN = +;
const int MAXM = +; int n, m, f[MAXN*]; struct Relation{
int a, b, c; friend bool operator < (const Relation& A, const Relation& B){
return A.c>B.c;
}
}r[MAXM]; inline int Find(int x){
return f[x]==x ? x : f[x] = Find(f[x]);
} inline int Solve(){
sort(r, r+m);
int a, b;
for (int i=; i<m; i++){
a = Find(r[i].a), b = Find(r[i].b);
if (a==b) return r[i].c;
else f[a] = Find(r[i].b+n), f[b] = Find(r[i].a+n);
}
return ;
} int main(){
scanf("%d %d", &n, &m);
for (int i=; i<=*n; i++)
f[i] = i;
for (int i=; i<m; i++)
scanf("%d %d %d", &r[i].a, &r[i].b, &r[i].c); printf("%d\n", Solve());
}

prison.cpp

引水入城

  题解:看懂题是关键...

     多么痛的领悟:windows下只能bfs,linux下就怎么搞都可以了TAT

 #include <cstdio>
#include <cstring> const int MAXN = +;
const int addX[] = {-, , , };
const int addY[] = {, , -, }; int n, m, X, Y, Need, Cant, anna[MAXN][MAXN];
bool vis[MAXN][MAXN]; struct Region{
int l, r;
}rg[MAXN]; inline int findLeft(){
for (int i=; i<=m; i++)
if (vis[n][i]) return i;
return ;
} inline int findRight(){
for (int i=m; i>=; i--)
if (vis[n][i]) return i;
return ;
} inline void DFS(int x, int y){
if (x< || x>n || y< || y>m) return;
vis[x][y] = true; for (int i=; i<; i++){
X = x+addX[i], Y = y+addY[i];
if (<=X && X<=n && <=Y && Y<=m && anna[X][Y]<anna[x][y] && !vis[X][Y])
DFS(X, Y);
}
} inline bool legal(){
memset(vis, false, sizeof(vis)); for (int i=; i<=m; i++)
DFS(, i); for (int i=; i<=m; i++)
if (not vis[n][i]) ++ Cant; return !Cant;
} inline int segmentCover(){
for (int i=; i<=m; i++){
memset(vis, false, sizeof(vis));
DFS(, i);
rg[i].l = findLeft(), rg[i].r = findRight();
} int i = , j, k = ;
while (i<=m){
for (j=; j<=m; j++)
if (rg[j].l<=i && rg[j].r>k) k = rg[j].r;
i = k+, ++ Need;
} return Need;
} int main(){
memset(anna, 0x3f, sizeof(anna)); scanf("%d %d", &n, &m), Cant = Need = ;
for (int i=; i<=n; i++)
for (int j=; j<=m; j++)
scanf("%d", &anna[i][j]); if (legal()) printf("1\n%d", segmentCover());
else printf("0\n%d", Cant);
}

flow.cpp

NOIP2010 题解的更多相关文章

  1. NOIP2010题解

    所有题目链接均来自洛谷 T1机器翻译 原题戳这里 自古T1是水题 因为每一个数字都小于1000,所以对于是否在队列中可以开数组查询 对于大小的限制,弄一个队列维护大小即可(水题呀...) 这题在Win ...

  2. noip2010提高组题解

    NOIP2010提高组题解 T1:机器翻译 题目大意:顺序输入n个数,有一个队列容量为m,遇到未出现元素入队,求入队次数. AC做法:直接开1000的队列模拟过程. T2:乌龟棋 题目大意:有长度为n ...

  3. 题解 【NOIP2010】关押罪犯

    [NOIP2010]关押罪犯 Description S城现有两座监狱,一共关押着N名罪犯,编号分别为1~N.他们之间的关系自然也极不和谐.很多罪犯之间甚至积怨已久,如果客观条件具备则随时可能爆发冲突 ...

  4. 题解【洛谷P1514】[NOIP2010]引水入城

    题目描述 在一个遥远的国度,一侧是风景秀美的湖泊,另一侧则是漫无边际的沙漠.该国的行政区划十分特殊,刚好构成一个 \(N\) 行 \(M\) 列的矩形,如上图所示,其中每个格子都代表一座城市,每座城市 ...

  5. noip2010提高组3题题解 by rLq

    本题地址http://www.luogu.org/problem/show?pid=1525 关押罪犯 题目描述 S 城现有两座监狱,一共关押着N 名罪犯,编号分别为1~N.他们之间的关系自然也极不和 ...

  6. NOIP2010普及组题解 -SilverN

    三国游戏 题目内容不放了 由于电脑总是会拆掉最大的组合,所以玩家最多只能得到数值第二大的组合 那么找出第二大的组合就行了 #include<iostream> #include<cs ...

  7. NOIP2010 引水入城 题解

    http://www.rqnoj.cn/problem/601 今天发现最小区间覆盖竟然是贪心,不用DP!于是我又找到这题出来撸了一发. 要找到最上面每个城市分别能覆盖最下面哪些城市,如果最下面有城市 ...

  8. 【题解】[Noip2010]机器翻译-C++

    题目Description小晨的电脑上安装了一个机器翻译软件,他经常用这个软件来翻译英语文章.这个翻译软件的原理很简单,它只是从头到尾,依次将每个英文单词用对应的中文含义来替换.对于每个英文单词,软件 ...

  9. luoguP1541 乌龟棋 题解(NOIP2010)

    P1541 乌龟棋 题目 #include<iostream> #include<cstdlib> #include<cstdio> #include<cma ...

随机推荐

  1. MySQL5.6:基于GTID的主从复制

    一.GTID简介 MySQL 5.6 的新特性之一,是加入了全局事务 ID (GTID) 来强化数据库的主备一致性,故障恢复,以及容错能力. 什么是GTID? 官方文档:http://dev.mysq ...

  2. CLASSIC VS INTERGRATED IN IIS 7.0

    Classic mode (the only mode in IIS6 and below) is a mode where IIS only works with ISAPI extensions ...

  3. linux 学习6 软件包安装

    一.软件包管理简介 二.RPM包管理-rpm命令管理 三.RPM包管理-yum在线管理 四.源码包管理 五.脚本安装包与软件包选择 .软件包分类 源码包 脚本安装包 二进制包(RPM包.系统默认 ...

  4. (转)关于Oracle AUTONOMOUS TRANSACTION(自治事务)的介绍

    AUTONOMOUS TRANSACTION(自治事务)的介绍 在基于低版本的ORACLE做一些项目的过程中,有时会遇到一些头疼的问题,比如想在执行当前一个由多个DML组成的transaction(事 ...

  5. Sql Server中不常用的表运算符之UNPIVOT

    在Sql Server中不常用的表运算符之PIVOT中,介绍了PIVOT表运算符,现在来说说与之相对应的另一个表运算符UNPIVOT. 从名字可以看出,这个运算符的作用与PIVOT刚好相反,是将一行的 ...

  6. ndoutils2.2.0(ndo2db)中文乱码问题解决

    ndoutils插入中文时,产生数据库乱码请用下面两个文件: 适用版本:ndoutils-2.0.0 数据库初始化mysql.sql: 修改ndoutils-2.0.0/src目录中的db.c ndo ...

  7. .NET 配置项扩展

    using System; using System.Configuration; namespace ConsoleApplication3 { /* web.config 或 app.config ...

  8. 检测是否IE浏览器

    function browserIsIE(){ if (window.ActiveXObject) return true; else{ var u_agent = navigator.userAge ...

  9. 编码UTF-8

    ☯,首先,这并不是图片,这是一个unicode字符,Yin Yang,即阴阳符,码点为U+262F.如果你的浏览器无法显示,可以查看这个链接http://www.fileformat.info/inf ...

  10. linux 账号管理与ACL权限设定

    此文涉及命令:useradd.usermod.userdel.passwd.chage.setfacl.getfacl.su.sudo.fingr.chfn.chsh.id.groupadd.grou ...