NOIP模拟6
期望得分:100+100+100=300
实际得分:0+100+90=190
T1 superman
二分给每条边加多少,判断是否存在负环
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 501
#define M 4951
using namespace std;
int n,tot,front[N],to[M],nxt[M],val[M],val_[M];
int front_[N],to_[M],nxt_[M];
int cnt[N],dis[N];
bool vis[N],ok[N];
void add(int u,int v,int w)
{
to[++tot]=v; nxt[tot]=front[u]; front[u]=tot; val_[tot]=w;
to_[tot]=u; nxt_[tot]=front_[v]; front_[v]=tot;
}
bool spfa()
{
memset(cnt,,sizeof(cnt));
memset(dis,,sizeof(dis));
memset(vis,false,sizeof(vis));
queue<int>q;
vis[]=true; q.push();
dis[]=;
cnt[]++;
int now;
while(!q.empty())
{
now=q.front(); q.pop(); vis[now]=false;
for(int i=front[now];i;i=nxt[i])
{
if(!ok[to[i]]) continue;
if(dis[to[i]]>dis[now]+val[i])
{
dis[to[i]]=dis[now]+val[i];
if(!vis[to[i]])
{
vis[to[i]]=true;
q.push(to[i]);
cnt[to[i]]++;
if(cnt[to[i]]>n) return false;
}
}
} }
return dis[n]>=;
}
bool check(int mid)
{
for(int i=;i<=tot;i++) val[i]=val_[i]+mid;
return spfa();
}
void solve(int tmp)
{
for(int i=;i<=tot;i++) val[i]=val_[i]+tmp;
spfa();
printf("%d\n",dis[n]);
}
void dfs(int x)
{
ok[x]=true;
for(int i=front[x];i;i=nxt[i])
if(!ok[to[i]]) dfs(to[i]);
}
void dfs2(int x)
{
ok[x]=true;
for(int i=front_[x];i;i=nxt_[i])
if(!ok[to_[i]]) dfs2(to_[i]);
}
int main()
{
freopen("superman.in","r",stdin);
freopen("superman.out","w",stdout);
int T,m,u,v,w;
scanf("%d",&T);
while(T--)
{
tot=;
memset(front,,sizeof(front));
memset(front_,,sizeof(front_));
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++)
{
scanf("%d%d%d",&u,&v,&w);
add(u,v,w);
}
memset(ok,false,sizeof(ok));
dfs();
if(!ok[n])
{
printf("-1\n");
continue;
}
memset(ok,false,sizeof(ok));
dfs2(n);
int l=-,r=,mid,tmp;
while(l<=r)
{
mid=(l+r)/;
if(check(mid)) tmp=mid,r=mid-;
else l=mid+;
}
solve(tmp);
}
}
T2 洛谷 P2647 最大收益
https://www.luogu.org/problem/show?pid=2647
如果一共选m个,第i个选了第j个物品,那对答案的贡献为wj-(m-i)*rj
所以如果确定选哪m个,肯定是先选rj小的
去除m的影响,倒着枚举
AC代码
#include<cstdio>
#include<algorithm>
#define N 3001
using namespace std;
struct node
{
int w,r;
}e[N];
int wi[N],ri[N],dp[N][N];
bool cmp(node p,node q)
{
return p.r>q.r;
}
int main()
{
//freopen("market.in","r",stdin);
//freopen("market.out","w",stdout);
int n,ans=;
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d%d",&e[i].w,&e[i].r);
sort(e+,e+n+,cmp);
for(int i=;i<=n;i++)
for(int j=;j<=i;j++)
dp[i][j]=max(dp[i-][j],dp[i-][j-]+e[i].w-e[i].r*(j-));
for(int i=;i<=n;i++) ans=max(ans,dp[n][i]);
printf("%d",ans); }
暴力1
#include<cstdio>
#include<algorithm>
#define N 3001
using namespace std;
struct node
{
int w,r;
}e[N];
int wi[N],ri[N],dp[N][N];
bool cmp(node p,node q)
{
return p.r<q.r;
}
int main()
{
int n,ans=;
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d%d",&e[i].w,&e[i].r);
sort(e+,e+n+,cmp);
for(int k=;k<=n;k++)
{
for(int i=;i<=n;i++)
for(int j=;j<=min(i,k);j++)
dp[i][j]=max(dp[i-][j],dp[i-][j-]+e[i].w-(k-j)*e[i].r);
ans=max(ans,dp[n][k]);
}
printf("%d",ans); }
暴力2
#include<cstdio>
#include<algorithm>
#define N 3001
using namespace std;
struct node
{
int w,r;
}e[N];
int wi[N],ri[N];
bool cmp(node p,node q)
{
return p.r<q.r;
}
int main()
{
int n;
scanf("%d",&n);
for(int i=;i<n;i++) scanf("%d%d",&wi[i],&ri[i]);
int S=<<n,tot=,tmp,ans=;
for(int i=;i<S;i++)
{
tot=;
for(int j=;j<n;j++)
if(i&(<<j)) e[++tot].w=wi[j],e[tot].r=ri[j];
sort(e+,e+tot+,cmp);
tmp=;
for(int j=;j<=tot;j++) tmp+=e[j].w-(tot-j)*e[j].r;
ans=max(ans,tmp);
}
printf("%d",ans);
}
T3 洛谷 P2759 奇怪的函数
x>=logx 10^(n-1)
x>=[log10 10^(n-1)]/log 10 x
x>=(n-1)/log10 x
特判当x=1时,答案为1
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long LL;
int n;
int main()
{
//freopen("Lemon_Soda.in","r",stdin);
//freopen("Lemon_Soda.out","w",stdout);
scanf("%d",&n);
LL l=,r=1ll<<,mid,ans;
if(n==)
{
printf("");
return ;
}
while(l<=r)
{
mid=l+r>>;
if((n-)*1.0/log10(mid)<=mid) r=mid-,ans=mid;
else l=mid+;
}
printf("%lld",ans);
}
NOIP模拟6的更多相关文章
- NOIP模拟赛20161022
NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...
- contesthunter暑假NOIP模拟赛第一场题解
contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...
- NOIP模拟赛 by hzwer
2015年10月04日NOIP模拟赛 by hzwer (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...
- 大家AK杯 灰天飞雁NOIP模拟赛题解/数据/标程
数据 http://files.cnblogs.com/htfy/data.zip 简要题解 桌球碰撞 纯模拟,注意一开始就在袋口和v=0的情况.v和坐标可以是小数.为保险起见最好用extended/ ...
- 队爷的讲学计划 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...
- 队爷的Au Plan CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的Au%20Plan 题解:看了题之后觉得肯定是DP ...
- 队爷的新书 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的新书 题解:看到这题就想到了 poetize 的封 ...
- CH Round #58 - OrzCC杯noip模拟赛day2
A:颜色问题 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2358%20-%20OrzCC杯noip模拟赛day2/颜色问题 题解:算一下每个仆人到它的目的地 ...
- CH Round #52 - Thinking Bear #1 (NOIP模拟赛)
A.拆地毯 题目:http://www.contesthunter.org/contest/CH%20Round%20%2352%20-%20Thinking%20Bear%20%231%20(NOI ...
- CH Round #49 - Streaming #4 (NOIP模拟赛Day2)
A.二叉树的的根 题目:http://www.contesthunter.org/contest/CH%20Round%20%2349%20-%20Streaming%20%234%20(NOIP 模 ...
随机推荐
- CS小分队第一阶段冲刺站立会议(5月14日)
昨日成果:为抽号计时器添加了第一类抽号,基本实现界面,功能出现了一些错误 遇到问题:我预想通过timer控件来实现随机抽号而拜托随机生成数,但是出现了只有个位随机滚动,其他位数不动的现象,我预计是数值 ...
- Java 将数字转为16进制,然后转为字符串类型 将空格去掉。终结版
//十进制转为十六进制 public class ArrayTest7 { public static void main(String[] args){ System.out.println(toH ...
- Eclipse 如何安装反编译插件
安装反编译插件 1.Help——Eclipse Marketplace 2.输入 Decompiler 搜索并安装此插件 3.根据提示无脑下一步,安装好,重启后(如果还是无法编译,需要把默认打开cla ...
- jdbc 1.0
1. jdbc : java数据库连接技术 2.主要用到的类及接口 Class Driver ManagerDriver Connection Statement PreparedStatement ...
- 基于图形学混色问题OpenGl的收获
void myDisplay(void) {glClearColor(0.0f,0.0f,0.0f,1.0f); glClear(GL_COLOR_BUFFER_BIT); glEnable(GL_B ...
- PHP初级
通过form get post表单提交的数据,数据内容由用户填写或选择而得到!
- 安恒杯-babysql
1. 库名 ?id= and extractvalue(,(select group_concat(0x3a,schema_name) from information_schema.schemata ...
- mysql子查询批量找id最大的
$sql = "select a.id as max_id,a.uid from(SELECT `uid`, idFROM (`users_level_change_log`)WHERE ` ...
- Win2019 显示 SMBV1 协议不安全的处理
1. 登录有问题. 报错 [Window Title] \\10.100.1.163 [Content] \\10.100.1.163 因为文件共享不安全,所以你不能连接到文件共享.此共享需要过时的 ...
- UVA11653_Buses
这个题目很有意思,一不小心就会让人坑在里面. 题意是这样的,给你n,k,l.分别表示总共的长度,长度为5和10的车的不同颜色数量现在问你要把n的填满有多少种方案. 很多人一开始都会脑子一根筋地想用排列 ...